From cf430e2ea4fb5a3e65cb4ca16061ac6663d0ab1c Mon Sep 17 00:00:00 2001 From: "aa@chromium.org" Date: Thu, 16 Jul 2009 18:04:36 +0000 Subject: Fix for bug where we would not create ExtensionFunctionDispatcher instances for ExtensionDOMUI if RenderView was reused. BUG=16853 TEST=Added browser test Review URL: http://codereview.chromium.org/155592 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20880 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/dom_ui/dom_ui.h | 8 ++++++++ chrome/browser/extensions/extension_browsertests_misc.cc | 12 ++++++++++++ chrome/browser/extensions/extension_dom_ui.cc | 6 ++++++ chrome/browser/extensions/extension_dom_ui.h | 1 + chrome/browser/tab_contents/render_view_host_manager.cc | 3 +++ 5 files changed, 30 insertions(+) diff --git a/chrome/browser/dom_ui/dom_ui.h b/chrome/browser/dom_ui/dom_ui.h index fad04e5..d5204b1 100644 --- a/chrome/browser/dom_ui/dom_ui.h +++ b/chrome/browser/dom_ui/dom_ui.h @@ -29,8 +29,16 @@ class DOMUI { explicit DOMUI(TabContents* contents); virtual ~DOMUI(); + // Called by RenderViewHost when the RenderView is first created. This is + // *not* called for every page load because in some cases + // RenderViewHostManager will reuse RenderView instances. In those cases, + // RenderViewReused will be called instead. virtual void RenderViewCreated(RenderViewHost* render_view_host) {} + // Called by RenderViewHostManager when a RenderView is reused to display a + // page. + virtual void RenderViewReused(RenderViewHost* render_view_host) {} + // Called from DOMUIContents. virtual void ProcessDOMUIMessage(const std::string& message, const std::string& content, diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index 99c8b19..48fb0ca 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -131,6 +131,18 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TabContents) { browser()->GetSelectedTabContents()->render_view_host(), L"", L"testTabsAPI()", &result); EXPECT_TRUE(result); + + // There was a bug where we would crash if we navigated to a page in the same + // extension because no new render view was getting created, so we would not + // do some setup. + ui_test_utils::NavigateToURL( + browser(), + GURL("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html")); + result = false; + ui_test_utils::ExecuteJavaScriptAndExtractBool( + browser()->GetSelectedTabContents()->render_view_host(), L"", + L"testTabsAPI()", &result); + EXPECT_TRUE(result); } // Tests that we can load page actions in the Omnibox. diff --git a/chrome/browser/extensions/extension_dom_ui.cc b/chrome/browser/extensions/extension_dom_ui.cc index 0d24345..2fa4eb3 100644 --- a/chrome/browser/extensions/extension_dom_ui.cc +++ b/chrome/browser/extensions/extension_dom_ui.cc @@ -18,6 +18,12 @@ void ExtensionDOMUI::RenderViewCreated(RenderViewHost* render_view_host) { tab_contents()->GetURL())); } +void ExtensionDOMUI::RenderViewReused(RenderViewHost* render_view_host) { + extension_function_dispatcher_.reset( + new ExtensionFunctionDispatcher(render_view_host, this, + tab_contents()->GetURL())); +} + void ExtensionDOMUI::ProcessDOMUIMessage(const std::string& message, const std::string& content, int request_id, diff --git a/chrome/browser/extensions/extension_dom_ui.h b/chrome/browser/extensions/extension_dom_ui.h index 2de94cf..d80c503 100644 --- a/chrome/browser/extensions/extension_dom_ui.h +++ b/chrome/browser/extensions/extension_dom_ui.h @@ -18,6 +18,7 @@ class ExtensionDOMUI // DOMUI virtual void RenderViewCreated(RenderViewHost* render_view_host); + virtual void RenderViewReused(RenderViewHost* render_view_host); virtual void ProcessDOMUIMessage(const std::string& message, const std::string& content, int request_id, diff --git a/chrome/browser/tab_contents/render_view_host_manager.cc b/chrome/browser/tab_contents/render_view_host_manager.cc index a34668c..e5b3645 100644 --- a/chrome/browser/tab_contents/render_view_host_manager.cc +++ b/chrome/browser/tab_contents/render_view_host_manager.cc @@ -564,6 +564,9 @@ RenderViewHost* RenderViewHostManager::UpdateRendererStateForNavigate( return pending_render_view_host_; } else { + if (pending_dom_ui_.get() && render_view_host_->IsRenderViewLive()) + pending_dom_ui_->RenderViewReused(render_view_host_); + // The renderer can exit view source mode when any error or cancellation // happen. We must overwrite to recover the mode. if (entry.IsViewSourceMode()) { -- cgit v1.1