diff options
author | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-04 00:19:00 +0000 |
---|---|---|
committer | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-04 00:19:00 +0000 |
commit | 24a6ccbb61dfad787afd8d199b9a1b278c00fa6f (patch) | |
tree | 9fe0a149bf0855bc2aed29b57d71f5bd6c313164 | |
parent | b76257d27a5916f9a2b5d80f8800ed1eef300a0b (diff) | |
download | chromium_src-24a6ccbb61dfad787afd8d199b9a1b278c00fa6f.zip chromium_src-24a6ccbb61dfad787afd8d199b9a1b278c00fa6f.tar.gz chromium_src-24a6ccbb61dfad787afd8d199b9a1b278c00fa6f.tar.bz2 |
Modify the IsNaClAllowed test to allow MIME type handling plugins.
The code to check whether to allow an invocation of NaCl doesn't
work correctly for content (MIME type) handlers. Change the app
URL checking code in that case.
BUG=235962
TEST=browser_tests, --gtest_filter="NaClExtensionTest.*"
R=jochen@chromium.org, jorgelo@chromium.org
Review URL: https://codereview.chromium.org/14796002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198259 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_nacl_browsertest.cc | 38 | ||||
-rw-r--r-- | chrome/renderer/chrome_content_renderer_client.cc | 31 | ||||
-rw-r--r-- | chrome/renderer/chrome_content_renderer_client.h | 2 |
3 files changed, 47 insertions, 24 deletions
diff --git a/chrome/browser/extensions/extension_nacl_browsertest.cc b/chrome/browser/extensions/extension_nacl_browsertest.cc index afb4c64..3d27049 100644 --- a/chrome/browser/extensions/extension_nacl_browsertest.cc +++ b/chrome/browser/extensions/extension_nacl_browsertest.cc @@ -46,6 +46,14 @@ class NaClExtensionTest : public ExtensionBrowserTest { INSTALL_TYPE_FROM_WEBSTORE, INSTALL_TYPE_NON_WEBSTORE, }; + enum PluginType { + PLUGIN_TYPE_NONE = 0, + PLUGIN_TYPE_EMBED = 1, + PLUGIN_TYPE_CONTENT_HANDLER = 2, + PLUGIN_TYPE_ALL = PLUGIN_TYPE_EMBED | + PLUGIN_TYPE_CONTENT_HANDLER, + }; + const Extension* InstallExtension(const base::FilePath& file_path, InstallType install_type) { @@ -105,7 +113,7 @@ class NaClExtensionTest : public ExtensionBrowserTest { return false; } - void CheckPluginsCreated(const GURL& url, bool should_create) { + void CheckPluginsCreated(const GURL& url, PluginType expected_to_succeed) { ui_test_utils::NavigateToURL(browser(), url); // Don't run tests if the NaCl plugin isn't loaded. if (!IsNaClPluginLoaded()) @@ -124,12 +132,16 @@ class NaClExtensionTest : public ExtensionBrowserTest { "window.domAutomationController.send(ContentHandlerPluginCreated());", &content_handler_plugin_created)); - EXPECT_EQ(should_create, embedded_plugin_created); - EXPECT_EQ(should_create, content_handler_plugin_created); + EXPECT_EQ(embedded_plugin_created, + (expected_to_succeed & PLUGIN_TYPE_EMBED) != 0); + EXPECT_EQ(content_handler_plugin_created, + (expected_to_succeed & PLUGIN_TYPE_CONTENT_HANDLER) != 0); } - void CheckPluginsCreated(const Extension* extension, bool should_create) { - CheckPluginsCreated(extension->GetResourceURL("test.html"), should_create); + void CheckPluginsCreated(const Extension* extension, + PluginType expected_to_succeed) { + CheckPluginsCreated(extension->GetResourceURL("test.html"), + expected_to_succeed); } }; @@ -140,7 +152,7 @@ IN_PROC_BROWSER_TEST_F(NaClExtensionTest, WebStoreExtension) { const Extension* extension = InstallExtension(INSTALL_TYPE_FROM_WEBSTORE); ASSERT_TRUE(extension); - CheckPluginsCreated(extension, true); + CheckPluginsCreated(extension, PLUGIN_TYPE_ALL); } // Test that the NaCl plugin is blocked for non-Webstore extensions. @@ -149,7 +161,7 @@ IN_PROC_BROWSER_TEST_F(NaClExtensionTest, NonWebStoreExtension) { const Extension* extension = InstallExtension(INSTALL_TYPE_NON_WEBSTORE); ASSERT_TRUE(extension); - CheckPluginsCreated(extension, false); + CheckPluginsCreated(extension, PLUGIN_TYPE_NONE); } // Test that the NaCl plugin isn't blocked for component extensions. @@ -159,7 +171,7 @@ IN_PROC_BROWSER_TEST_F(NaClExtensionTest, ComponentExtension) { const Extension* extension = InstallExtension(INSTALL_TYPE_COMPONENT); ASSERT_TRUE(extension); ASSERT_EQ(extension->location(), Manifest::COMPONENT); - CheckPluginsCreated(extension, true); + CheckPluginsCreated(extension, PLUGIN_TYPE_ALL); } // Test that the NaCl plugin isn't blocked for unpacked extensions. @@ -169,17 +181,19 @@ IN_PROC_BROWSER_TEST_F(NaClExtensionTest, UnpackedExtension) { const Extension* extension = InstallExtension(INSTALL_TYPE_UNPACKED); ASSERT_TRUE(extension); ASSERT_EQ(extension->location(), Manifest::UNPACKED); - CheckPluginsCreated(extension, true); + CheckPluginsCreated(extension, PLUGIN_TYPE_ALL); } -// Test that the NaCl plugin is blocked for non chrome-extension urls. +// Test that the NaCl plugin is blocked for non chrome-extension urls, except +// if it's a content (MIME type) handler. IN_PROC_BROWSER_TEST_F(NaClExtensionTest, NonExtensionScheme) { ASSERT_TRUE(test_server()->Start()); const Extension* extension = InstallExtension(INSTALL_TYPE_FROM_WEBSTORE); ASSERT_TRUE(extension); CheckPluginsCreated( - test_server()->GetURL("files/extensions/native_client/test.html"), false); + test_server()->GetURL("files/extensions/native_client/test.html"), + PLUGIN_TYPE_CONTENT_HANDLER); } // Test that NaCl plugin isn't blocked for hosted app URLs. @@ -196,7 +210,7 @@ IN_PROC_BROWSER_TEST_F(NaClExtensionTest, HostedApp) { const Extension* extension = InstallHostedApp(); ASSERT_TRUE(extension); - CheckPluginsCreated(url, true); + CheckPluginsCreated(url, PLUGIN_TYPE_ALL); } } // namespace diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index 34ed018..f4e8285 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -587,14 +587,23 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( is_nacl_unrestricted = true; } if (is_nacl_plugin || is_nacl_mime_type) { - GURL manifest_url = is_nacl_mime_type ? - url : GetNaClContentHandlerURL(actual_mime_type, plugin); + GURL manifest_url; + GURL app_url; + if (is_nacl_mime_type) { + // Normal NaCl embed. The app URL is the page URL. + manifest_url = url; + app_url = frame->top()->document().url(); + } else { + // NaCl is being invoked as a content handler. Look up the NaCl + // module using the MIME type. The app URL is the manifest URL. + manifest_url = GetNaClContentHandlerURL(actual_mime_type, plugin); + app_url = manifest_url; + } const Extension* extension = g_current_client->extension_dispatcher_->extensions()-> GetExtensionOrAppByURL(ExtensionURLInfo(manifest_url)); - GURL top_url = frame->top()->document().url(); if (!IsNaClAllowed(manifest_url, - top_url, + app_url, is_nacl_unrestricted, extension, ¶ms)) { @@ -736,32 +745,32 @@ GURL ChromeContentRendererClient::GetNaClContentHandlerURL( // static bool ChromeContentRendererClient::IsNaClAllowed( const GURL& manifest_url, - const GURL& top_url, + const GURL& app_url, bool is_nacl_unrestricted, const Extension* extension, WebPluginParams* params) { // Temporarily allow these URLs to run NaCl apps. We should remove this // code when PNaCl ships. bool is_whitelisted_url = - top_url.SchemeIs("https") && - (top_url.host() == "plus.google.com" || - top_url.host() == "plus.sandbox.google.com"); + app_url.SchemeIs("https") && + (app_url.host() == "plus.google.com" || + app_url.host() == "plus.sandbox.google.com"); bool is_extension_from_webstore = extension && extension->from_webstore(); bool is_invoked_by_hosted_app = extension && extension->is_hosted_app() && - extension->web_extent().MatchesURL(top_url); + extension->web_extent().MatchesURL(app_url); // Allow built-in extensions and extensions under development. bool is_extension_unrestricted = extension && (extension->location() == extensions::Manifest::COMPONENT || extensions::Manifest::IsUnpackedLocation(extension->location())); - bool is_invoked_by_extension = top_url.SchemeIs("chrome-extension"); + bool is_invoked_by_extension = app_url.SchemeIs("chrome-extension"); - // NaCl PDF viewer can be loaded from all URLs. + // The NaCl PDF viewer is always allowed and can use 'Dev' interfaces. bool is_nacl_pdf_viewer = (is_extension_from_webstore && manifest_url.SchemeIs("chrome-extension") && diff --git a/chrome/renderer/chrome_content_renderer_client.h b/chrome/renderer/chrome_content_renderer_client.h index 2aa2b30..937f9fc 100644 --- a/chrome/renderer/chrome_content_renderer_client.h +++ b/chrome/renderer/chrome_content_renderer_client.h @@ -165,7 +165,7 @@ class ChromeContentRendererClient : public content::ContentRendererClient { static GURL GetNaClContentHandlerURL(const std::string& actual_mime_type, const webkit::WebPluginInfo& plugin); static bool IsNaClAllowed(const GURL& manifest_url, - const GURL& top_url, + const GURL& app_url, bool is_nacl_unrestricted, const extensions::Extension* extension, WebKit::WebPluginParams* params); |