diff options
-rw-r--r-- | chrome/browser/chrome_content_browser_client.cc | 11 | ||||
-rw-r--r-- | chrome/browser/extensions/chrome_app_api_browsertest.cc | 35 | ||||
-rw-r--r-- | chrome/common/extensions/extension_messages.h | 4 | ||||
-rw-r--r-- | chrome/renderer/extensions/chrome_app_bindings.cc | 7 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_dispatcher.cc | 15 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_dispatcher.h | 7 |
6 files changed, 57 insertions, 22 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 6f09c2f..dfde2e9 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -101,11 +101,14 @@ void InitRenderViewHostForExtensions(RenderViewHost* render_view_host) { // ExtensionProcessManager. process_manager->RegisterExtensionProcess(extension->id(), process->id()); - // Record which, if any, installed app is associated with this process. - // TODO(aa): Totally lame to store this state in a global map in extension - // service. Can we get it from EPM instead? - if (extension->is_app()) + if (extension->is_app()) { + render_view_host->Send( + new ExtensionMsg_ActivateApplication(extension->id())); + // Record which, if any, installed app is associated with this process. + // TODO(aa): Totally lame to store this state in a global map in extension + // service. Can we get it from EPM instead? service->SetInstalledAppForRenderer(process->id(), extension); + } // Some extensions use chrome:// URLs. Extension::Type type = extension->GetType(); diff --git a/chrome/browser/extensions/chrome_app_api_browsertest.cc b/chrome/browser/extensions/chrome_app_api_browsertest.cc index ff4c638..2fafc94 100644 --- a/chrome/browser/extensions/chrome_app_api_browsertest.cc +++ b/chrome/browser/extensions/chrome_app_api_browsertest.cc @@ -19,6 +19,18 @@ #include "net/base/mock_host_resolver.h" class ChromeAppAPITest : public ExtensionBrowserTest { + protected: + bool IsAppInstalled() { + std::wstring get_app_is_installed = + L"window.domAutomationController.send(window.chrome.app.isInstalled);"; + bool result; + CHECK( + ui_test_utils::ExecuteJavaScriptAndExtractBool( + browser()->GetSelectedTabContents()->render_view_host(), + L"", get_app_is_installed, &result)); + return result; + } + private: virtual void SetUpCommandLine(CommandLine* command_line) { ExtensionBrowserTest::SetUpCommandLine(command_line); @@ -44,29 +56,28 @@ IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, IsInstalled) { replace_host.SetHostStr(nonapp_host); GURL non_app_url(test_file_url.ReplaceComponents(replace_host)); + // Before the app is installed, app.com does not think that it is installed + ui_test_utils::NavigateToURL(browser(), app_url); + EXPECT_FALSE(IsAppInstalled()); // Load an app which includes app.com in its extent. const Extension* extension = LoadExtension( test_data_dir_.AppendASCII("app_dot_com_app")); ASSERT_TRUE(extension); + // Even after the app is installed, the existing app.com tab is not in an + // app process, so chrome.app.isInstalled should return false. + EXPECT_FALSE(IsAppInstalled()); // Test that a non-app page has chrome.app.isInstalled = false. ui_test_utils::NavigateToURL(browser(), non_app_url); - std::wstring get_app_is_installed = - L"window.domAutomationController.send(" - L" JSON.stringify(window.chrome.app.isInstalled));"; - std::string result; - ASSERT_TRUE( - ui_test_utils::ExecuteJavaScriptAndExtractString( - browser()->GetSelectedTabContents()->render_view_host(), - L"", get_app_is_installed, &result)); - EXPECT_EQ("false", result); + EXPECT_FALSE(IsAppInstalled()); // Test that a non-app page returns null for chrome.app.getDetails(). std::wstring get_app_details = L"window.domAutomationController.send(" L" JSON.stringify(window.chrome.app.getDetails()));"; + std::string result; ASSERT_TRUE( ui_test_utils::ExecuteJavaScriptAndExtractString( browser()->GetSelectedTabContents()->render_view_host(), @@ -75,11 +86,7 @@ IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, IsInstalled) { // Check that an app page has chrome.app.isInstalled = true. ui_test_utils::NavigateToURL(browser(), app_url); - ASSERT_TRUE( - ui_test_utils::ExecuteJavaScriptAndExtractString( - browser()->GetSelectedTabContents()->render_view_host(), - L"", get_app_is_installed, &result)); - EXPECT_EQ("true", result); + EXPECT_TRUE(IsAppInstalled()); // Check that an app page returns the correct result for // chrome.app.getDetails(). diff --git a/chrome/common/extensions/extension_messages.h b/chrome/common/extensions/extension_messages.h index a20d8b0..6a4318d 100644 --- a/chrome/common/extensions/extension_messages.h +++ b/chrome/common/extensions/extension_messages.h @@ -175,6 +175,10 @@ IPC_MESSAGE_CONTROL1(ExtensionMsg_SetFunctionNames, IPC_MESSAGE_CONTROL1(ExtensionMsg_ActivateExtension, std::string /* extension_id */) +// Marks an application as 'active' in a process. +IPC_MESSAGE_CONTROL1(ExtensionMsg_ActivateApplication, + std::string /* extension_id */) + // Notifies the renderer that an extension was loaded in the browser. IPC_MESSAGE_CONTROL1(ExtensionMsg_Loaded, ExtensionMsg_Loaded_Params) diff --git a/chrome/renderer/extensions/chrome_app_bindings.cc b/chrome/renderer/extensions/chrome_app_bindings.cc index 5c760dd..089c80c 100644 --- a/chrome/renderer/extensions/chrome_app_bindings.cc +++ b/chrome/renderer/extensions/chrome_app_bindings.cc @@ -109,8 +109,11 @@ class ChromeAppExtensionWrapper : public v8::Extension { !(url.SchemeIs("http") || url.SchemeIs("https"))) return v8::Boolean::New(false); - bool has_web_extent = - extension_dispatcher_->extensions()->GetByURL(url) != NULL; + const ::Extension* extension = + extension_dispatcher_->extensions()->GetByURL(frame->url()); + + bool has_web_extent = extension && + extension_dispatcher_->IsApplicationActive(extension->id()); return v8::Boolean::New(has_web_extent); } diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc index c57d037..370f36d 100644 --- a/chrome/renderer/extensions/extension_dispatcher.cc +++ b/chrome/renderer/extensions/extension_dispatcher.cc @@ -64,6 +64,7 @@ bool ExtensionDispatcher::OnControlMessageReceived( IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, OnSetScriptingWhitelist) IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) + IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateApplication, OnActivateApplication) IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -163,7 +164,14 @@ void ExtensionDispatcher::OnSetScriptingWhitelist( Extension::SetScriptingWhitelist(extension_ids); } -bool ExtensionDispatcher::IsExtensionActive(const std::string& extension_id) { +bool ExtensionDispatcher::IsApplicationActive( + const std::string& extension_id) const { + return active_application_ids_.find(extension_id) != + active_application_ids_.end(); +} + +bool ExtensionDispatcher::IsExtensionActive( + const std::string& extension_id) const { return active_extension_ids_.find(extension_id) != active_extension_ids_.end(); } @@ -202,6 +210,11 @@ bool ExtensionDispatcher::AllowScriptExtension( } +void ExtensionDispatcher::OnActivateApplication( + const std::string& extension_id) { + active_application_ids_.insert(extension_id); +} + void ExtensionDispatcher::OnActivateExtension( const std::string& extension_id) { active_extension_ids_.insert(extension_id); diff --git a/chrome/renderer/extensions/extension_dispatcher.h b/chrome/renderer/extensions/extension_dispatcher.h index bce3c0f..8050522 100644 --- a/chrome/renderer/extensions/extension_dispatcher.h +++ b/chrome/renderer/extensions/extension_dispatcher.h @@ -45,7 +45,8 @@ class ExtensionDispatcher : public RenderProcessObserver { const ExtensionSet* extensions() const { return &extensions_; } UserScriptSlave* user_script_slave() { return user_script_slave_.get(); } - bool IsExtensionActive(const std::string& extension_id); + bool IsApplicationActive(const std::string& extension_id) const; + bool IsExtensionActive(const std::string& extension_id) const; // See WebKit::WebPermissionClient::allowScriptExtension bool AllowScriptExtension(WebKit::WebFrame* frame, @@ -71,6 +72,7 @@ class ExtensionDispatcher : public RenderProcessObserver { const Extension::ScriptingWhitelist& extension_ids); void OnPageActionsUpdated(const std::string& extension_id, const std::vector<std::string>& page_actions); + void OnActivateApplication(const std::string& extension_id); void OnActivateExtension(const std::string& extension_id); void OnUpdateUserScripts(base::SharedMemoryHandle table); @@ -107,6 +109,9 @@ class ExtensionDispatcher : public RenderProcessObserver { // The extensions that are active in this process. std::set<std::string> active_extension_ids_; + // The applications that are active in this process. + std::set<std::string> active_application_ids_; + // True once WebKit has been initialized (and it is therefore safe to poke). bool is_webkit_initialized_; |