diff --git a/chrome/browser/apps/web_view_browsertest.cc b/chrome/browser/apps/web_view_browsertest.cc index d63c05794ae9..9526aab62fc4 100644 --- a/chrome/browser/apps/web_view_browsertest.cc +++ b/chrome/browser/apps/web_view_browsertest.cc @@ -730,6 +730,13 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPI) { "web_view/shim"); } +IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIGoogleProperty) { + TestHelper("testWebRequestAPIGoogleProperty", + "DoneShimTest.PASSED", + "DoneShimTest.FAILED", + "web_view/shim"); +} + IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadStartLoadRedirect) { TestHelper("testLoadStartLoadRedirect", "DoneShimTest.PASSED", diff --git a/chrome/browser/extensions/api/web_request/web_request_permissions.cc b/chrome/browser/extensions/api/web_request/web_request_permissions.cc index 7b7e6af2b081..480bf8471818 100644 --- a/chrome/browser/extensions/api/web_request/web_request_permissions.cc +++ b/chrome/browser/extensions/api/web_request/web_request_permissions.cc @@ -7,6 +7,7 @@ #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "chrome/browser/extensions/extension_info_map.h" +#include "chrome/browser/extensions/extension_renderer_state.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/permissions/permissions_data.h" @@ -82,12 +83,21 @@ bool WebRequestPermissions::HideRequest( const net::URLRequest* request) { // Hide requests from the Chrome WebStore App or signin process. const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); - if (info && extension_info_map) { + if (info) { int process_id = info->GetChildID(); - if (extension_info_map->IsSigninProcess(process_id) || + int route_id = info->GetRouteID(); + ExtensionRendererState::WebViewInfo webview_info; + // Never hide requests from guest processes. + if (ExtensionRendererState::GetInstance()->GetWebViewInfo( + process_id, route_id, &webview_info)) { + return false; + } + if (extension_info_map && ( + extension_info_map->IsSigninProcess(process_id) || extension_info_map->process_map().Contains( - extension_misc::kWebStoreAppId, process_id)) + extension_misc::kWebStoreAppId, process_id))) { return true; + } } const GURL& url = request->url(); diff --git a/chrome/browser/extensions/api/web_request/web_request_permissions_unittest.cc b/chrome/browser/extensions/api/web_request/web_request_permissions_unittest.cc index d2858234fb76..ece2ee232188 100644 --- a/chrome/browser/extensions/api/web_request/web_request_permissions_unittest.cc +++ b/chrome/browser/extensions/api/web_request/web_request_permissions_unittest.cc @@ -68,10 +68,8 @@ void ExtensionWebRequestHelpersTestWithThreadsTest::SetUp() { com_extension_.get(), base::Time::Now(), false /*incognito_enabled*/); } -TEST(ExtensionWebRequestHelpersTest, TestHideRequestForURL) { - base::MessageLoopForIO message_loop; +TEST_F(ExtensionWebRequestHelpersTestWithThreadsTest, TestHideRequestForURL) { net::TestURLRequestContext context; - scoped_refptr extension_info_map(new ExtensionInfoMap); const char* sensitive_urls[] = { "http://clients2.google.com", "http://clients22.google.com", @@ -88,14 +86,14 @@ TEST(ExtensionWebRequestHelpersTest, TestHideRequestForURL) { "http://www.google.com/" }; const int kSigninProcessId = 99; - extension_info_map->SetSigninProcess(kSigninProcessId); + extension_info_map_->SetSigninProcess(kSigninProcessId); // Check that requests are rejected based on the destination for (size_t i = 0; i < arraysize(sensitive_urls); ++i) { GURL sensitive_url(sensitive_urls[i]); net::TestURLRequest request(sensitive_url, NULL, &context, NULL); EXPECT_TRUE( - WebRequestPermissions::HideRequest(extension_info_map.get(), &request)) + WebRequestPermissions::HideRequest(extension_info_map_.get(), &request)) << sensitive_urls[i]; } // Check that requests are accepted if they don't touch sensitive urls. @@ -103,7 +101,7 @@ TEST(ExtensionWebRequestHelpersTest, TestHideRequestForURL) { GURL non_sensitive_url(non_sensitive_urls[i]); net::TestURLRequest request(non_sensitive_url, NULL, &context, NULL); EXPECT_FALSE( - WebRequestPermissions::HideRequest(extension_info_map.get(), &request)) + WebRequestPermissions::HideRequest(extension_info_map_.get(), &request)) << non_sensitive_urls[i]; } @@ -113,7 +111,7 @@ TEST(ExtensionWebRequestHelpersTest, TestHideRequestForURL) { GURL non_sensitive_url("http://www.google.com/test.js"); net::TestURLRequest non_sensitive_request( non_sensitive_url, NULL, &context, NULL); - EXPECT_FALSE(WebRequestPermissions::HideRequest(extension_info_map.get(), + EXPECT_FALSE(WebRequestPermissions::HideRequest(extension_info_map_.get(), &non_sensitive_request)); // If the origin is labeled by the WebStoreAppId, it becomes protected. { @@ -124,9 +122,9 @@ TEST(ExtensionWebRequestHelpersTest, TestHideRequestForURL) { non_sensitive_url, NULL, &context, NULL); ResourceRequestInfo::AllocateForTesting(&sensitive_request, ResourceType::SCRIPT, NULL, process_id, frame_id); - extension_info_map->RegisterExtensionProcess(extension_misc::kWebStoreAppId, - process_id, site_instance_id); - EXPECT_TRUE(WebRequestPermissions::HideRequest(extension_info_map.get(), + extension_info_map_->RegisterExtensionProcess( + extension_misc::kWebStoreAppId, process_id, site_instance_id); + EXPECT_TRUE(WebRequestPermissions::HideRequest(extension_info_map_.get(), &sensitive_request)); } // If the process is the signin process, it becomes protected. @@ -137,7 +135,7 @@ TEST(ExtensionWebRequestHelpersTest, TestHideRequestForURL) { non_sensitive_url, NULL, &context, NULL); ResourceRequestInfo::AllocateForTesting(&sensitive_request, ResourceType::SCRIPT, NULL, process_id, frame_id); - EXPECT_TRUE(WebRequestPermissions::HideRequest(extension_info_map.get(), + EXPECT_TRUE(WebRequestPermissions::HideRequest(extension_info_map_.get(), &sensitive_request)); } } diff --git a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js index 03bf28ea90d1..ee7bb4dc05ec 100644 --- a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js +++ b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js @@ -695,6 +695,23 @@ function testWebRequestAPI() { document.body.appendChild(webview); } +// This test verifies that the WebRequest API onBeforeRequest event fires on +// clients*.google.com URLs. +function testWebRequestAPIGoogleProperty() { + var webview = document.createElement('webview'); + webview.setAttribute('src', 'data:text/html,trigger navigation'); + var firstLoad = function() { + webview.removeEventListener('loadstop', firstLoad); + webview.onBeforeRequest.addListener(function(e) { + embedder.test.succeed(); + return {cancel: true}; + }, { urls: ['']}, ['blocking']) ; + webview.src = 'http://clients6.google.com'; + }; + webview.addEventListener('loadstop', firstLoad); + document.body.appendChild(webview); +} + // This test verifies that getProcessId is defined and returns a non-zero // value corresponding to the processId of the guest process. function testGetProcessId() { @@ -853,6 +870,7 @@ embedder.test.testList = { 'testNewWindowNoReferrerLink': testNewWindowNoReferrerLink, 'testContentLoadEvent': testContentLoadEvent, 'testWebRequestAPI': testWebRequestAPI, + 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty, 'testGetProcessId': testGetProcessId, 'testLoadStartLoadRedirect': testLoadStartLoadRedirect, 'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse,