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

Unified Diff: chrome/browser/chrome_content_browser_client.cc

Issue 2821473002: Service CreateNewWindow on the UI thread with a new mojo interface (Closed)
Patch Set: fix up logic errors Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chrome_content_browser_client.cc
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index 260c28e23b0541928285fb393f15dd3911d183e2..e0dd1e95df8b433c3350bbe7ffaf35ef48ea4059 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -2443,23 +2443,52 @@ bool ChromeContentBrowserClient::CanCreateWindow(
const blink::mojom::WindowFeatures& features,
bool user_gesture,
bool opener_suppressed,
- content::ResourceContext* context,
bool* no_javascript_access) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ content::RenderFrameHost* opener = content::RenderFrameHost::FromID(
+ opener_render_process_id, opener_render_frame_id);
+ content::WebContents* web_contents =
+ content::WebContents::FromRenderFrameHost(opener);
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents->GetBrowserContext());
+ DCHECK(profile);
*no_javascript_access = false;
// If the opener is trying to create a background window but doesn't have
// the appropriate permission, fail the attempt.
if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
- ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
- InfoMap* map = io_data->GetExtensionInfoMap();
- if (!map->SecurityOriginHasAPIPermission(source_origin,
- opener_render_process_id,
- APIPermission::kBackground)) {
- return false;
+ // TODO(csharrison): Consider moving this logic into a static method
Devlin 2017/04/17 21:45:42 Maybe just do this now in a local anonymous namesp
Charlie Harrison 2017/04/18 20:38:52 Done.
+ // somewhere.
+ auto* process_map = extensions::ProcessMap::Get(profile);
+ auto* registry = extensions::ExtensionRegistry::Get(profile);
+ if (source_origin.SchemeIs(extensions::kExtensionScheme)) {
+ const std::string& id = source_origin.host();
+ const Extension* extension = registry->GetExtensionById(
+ id, extensions::ExtensionRegistry::ENABLED);
Devlin 2017/04/17 21:45:42 nit: prefer registry->enabled_extensions().GetByID
Charlie Harrison 2017/04/18 20:38:52 Done.
+ bool extension_has_api_permission =
+ extension &&
+ extension->permissions_data()->HasAPIPermission(
+ APIPermission::kBackground) &&
+ process_map->Contains(id, opener_render_process_id);
+ if (!extension_has_api_permission)
+ return false;
}
+ bool has_permission = false;
+ for (const auto& extension_id :
Devlin 2017/04/17 21:45:42 This loop should only be done if the scheme isn't
Charlie Harrison 2017/04/18 20:38:52 Done.
+ process_map->GetExtensionsInProcess(opener_render_process_id)) {
+ const Extension* extension = registry->GetExtensionById(
+ extension_id, extensions::ExtensionRegistry::ENABLED);
+ if (extension->web_extent().MatchesSecurityOrigin(source_origin) &&
+ extension->permissions_data()->HasAPIPermission(
+ APIPermission::kBackground)) {
+ has_permission = true;
+ break;
+ }
+ }
+ if (!has_permission)
+ return false;
// Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
// return a recently installed Extension even if this CanCreateWindow call
@@ -2468,7 +2497,7 @@ bool ChromeContentBrowserClient::CanCreateWindow(
// already. We must use the full URL to find hosted apps, though, and not
// just the origin.
const Extension* extension =
- map->extensions().GetExtensionOrAppByURL(opener_url);
+ registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
*no_javascript_access = true;
#endif
@@ -2486,10 +2515,9 @@ bool ChromeContentBrowserClient::CanCreateWindow(
// Intentionally duplicating |io_data| and |map| code from above because we
// want to reduce calls to retrieve them as this function is a SYNC IPC
// handler.
- ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
- InfoMap* map = io_data->GetExtensionInfoMap();
+ auto* registry = extensions::ExtensionRegistry::Get(profile);
const Extension* extension =
- map->extensions().GetExtensionOrAppByURL(opener_url);
+ registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
if (extension && extension->is_platform_app()) {
AppLoadedInTabSource source =
opener_top_level_frame_url ==
@@ -2509,17 +2537,15 @@ bool ChromeContentBrowserClient::CanCreateWindow(
#endif
HostContentSettingsMap* content_settings =
- ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
+ HostContentSettingsMapFactory::GetForProfile(profile);
#if BUILDFLAG(ENABLE_PLUGINS)
if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
content_settings, opener_top_level_frame_url, target_url,
user_gesture)) {
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&HandleFlashDownloadActionOnUIThread,
- opener_render_process_id, opener_render_frame_id,
- opener_top_level_frame_url));
+ HandleFlashDownloadActionOnUIThread(opener_render_process_id,
+ opener_render_frame_id,
+ opener_top_level_frame_url);
return false;
}
#endif
@@ -2531,15 +2557,11 @@ bool ChromeContentBrowserClient::CanCreateWindow(
if (!user_gesture &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisablePopupBlocking)) {
- if (content_settings->GetContentSetting(opener_top_level_frame_url,
- opener_top_level_frame_url,
- CONTENT_SETTINGS_TYPE_POPUPS,
- std::string()) !=
- CONTENT_SETTING_ALLOW) {
- BrowserThread::PostTask(BrowserThread::UI,
- FROM_HERE,
- base::Bind(&HandleBlockedPopupOnUIThread,
- blocked_params));
+ if (content_settings->GetContentSetting(
+ opener_top_level_frame_url, opener_top_level_frame_url,
+ CONTENT_SETTINGS_TYPE_POPUPS,
+ std::string()) != CONTENT_SETTING_ALLOW) {
+ HandleBlockedPopupOnUIThread(blocked_params);
return false;
}
}

Powered by Google App Engine
This is Rietveld 408576698