Skip to content

Commit

Permalink
<webview>: Expose all URLs to WebRequest API
Browse files Browse the repository at this point in the history
Some URLs are blacklisted from the WebRequest extensions API. <webview>'s WebRequest API should not be affected by this blacklist.

BUG=276706
Test=WebViewTest.Shim_TestWebRequestAPIGoogleProperty

Review URL: https://chromiumcodereview.appspot.com/23088011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218999 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
fsamuel@chromium.org committed Aug 22, 2013
1 parent 28c9a74 commit 7794f0f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
7 changes: 7 additions & 0 deletions chrome/browser/apps/web_view_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtensionInfoMap> extension_info_map(new ExtensionInfoMap);
const char* sensitive_urls[] = {
"http://clients2.google.com",
"http://clients22.google.com",
Expand All @@ -88,22 +86,22 @@ 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.
for (size_t i = 0; i < arraysize(non_sensitive_urls); ++i) {
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];
}

Expand All @@ -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.
{
Expand All @@ -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.
Expand All @@ -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));
}
}
Expand Down
18 changes: 18 additions & 0 deletions chrome/test/data/extensions/platform_apps/web_view/shim/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ['<all_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() {
Expand Down Expand Up @@ -853,6 +870,7 @@ embedder.test.testList = {
'testNewWindowNoReferrerLink': testNewWindowNoReferrerLink,
'testContentLoadEvent': testContentLoadEvent,
'testWebRequestAPI': testWebRequestAPI,
'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty,
'testGetProcessId': testGetProcessId,
'testLoadStartLoadRedirect': testLoadStartLoadRedirect,
'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse,
Expand Down

0 comments on commit 7794f0f

Please sign in to comment.