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"},
......
...@@ -339,7 +339,7 @@ bool InstantController::Update(const AutocompleteMatch& match, ...@@ -339,7 +339,7 @@ bool InstantController::Update(const AutocompleteMatch& match,
// when keyword search is in effect. // when keyword search is in effect.
if (is_keyword_search) { if (is_keyword_search) {
if (UseTabForSuggestions()) if (UseTabForSuggestions())
instant_tab_->Update(string16(), 0, 0, true); instant_tab_->sender()->Update(string16(), 0, 0, true);
else else
HideOverlay(); HideOverlay();
last_match_was_search_ = false; last_match_was_search_ = false;
...@@ -413,10 +413,10 @@ bool InstantController::Update(const AutocompleteMatch& match, ...@@ -413,10 +413,10 @@ bool InstantController::Update(const AutocompleteMatch& match,
// onsubmit(full_text). Fix. // onsubmit(full_text). Fix.
if (full_text.empty()) { if (full_text.empty()) {
// Call onchange("") to clear the query for the page. // Call onchange("") to clear the query for the page.
instant_tab_->Update(string16(), 0, 0, true); instant_tab_->sender()->Update(string16(), 0, 0, true);
instant_tab_->EscKeyPressed(); instant_tab_->sender()->EscKeyPressed();
} else { } else {
instant_tab_->Submit(full_text); instant_tab_->sender()->Submit(full_text);
} }
} }
} else if (!full_text.empty()) { } else if (!full_text.empty()) {
...@@ -432,7 +432,7 @@ bool InstantController::Update(const AutocompleteMatch& match, ...@@ -432,7 +432,7 @@ bool InstantController::Update(const AutocompleteMatch& match,
last_suggestion_ = InstantSuggestion(); last_suggestion_ = InstantSuggestion();
if (UseTabForSuggestions()) { if (UseTabForSuggestions()) {
// On a search results page, tell it to clear old results. // On a search results page, tell it to clear old results.
instant_tab_->Update(string16(), 0, 0, true); instant_tab_->sender()->Update(string16(), 0, 0, true);
} else if (overlay_ && search_mode_.is_origin_ntp()) { } else if (overlay_ && search_mode_.is_origin_ntp()) {
// On the NTP, tell the overlay to clear old results. Don't hide the // On the NTP, tell the overlay to clear old results. Don't hide the
// overlay so it can show a blank page or logo if it wants. // overlay so it can show a blank page or logo if it wants.
...@@ -447,9 +447,10 @@ bool InstantController::Update(const AutocompleteMatch& match, ...@@ -447,9 +447,10 @@ bool InstantController::Update(const AutocompleteMatch& match,
// The new tab may or may not be a search results page; we don't know // The new tab may or may not be a search results page; we don't know
// since SearchModeChanged() hasn't been called yet. If it later turns // since SearchModeChanged() hasn't been called yet. If it later turns
// out to be, we should store |full_text| now, so that if the user hits // out to be, we should store |full_text| now, so that if the user hits
// Enter, we'll send the correct query to instant_tab_->Submit(). If the // Enter, we'll send the correct query to
// partial text is not a query (|last_match_was_search_| is false), we // instant_tab_->sender()->Submit(). If the partial text is not a query
// won't Submit(), so no need to worry about that. // (|last_match_was_search_| is false), we won't Submit(), so no need to
// worry about that.
last_user_text_ = user_text; last_user_text_ = user_text;
last_suggestion_ = InstantSuggestion(); last_suggestion_ = InstantSuggestion();
} }
...@@ -460,7 +461,7 @@ bool InstantController::Update(const AutocompleteMatch& match, ...@@ -460,7 +461,7 @@ bool InstantController::Update(const AutocompleteMatch& match,
last_user_text_.clear(); last_user_text_.clear();
last_suggestion_ = InstantSuggestion(); last_suggestion_ = InstantSuggestion();
if (UseTabForSuggestions()) if (UseTabForSuggestions())
instant_tab_->Update(string16(), 0, 0, true); instant_tab_->sender()->Update(string16(), 0, 0, true);
else if (overlay_ && search_mode_.is_origin_ntp()) else if (overlay_ && search_mode_.is_origin_ntp())
overlay_->Update(string16(), 0, 0, true); overlay_->Update(string16(), 0, 0, true);
else else
...@@ -516,7 +517,8 @@ bool InstantController::Update(const AutocompleteMatch& match, ...@@ -516,7 +517,8 @@ bool InstantController::Update(const AutocompleteMatch& match,
search_mode_.mode = SearchMode::MODE_SEARCH_SUGGESTIONS; search_mode_.mode = SearchMode::MODE_SEARCH_SUGGESTIONS;
if (UseTabForSuggestions()) { if (UseTabForSuggestions()) {
instant_tab_->Update(user_text, selection_start, selection_end, verbatim); instant_tab_->sender()->Update(user_text, selection_start,
selection_end, verbatim);
} else if (overlay_) { } else if (overlay_) {
allow_overlay_to_show_search_suggestions_ = true; allow_overlay_to_show_search_suggestions_ = true;
...@@ -595,11 +597,11 @@ void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { ...@@ -595,11 +597,11 @@ void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) {
omnibox_bounds_ = bounds; omnibox_bounds_ = bounds;
if (overlay_) if (overlay_)
overlay_->SetOmniboxBounds(omnibox_bounds_); overlay_->sender()->SetOmniboxBounds(omnibox_bounds_);
if (ntp_) if (ntp_)
ntp_->SetOmniboxBounds(omnibox_bounds_); ntp_->sender()->SetOmniboxBounds(omnibox_bounds_);
if (instant_tab_) if (instant_tab_)
instant_tab_->SetOmniboxBounds(omnibox_bounds_); instant_tab_->sender()->SetOmniboxBounds(omnibox_bounds_);
} }
void InstantController::HandleAutocompleteResults( void InstantController::HandleAutocompleteResults(
...@@ -670,9 +672,9 @@ void InstantController::HandleAutocompleteResults( ...@@ -670,9 +672,9 @@ void InstantController::HandleAutocompleteResults(
static_cast<int>(results.size()))); static_cast<int>(results.size())));
if (UseTabForSuggestions()) if (UseTabForSuggestions())
instant_tab_->SendAutocompleteResults(results); instant_tab_->sender()->SendAutocompleteResults(results);
else if (overlay_) else if (overlay_)
overlay_->SendAutocompleteResults(results); overlay_->sender()->SendAutocompleteResults(results);
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
chrome::NOTIFICATION_INSTANT_SENT_AUTOCOMPLETE_RESULTS, chrome::NOTIFICATION_INSTANT_SENT_AUTOCOMPLETE_RESULTS,
...@@ -706,9 +708,9 @@ bool InstantController::OnUpOrDownKeyPressed(int count) { ...@@ -706,9 +708,9 @@ bool InstantController::OnUpOrDownKeyPressed(int count) {
return false; return false;
if (UseTabForSuggestions()) if (UseTabForSuggestions())
instant_tab_->UpOrDownKeyPressed(count); instant_tab_->sender()->UpOrDownKeyPressed(count);
else if (overlay_) else if (overlay_)
overlay_->UpOrDownKeyPressed(count); overlay_->sender()->UpOrDownKeyPressed(count);
return true; return true;
} }
...@@ -735,11 +737,11 @@ void InstantController::OnCancel(const AutocompleteMatch& match, ...@@ -735,11 +737,11 @@ void InstantController::OnCancel(const AutocompleteMatch& match,
// user_text.size() to full_text.size(). The selection bounds are inverted // user_text.size() to full_text.size(). The selection bounds are inverted
// because the caret is at the end of |user_text|, not |full_text|. // because the caret is at the end of |user_text|, not |full_text|.
if (UseTabForSuggestions()) { if (UseTabForSuggestions()) {
instant_tab_->CancelSelection(user_text, full_text.size(), user_text.size(), instant_tab_->sender()->CancelSelection(user_text, full_text.size(),
last_verbatim_); user_text.size(), last_verbatim_);
} else if (overlay_) { } else if (overlay_) {
overlay_->CancelSelection(user_text, full_text.size(), user_text.size(), overlay_->sender()->CancelSelection(user_text, full_text.size(),
last_verbatim_); user_text.size(), last_verbatim_);
} }
} }
...@@ -748,12 +750,12 @@ void InstantController::OmniboxNavigateToURL() { ...@@ -748,12 +750,12 @@ void InstantController::OmniboxNavigateToURL() {
if (!extended_enabled()) if (!extended_enabled())
return; return;
if (UseTabForSuggestions()) if (UseTabForSuggestions())
instant_tab_->Submit(string16()); instant_tab_->sender()->Submit(string16());
} }
void InstantController::ToggleVoiceSearch() { void InstantController::ToggleVoiceSearch() {
if (instant_tab_) if (instant_tab_)
instant_tab_->ToggleVoiceSearch(); instant_tab_->sender()->ToggleVoiceSearch();
} }
void InstantController::InstantPageLoadFailed(content::WebContents* contents) { void InstantController::InstantPageLoadFailed(content::WebContents* contents) {
...@@ -816,7 +818,7 @@ bool InstantController::SubmitQuery(const string16& search_terms) { ...@@ -816,7 +818,7 @@ bool InstantController::SubmitQuery(const string16& search_terms) {
search_mode_.is_origin_search()) { search_mode_.is_origin_search()) {
// Use |instant_tab_| to run the query if we're already on a search results // Use |instant_tab_| to run the query if we're already on a search results
// page. (NOTE: in particular, we do not send the query to NTPs.) // page. (NOTE: in particular, we do not send the query to NTPs.)
instant_tab_->Submit(search_terms); instant_tab_->sender()->Submit(search_terms);
instant_tab_->contents()->GetView()->Focus(); instant_tab_->contents()->GetView()->Focus();
EnsureSearchTermsAreSet(instant_tab_->contents(), search_terms); EnsureSearchTermsAreSet(instant_tab_->contents(), search_terms);
return true; return true;
...@@ -842,7 +844,7 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { ...@@ -842,7 +844,7 @@ bool InstantController::CommitIfPossible(InstantCommitType type) {
(last_match_was_search_ || (last_match_was_search_ ||
last_suggestion_.behavior == INSTANT_COMPLETE_NEVER)) { last_suggestion_.behavior == INSTANT_COMPLETE_NEVER)) {
last_suggestion_.text.clear(); last_suggestion_.text.clear();
instant_tab_->Submit(last_omnibox_text_); instant_tab_->sender()->Submit(last_omnibox_text_);
instant_tab_->contents()->GetView()->Focus(); instant_tab_->contents()->GetView()->Focus();
EnsureSearchTermsAreSet(instant_tab_->contents(), last_omnibox_text_); EnsureSearchTermsAreSet(instant_tab_->contents(), last_omnibox_text_);
return true; return true;
...@@ -875,9 +877,9 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { ...@@ -875,9 +877,9 @@ bool InstantController::CommitIfPossible(InstantCommitType type) {
if (type == INSTANT_COMMIT_FOCUS_LOST) { if (type == INSTANT_COMMIT_FOCUS_LOST) {
// Extended mode doesn't need or use the Cancel message. // Extended mode doesn't need or use the Cancel message.
if (!extended_enabled()) if (!extended_enabled())
overlay_->Cancel(last_omnibox_text_); overlay_->sender()->Cancel(last_omnibox_text_);
} else if (type != INSTANT_COMMIT_NAVIGATED) { } else if (type != INSTANT_COMMIT_NAVIGATED) {
overlay_->Submit(last_omnibox_text_); overlay_->sender()->Submit(last_omnibox_text_);
} }
// We expect the WebContents to be in a valid state (i.e., has a last // We expect the WebContents to be in a valid state (i.e., has a last
...@@ -989,15 +991,15 @@ void InstantController::OmniboxFocusChanged( ...@@ -989,15 +991,15 @@ void InstantController::OmniboxFocusChanged(
if (extended_enabled()) { if (extended_enabled()) {
if (overlay_) if (overlay_)
overlay_->FocusChanged(omnibox_focus_state_, reason); overlay_->sender()->FocusChanged(omnibox_focus_state_, reason);
if (instant_tab_) { if (instant_tab_) {
instant_tab_->FocusChanged(omnibox_focus_state_, reason); instant_tab_->sender()->FocusChanged(omnibox_focus_state_, reason);
// Don't send oninputstart/oninputend updates in response to focus changes // Don't send oninputstart/oninputend updates in response to focus changes
// if there's a navigation in progress. This prevents Chrome from sending // if there's a navigation in progress. This prevents Chrome from sending
// a spurious oninputend when the user accepts a match in the omnibox. // a spurious oninputend when the user accepts a match in the omnibox.
if (instant_tab_->contents()->GetController().GetPendingEntry() == NULL) if (instant_tab_->contents()->GetController().GetPendingEntry() == NULL)
instant_tab_->SetInputInProgress(IsInputInProgress()); instant_tab_->sender()->SetInputInProgress(IsInputInProgress());
} }
} }
...@@ -1031,7 +1033,7 @@ void InstantController::SearchModeChanged(const SearchMode& old_mode, ...@@ -1031,7 +1033,7 @@ void InstantController::SearchModeChanged(const SearchMode& old_mode,
ResetInstantTab(); ResetInstantTab();
if (instant_tab_ && old_mode.is_ntp() != new_mode.is_ntp()) if (instant_tab_ && old_mode.is_ntp() != new_mode.is_ntp())
instant_tab_->SetInputInProgress(IsInputInProgress()); instant_tab_->sender()->SetInputInProgress(IsInputInProgress());
} }
void InstantController::ActiveTabChanged() { void InstantController::ActiveTabChanged() {
...@@ -1085,7 +1087,7 @@ void InstantController::SetInstantEnabled(bool instant_enabled, ...@@ -1085,7 +1087,7 @@ void InstantController::SetInstantEnabled(bool instant_enabled,
ResetNTP(GetInstantURL()); ResetNTP(GetInstantURL());
if (instant_tab_) if (instant_tab_)
instant_tab_->SetDisplayInstantResults(instant_enabled_); instant_tab_->sender()->SetDisplayInstantResults(instant_enabled_);
} }
void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) {
...@@ -1093,11 +1095,11 @@ void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { ...@@ -1093,11 +1095,11 @@ void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) {
return; return;
if (overlay_) if (overlay_)
overlay_->SendThemeBackgroundInfo(theme_info); overlay_->sender()->SendThemeBackgroundInfo(theme_info);
if (ntp_) if (ntp_)
ntp_->SendThemeBackgroundInfo(theme_info); ntp_->sender()->SendThemeBackgroundInfo(theme_info);
if (instant_tab_) if (instant_tab_)
instant_tab_->SendThemeBackgroundInfo(theme_info); instant_tab_->sender()->SendThemeBackgroundInfo(theme_info);
} }
void InstantController::SwappedOverlayContents() { void InstantController::SwappedOverlayContents() {
...@@ -1165,19 +1167,19 @@ void InstantController::UpdateMostVisitedItems() { ...@@ -1165,19 +1167,19 @@ void InstantController::UpdateMostVisitedItems() {
if (overlay_ && GetOverlayContents() && if (overlay_ && GetOverlayContents() &&
SearchTabHelper::FromWebContents(overlay_->contents())-> SearchTabHelper::FromWebContents(overlay_->contents())->
UpdateLastKnownMostVisitedItems(items)) { UpdateLastKnownMostVisitedItems(items)) {
overlay_->SendMostVisitedItems(items); overlay_->sender()->SendMostVisitedItems(items);
} }
if (ntp_ && ntp_->contents() && if (ntp_ && ntp_->contents() &&
SearchTabHelper::FromWebContents(ntp_->contents())-> SearchTabHelper::FromWebContents(ntp_->contents())->
UpdateLastKnownMostVisitedItems(items)) { UpdateLastKnownMostVisitedItems(items)) {
ntp_->SendMostVisitedItems(items); ntp_->sender()->SendMostVisitedItems(items);
} }
if (instant_tab_ && instant_tab_->contents() && if (instant_tab_ && instant_tab_->contents() &&
SearchTabHelper::FromWebContents(instant_tab_->contents())-> SearchTabHelper::FromWebContents(instant_tab_->contents())->
UpdateLastKnownMostVisitedItems(items)) { UpdateLastKnownMostVisitedItems(items)) {
instant_tab_->SendMostVisitedItems(items); instant_tab_->sender()->SendMostVisitedItems(items);
} }
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
...@@ -1243,13 +1245,14 @@ void InstantController::InstantPageRenderViewCreated( ...@@ -1243,13 +1245,14 @@ void InstantController::InstantPageRenderViewCreated(
// Ensure the searchbox API has the correct initial state. // Ensure the searchbox API has the correct initial state.
if (IsContentsFrom(overlay(), contents)) { if (IsContentsFrom(overlay(), contents)) {
overlay_->SetDisplayInstantResults(instant_enabled_); overlay_->sender()->SetDisplayInstantResults(instant_enabled_);
overlay_->FocusChanged(omnibox_focus_state_, omnibox_focus_change_reason_); overlay_->sender()->FocusChanged(omnibox_focus_state_,
overlay_->SetOmniboxBounds(omnibox_bounds_); omnibox_focus_change_reason_);
overlay_->sender()->SetOmniboxBounds(omnibox_bounds_);
overlay_->InitializeFonts(); overlay_->InitializeFonts();
} else if (IsContentsFrom(ntp(), contents)) { } else if (IsContentsFrom(ntp(), contents)) {
ntp_->SetDisplayInstantResults(instant_enabled_); ntp_->sender()->SetDisplayInstantResults(instant_enabled_);
ntp_->SetOmniboxBounds(omnibox_bounds_); ntp_->sender()->SetOmniboxBounds(omnibox_bounds_);
ntp_->InitializeFonts(); ntp_->InitializeFonts();
} else { } else {
NOTREACHED(); NOTREACHED();
...@@ -1599,7 +1602,8 @@ void InstantController::ResetNTP(const std::string& instant_url) { ...@@ -1599,7 +1602,8 @@ void InstantController::ResetNTP(const std::string& instant_url) {
// Instant NTP is only used in extended mode so we should always have a // Instant NTP is only used in extended mode so we should always have a
// non-empty URL to use. // non-empty URL to use.
DCHECK(!instant_url.empty()); DCHECK(!instant_url.empty());
ntp_.reset(new InstantNTP(this, instant_url)); ntp_.reset(new InstantNTP(this, instant_url,
browser_->profile()->IsOffTheRecord()));
ntp_->InitContents(profile(), browser_->GetActiveWebContents(), ntp_->InitContents(profile(), browser_->GetActiveWebContents(),
base::Bind(&InstantController::ReloadStaleNTP, base::Bind(&InstantController::ReloadStaleNTP,
base::Unretained(this))); base::Unretained(this)));
...@@ -1661,13 +1665,11 @@ InstantController::ShouldSwitchToLocalOverlay() const { ...@@ -1661,13 +1665,11 @@ InstantController::ShouldSwitchToLocalOverlay() const {
} }
void InstantController::ResetInstantTab() { void InstantController::ResetInstantTab() {
// Do not wire up the InstantTab in Incognito, to prevent it from sending data if (!search_mode_.is_origin_default()) {
// to the page.
if (!search_mode_.is_origin_default() &&
!browser_->profile()->IsOffTheRecord()) {
content::WebContents* active_tab = browser_->GetActiveWebContents(); content::WebContents* active_tab = browser_->GetActiveWebContents();
if (!instant_tab_ || active_tab != instant_tab_->contents()) { if (!instant_tab_ || active_tab != instant_tab_->contents()) {
instant_tab_.reset(new InstantTab(this)); instant_tab_.reset(
new InstantTab(this, browser_->profile()->IsOffTheRecord()));
instant_tab_->Init(active_tab); instant_tab_->Init(active_tab);
UpdateInfoForInstantTab(); UpdateInfoForInstantTab();
use_tab_for_suggestions_ = true; use_tab_for_suggestions_ = true;
...@@ -1683,13 +1685,13 @@ void InstantController::ResetInstantTab() { ...@@ -1683,13 +1685,13 @@ void InstantController::ResetInstantTab() {
void InstantController::UpdateInfoForInstantTab() { void InstantController::UpdateInfoForInstantTab() {
if (instant_tab_) { if (instant_tab_) {
browser_->UpdateThemeInfo(); browser_->UpdateThemeInfo();
instant_tab_->SetDisplayInstantResults(instant_enabled_); instant_tab_->sender()->SetDisplayInstantResults(instant_enabled_);
instant_tab_->SetOmniboxBounds(omnibox_bounds_); instant_tab_->sender()->SetOmniboxBounds(omnibox_bounds_);
instant_tab_->InitializeFonts(); instant_tab_->InitializeFonts();
UpdateMostVisitedItems(); UpdateMostVisitedItems();
instant_tab_->FocusChanged(omnibox_focus_state_, instant_tab_->sender()->FocusChanged(omnibox_focus_state_,
omnibox_focus_change_reason_); omnibox_focus_change_reason_);
instant_tab_->SetInputInProgress(IsInputInProgress()); instant_tab_->sender()->SetInputInProgress(IsInputInProgress());
} }
} }
...@@ -1792,7 +1794,7 @@ void InstantController::SendPopupBoundsToPage() { ...@@ -1792,7 +1794,7 @@ void InstantController::SendPopupBoundsToPage() {
DCHECK_LE(0, intersection.width()); DCHECK_LE(0, intersection.width());
DCHECK_LE(0, intersection.height()); DCHECK_LE(0, intersection.height());
overlay_->SetPopupBounds(intersection); overlay_->sender()->SetPopupBounds(intersection);
} }
......
...@@ -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