Commit 215ebc40 authored by samarth@chromium.org's avatar samarth@chromium.org

InstantExtended: hook up InstantTab in incognito.

Hook up InstantTab in incognito, but don't send any data except submit events.

BUG=181427
TESTED=manually per report, also modes still work in incognito
R=jered@chromium.org

Review URL: https://codereview.chromium.org/17303003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207969 0039d316-1c4b-4281-b951-d872f2087c98
parent c724a0a1
...@@ -420,7 +420,7 @@ const SearchTestCase kInstantNTPTestCases[] = { ...@@ -420,7 +420,7 @@ const SearchTestCase kInstantNTPTestCases[] = {
{"http://foo.com/instant?strk=1", false, "Insecure URL"}, {"http://foo.com/instant?strk=1", false, "Insecure URL"},
{"https://foo.com/instant", false, "No search term replacement"}, {"https://foo.com/instant", false, "No search term replacement"},
{"chrome://blank/", false, "Chrome scheme"}, {"chrome://blank/", false, "Chrome scheme"},
{"chrome-search://foo", false, "Chrome-search scheme"}, {"chrome-search://foo", false, "Chrome-search scheme"},
{chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"},
{chrome::kChromeSearchLocalGoogleNtpUrl, true, "Local new tab page"}, {chrome::kChromeSearchLocalGoogleNtpUrl, true, "Local new tab page"},
{"https://bar.com/instant?strk=1", false, "Random non-search page"}, {"https://bar.com/instant?strk=1", false, "Random non-search page"},
......
...@@ -26,7 +26,7 @@ class TestableInstantOverlay : public InstantOverlay { ...@@ -26,7 +26,7 @@ class TestableInstantOverlay : public InstantOverlay {
public: public:
TestableInstantOverlay(InstantController* controller, TestableInstantOverlay(InstantController* controller,
const std::string& instant_url) const std::string& instant_url)
: InstantOverlay(controller, instant_url) { : InstantOverlay(controller, instant_url, false) {
} }
// Overrides from InstantPage // Overrides from InstantPage
...@@ -56,7 +56,7 @@ class TestableInstantNTP : public InstantNTP { ...@@ -56,7 +56,7 @@ class TestableInstantNTP : public InstantNTP {
public: public:
TestableInstantNTP(InstantController* controller, TestableInstantNTP(InstantController* controller,
const std::string& instant_url) const std::string& instant_url)
: InstantNTP(controller, instant_url) { : InstantNTP(controller, instant_url, false) {
} }
// Overrides from InstantPage // Overrides from InstantPage
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/search/instant_ipc_sender.h"
#include "chrome/common/render_messages.h"
namespace {
// Implementation for regular profiles.
class InstantIPCSenderImpl : public InstantIPCSender {
public:
InstantIPCSenderImpl() {}
virtual ~InstantIPCSenderImpl() {}
private:
virtual void Update(const string16& text,
size_t selection_start,
size_t selection_end,
bool verbatim) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxChange(routing_id(), text, verbatim,
selection_start, selection_end));
}
virtual void Submit(const string16& text) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text));
}
virtual void Cancel(const string16& text) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text));
}
virtual void SetPopupBounds(const gfx::Rect& bounds) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds));
}
virtual void SetOmniboxBounds(const gfx::Rect& bounds) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxMarginChange(
routing_id(), bounds.x(), bounds.width()));
}
virtual void SetFontInformation(const string16& omnibox_font_name,
size_t omnibox_font_size) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxFontInformation(
routing_id(), omnibox_font_name, omnibox_font_size));
}
virtual void SendAutocompleteResults(
const std::vector<InstantAutocompleteResult>& results) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results));
}
virtual void UpOrDownKeyPressed(int count) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count));
}
virtual void EscKeyPressed() OVERRIDE {
Send(new ChromeViewMsg_SearchBoxEscKeyPressed(routing_id()));
}
virtual void CancelSelection(const string16& user_text,
size_t selection_start,
size_t selection_end,
bool verbatim) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxCancelSelection(
routing_id(), user_text, verbatim, selection_start, selection_end));
}
virtual void SendThemeBackgroundInfo(
const ThemeBackgroundInfo& theme_info) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info));
}
virtual void SetDisplayInstantResults(bool display_instant_results) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults(
routing_id(), display_instant_results));
}
virtual void FocusChanged(OmniboxFocusState state,
OmniboxFocusChangeReason reason) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxFocusChanged(routing_id(), state, reason));
}
virtual void SetInputInProgress(bool input_in_progress) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxSetInputInProgress(
routing_id(), input_in_progress));
}
virtual void SendMostVisitedItems(
const std::vector<InstantMostVisitedItem>& items) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(
routing_id(), items));
}
virtual void ToggleVoiceSearch() OVERRIDE {
Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id()));
}
DISALLOW_COPY_AND_ASSIGN(InstantIPCSenderImpl);
};
// Implementation for incognito profiles.
class IncognitoInstantIPCSenderImpl : public InstantIPCSender {
public:
IncognitoInstantIPCSenderImpl() {}
virtual ~IncognitoInstantIPCSenderImpl() {}
private:
virtual void Submit(const string16& text) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text));
}
virtual void SetOmniboxBounds(const gfx::Rect& bounds) OVERRIDE {
Send(new ChromeViewMsg_SearchBoxMarginChange(
routing_id(), bounds.x(), bounds.width()));
}
DISALLOW_COPY_AND_ASSIGN(IncognitoInstantIPCSenderImpl);
};
} // anonymous namespace
// static
scoped_ptr<InstantIPCSender> InstantIPCSender::Create(bool is_incognito) {
scoped_ptr<InstantIPCSender> sender(
is_incognito ?
static_cast<InstantIPCSender*>(new IncognitoInstantIPCSenderImpl()) :
static_cast<InstantIPCSender*>(new InstantIPCSenderImpl()));
return sender.Pass();
}
void InstantIPCSender::SetContents(content::WebContents* web_contents) {
Observe(web_contents);
}
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_IPC_SENDER_H_
#define CHROME_BROWSER_UI_SEARCH_INSTANT_IPC_SENDER_H_
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "chrome/common/instant_types.h"
#include "chrome/common/omnibox_focus_state.h"
#include "content/public/browser/web_contents_observer.h"
namespace gfx {
class Rect;
}
namespace IPC {
class Sender;
}
class InstantIPCSender : public content::WebContentsObserver {
public:
// Creates a new instance of InstantIPCSender. If |is_incognito| is true,
// the instance will only send appropriate IPCs for incognito profiles.
static scoped_ptr<InstantIPCSender> Create(bool is_incognito);
virtual ~InstantIPCSender() {}
// Sets |web_contents| as the receiver of IPCs.
void SetContents(content::WebContents* web_contents);
// Tells the page that the user typed |text| into the omnibox. If |verbatim|
// is false, the page predicts the query the user means to type and fetches
// results for the prediction. If |verbatim| is true, |text| is taken as the
// exact query (no prediction is made). |selection_start| and |selection_end|
// mark the inline autocompleted portion (i.e., blue highlighted text). The
// omnibox caret (cursor) is at |selection_end|.
virtual void Update(const string16& text,
size_t selection_start,
size_t selection_end,
bool verbatim) {}
// Tells the page that the user pressed Enter in the omnibox.
virtual void Submit(const string16& text) {}
// Tells the page that the user clicked on it. Nothing is being cancelled; the
// poor choice of name merely reflects the IPC of the same (poor) name.
virtual void Cancel(const string16& text) {}
// Tells the page the bounds of the omnibox dropdown (in screen coordinates).
// This is used by the page to offset the results to avoid them being covered
// by the omnibox dropdown.
virtual void SetPopupBounds(const gfx::Rect& bounds) {}
// Tells the page the bounds of the omnibox (in screen coordinates). This is
// used by the page to align text or assets properly with the omnibox.
virtual void SetOmniboxBounds(const gfx::Rect& bounds) {}
// Tells the page about the font information.
virtual void SetFontInformation(const string16& omnibox_font_name,
size_t omnibox_font_size) {}
// Tells the page about the available autocomplete results.
virtual void SendAutocompleteResults(
const std::vector<InstantAutocompleteResult>& results) {}
// Tells the page that the user pressed Up or Down in the omnibox. |count| is
// a repeat count, negative for moving up, positive for moving down.
virtual void UpOrDownKeyPressed(int count) {}
// Tells the page that the user pressed Esc key in the omnibox.
virtual void EscKeyPressed() {}
// Tells the page that the user pressed Esc in the omnibox after having
// arrowed down in the suggestions. The page should reset the selection to
// the first suggestion. Arguments are the same as those for Update().
virtual void CancelSelection(const string16& user_text,
size_t selection_start,
size_t selection_end,
bool verbatim) {}
// Tells the page about the current theme background.
virtual void SendThemeBackgroundInfo(
const ThemeBackgroundInfo& theme_info) {}
// Tells the page whether it is allowed to display Instant results.
virtual void SetDisplayInstantResults(bool display_instant_results) {}
// Tells the page that the omnibox focus has changed.
virtual void FocusChanged(OmniboxFocusState state,
OmniboxFocusChangeReason reason) {}
// Tells the page that user input started or stopped.
virtual void SetInputInProgress(bool input_in_progress) {}
// Tells the page about new Most Visited data.
virtual void SendMostVisitedItems(
const std::vector<InstantMostVisitedItem>& items) {}
// Tells the page to toggle voice search.
virtual void ToggleVoiceSearch() {}
protected:
InstantIPCSender() {}
private:
DISALLOW_COPY_AND_ASSIGN(InstantIPCSender);
};
#endif // CHROME_BROWSER_UI_SEARCH_INSTANT_IPC_SENDER_H_
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
InstantNTP::InstantNTP(InstantPage::Delegate* delegate, InstantNTP::InstantNTP(InstantPage::Delegate* delegate,
const std::string& instant_url) const std::string& instant_url,
: InstantPage(delegate, instant_url), bool is_incognito)
: InstantPage(delegate, instant_url, is_incognito),
loader_(this) { loader_(this) {
} }
......
...@@ -21,7 +21,8 @@ class Profile; ...@@ -21,7 +21,8 @@ class Profile;
class InstantNTP : public InstantPage, class InstantNTP : public InstantPage,
public InstantLoader::Delegate { public InstantLoader::Delegate {
public: public:
InstantNTP(InstantPage::Delegate* delegate, const std::string& instant_url); InstantNTP(InstantPage::Delegate* delegate, const std::string& instant_url,
bool is_incognito);
virtual ~InstantNTP(); virtual ~InstantNTP();
// Creates a new WebContents and loads |instant_url_| into it. Uses // Creates a new WebContents and loads |instant_url_| into it. Uses
......
...@@ -40,8 +40,9 @@ InstantOverlay* InstantOverlay::FromWebContents( ...@@ -40,8 +40,9 @@ InstantOverlay* InstantOverlay::FromWebContents(
} }
InstantOverlay::InstantOverlay(InstantController* controller, InstantOverlay::InstantOverlay(InstantController* controller,
const std::string& instant_url) const std::string& instant_url,
: InstantPage(controller, instant_url), bool is_incognito)
: InstantPage(controller, instant_url, is_incognito),
loader_(this), loader_(this),
is_stale_(false), is_stale_(false),
is_pointer_down_from_activate_(false) { is_pointer_down_from_activate_(false) {
...@@ -76,7 +77,7 @@ void InstantOverlay::Update(const string16& text, ...@@ -76,7 +77,7 @@ void InstantOverlay::Update(const string16& text,
size_t selection_end, size_t selection_end,
bool verbatim) { bool verbatim) {
last_navigation_ = history::HistoryAddPageArgs(); last_navigation_ = history::HistoryAddPageArgs();
InstantPage::Update(text, selection_start, selection_end, verbatim); sender()->Update(text, selection_start, selection_end, verbatim);
} }
bool InstantOverlay::ShouldProcessRenderViewCreated() { bool InstantOverlay::ShouldProcessRenderViewCreated() {
......
...@@ -32,7 +32,8 @@ class InstantOverlay : public InstantPage, ...@@ -32,7 +32,8 @@ class InstantOverlay : public InstantPage,
static InstantOverlay* FromWebContents(const content::WebContents* contents); static InstantOverlay* FromWebContents(const content::WebContents* contents);
InstantOverlay(InstantController* controller, InstantOverlay(InstantController* controller,
const std::string& instant_url); const std::string& instant_url,
bool is_incognito);
virtual ~InstantOverlay(); virtual ~InstantOverlay();
// Creates a new WebContents and loads |instant_url_| into it. Uses // Creates a new WebContents and loads |instant_url_| into it. Uses
...@@ -64,11 +65,12 @@ class InstantOverlay : public InstantPage, ...@@ -64,11 +65,12 @@ class InstantOverlay : public InstantPage,
// to the history service had this WebContents not been used for Instant. // to the history service had this WebContents not been used for Instant.
void DidNavigate(const history::HistoryAddPageArgs& add_page_args); void DidNavigate(const history::HistoryAddPageArgs& add_page_args);
// Overridden from InstantPage: // Wrapper around InstantIPCSender::Update that also clears
virtual void Update(const string16& text, // |last_navigation_|.
size_t selection_start, void Update(const string16& text,
size_t selection_end, size_t selection_start,
bool verbatim) OVERRIDE; size_t selection_end,
bool verbatim);
private: private:
FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefresh); FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefresh);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/search/search.h" #include "chrome/browser/search/search.h"
#include "chrome/browser/ui/search/instant_ipc_sender.h"
#include "chrome/browser/ui/search/search_model.h" #include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/search/search_tab_helper.h" #include "chrome/browser/ui/search/search_tab_helper.h"
#include "chrome/common/render_messages.h" #include "chrome/common/render_messages.h"
...@@ -41,31 +42,6 @@ bool InstantPage::IsLocal() const { ...@@ -41,31 +42,6 @@ bool InstantPage::IsLocal() const {
contents()->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl)); contents()->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl));
} }
void InstantPage::Update(const string16& text,
size_t selection_start,
size_t selection_end,
bool verbatim) {
Send(new ChromeViewMsg_SearchBoxChange(routing_id(), text, verbatim,
selection_start, selection_end));
}
void InstantPage::Submit(const string16& text) {
Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text));
}
void InstantPage::Cancel(const string16& text) {
Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text));
}
void InstantPage::SetPopupBounds(const gfx::Rect& bounds) {
Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds));
}
void InstantPage::SetOmniboxBounds(const gfx::Rect& bounds) {
Send(new ChromeViewMsg_SearchBoxMarginChange(
routing_id(), bounds.x(), bounds.width()));
}
void InstantPage::InitializeFonts() { void InstantPage::InitializeFonts() {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
// This value should be kept in sync with OmniboxViewMac::GetFieldFont. // This value should be kept in sync with OmniboxViewMac::GetFieldFont.
...@@ -77,65 +53,16 @@ void InstantPage::InitializeFonts() { ...@@ -77,65 +53,16 @@ void InstantPage::InitializeFonts() {
ui::ResourceBundle::GetSharedInstance().GetFont( ui::ResourceBundle::GetSharedInstance().GetFont(
ui::ResourceBundle::MediumFont); ui::ResourceBundle::MediumFont);
#endif #endif
string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName()); sender()->SetFontInformation(UTF8ToUTF16(omnibox_font.GetFontName()),
size_t omnibox_font_size = omnibox_font.GetFontSize(); omnibox_font.GetFontSize());
Send(new ChromeViewMsg_SearchBoxFontInformation(
routing_id(), omnibox_font_name, omnibox_font_size));
}
void InstantPage::SendAutocompleteResults(
const std::vector<InstantAutocompleteResult>& results) {
Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results));
}
void InstantPage::UpOrDownKeyPressed(int count) {
Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count));
}
void InstantPage::EscKeyPressed() {
Send(new ChromeViewMsg_SearchBoxEscKeyPressed(routing_id()));
} }
void InstantPage::CancelSelection(const string16& user_text, InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url,
size_t selection_start, bool is_incognito)
size_t selection_end,
bool verbatim) {
Send(new ChromeViewMsg_SearchBoxCancelSelection(
routing_id(), user_text, verbatim, selection_start, selection_end));
}
void InstantPage::SendThemeBackgroundInfo(
const ThemeBackgroundInfo& theme_info) {
Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info));
}
void InstantPage::SetDisplayInstantResults(bool display_instant_results) {
Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults(
routing_id(), display_instant_results));
}
void InstantPage::FocusChanged(OmniboxFocusState state,
OmniboxFocusChangeReason reason) {
Send(new ChromeViewMsg_SearchBoxFocusChanged(routing_id(), state, reason));
}
void InstantPage::SetInputInProgress(bool input_in_progress) {
Send(new ChromeViewMsg_SearchBoxSetInputInProgress(
routing_id(), input_in_progress));
}
void InstantPage::SendMostVisitedItems(
const std::vector<InstantMostVisitedItem>& items) {
Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(routing_id(), items));
}
void InstantPage::ToggleVoiceSearch() {
Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id()));
}
InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url)
: delegate_(delegate), : delegate_(delegate),
instant_url_(instant_url) { ipc_sender_(InstantIPCSender::Create(is_incognito)),
instant_url_(instant_url),
is_incognito_(is_incognito) {
} }
void InstantPage::SetContents(content::WebContents* web_contents) { void InstantPage::SetContents(content::WebContents* web_contents) {
...@@ -144,6 +71,7 @@ void InstantPage::SetContents(content::WebContents* web_contents) { ...@@ -144,6 +71,7 @@ void InstantPage::SetContents(content::WebContents* web_contents) {
if (!web_contents) if (!web_contents)
return; return;
sender()->SetContents(web_contents);
Observe(web_contents); Observe(web_contents);
SearchModel* model = SearchTabHelper::FromWebContents(contents())->model(); SearchModel* model = SearchTabHelper::FromWebContents(contents())->model();
model->AddObserver(this); model->AddObserver(this);
...@@ -199,6 +127,9 @@ void InstantPage::RenderViewCreated(content::RenderViewHost* render_view_host) { ...@@ -199,6 +127,9 @@ void InstantPage::RenderViewCreated(content::RenderViewHost* render_view_host) {
} }
bool InstantPage::OnMessageReceived(const IPC::Message& message) { bool InstantPage::OnMessageReceived(const IPC::Message& message) {
if (is_incognito_)
return false;
bool handled = true; bool handled = true;
IPC_BEGIN_MESSAGE_MAP(InstantPage, message) IPC_BEGIN_MESSAGE_MAP(InstantPage, message)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions)
...@@ -359,5 +290,6 @@ void InstantPage::ClearContents() { ...@@ -359,5 +290,6 @@ void InstantPage::ClearContents() {
if (contents()) if (contents())
SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this); SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this);
sender()->SetContents(NULL);
Observe(NULL); Observe(NULL);
} }
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/ui/search/instant_ipc_sender.h"
#include "chrome/browser/ui/search/search_model_observer.h" #include "chrome/browser/ui/search/search_model_observer.h"
#include "chrome/common/instant_types.h" #include "chrome/common/instant_types.h"
#include "chrome/common/omnibox_focus_state.h" #include "chrome/common/omnibox_focus_state.h"
...@@ -111,6 +113,9 @@ class InstantPage : public content::WebContentsObserver, ...@@ -111,6 +113,9 @@ class InstantPage : public content::WebContentsObserver,
// The WebContents corresponding to the page we're talking to. May be NULL. // The WebContents corresponding to the page we're talking to. May be NULL.
content::WebContents* contents() const { return web_contents(); } content::WebContents* contents() const { return web_contents(); }
// Used to send IPC messages to the page.
InstantIPCSender* sender() const { return ipc_sender_.get(); }
// Returns the Instant URL that was loaded for this page. Returns the empty // Returns the Instant URL that was loaded for this page. Returns the empty
// string if no URL was explicitly loaded as is the case for InstantTab. // string if no URL was explicitly loaded as is the case for InstantTab.
virtual const std::string& instant_url() const; virtual const std::string& instant_url() const;
...@@ -125,76 +130,11 @@ class InstantPage : public content::WebContentsObserver, ...@@ -125,76 +130,11 @@ class InstantPage : public content::WebContentsObserver,
// chrome::kChromeSearchLocalNTPURL). // chrome::kChromeSearchLocalNTPURL).
virtual bool IsLocal() const; virtual bool IsLocal() const;
// Tells the page that the user typed |text| into the omnibox. If |verbatim|
// is false, the page predicts the query the user means to type and fetches
// results for the prediction. If |verbatim| is true, |text| is taken as the
// exact query (no prediction is made). |selection_start| and |selection_end|
// mark the inline autocompleted portion (i.e., blue highlighted text). The
// omnibox caret (cursor) is at |selection_end|.
virtual void Update(const string16& text,
size_t selection_start,
size_t selection_end,
bool verbatim);
// Tells the page that the user pressed Enter in the omnibox.
void Submit(const string16& text);
// Tells the page that the user clicked on it. Nothing is being cancelled; the
// poor choice of name merely reflects the IPC of the same (poor) name.
void Cancel(const string16& text);
// Tells the page the bounds of the omnibox dropdown (in screen coordinates).
// This is used by the page to offset the results to avoid them being covered
// by the omnibox dropdown.
void SetPopupBounds(const gfx::Rect& bounds);
// Tells the page the bounds of the omnibox (in screen coordinates). This is
// used by the page to align text or assets properly with the omnibox.
void SetOmniboxBounds(const gfx::Rect& bounds);
// Tells the page about the font information.
void InitializeFonts(); void InitializeFonts();
// Tells the page about the available autocomplete results.
void SendAutocompleteResults(
const std::vector<InstantAutocompleteResult>& results);
// Tells the page that the user pressed Up or Down in the omnibox. |count| is
// a repeat count, negative for moving up, positive for moving down.
void UpOrDownKeyPressed(int count);
// Tells the page that the user pressed Esc key in the omnibox.
void EscKeyPressed();
// Tells the page that the user pressed Esc in the omnibox after having
// arrowed down in the suggestions. The page should reset the selection to
// the first suggestion. Arguments are the same as those for Update().
void CancelSelection(const string16& user_text,
size_t selection_start,
size_t selection_end,
bool verbatim);
// Tells the page about the current theme background.
void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info);
// Tells the page whether it is allowed to display Instant results.
void SetDisplayInstantResults(bool display_instant_results);
// Tells the page that the omnibox focus has changed.
void FocusChanged(OmniboxFocusState state, OmniboxFocusChangeReason reason);
// Tells the page that user input started or stopped.
void SetInputInProgress(bool input_in_progress);
// Tells the page about new Most Visited data.
void SendMostVisitedItems(
const std::vector<InstantMostVisitedItem>& items);
// Tells the page to toggle voice search.
void ToggleVoiceSearch();
protected: protected:
InstantPage(Delegate* delegate, const std::string& instant_url); InstantPage(Delegate* delegate, const std::string& instant_url,
bool is_incognito);
// Sets |web_contents| as the page to communicate with. |web_contents| may be // Sets |web_contents| as the page to communicate with. |web_contents| may be
// NULL, which effectively stops all communication. // NULL, which effectively stops all communication.
...@@ -228,6 +168,8 @@ class InstantPage : public content::WebContentsObserver, ...@@ -228,6 +168,8 @@ class InstantPage : public content::WebContentsObserver,
IgnoreMessageIfThePageIsNotActive); IgnoreMessageIfThePageIsNotActive);
FRIEND_TEST_ALL_PREFIXES(InstantPageTest, FRIEND_TEST_ALL_PREFIXES(InstantPageTest,
IgnoreMessageReceivedFromThePage); IgnoreMessageReceivedFromThePage);
FRIEND_TEST_ALL_PREFIXES(InstantPageTest,
IgnoreMessageReceivedFromIncognitoPage);
// Overridden from content::WebContentsObserver: // Overridden from content::WebContentsObserver:
virtual void RenderViewCreated( virtual void RenderViewCreated(
...@@ -276,7 +218,9 @@ class InstantPage : public content::WebContentsObserver, ...@@ -276,7 +218,9 @@ class InstantPage : public content::WebContentsObserver,
void ClearContents(); void ClearContents();
Delegate* const delegate_; Delegate* const delegate_;
scoped_ptr<InstantIPCSender> ipc_sender_;
const std::string instant_url_; const std::string instant_url_;
const bool is_incognito_;
DISALLOW_COPY_AND_ASSIGN(InstantPage); DISALLOW_COPY_AND_ASSIGN(InstantPage);
}; };
......
...@@ -62,7 +62,8 @@ class FakePageDelegate : public InstantPage::Delegate { ...@@ -62,7 +62,8 @@ class FakePageDelegate : public InstantPage::Delegate {
class FakePage : public InstantPage { class FakePage : public InstantPage {
public: public:
FakePage(Delegate* delegate, const std::string& instant_url); FakePage(Delegate* delegate, const std::string& instant_url,
bool is_incognito);
virtual ~FakePage(); virtual ~FakePage();
// InstantPage overrride. // InstantPage overrride.
...@@ -81,8 +82,9 @@ class FakePage : public InstantPage { ...@@ -81,8 +82,9 @@ class FakePage : public InstantPage {
DISALLOW_COPY_AND_ASSIGN(FakePage); DISALLOW_COPY_AND_ASSIGN(FakePage);
}; };
FakePage::FakePage(Delegate* delegate, const std::string& instant_url) FakePage::FakePage(Delegate* delegate, const std::string& instant_url,
: InstantPage(delegate, instant_url), bool is_incognito)
: InstantPage(delegate, instant_url, is_incognito),
should_handle_messages_(true) { should_handle_messages_(true) {
} }
...@@ -111,6 +113,10 @@ class InstantPageTest : public ChromeRenderViewHostTestHarness { ...@@ -111,6 +113,10 @@ class InstantPageTest : public ChromeRenderViewHostTestHarness {
public: public:
virtual void SetUp() OVERRIDE; virtual void SetUp() OVERRIDE;
bool MessageWasSent(uint32 id) {
return process()->sink().GetFirstMessageMatching(id) != NULL;
}
scoped_ptr<FakePage> page; scoped_ptr<FakePage> page;
FakePageDelegate delegate; FakePageDelegate delegate;
}; };
...@@ -123,7 +129,7 @@ void InstantPageTest::SetUp() { ...@@ -123,7 +129,7 @@ void InstantPageTest::SetUp() {
} }
TEST_F(InstantPageTest, IsLocal) { TEST_F(InstantPageTest, IsLocal) {
page.reset(new FakePage(&delegate, "")); page.reset(new FakePage(&delegate, "", false));
EXPECT_FALSE(page->supports_instant()); EXPECT_FALSE(page->supports_instant());
EXPECT_FALSE(page->IsLocal()); EXPECT_FALSE(page->IsLocal());
page->SetContents(web_contents()); page->SetContents(web_contents());
...@@ -136,7 +142,7 @@ TEST_F(InstantPageTest, IsLocal) { ...@@ -136,7 +142,7 @@ TEST_F(InstantPageTest, IsLocal) {
} }
TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) { TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) {
page.reset(new FakePage(&delegate, "")); page.reset(new FakePage(&delegate, "", false));
EXPECT_FALSE(page->supports_instant()); EXPECT_FALSE(page->supports_instant());
page->SetContents(web_contents()); page->SetContents(web_contents());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
...@@ -149,7 +155,7 @@ TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) { ...@@ -149,7 +155,7 @@ TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) {
} }
TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) { TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) {
page.reset(new FakePage(&delegate, "")); page.reset(new FakePage(&delegate, "", false));
EXPECT_FALSE(page->supports_instant()); EXPECT_FALSE(page->supports_instant());
page->SetContents(web_contents()); page->SetContents(web_contents());
NavigateAndCommit(GURL("chrome-search://foo/bar")); NavigateAndCommit(GURL("chrome-search://foo/bar"));
...@@ -164,7 +170,7 @@ TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) { ...@@ -164,7 +170,7 @@ TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) {
} }
TEST_F(InstantPageTest, DispatchRequestToDeleteMostVisitedItem) { TEST_F(InstantPageTest, DispatchRequestToDeleteMostVisitedItem) {
page.reset(new FakePage(&delegate, "")); page.reset(new FakePage(&delegate, "", false));
page->SetContents(web_contents()); page->SetContents(web_contents());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
GURL item_url("www.foo.com"); GURL item_url("www.foo.com");
...@@ -176,7 +182,7 @@ TEST_F(InstantPageTest, DispatchRequestToDeleteMostVisitedItem) { ...@@ -176,7 +182,7 @@ TEST_F(InstantPageTest, DispatchRequestToDeleteMostVisitedItem) {
} }
TEST_F(InstantPageTest, DispatchRequestToUndoMostVisitedDeletion) { TEST_F(InstantPageTest, DispatchRequestToUndoMostVisitedDeletion) {
page.reset(new FakePage(&delegate, "")); page.reset(new FakePage(&delegate, "", false));
page->SetContents(web_contents()); page->SetContents(web_contents());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
GURL item_url("www.foo.com"); GURL item_url("www.foo.com");
...@@ -188,7 +194,7 @@ TEST_F(InstantPageTest, DispatchRequestToUndoMostVisitedDeletion) { ...@@ -188,7 +194,7 @@ TEST_F(InstantPageTest, DispatchRequestToUndoMostVisitedDeletion) {
} }
TEST_F(InstantPageTest, DispatchRequestToUndoAllMostVisitedDeletions) { TEST_F(InstantPageTest, DispatchRequestToUndoAllMostVisitedDeletions) {
page.reset(new FakePage(&delegate, "")); page.reset(new FakePage(&delegate, "", false));
page->SetContents(web_contents()); page->SetContents(web_contents());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID(); int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID();
...@@ -198,8 +204,33 @@ TEST_F(InstantPageTest, DispatchRequestToUndoAllMostVisitedDeletions) { ...@@ -198,8 +204,33 @@ TEST_F(InstantPageTest, DispatchRequestToUndoAllMostVisitedDeletions) {
rvh()->GetRoutingID(), page_id))); rvh()->GetRoutingID(), page_id)));
} }
TEST_F(InstantPageTest, IgnoreMessageReceivedFromIncognitoPage) {
page.reset(new FakePage(&delegate, "", true));
page->SetContents(web_contents());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
GURL item_url("www.foo.com");
int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID();
EXPECT_CALL(delegate, DeleteMostVisitedItem(item_url)).Times(0);
EXPECT_FALSE(page->OnMessageReceived(
ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(rvh()->GetRoutingID(),
page_id,
item_url)));
EXPECT_CALL(delegate, UndoMostVisitedDeletion(item_url)).Times(0);
EXPECT_FALSE(page->OnMessageReceived(
ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(rvh()->GetRoutingID(),
page_id,
item_url)));
EXPECT_CALL(delegate, UndoAllMostVisitedDeletions()).Times(0);
EXPECT_FALSE(page->OnMessageReceived(
ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
rvh()->GetRoutingID(), page_id)));
}
TEST_F(InstantPageTest, IgnoreMessageIfThePageIsNotActive) { TEST_F(InstantPageTest, IgnoreMessageIfThePageIsNotActive) {
page.reset(new FakePage(&delegate, "")); page.reset(new FakePage(&delegate, "", false));
page->SetContents(web_contents()); page->SetContents(web_contents());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
GURL item_url("www.foo.com"); GURL item_url("www.foo.com");
...@@ -224,7 +255,7 @@ TEST_F(InstantPageTest, IgnoreMessageIfThePageIsNotActive) { ...@@ -224,7 +255,7 @@ TEST_F(InstantPageTest, IgnoreMessageIfThePageIsNotActive) {
} }
TEST_F(InstantPageTest, IgnoreMessageReceivedFromThePage) { TEST_F(InstantPageTest, IgnoreMessageReceivedFromThePage) {
page.reset(new FakePage(&delegate, "")); page.reset(new FakePage(&delegate, "", false));
page->SetContents(web_contents()); page->SetContents(web_contents());
// Ignore the messages received from the page. // Ignore the messages received from the page.
...@@ -250,7 +281,7 @@ TEST_F(InstantPageTest, IgnoreMessageReceivedFromThePage) { ...@@ -250,7 +281,7 @@ TEST_F(InstantPageTest, IgnoreMessageReceivedFromThePage) {
} }
TEST_F(InstantPageTest, PageURLDoesntBelongToInstantRenderer) { TEST_F(InstantPageTest, PageURLDoesntBelongToInstantRenderer) {
page.reset(new FakePage(&delegate, "")); page.reset(new FakePage(&delegate, "", false));
EXPECT_FALSE(page->supports_instant()); EXPECT_FALSE(page->supports_instant());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
page->SetContents(web_contents()); page->SetContents(web_contents());
...@@ -275,7 +306,7 @@ TEST_F(InstantPageTest, PageURLDoesntBelongToInstantRenderer) { ...@@ -275,7 +306,7 @@ TEST_F(InstantPageTest, PageURLDoesntBelongToInstantRenderer) {
// Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message
// reply handler updates the instant support state in InstantPage. // reply handler updates the instant support state in InstantPage.
TEST_F(InstantPageTest, PageSupportsInstant) { TEST_F(InstantPageTest, PageSupportsInstant) {
page.reset(new FakePage(&delegate, "")); page.reset(new FakePage(&delegate, "", false));
EXPECT_FALSE(page->supports_instant()); EXPECT_FALSE(page->supports_instant());
page->SetContents(web_contents()); page->SetContents(web_contents());
NavigateAndCommit(GURL("chrome-search://foo/bar")); NavigateAndCommit(GURL("chrome-search://foo/bar"));
...@@ -299,3 +330,63 @@ TEST_F(InstantPageTest, PageSupportsInstant) { ...@@ -299,3 +330,63 @@ TEST_F(InstantPageTest, PageSupportsInstant) {
OnInstantSupportDetermined(entry->GetPageID(), true); OnInstantSupportDetermined(entry->GetPageID(), true);
EXPECT_TRUE(page->supports_instant()); EXPECT_TRUE(page->supports_instant());
} }
TEST_F(InstantPageTest, AppropriateMessagesSentToIncognitoPages) {
page.reset(new FakePage(&delegate, "", true));
page->SetContents(web_contents());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
process()->sink().ClearMessages();
// Incognito pages should get these messages.
page->sender()->Submit(string16());
EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxSubmit::ID));
page->sender()->SetOmniboxBounds(gfx::Rect());
EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxMarginChange::ID));
// Incognito pages should not get any others.
page->sender()->Update(string16(), 0, 0, false);
EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxChange::ID));
page->sender()->Cancel(string16());
EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxCancel::ID));
page->sender()->SetPopupBounds(gfx::Rect());
EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxPopupResize::ID));
page->sender()->SetFontInformation(string16(), 0);
EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxFontInformation::ID));
page->sender()->SendAutocompleteResults(
std::vector<InstantAutocompleteResult>());
EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxAutocompleteResults::ID));
page->sender()->UpOrDownKeyPressed(0);
EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxUpOrDownKeyPressed::ID));
page->sender()->EscKeyPressed();
EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxEscKeyPressed::ID));
page->sender()->CancelSelection(string16(), 0, 0, false);
EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxCancelSelection::ID));
page->sender()->SendThemeBackgroundInfo(ThemeBackgroundInfo());
EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxThemeChanged::ID));
page->sender()->SetDisplayInstantResults(false);
EXPECT_FALSE(MessageWasSent(
ChromeViewMsg_SearchBoxSetDisplayInstantResults::ID));
page->sender()->FocusChanged(
OMNIBOX_FOCUS_NONE, OMNIBOX_FOCUS_CHANGE_EXPLICIT);
EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxFocusChanged::ID));
page->sender()->SetInputInProgress(false);
EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxSetInputInProgress::ID));
page->sender()->SendMostVisitedItems(std::vector<InstantMostVisitedItem>());
EXPECT_FALSE(MessageWasSent(
ChromeViewMsg_SearchBoxMostVisitedItemsChanged::ID));
page->sender()->ToggleVoiceSearch();
EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID));
}
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
#include "chrome/browser/ui/search/instant_tab.h" #include "chrome/browser/ui/search/instant_tab.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
InstantTab::InstantTab(InstantPage::Delegate* delegate) InstantTab::InstantTab(InstantPage::Delegate* delegate,
: InstantPage(delegate, "") { bool is_incognito)
: InstantPage(delegate, "", is_incognito) {
} }
InstantTab::~InstantTab() { InstantTab::~InstantTab() {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// that supports the Instant API. // that supports the Instant API.
class InstantTab : public InstantPage { class InstantTab : public InstantPage {
public: public:
explicit InstantTab(InstantPage::Delegate* delegate); InstantTab(InstantPage::Delegate* delegate, bool is_incognito);
virtual ~InstantTab(); virtual ~InstantTab();
// Start observing |contents| for messages. Sends a message to determine if // Start observing |contents| for messages. Sends a message to determine if
......
...@@ -1349,6 +1349,8 @@ ...@@ -1349,6 +1349,8 @@
'browser/ui/search/instant_commit_type.h', 'browser/ui/search/instant_commit_type.h',
'browser/ui/search/instant_controller.cc', 'browser/ui/search/instant_controller.cc',
'browser/ui/search/instant_controller.h', 'browser/ui/search/instant_controller.h',
'browser/ui/search/instant_ipc_sender.cc',
'browser/ui/search/instant_ipc_sender.h',
'browser/ui/search/instant_loader.cc', 'browser/ui/search/instant_loader.cc',
'browser/ui/search/instant_loader.h', 'browser/ui/search/instant_loader.h',
'browser/ui/search/instant_ntp.cc', 'browser/ui/search/instant_ntp.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment