summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-09 12:58:23 +0000
committerkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-09 12:58:23 +0000
commit72238aac3b0551c82d5908723042025f046986fe (patch)
treea0ec62cc63b0f22042a8d747b75a12cef279d88a
parentbcdd992ff0e84a9cdeff1ac0f7982cd6f2898782 (diff)
downloadchromium_src-72238aac3b0551c82d5908723042025f046986fe.zip
chromium_src-72238aac3b0551c82d5908723042025f046986fe.tar.gz
chromium_src-72238aac3b0551c82d5908723042025f046986fe.tar.bz2
Invoke InstantPage::Delegate functions only if the IPC message is for the active page entry and if the InstantPage should process the message.
BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/16345002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205117 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/search/instant_page.cc39
-rw-r--r--chrome/browser/ui/search/instant_page.h15
-rw-r--r--chrome/browser/ui/search/instant_page_unittest.cc109
-rw-r--r--chrome/browser/ui/search/instant_tab.cc12
-rw-r--r--chrome/browser/ui/search/instant_tab.h3
-rw-r--r--chrome/common/render_messages.h9
-rw-r--r--chrome/renderer/searchbox/searchbox.cc6
7 files changed, 172 insertions, 21 deletions
diff --git a/chrome/browser/ui/search/instant_page.cc b/chrome/browser/ui/search/instant_page.cc
index 1c0b6a2..3fe82ba 100644
--- a/chrome/browser/ui/search/instant_page.cc
+++ b/chrome/browser/ui/search/instant_page.cc
@@ -165,6 +165,18 @@ bool InstantPage::ShouldProcessNavigateToURL() {
return false;
}
+bool InstantPage::ShouldProcessDeleteMostVisitedItem() {
+ return false;
+}
+
+bool InstantPage::ShouldProcessUndoMostVisitedDeletion() {
+ return false;
+}
+
+bool InstantPage::ShouldProcessUndoAllMostVisitedDeletions() {
+ return false;
+}
+
void InstantPage::RenderViewCreated(content::RenderViewHost* render_view_host) {
if (ShouldProcessRenderViewCreated())
delegate_->InstantPageRenderViewCreated(contents());
@@ -307,14 +319,35 @@ void InstantPage::OnSearchBoxNavigate(int page_id,
contents(), url, transition, disposition, is_search_type);
}
-void InstantPage::OnDeleteMostVisitedItem(const GURL& url) {
+void InstantPage::OnDeleteMostVisitedItem(int page_id, const GURL& url) {
+ if (!contents()->IsActiveEntry(page_id))
+ return;
+
+ OnInstantSupportDetermined(page_id, true);
+ if (!ShouldProcessDeleteMostVisitedItem())
+ return;
+
delegate_->DeleteMostVisitedItem(url);
}
-void InstantPage::OnUndoMostVisitedDeletion(const GURL& url) {
+void InstantPage::OnUndoMostVisitedDeletion(int page_id, const GURL& url) {
+ if (!contents()->IsActiveEntry(page_id))
+ return;
+
+ OnInstantSupportDetermined(page_id, true);
+ if (!ShouldProcessUndoMostVisitedDeletion())
+ return;
+
delegate_->UndoMostVisitedDeletion(url);
}
-void InstantPage::OnUndoAllMostVisitedDeletions() {
+void InstantPage::OnUndoAllMostVisitedDeletions(int page_id) {
+ if (!contents()->IsActiveEntry(page_id))
+ return;
+
+ OnInstantSupportDetermined(page_id, true);
+ if (!ShouldProcessUndoAllMostVisitedDeletions())
+ return;
+
delegate_->UndoAllMostVisitedDeletions();
}
diff --git a/chrome/browser/ui/search/instant_page.h b/chrome/browser/ui/search/instant_page.h
index 7c3d719..e96b980 100644
--- a/chrome/browser/ui/search/instant_page.h
+++ b/chrome/browser/ui/search/instant_page.h
@@ -209,7 +209,7 @@ class InstantPage : public content::WebContentsObserver {
// These functions are called before processing messages received from the
// page. By default, all messages are handled, but any derived classes may
- // choose to ingore some or all of the received messages by overriding these
+ // choose to ignore some or all of the received messages by overriding these
// methods.
virtual bool ShouldProcessRenderViewCreated();
virtual bool ShouldProcessRenderViewGone();
@@ -218,6 +218,9 @@ class InstantPage : public content::WebContentsObserver {
virtual bool ShouldProcessShowInstantOverlay();
virtual bool ShouldProcessFocusOmnibox();
virtual bool ShouldProcessNavigateToURL();
+ virtual bool ShouldProcessDeleteMostVisitedItem();
+ virtual bool ShouldProcessUndoMostVisitedDeletion();
+ virtual bool ShouldProcessUndoAllMostVisitedDeletions();
private:
FRIEND_TEST_ALL_PREFIXES(InstantPageTest,
@@ -226,6 +229,10 @@ class InstantPage : public content::WebContentsObserver {
DispatchRequestToUndoMostVisitedDeletion);
FRIEND_TEST_ALL_PREFIXES(InstantPageTest,
DispatchRequestToUndoAllMostVisitedDeletions);
+ FRIEND_TEST_ALL_PREFIXES(InstantPageTest,
+ IgnoreMessageIfThePageIsNotActive);
+ FRIEND_TEST_ALL_PREFIXES(InstantPageTest,
+ IgnoreMessageReceivedFromThePage);
// Overridden from content::WebContentsObserver:
virtual void RenderViewCreated(
@@ -266,9 +273,9 @@ class InstantPage : public content::WebContentsObserver {
content::PageTransition transition,
WindowOpenDisposition disposition,
bool is_search_type);
- void OnDeleteMostVisitedItem(const GURL& url);
- void OnUndoMostVisitedDeletion(const GURL& url);
- void OnUndoAllMostVisitedDeletions();
+ void OnDeleteMostVisitedItem(int page_id, const GURL& url);
+ void OnUndoMostVisitedDeletion(int page_id, const GURL& url);
+ void OnUndoAllMostVisitedDeletions(int page_id);
Delegate* const delegate_;
const std::string instant_url_;
diff --git a/chrome/browser/ui/search/instant_page_unittest.cc b/chrome/browser/ui/search/instant_page_unittest.cc
index 592c510..c9830ee 100644
--- a/chrome/browser/ui/search/instant_page_unittest.cc
+++ b/chrome/browser/ui/search/instant_page_unittest.cc
@@ -8,6 +8,8 @@
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
+#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/mock_render_process_host.h"
#include "googleurl/src/gurl.h"
@@ -57,15 +59,49 @@ class FakePageDelegate : public InstantPage::Delegate {
class FakePage : public InstantPage {
public:
- FakePage(Delegate* delegate, const std::string& instant_url)
- : InstantPage(delegate, instant_url) {
- }
- virtual ~FakePage() {
- }
+ FakePage(Delegate* delegate, const std::string& instant_url);
+ virtual ~FakePage();
+
+ // InstantPage overrride.
+ virtual bool ShouldProcessDeleteMostVisitedItem() OVERRIDE;
+ virtual bool ShouldProcessUndoMostVisitedDeletion() OVERRIDE;
+ virtual bool ShouldProcessUndoAllMostVisitedDeletions() OVERRIDE;
+
+ void set_should_handle_messages(bool should_handle_messages);
using InstantPage::SetContents;
+
+ private:
+ // Initialized to true to handle the messages sent by the renderer.
+ bool should_handle_messages_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakePage);
};
+FakePage::FakePage(Delegate* delegate, const std::string& instant_url)
+ : InstantPage(delegate, instant_url),
+ should_handle_messages_(true) {
+}
+
+FakePage::~FakePage() {
+}
+
+void FakePage::set_should_handle_messages(bool should_handle_messages) {
+ should_handle_messages_ = should_handle_messages;
+}
+
+bool FakePage::ShouldProcessDeleteMostVisitedItem() {
+ return should_handle_messages_;
+}
+
+bool FakePage::ShouldProcessUndoMostVisitedDeletion() {
+ return should_handle_messages_;
+}
+
+bool FakePage::ShouldProcessUndoAllMostVisitedDeletions() {
+ return should_handle_messages_;
+}
+
} // namespace
class InstantPageTest : public ChromeRenderViewHostTestHarness {
@@ -115,28 +151,85 @@ TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) {
TEST_F(InstantPageTest, DispatchRequestToDeleteMostVisitedItem) {
page.reset(new FakePage(&delegate, ""));
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(1);
EXPECT_TRUE(page->OnMessageReceived(
ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(rvh()->GetRoutingID(),
- item_url)));
+ page_id, item_url)));
}
TEST_F(InstantPageTest, DispatchRequestToUndoMostVisitedDeletion) {
page.reset(new FakePage(&delegate, ""));
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, UndoMostVisitedDeletion(item_url)).Times(1);
EXPECT_TRUE(page->OnMessageReceived(
ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(rvh()->GetRoutingID(),
- item_url)));
+ page_id, item_url)));
}
TEST_F(InstantPageTest, DispatchRequestToUndoAllMostVisitedDeletions) {
page.reset(new FakePage(&delegate, ""));
page->SetContents(web_contents());
+ NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
+ int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID();
EXPECT_CALL(delegate, UndoAllMostVisitedDeletions()).Times(1);
EXPECT_TRUE(page->OnMessageReceived(
ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
- rvh()->GetRoutingID())));
+ rvh()->GetRoutingID(), page_id)));
+}
+
+TEST_F(InstantPageTest, IgnoreMessageIfThePageIsNotActive) {
+ page.reset(new FakePage(&delegate, ""));
+ page->SetContents(web_contents());
+ NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
+ GURL item_url("www.foo.com");
+ int inactive_page_id = 1999;
+
+ EXPECT_CALL(delegate, DeleteMostVisitedItem(item_url)).Times(0);
+ EXPECT_TRUE(page->OnMessageReceived(
+ ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(rvh()->GetRoutingID(),
+ inactive_page_id,
+ item_url)));
+
+ EXPECT_CALL(delegate, UndoMostVisitedDeletion(item_url)).Times(0);
+ EXPECT_TRUE(page->OnMessageReceived(
+ ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(rvh()->GetRoutingID(),
+ inactive_page_id,
+ item_url)));
+
+ EXPECT_CALL(delegate, UndoAllMostVisitedDeletions()).Times(0);
+ EXPECT_TRUE(page->OnMessageReceived(
+ ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
+ rvh()->GetRoutingID(), inactive_page_id)));
+}
+
+TEST_F(InstantPageTest, IgnoreMessageReceivedFromThePage) {
+ page.reset(new FakePage(&delegate, ""));
+ page->SetContents(web_contents());
+
+ // Ignore the messages received from the page.
+ page->set_should_handle_messages(false);
+ 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_TRUE(page->OnMessageReceived(
+ ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(rvh()->GetRoutingID(),
+ page_id, item_url)));
+
+ EXPECT_CALL(delegate, UndoMostVisitedDeletion(item_url)).Times(0);
+ EXPECT_TRUE(page->OnMessageReceived(
+ ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(rvh()->GetRoutingID(),
+ page_id, item_url)));
+
+ EXPECT_CALL(delegate, UndoAllMostVisitedDeletions()).Times(0);
+ EXPECT_TRUE(page->OnMessageReceived(
+ ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
+ rvh()->GetRoutingID(), page_id)));
}
diff --git a/chrome/browser/ui/search/instant_tab.cc b/chrome/browser/ui/search/instant_tab.cc
index d92688a..e1c5b2a 100644
--- a/chrome/browser/ui/search/instant_tab.cc
+++ b/chrome/browser/ui/search/instant_tab.cc
@@ -33,3 +33,15 @@ bool InstantTab::ShouldProcessFocusOmnibox() {
bool InstantTab::ShouldProcessNavigateToURL() {
return true;
}
+
+bool InstantTab::ShouldProcessDeleteMostVisitedItem() {
+ return true;
+}
+
+bool InstantTab::ShouldProcessUndoMostVisitedDeletion() {
+ return true;
+}
+
+bool InstantTab::ShouldProcessUndoAllMostVisitedDeletions() {
+ return true;
+}
diff --git a/chrome/browser/ui/search/instant_tab.h b/chrome/browser/ui/search/instant_tab.h
index 43b7fc6..6951c58 100644
--- a/chrome/browser/ui/search/instant_tab.h
+++ b/chrome/browser/ui/search/instant_tab.h
@@ -26,6 +26,9 @@ class InstantTab : public InstantPage {
virtual bool ShouldProcessSetSuggestions() OVERRIDE;
virtual bool ShouldProcessFocusOmnibox() OVERRIDE;
virtual bool ShouldProcessNavigateToURL() OVERRIDE;
+ virtual bool ShouldProcessDeleteMostVisitedItem() OVERRIDE;
+ virtual bool ShouldProcessUndoMostVisitedDeletion() OVERRIDE;
+ virtual bool ShouldProcessUndoAllMostVisitedDeletions() OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(InstantTab);
};
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index a54d64f..70d5ac7 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -370,13 +370,16 @@ IPC_MESSAGE_ROUTED2(ChromeViewMsg_SearchBoxFocusChanged,
IPC_MESSAGE_ROUTED1(ChromeViewMsg_SearchBoxMostVisitedItemsChanged,
std::vector<InstantMostVisitedItem> /* items */)
-IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem,
+IPC_MESSAGE_ROUTED2(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem,
+ int /* page_id */,
GURL /* url */)
-IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion,
+IPC_MESSAGE_ROUTED2(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion,
+ int /* page_id */,
GURL /* url */)
-IPC_MESSAGE_ROUTED0(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions)
+IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions,
+ int /* page_id */)
IPC_MESSAGE_ROUTED0(ChromeViewMsg_SearchBoxToggleVoiceSearch)
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
index 8e1121c..129420c 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -132,21 +132,21 @@ void SearchBox::NavigateToURL(const GURL& url,
void SearchBox::DeleteMostVisitedItem(
InstantRestrictedID most_visited_item_id) {
render_view()->Send(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
- render_view()->GetRoutingID(),
+ render_view()->GetRoutingID(), render_view()->GetPageId(),
GetURLForMostVisitedItem(most_visited_item_id)));
}
void SearchBox::UndoMostVisitedDeletion(
InstantRestrictedID most_visited_item_id) {
render_view()->Send(new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
- render_view()->GetRoutingID(),
+ render_view()->GetRoutingID(), render_view()->GetPageId(),
GetURLForMostVisitedItem(most_visited_item_id)));
}
void SearchBox::UndoAllMostVisitedDeletions() {
render_view()->Send(
new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
- render_view()->GetRoutingID()));
+ render_view()->GetRoutingID(), render_view()->GetPageId()));
}
void SearchBox::ShowBars() {