diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-28 21:50:56 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-28 21:50:56 +0000 |
commit | 064f57affdcdbc6b5e85bc1fc2082a5e393ff0af (patch) | |
tree | 8c1e05e7c59a3e468c03438ef059711e6e8f3488 | |
parent | 7a477b97f3b6cedaa45ba37b0f4fbcf0d76c3c1c (diff) | |
download | chromium_src-064f57affdcdbc6b5e85bc1fc2082a5e393ff0af.zip chromium_src-064f57affdcdbc6b5e85bc1fc2082a5e393ff0af.tar.gz chromium_src-064f57affdcdbc6b5e85bc1fc2082a5e393ff0af.tar.bz2 |
Refactored ChromeViewHostMsg_SearchBoxNavigate IPC message related code.
(1) InstantPage no longer process ChromeViewHostMsg_SearchBoxNavigate IPC message.
(2) SearchIPCRouter now handles ChromeViewHostMsg_SearchBoxNavigate IPC message.
(3) Removed unused params from SearchBox::NavigateToURL() and updated the message handler accordingly.
(4) Deprecated Instant navigation histogram since the HTML popup went away.
BUG=272583
TEST=none
Review URL: https://codereview.chromium.org/26643002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231413 0039d316-1c4b-4281-b951-d872f2087c98
24 files changed, 173 insertions, 161 deletions
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc index 25bb416..97771a2 100644 --- a/chrome/browser/ui/browser_instant_controller.cc +++ b/chrome/browser/ui/browser_instant_controller.cc @@ -156,17 +156,6 @@ void BrowserInstantController::TabDeactivated(content::WebContents* contents) { instant_.TabDeactivated(contents); } -void BrowserInstantController::OpenURL( - const GURL& url, - content::PageTransition transition, - WindowOpenDisposition disposition) { - browser_->OpenURL(content::OpenURLParams(url, - content::Referrer(), - disposition, - transition, - false)); -} - void BrowserInstantController::PasteIntoOmnibox(const string16& text) { OmniboxView* omnibox_view = browser_->window()->GetLocationBar()-> GetLocationEntry(); diff --git a/chrome/browser/ui/browser_instant_controller.h b/chrome/browser/ui/browser_instant_controller.h index 78f08ec..cd53f23 100644 --- a/chrome/browser/ui/browser_instant_controller.h +++ b/chrome/browser/ui/browser_instant_controller.h @@ -13,7 +13,6 @@ #include "chrome/browser/ui/search/instant_controller.h" #include "chrome/browser/ui/search/instant_unload_handler.h" #include "chrome/browser/ui/search/search_model_observer.h" -#include "ui/base/window_open_disposition.h" class Browser; struct InstantSuggestion; @@ -65,11 +64,6 @@ class BrowserInstantController : public SearchModelObserver, // Invoked by |browser_| when the active tab is about to be deactivated. void TabDeactivated(content::WebContents* contents); - // Invoked by the InstantController when it wants to open a URL. - void OpenURL(const GURL& url, - content::PageTransition transition, - WindowOpenDisposition disposition); - // Invoked by |instant_| to paste the |text| (or clipboard content if text is // empty) into the omnibox. It will set focus to the omnibox if the omnibox is // not focused. diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc index 8307c64..334d93a 100644 --- a/chrome/browser/ui/search/instant_controller.cc +++ b/chrome/browser/ui/search/instant_controller.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/search/instant_controller.h" -#include "base/metrics/histogram.h" #include "base/prefs/pref_service.h" #include "base/strings/stringprintf.h" #include "chrome/browser/chrome_notification_types.h" @@ -31,7 +30,6 @@ #include "content/public/browser/notification_service.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_widget_host_view.h" -#include "content/public/browser/user_metrics.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" #include "net/base/escape.h" @@ -44,32 +42,6 @@ namespace { -// For reporting Instant navigations. -enum InstantNavigation { - INSTANT_NAVIGATION_LOCAL_CLICK = 0, - INSTANT_NAVIGATION_LOCAL_SUBMIT = 1, - INSTANT_NAVIGATION_ONLINE_CLICK = 2, - INSTANT_NAVIGATION_ONLINE_SUBMIT = 3, - INSTANT_NAVIGATION_NONEXTENDED = 4, - INSTANT_NAVIGATION_MAX = 5 -}; - -void RecordNavigationHistogram(bool is_local, bool is_click, bool is_extended) { - InstantNavigation navigation; - if (!is_extended) { - navigation = INSTANT_NAVIGATION_NONEXTENDED; - } else if (is_local) { - navigation = is_click ? INSTANT_NAVIGATION_LOCAL_CLICK : - INSTANT_NAVIGATION_LOCAL_SUBMIT; - } else { - navigation = is_click ? INSTANT_NAVIGATION_ONLINE_CLICK : - INSTANT_NAVIGATION_ONLINE_SUBMIT; - } - UMA_HISTOGRAM_ENUMERATION("InstantExtended.InstantNavigation", - navigation, - INSTANT_NAVIGATION_MAX); -} - bool IsContentsFrom(const InstantPage* page, const content::WebContents* contents) { return page && (page->contents() == contents); @@ -289,27 +261,6 @@ void InstantController::InstantPageAboutToNavigateMainFrame( UpdateInfoForInstantTab(); } -void InstantController::NavigateToURL(const content::WebContents* contents, - const GURL& url, - content::PageTransition transition, - WindowOpenDisposition disposition, - bool is_search_type) { - LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( - "NavigateToURL: url='%s'", url.spec().c_str())); - - // TODO(samarth): handle case where contents are no longer "active" (e.g. user - // has switched tabs). - if (transition == content::PAGE_TRANSITION_AUTO_BOOKMARK) { - content::RecordAction( - content::UserMetricsAction("InstantExtended.MostVisitedClicked")); - } else { - // Exclude navigation by Most Visited click and searches. - if (!is_search_type) - RecordNavigationHistogram(UsingLocalPage(), true, true); - } - browser_->OpenURL(url, transition, disposition); -} - void InstantController::PasteIntoOmnibox(const content::WebContents* contents, const string16& text) { if (search_mode_.is_origin_default()) @@ -355,10 +306,6 @@ bool InstantController::IsInputInProgress() const { omnibox_focus_state_ == OMNIBOX_FOCUS_VISIBLE; } -bool InstantController::UsingLocalPage() const { - return instant_tab_ && instant_tab_->IsLocal(); -} - void InstantController::RedirectToLocalNTP(content::WebContents* contents) { contents->GetController().LoadURL( GURL(chrome::kChromeSearchLocalNtpUrl), diff --git a/chrome/browser/ui/search/instant_controller.h b/chrome/browser/ui/search/instant_controller.h index 845032c..d23b254 100644 --- a/chrome/browser/ui/search/instant_controller.h +++ b/chrome/browser/ui/search/instant_controller.h @@ -18,8 +18,6 @@ #include "chrome/common/instant_types.h" #include "chrome/common/omnibox_focus_state.h" #include "chrome/common/search_types.h" -#include "content/public/common/page_transition_types.h" -#include "ui/base/window_open_disposition.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/rect.h" @@ -159,12 +157,6 @@ class InstantController : public InstantPage::Delegate { virtual void InstantPageAboutToNavigateMainFrame( const content::WebContents* contents, const GURL& url) OVERRIDE; - virtual void NavigateToURL( - const content::WebContents* contents, - const GURL& url, - content::PageTransition transition, - WindowOpenDisposition disposition, - bool is_search_type) OVERRIDE; virtual void PasteIntoOmnibox(const content::WebContents* contents, const string16& text) OVERRIDE; virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; @@ -187,9 +179,6 @@ class InstantController : public InstantPage::Delegate { // active tab is in mode SEARCH_SUGGESTIONS. bool IsInputInProgress() const; - // Returns true if the local page is being used. - bool UsingLocalPage() const; - // Returns the InstantService for the browser profile. InstantService* GetInstantService() const; diff --git a/chrome/browser/ui/search/instant_ntp_prerenderer.cc b/chrome/browser/ui/search/instant_ntp_prerenderer.cc index a4300c0..e009b97 100644 --- a/chrome/browser/ui/search/instant_ntp_prerenderer.cc +++ b/chrome/browser/ui/search/instant_ntp_prerenderer.cc @@ -207,15 +207,6 @@ void InstantNTPPrerenderer::InstantPageAboutToNavigateMainFrame( NOTREACHED(); } -void InstantNTPPrerenderer::NavigateToURL( - const content::WebContents* /* contents */, - const GURL& /* url */, - content::PageTransition /* transition */, - WindowOpenDisposition /* disposition */, - bool /* is_search_type */) { - NOTREACHED(); -} - void InstantNTPPrerenderer::PasteIntoOmnibox( const content::WebContents* /* contents */, const string16& /* text */) { diff --git a/chrome/browser/ui/search/instant_ntp_prerenderer.h b/chrome/browser/ui/search/instant_ntp_prerenderer.h index 0fda843..47163081 100644 --- a/chrome/browser/ui/search/instant_ntp_prerenderer.h +++ b/chrome/browser/ui/search/instant_ntp_prerenderer.h @@ -125,11 +125,6 @@ class InstantNTPPrerenderer virtual void InstantPageAboutToNavigateMainFrame( const content::WebContents* contents, const GURL& url) OVERRIDE; - virtual void NavigateToURL(const content::WebContents* contents, - const GURL& url, - content::PageTransition transition, - WindowOpenDisposition disposition, - bool is_search_type) OVERRIDE; virtual void PasteIntoOmnibox(const content::WebContents* contents, const string16& text) OVERRIDE; virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; diff --git a/chrome/browser/ui/search/instant_page.cc b/chrome/browser/ui/search/instant_page.cc index 1732a3c..83b7820 100644 --- a/chrome/browser/ui/search/instant_page.cc +++ b/chrome/browser/ui/search/instant_page.cc @@ -69,10 +69,6 @@ bool InstantPage::ShouldProcessAboutToNavigateMainFrame() { return false; } -bool InstantPage::ShouldProcessNavigateToURL() { - return false; -} - bool InstantPage::ShouldProcessPasteIntoOmnibox() { return false; } @@ -83,8 +79,6 @@ bool InstantPage::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(InstantPage, message) - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate, - OnSearchBoxNavigate); IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PasteAndOpenDropdown, OnSearchBoxPaste); IPC_MESSAGE_UNHANDLED(handled = false) @@ -139,22 +133,6 @@ void InstantPage::InstantSupportDetermined(bool supports_instant) { ClearContents(); } -void InstantPage::OnSearchBoxNavigate(int page_id, - const GURL& url, - content::PageTransition transition, - WindowOpenDisposition disposition, - bool is_search_type) { - if (!contents()->IsActiveEntry(page_id)) - return; - - SearchTabHelper::FromWebContents(contents())->InstantSupportChanged(true); - if (!ShouldProcessNavigateToURL()) - return; - - delegate_->NavigateToURL( - contents(), url, transition, disposition, is_search_type); -} - void InstantPage::OnSearchBoxPaste(int page_id, const string16& text) { if (!contents()->IsActiveEntry(page_id)) return; diff --git a/chrome/browser/ui/search/instant_page.h b/chrome/browser/ui/search/instant_page.h index cb85102..13af498 100644 --- a/chrome/browser/ui/search/instant_page.h +++ b/chrome/browser/ui/search/instant_page.h @@ -52,16 +52,6 @@ class InstantPage : public content::WebContentsObserver, const content::WebContents* contents, const GURL& url) = 0; - // Called when the page wants to navigate to |url|. Usually used by the - // page to navigate to privileged destinations (e.g. chrome:// URLs) or to - // navigate to URLs that are hidden from the page using Restricted IDs (rid - // in the API). - virtual void NavigateToURL(const content::WebContents* contents, - const GURL& url, - content::PageTransition transition, - WindowOpenDisposition disposition, - bool is_search_type) = 0; - // Called when the page wants to paste the |text| (or the clipboard content // if the |text| is empty) into the omnibox. virtual void PasteIntoOmnibox(const content::WebContents* contents, @@ -113,7 +103,6 @@ class InstantPage : public content::WebContentsObserver, // choose to ignore some or all of the received messages by overriding these // methods. virtual bool ShouldProcessAboutToNavigateMainFrame(); - virtual bool ShouldProcessNavigateToURL(); virtual bool ShouldProcessPasteIntoOmnibox(); private: @@ -156,11 +145,6 @@ class InstantPage : public content::WebContentsObserver, // Update the status of Instant support. void InstantSupportDetermined(bool supports_instant); - void OnSearchBoxNavigate(int page_id, - const GURL& url, - content::PageTransition transition, - WindowOpenDisposition disposition, - bool is_search_type); void OnSearchBoxPaste(int page_id, const string16& text); void ClearContents(); diff --git a/chrome/browser/ui/search/instant_tab.cc b/chrome/browser/ui/search/instant_tab.cc index 14a53c7..129f3dd 100644 --- a/chrome/browser/ui/search/instant_tab.cc +++ b/chrome/browser/ui/search/instant_tab.cc @@ -31,10 +31,6 @@ bool InstantTab::ShouldProcessAboutToNavigateMainFrame() { return true; } -bool InstantTab::ShouldProcessNavigateToURL() { - return true; -} - bool InstantTab::ShouldProcessPasteIntoOmnibox() { return true; } diff --git a/chrome/browser/ui/search/instant_tab.h b/chrome/browser/ui/search/instant_tab.h index 3b2430a..004edfa 100644 --- a/chrome/browser/ui/search/instant_tab.h +++ b/chrome/browser/ui/search/instant_tab.h @@ -28,7 +28,6 @@ class InstantTab : public InstantPage { private: // Overridden from InstantPage: virtual bool ShouldProcessAboutToNavigateMainFrame() OVERRIDE; - virtual bool ShouldProcessNavigateToURL() OVERRIDE; virtual bool ShouldProcessPasteIntoOmnibox() OVERRIDE; DISALLOW_COPY_AND_ASSIGN(InstantTab); diff --git a/chrome/browser/ui/search/search_ipc_router.cc b/chrome/browser/ui/search/search_ipc_router.cc index 4b7b424..ae37ff4 100644 --- a/chrome/browser/ui/search/search_ipc_router.cc +++ b/chrome/browser/ui/search/search_ipc_router.cc @@ -91,6 +91,8 @@ bool SearchIPCRouter::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetVoiceSearchSupported, OnVoiceSearchSupportDetermined) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FocusOmnibox, OnFocusOmnibox); + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate, + OnSearchBoxNavigate); IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem, OnDeleteMostVisitedItem); IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion, @@ -136,6 +138,21 @@ void SearchIPCRouter::OnFocusOmnibox(int page_id, delegate_->FocusOmnibox(state); } +void SearchIPCRouter::OnSearchBoxNavigate( + int page_id, + const GURL& url, + WindowOpenDisposition disposition, + bool is_most_visited_item_url) const { + if (!web_contents()->IsActiveEntry(page_id)) + return; + + delegate_->OnInstantSupportDetermined(true); + if (!policy_->ShouldProcessNavigateToURL(is_active_tab_)) + return; + + delegate_->NavigateToURL(url, disposition, is_most_visited_item_url); +} + void SearchIPCRouter::OnDeleteMostVisitedItem(int page_id, const GURL& url) const { if (!web_contents()->IsActiveEntry(page_id)) diff --git a/chrome/browser/ui/search/search_ipc_router.h b/chrome/browser/ui/search/search_ipc_router.h index ae50009..aa1ae92 100644 --- a/chrome/browser/ui/search/search_ipc_router.h +++ b/chrome/browser/ui/search/search_ipc_router.h @@ -13,6 +13,7 @@ #include "chrome/common/ntp_logging_events.h" #include "chrome/common/omnibox_focus_state.h" #include "content/public/browser/web_contents_observer.h" +#include "ui/base/window_open_disposition.h" class GURL; @@ -41,6 +42,14 @@ class SearchIPCRouter : public content::WebContentsObserver { // the omnibox focus state. virtual void FocusOmnibox(OmniboxFocusState state) = 0; + // Called when the page wants to navigate to |url|. Usually used by the + // page to navigate to privileged destinations (e.g. chrome:// URLs) or to + // navigate to URLs that are hidden from the page using Restricted IDs (rid + // in the API). + virtual void NavigateToURL(const GURL& url, + WindowOpenDisposition disposition, + bool is_most_visited_item_url) = 0; + // Called when the SearchBox wants to delete a Most Visited item. virtual void OnDeleteMostVisitedItem(const GURL& url) = 0; @@ -65,6 +74,7 @@ class SearchIPCRouter : public content::WebContentsObserver { // to/from the page. virtual bool ShouldProcessSetVoiceSearchSupport() = 0; virtual bool ShouldProcessFocusOmnibox(bool is_active_tab) = 0; + virtual bool ShouldProcessNavigateToURL(bool is_active_tab) = 0; virtual bool ShouldProcessDeleteMostVisitedItem() = 0; virtual bool ShouldProcessUndoMostVisitedDeletion() = 0; virtual bool ShouldProcessUndoAllMostVisitedDeletions() = 0; @@ -142,6 +152,7 @@ class SearchIPCRouter : public content::WebContentsObserver { FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterPolicyTest, SendSetPromoInformation); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterPolicyTest, DoNotSendSetPromoInformation); + FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterPolicyTest, ProcessNavigateToURL); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterPolicyTest, ProcessDeleteMostVisitedItem); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterPolicyTest, @@ -162,6 +173,8 @@ class SearchIPCRouter : public content::WebContentsObserver { DoNotSendSetPromoInformationMsg); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, ProcessLogEventMsg); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, IgnoreLogEventMsg); + FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, ProcessNavigateToURLMsg); + FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, IgnoreNavigateToURLMsg); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, @@ -184,6 +197,10 @@ class SearchIPCRouter : public content::WebContentsObserver { void OnVoiceSearchSupportDetermined(int page_id, bool supports_voice_search) const; void OnFocusOmnibox(int page_id, OmniboxFocusState state) const; + void OnSearchBoxNavigate(int page_id, + const GURL& url, + WindowOpenDisposition disposition, + bool is_most_visited_item_url) const; void OnDeleteMostVisitedItem(int page_id, const GURL& url) const; void OnUndoMostVisitedDeletion(int page_id, const GURL& url) const; void OnUndoAllMostVisitedDeletions(int page_id) const; diff --git a/chrome/browser/ui/search/search_ipc_router_policy_impl.cc b/chrome/browser/ui/search/search_ipc_router_policy_impl.cc index bf84580..30b6995 100644 --- a/chrome/browser/ui/search/search_ipc_router_policy_impl.cc +++ b/chrome/browser/ui/search/search_ipc_router_policy_impl.cc @@ -30,6 +30,10 @@ bool SearchIPCRouterPolicyImpl::ShouldProcessFocusOmnibox(bool is_active_tab) { return is_active_tab && !is_incognito_ && chrome::IsInstantNTP(web_contents_); } +bool SearchIPCRouterPolicyImpl::ShouldProcessNavigateToURL(bool is_active_tab) { + return is_active_tab && !is_incognito_; +} + bool SearchIPCRouterPolicyImpl::ShouldProcessDeleteMostVisitedItem() { return !is_incognito_ && chrome::IsInstantNTP(web_contents_); } diff --git a/chrome/browser/ui/search/search_ipc_router_policy_impl.h b/chrome/browser/ui/search/search_ipc_router_policy_impl.h index 43820fa..49ab037 100644 --- a/chrome/browser/ui/search/search_ipc_router_policy_impl.h +++ b/chrome/browser/ui/search/search_ipc_router_policy_impl.h @@ -33,6 +33,7 @@ class SearchIPCRouterPolicyImpl : public SearchIPCRouter::Policy { // Overridden from SearchIPCRouter::Policy: virtual bool ShouldProcessSetVoiceSearchSupport() OVERRIDE; virtual bool ShouldProcessFocusOmnibox(bool is_active_tab) OVERRIDE; + virtual bool ShouldProcessNavigateToURL(bool is_active_tab) OVERRIDE; virtual bool ShouldProcessDeleteMostVisitedItem() OVERRIDE; virtual bool ShouldProcessUndoMostVisitedDeletion() OVERRIDE; virtual bool ShouldProcessUndoAllMostVisitedDeletions() OVERRIDE; diff --git a/chrome/browser/ui/search/search_ipc_router_policy_unittest.cc b/chrome/browser/ui/search/search_ipc_router_policy_unittest.cc index c8d49ab..8aa1f4d 100644 --- a/chrome/browser/ui/search/search_ipc_router_policy_unittest.cc +++ b/chrome/browser/ui/search/search_ipc_router_policy_unittest.cc @@ -84,9 +84,6 @@ TEST_F(SearchIPCRouterPolicyTest, ProcessUndoMostVisitedDeletion) { TEST_F(SearchIPCRouterPolicyTest, ProcessUndoAllMostVisitedDeletions) { NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); - SearchTabHelper* search_tab_helper = - SearchTabHelper::FromWebContents(web_contents()); - ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); EXPECT_TRUE(GetSearchTabHelper()->ipc_router().policy()-> ShouldProcessUndoAllMostVisitedDeletions()); } @@ -104,6 +101,12 @@ TEST_F(SearchIPCRouterPolicyTest, DoNotProcessLogEvent) { ShouldProcessLogEvent()); } +TEST_F(SearchIPCRouterPolicyTest, ProcessNavigateToURL) { + NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); + EXPECT_TRUE(GetSearchTabHelper()->ipc_router().policy()-> + ShouldProcessNavigateToURL(true)); +} + TEST_F(SearchIPCRouterPolicyTest, DoNotProcessMessagesForIncognitoPage) { NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); SearchTabHelper* search_tab_helper = GetSearchTabHelper(); @@ -115,6 +118,8 @@ TEST_F(SearchIPCRouterPolicyTest, DoNotProcessMessagesForIncognitoPage) { EXPECT_FALSE(search_tab_helper->ipc_router().policy()-> ShouldProcessFocusOmnibox(true)); EXPECT_FALSE(search_tab_helper->ipc_router().policy()-> + ShouldProcessNavigateToURL(true)); + EXPECT_FALSE(search_tab_helper->ipc_router().policy()-> ShouldProcessDeleteMostVisitedItem()); EXPECT_FALSE(search_tab_helper->ipc_router().policy()-> ShouldProcessUndoMostVisitedDeletion()); @@ -128,8 +133,11 @@ TEST_F(SearchIPCRouterPolicyTest, DoNotProcessMessagesForInactiveTab) { NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); // Assume the NTP is deactivated. - EXPECT_FALSE(GetSearchTabHelper()->ipc_router().policy()-> + SearchTabHelper* search_tab_helper = GetSearchTabHelper(); + EXPECT_FALSE(search_tab_helper->ipc_router().policy()-> ShouldProcessFocusOmnibox(false)); + EXPECT_FALSE(search_tab_helper->ipc_router().policy()-> + ShouldProcessNavigateToURL(false)); } TEST_F(SearchIPCRouterPolicyTest, SendSetDisplayInstantResults) { diff --git a/chrome/browser/ui/search/search_ipc_router_unittest.cc b/chrome/browser/ui/search/search_ipc_router_unittest.cc index 72c63f1..7d89d4c 100644 --- a/chrome/browser/ui/search/search_ipc_router_unittest.cc +++ b/chrome/browser/ui/search/search_ipc_router_unittest.cc @@ -27,6 +27,7 @@ #include "ipc/ipc_test_sink.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +#include "ui/base/window_open_disposition.h" #include "url/gurl.h" namespace { @@ -38,6 +39,7 @@ class MockSearchIPCRouterDelegate : public SearchIPCRouter::Delegate { MOCK_METHOD1(OnInstantSupportDetermined, void(bool supports_instant)); MOCK_METHOD1(OnSetVoiceSearchSupport, void(bool supports_voice_search)); MOCK_METHOD1(FocusOmnibox, void(OmniboxFocusState state)); + MOCK_METHOD3(NavigateToURL, void(const GURL&, WindowOpenDisposition, bool)); MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url)); MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url)); MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void()); @@ -50,6 +52,7 @@ class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { MOCK_METHOD0(ShouldProcessSetVoiceSearchSupport, bool()); MOCK_METHOD1(ShouldProcessFocusOmnibox, bool(bool)); + MOCK_METHOD1(ShouldProcessNavigateToURL, bool(bool)); MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool()); MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool()); MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool()); @@ -227,6 +230,53 @@ TEST_F(SearchIPCRouterTest, HandleTabChangedEvents) { EXPECT_TRUE(search_tab_helper->ipc_router().is_active_tab_); } +TEST_F(SearchIPCRouterTest, ProcessNavigateToURLMsg) { + NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); + process()->sink().ClearMessages(); + + content::WebContents* contents = web_contents(); + SetupMockDelegateAndPolicy(contents); + MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(contents); + + GURL destination_url("www.foo.com"); + EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB, + true)).Times(1); + SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents); + bool is_active_tab = search_tab_helper->ipc_router().is_active_tab_; + EXPECT_TRUE(is_active_tab); + EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1) + .WillOnce(testing::Return(true)); + + scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( + contents->GetRoutingID(), + contents->GetController().GetVisibleEntry()->GetPageID(), + destination_url, CURRENT_TAB, true)); + search_tab_helper->ipc_router().OnMessageReceived(*message); +} + +TEST_F(SearchIPCRouterTest, IgnoreNavigateToURLMsg) { + NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); + process()->sink().ClearMessages(); + GURL destination_url("www.foo.com"); + + content::WebContents* contents = web_contents(); + SetupMockDelegateAndPolicy(contents); + MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(contents); + EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB, + true)).Times(0); + SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents); + bool is_active_tab = search_tab_helper->ipc_router().is_active_tab_; + EXPECT_TRUE(is_active_tab); + EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1) + .WillOnce(testing::Return(false)); + + scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( + contents->GetRoutingID(), + contents->GetController().GetVisibleEntry()->GetPageID(), + destination_url, CURRENT_TAB, true)); + search_tab_helper->ipc_router().OnMessageReceived(*message); +} + TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) { NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); process()->sink().ClearMessages(); @@ -402,11 +452,19 @@ TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) { SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents); int invalid_page_id = 1000; GURL item_url("www.foo.com"); + EXPECT_CALL(*mock_delegate(), NavigateToURL(item_url, CURRENT_TAB, + true)).Times(0); + EXPECT_CALL(*policy, ShouldProcessNavigateToURL( + search_tab_helper->ipc_router().is_active_tab_)).Times(0); + scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( + contents->GetRoutingID(), invalid_page_id, item_url, CURRENT_TAB, + true)); + search_tab_helper->ipc_router().OnMessageReceived(*message); + EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0); EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(0); - scoped_ptr<IPC::Message> message( - new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( - contents->GetRoutingID(), invalid_page_id, item_url)); + message.reset(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( + contents->GetRoutingID(), invalid_page_id, item_url)); search_tab_helper->ipc_router().OnMessageReceived(*message); EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0); diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc index 24147ce..f8daa04 100644 --- a/chrome/browser/ui/search/search_tab_helper.cc +++ b/chrome/browser/ui/search/search_tab_helper.cc @@ -18,6 +18,7 @@ #include "chrome/browser/ui/app_list/app_list_util.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_finder.h" +#include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/omnibox/location_bar.h" #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" @@ -34,9 +35,11 @@ #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" #include "content/public/browser/render_process_host.h" +#include "content/public/browser/user_metrics.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" #include "content/public/common/page_transition_types.h" +#include "content/public/common/referrer.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" #include "url/gurl.h" @@ -420,6 +423,36 @@ void SearchTabHelper::FocusOmnibox(OmniboxFocusState state) { #endif } +void SearchTabHelper::NavigateToURL(const GURL& url, + WindowOpenDisposition disposition, + bool is_most_visited_item_url) { +// iOS and Android don't use the Instant framework. +#if !defined(OS_IOS) && !defined(OS_ANDROID) + // TODO(kmadhusu): Remove chrome::FindBrowser...() function call from here. + // Create a SearchTabHelperDelegate interface and have the Browser object + // implement that interface to provide the necessary functionality. + Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); + Profile* profile = + Profile::FromBrowserContext(web_contents_->GetBrowserContext()); + if (!browser || !profile) + return; + + if (is_most_visited_item_url) { + content::RecordAction( + content::UserMetricsAction("InstantExtended.MostVisitedClicked")); + } + + chrome::NavigateParams params(browser, url, + content::PAGE_TRANSITION_AUTO_BOOKMARK); + params.referrer = content::Referrer(); + params.source_contents = web_contents_; + params.disposition = disposition; + params.is_renderer_initiated = false; + params.initiating_profile = profile; + chrome::Navigate(¶ms); +#endif +} + void SearchTabHelper::OnDeleteMostVisitedItem(const GURL& url) { DCHECK(!url.is_empty()); if (instant_service_) diff --git a/chrome/browser/ui/search/search_tab_helper.h b/chrome/browser/ui/search/search_tab_helper.h index 23c4126..308a1ea 100644 --- a/chrome/browser/ui/search/search_tab_helper.h +++ b/chrome/browser/ui/search/search_tab_helper.h @@ -19,11 +19,13 @@ #include "content/public/browser/notification_registrar.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_user_data.h" +#include "ui/base/window_open_disposition.h" namespace content { class WebContents; } +class GURL; class InstantPageTest; class InstantService; class Profile; @@ -114,6 +116,7 @@ class SearchTabHelper : public content::NotificationObserver, FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterPolicyTest, AppropriateMessagesSentToIncognitoPages); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterPolicyTest, SubmitQuery); + FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterPolicyTest, ProcessNavigateToURL); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterPolicyTest, ProcessDeleteMostVisitedItem); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterPolicyTest, @@ -134,6 +137,8 @@ class SearchTabHelper : public content::NotificationObserver, DoNotSendSetPromoInformationMsg); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, ProcessLogEventMsg); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, IgnoreLogEventMsg); + FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, ProcessNavigateToURLMsg); + FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, IgnoreNavigateToURLMsg); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg); FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, @@ -198,6 +203,9 @@ class SearchTabHelper : public content::NotificationObserver, virtual void OnInstantSupportDetermined(bool supports_instant) OVERRIDE; virtual void OnSetVoiceSearchSupport(bool supports_voice_search) OVERRIDE; virtual void FocusOmnibox(OmniboxFocusState state) OVERRIDE; + virtual void NavigateToURL(const GURL& url, + WindowOpenDisposition disposition, + bool is_most_visited_item_url) OVERRIDE; virtual void OnDeleteMostVisitedItem(const GURL& url) OVERRIDE; virtual void OnUndoMostVisitedDeletion(const GURL& url) OVERRIDE; virtual void OnUndoAllMostVisitedDeletions() OVERRIDE; diff --git a/chrome/browser/ui/search/search_tab_helper_unittest.cc b/chrome/browser/ui/search/search_tab_helper_unittest.cc index 7e8fc3a..735ad15 100644 --- a/chrome/browser/ui/search/search_tab_helper_unittest.cc +++ b/chrome/browser/ui/search/search_tab_helper_unittest.cc @@ -32,6 +32,7 @@ class MockSearchIPCRouterDelegate : public SearchIPCRouter::Delegate { MOCK_METHOD1(OnInstantSupportDetermined, void(bool supports_instant)); MOCK_METHOD1(OnSetVoiceSearchSupport, void(bool supports_voice_search)); MOCK_METHOD1(FocusOmnibox, void(OmniboxFocusState state)); + MOCK_METHOD3(NavigateToURL, void(const GURL&, WindowOpenDisposition, bool)); MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url)); MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url)); MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void()); diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 090cad7..f44bb7f 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -730,14 +730,13 @@ IPC_MESSAGE_ROUTED2(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem, int /* page_id */, GURL /* url */) -// Tells InstantExtended to navigate the active tab to a possibly priveleged +// Tells InstantExtended to navigate the active tab to a possibly privileged // URL. -IPC_MESSAGE_ROUTED5(ChromeViewHostMsg_SearchBoxNavigate, +IPC_MESSAGE_ROUTED4(ChromeViewHostMsg_SearchBoxNavigate, int /* page_id */, GURL /* destination */, - content::PageTransition /* transition */, WindowOpenDisposition /* disposition */, - bool /* is_search_type */) + bool /*is_most_visited_item_url*/) // Tells InstantExtended to undo all most visited item deletions. IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions, diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc index f7948d8..b6f3cab 100644 --- a/chrome/renderer/searchbox/searchbox.cc +++ b/chrome/renderer/searchbox/searchbox.cc @@ -228,12 +228,11 @@ void SearchBox::Focus() { } void SearchBox::NavigateToURL(const GURL& url, - content::PageTransition transition, WindowOpenDisposition disposition, - bool is_search_type) { + bool is_most_visited_item_url) { render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate( - render_view()->GetRoutingID(), render_view()->GetPageId(), - url, transition, disposition, is_search_type)); + render_view()->GetRoutingID(), render_view()->GetPageId(), url, + disposition, is_most_visited_item_url)); } void SearchBox::Paste(const string16& text) { diff --git a/chrome/renderer/searchbox/searchbox.h b/chrome/renderer/searchbox/searchbox.h index 51db602..51247db 100644 --- a/chrome/renderer/searchbox/searchbox.h +++ b/chrome/renderer/searchbox/searchbox.h @@ -13,7 +13,6 @@ #include "chrome/common/instant_types.h" #include "chrome/common/ntp_logging_events.h" #include "chrome/common/omnibox_focus_state.h" -#include "content/public/common/page_transition_types.h" #include "content/public/renderer/render_view_observer.h" #include "content/public/renderer/render_view_observer_tracker.h" #include "ui/base/window_open_disposition.h" @@ -71,9 +70,8 @@ class SearchBox : public content::RenderViewObserver, // Sends ChromeViewHostMsg_SearchBoxNavigate to the browser. void NavigateToURL(const GURL& url, - content::PageTransition transition, WindowOpenDisposition disposition, - bool is_search_type); + bool is_most_visited_item_url); // Sends ChromeViewHostMsg_SearchBoxPaste to the browser. void Paste(const string16& text); diff --git a/chrome/renderer/searchbox/searchbox_extension.cc b/chrome/renderer/searchbox/searchbox_extension.cc index f9488ee..9dc6ca1 100644 --- a/chrome/renderer/searchbox/searchbox_extension.cc +++ b/chrome/renderer/searchbox/searchbox_extension.cc @@ -855,14 +855,14 @@ void SearchBoxExtensionWrapper::NavigateContentWindow( if (!render_view || !args.Length()) return; GURL destination_url; - content::PageTransition transition = content::PAGE_TRANSITION_AUTO_BOOKMARK; - + bool is_most_visited_item_url = false; // Check if the url is a rid if (args[0]->IsNumber()) { InstantMostVisitedItem item; if (SearchBox::Get(render_view)->GetMostVisitedItemWithID( - args[0]->IntegerValue(), &item)) { + args[0]->IntegerValue(), &item)) { destination_url = item.url; + is_most_visited_item_url = true; } } else { // Resolve the URL @@ -878,8 +878,8 @@ void SearchBoxExtensionWrapper::NavigateContentWindow( WindowOpenDisposition disposition = CURRENT_TAB; if (args[1]->Uint32Value() == 2) disposition = NEW_BACKGROUND_TAB; - SearchBox::Get(render_view)->NavigateToURL( - destination_url, transition, disposition, false); + SearchBox::Get(render_view)->NavigateToURL(destination_url, disposition, + is_most_visited_item_url); } } diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index 823e0f4..3ce511f 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -5255,6 +5255,10 @@ other types of suffix sets. <histogram name="InstantExtended.InstantNavigation" enum="InstantExtended_InstantNavigation"> + <obsolete> + Deprecated as of 10/2013. This histogram is no longer relevant since the + HTML overlay went away. + </obsolete> <summary> Records a histogram for instant extended (Local NTP and Online NTP) and non-extended navigations. @@ -23258,6 +23262,9 @@ other types of suffix sets. </enum> <enum name="InstantExtended_InstantNavigation" type="int"> + <obsolete> + Deprecated as of 10/2013. + </obsolete> <int value="0" label="Local click"/> <int value="1" label="Local submit"/> <int value="2" label="Online click"/> |