Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: chrome/browser/chrome_content_browser_client.cc

Issue 9837074: Make it so that allow_js_access: false can be used with background pages created by window.open. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix indentation. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 #else 1262 #else
1263 NOTIMPLEMENTED(); 1263 NOTIMPLEMENTED();
1264 #endif 1264 #endif
1265 } 1265 }
1266 1266
1267 bool ChromeContentBrowserClient::CanCreateWindow( 1267 bool ChromeContentBrowserClient::CanCreateWindow(
1268 const GURL& opener_url, 1268 const GURL& opener_url,
1269 const GURL& source_origin, 1269 const GURL& source_origin,
1270 WindowContainerType container_type, 1270 WindowContainerType container_type,
1271 content::ResourceContext* context, 1271 content::ResourceContext* context,
1272 int render_process_id) { 1272 int render_process_id,
1273 bool* no_javascript_access) {
1273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1275
1276 *no_javascript_access = false;
1277
1274 // If the opener is trying to create a background window but doesn't have 1278 // If the opener is trying to create a background window but doesn't have
1275 // the appropriate permission, fail the attempt. 1279 // the appropriate permission, fail the attempt.
1276 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { 1280 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1277 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1281 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1278 ExtensionInfoMap* map = io_data->GetExtensionInfoMap(); 1282 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1279 1283
1280 // If the opener is not allowed to script its background window, then return 1284 if (!map->SecurityOriginHasAPIPermission(
1281 // false so that the window.open call returns null. In this case, only 1285 source_origin,
1282 // the manifest is permitted to create a background window. 1286 render_process_id,
1287 ExtensionAPIPermission::kBackground)) {
1288 return false;
1289 }
1290
1283 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may 1291 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1284 // return a recently installed Extension even if this CanCreateWindow call 1292 // return a recently installed Extension even if this CanCreateWindow call
1285 // was made by an old copy of the page in a normal web process. That's ok, 1293 // was made by an old copy of the page in a normal web process. That's ok,
1286 // because the permission check below will still fail. We must use the 1294 // because the permission check above would have caused an early return
1287 // full URL to find hosted apps, though, and not just the origin. 1295 // already. We must use the full URL to find hosted apps, though, and not
1296 // just the origin.
1288 const Extension* extension = map->extensions().GetExtensionOrAppByURL( 1297 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
1289 ExtensionURLInfo(opener_url)); 1298 ExtensionURLInfo(opener_url));
1290 if (extension && !extension->allow_background_js_access()) 1299 if (extension && !extension->allow_background_js_access())
1291 return false; 1300 *no_javascript_access = true;
1292
1293 return map->SecurityOriginHasAPIPermission(
1294 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
1295 } 1301 }
1296 return true; 1302 return true;
1297 } 1303 }
1298 1304
1299 std::string ChromeContentBrowserClient::GetWorkerProcessTitle( 1305 std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
1300 const GURL& url, content::ResourceContext* context) { 1306 const GURL& url, content::ResourceContext* context) {
1301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1302 // Check if it's an extension-created worker, in which case we want to use 1308 // Check if it's an extension-created worker, in which case we want to use
1303 // the name of the extension. 1309 // the name of the extension.
1304 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1310 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1637 #if defined(USE_NSS) 1643 #if defined(USE_NSS)
1638 crypto::CryptoModuleBlockingPasswordDelegate* 1644 crypto::CryptoModuleBlockingPasswordDelegate*
1639 ChromeContentBrowserClient::GetCryptoPasswordDelegate( 1645 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1640 const GURL& url) { 1646 const GURL& url) {
1641 return browser::NewCryptoModuleBlockingDialogDelegate( 1647 return browser::NewCryptoModuleBlockingDialogDelegate(
1642 browser::kCryptoModulePasswordKeygen, url.host()); 1648 browser::kCryptoModulePasswordKeygen, url.host());
1643 } 1649 }
1644 #endif 1650 #endif
1645 1651
1646 } // namespace chrome 1652 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.h ('k') | chrome/browser/extensions/app_background_page_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698