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

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

Issue 2821473002: Service CreateNewWindow on the UI thread with a new mojo interface (Closed)
Patch Set: associated with IPC channel 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 unified diff | Download patch
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 <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 2415 matching lines...) Expand 10 before | Expand all | Expand 10 after
2426 2426
2427 content::PlatformNotificationService* 2427 content::PlatformNotificationService*
2428 ChromeContentBrowserClient::GetPlatformNotificationService() { 2428 ChromeContentBrowserClient::GetPlatformNotificationService() {
2429 return PlatformNotificationServiceImpl::GetInstance(); 2429 return PlatformNotificationServiceImpl::GetInstance();
2430 } 2430 }
2431 2431
2432 bool ChromeContentBrowserClient::CanCreateWindow( 2432 bool ChromeContentBrowserClient::CanCreateWindow(
2433 int opener_render_process_id, 2433 int opener_render_process_id,
2434 int opener_render_frame_id, 2434 int opener_render_frame_id,
2435 const GURL& opener_url, 2435 const GURL& opener_url,
2436 const GURL& opener_top_level_frame_url, 2436 const GURL& opener_top_level_frame_url,
alexmos 2017/04/17 19:41:07 Yay, doing this might allow us to fix this for OOP
Charlie Harrison 2017/04/17 20:10:51 w00t!
2437 const GURL& source_origin, 2437 const GURL& source_origin,
2438 content::mojom::WindowContainerType container_type, 2438 content::mojom::WindowContainerType container_type,
2439 const GURL& target_url, 2439 const GURL& target_url,
2440 const content::Referrer& referrer, 2440 const content::Referrer& referrer,
2441 const std::string& frame_name, 2441 const std::string& frame_name,
2442 WindowOpenDisposition disposition, 2442 WindowOpenDisposition disposition,
2443 const blink::mojom::WindowFeatures& features, 2443 const blink::mojom::WindowFeatures& features,
2444 bool user_gesture, 2444 bool user_gesture,
2445 bool opener_suppressed, 2445 bool opener_suppressed,
2446 content::ResourceContext* context,
2447 bool* no_javascript_access) { 2446 bool* no_javascript_access) {
2448 DCHECK_CURRENTLY_ON(BrowserThread::IO); 2447 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2449 2448
2449 content::RenderFrameHost* opener = content::RenderFrameHost::FromID(
2450 opener_render_process_id, opener_render_frame_id);
2451 content::WebContents* web_contents =
2452 content::WebContents::FromRenderFrameHost(opener);
2453 Profile* profile =
2454 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2455 DCHECK(profile);
2450 *no_javascript_access = false; 2456 *no_javascript_access = false;
2451 2457
2452 // If the opener is trying to create a background window but doesn't have 2458 // If the opener is trying to create a background window but doesn't have
2453 // the appropriate permission, fail the attempt. 2459 // the appropriate permission, fail the attempt.
2454 if (container_type == content::mojom::WindowContainerType::BACKGROUND) { 2460 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
2455 #if BUILDFLAG(ENABLE_EXTENSIONS) 2461 #if BUILDFLAG(ENABLE_EXTENSIONS)
2456 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 2462 // TODO(csharrison): Consider moving this logic into a static method
2457 InfoMap* map = io_data->GetExtensionInfoMap(); 2463 // somewhere.
2458 if (!map->SecurityOriginHasAPIPermission(source_origin, 2464 auto* process_map = extensions::ProcessMap::Get(profile);
2459 opener_render_process_id, 2465 auto* registry = extensions::ExtensionRegistry::Get(profile);
2460 APIPermission::kBackground)) { 2466 if (source_origin.SchemeIs(extensions::kExtensionScheme)) {
2461 return false; 2467 const std::string& id = source_origin.host();
2468 const Extension* extension = registry->GetExtensionById(
2469 id, extensions::ExtensionRegistry::ENABLED);
2470 return extension &&
2471 extension->permissions_data()->HasAPIPermission(
alexmos 2017/04/17 19:41:07 This doesn't seem to quite match the old check. T
Charlie Harrison 2017/04/17 20:10:51 Yep, fixed.
2472 APIPermission::kBackground) &&
2473 process_map->Contains(id, opener_render_process_id);
2474 }
2475 bool has_permission = false;
2476 for (const auto& extension_id :
2477 process_map->GetExtensionsInProcess(opener_render_process_id)) {
2478 const Extension* extension = registry->GetExtensionById(
2479 extension_id, extensions::ExtensionRegistry::ENABLED);
2480 if (extension->web_extent().MatchesSecurityOrigin(source_origin) &&
2481 extension->permissions_data()->HasAPIPermission(
2482 APIPermission::kBackground)) {
2483 has_permission = true;
2484 }
2485 if (!has_permission)
alexmos 2017/04/17 19:41:07 Is this right? Or should it be outside the loop (
Charlie Harrison 2017/04/17 20:10:52 Yep, fixed.
2486 return false;
2462 } 2487 }
2463 2488
2464 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may 2489 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2465 // return a recently installed Extension even if this CanCreateWindow call 2490 // return a recently installed Extension even if this CanCreateWindow call
2466 // was made by an old copy of the page in a normal web process. That's ok, 2491 // was made by an old copy of the page in a normal web process. That's ok,
2467 // because the permission check above would have caused an early return 2492 // because the permission check above would have caused an early return
2468 // already. We must use the full URL to find hosted apps, though, and not 2493 // already. We must use the full URL to find hosted apps, though, and not
2469 // just the origin. 2494 // just the origin.
2470 const Extension* extension = 2495 const Extension* extension =
2471 map->extensions().GetExtensionOrAppByURL(opener_url); 2496 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
2472 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) 2497 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
2473 *no_javascript_access = true; 2498 *no_javascript_access = true;
2474 #endif 2499 #endif
2475 2500
2476 return true; 2501 return true;
2477 } 2502 }
2478 2503
2479 #if BUILDFLAG(ENABLE_EXTENSIONS) 2504 #if BUILDFLAG(ENABLE_EXTENSIONS)
2480 if (extensions::WebViewRendererState::GetInstance()->IsGuest( 2505 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
2481 opener_render_process_id)) { 2506 opener_render_process_id)) {
2482 return true; 2507 return true;
2483 } 2508 }
2484 2509
2485 if (target_url.SchemeIs(extensions::kExtensionScheme)) { 2510 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
2486 // Intentionally duplicating |io_data| and |map| code from above because we 2511 // Intentionally duplicating |io_data| and |map| code from above because we
2487 // want to reduce calls to retrieve them as this function is a SYNC IPC 2512 // want to reduce calls to retrieve them as this function is a SYNC IPC
2488 // handler. 2513 // handler.
2489 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 2514 auto* registry = extensions::ExtensionRegistry::Get(profile);
2490 InfoMap* map = io_data->GetExtensionInfoMap();
2491 const Extension* extension = 2515 const Extension* extension =
2492 map->extensions().GetExtensionOrAppByURL(opener_url); 2516 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
2493 if (extension && extension->is_platform_app()) { 2517 if (extension && extension->is_platform_app()) {
2494 AppLoadedInTabSource source = 2518 AppLoadedInTabSource source =
2495 opener_top_level_frame_url == 2519 opener_top_level_frame_url ==
2496 extensions::BackgroundInfo::GetBackgroundURL(extension) 2520 extensions::BackgroundInfo::GetBackgroundURL(extension)
2497 ? APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE 2521 ? APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE
2498 : APP_LOADED_IN_TAB_SOURCE_APP; 2522 : APP_LOADED_IN_TAB_SOURCE_APP;
2499 // TODO(lazyboy): Remove this UMA once the change below to disallow apps 2523 // TODO(lazyboy): Remove this UMA once the change below to disallow apps
2500 // in tabs has settled in stable branch. 2524 // in tabs has settled in stable branch.
2501 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLoadedInTab", source, 2525 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLoadedInTab", source,
2502 APP_LOADED_IN_TAB_SOURCE_MAX); 2526 APP_LOADED_IN_TAB_SOURCE_MAX);
2503 // Platform apps and their background pages should not be able to call 2527 // Platform apps and their background pages should not be able to call
2504 // window.open() to load v2 apps in regular tab. 2528 // window.open() to load v2 apps in regular tab.
2505 // Simply disallow window.open() calls in this case. 2529 // Simply disallow window.open() calls in this case.
2506 return false; 2530 return false;
2507 } 2531 }
2508 } 2532 }
2509 #endif 2533 #endif
2510 2534
2511 HostContentSettingsMap* content_settings = 2535 HostContentSettingsMap* content_settings =
2512 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap(); 2536 HostContentSettingsMapFactory::GetForProfile(profile);
2513 2537
2514 #if BUILDFLAG(ENABLE_PLUGINS) 2538 #if BUILDFLAG(ENABLE_PLUGINS)
2515 if (FlashDownloadInterception::ShouldStopFlashDownloadAction( 2539 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
2516 content_settings, opener_top_level_frame_url, target_url, 2540 content_settings, opener_top_level_frame_url, target_url,
2517 user_gesture)) { 2541 user_gesture)) {
2518 BrowserThread::PostTask( 2542 HandleFlashDownloadActionOnUIThread(opener_render_process_id,
2519 BrowserThread::UI, FROM_HERE, 2543 opener_render_frame_id,
2520 base::Bind(&HandleFlashDownloadActionOnUIThread, 2544 opener_top_level_frame_url);
2521 opener_render_process_id, opener_render_frame_id,
2522 opener_top_level_frame_url));
2523 return false; 2545 return false;
2524 } 2546 }
2525 #endif 2547 #endif
2526 2548
2527 BlockedWindowParams blocked_params( 2549 BlockedWindowParams blocked_params(
2528 target_url, referrer, frame_name, disposition, features, user_gesture, 2550 target_url, referrer, frame_name, disposition, features, user_gesture,
2529 opener_suppressed, opener_render_process_id, opener_render_frame_id); 2551 opener_suppressed, opener_render_process_id, opener_render_frame_id);
2530 2552
2531 if (!user_gesture && 2553 if (!user_gesture &&
2532 !base::CommandLine::ForCurrentProcess()->HasSwitch( 2554 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2533 switches::kDisablePopupBlocking)) { 2555 switches::kDisablePopupBlocking)) {
2534 if (content_settings->GetContentSetting(opener_top_level_frame_url, 2556 if (content_settings->GetContentSetting(
2535 opener_top_level_frame_url, 2557 opener_top_level_frame_url, opener_top_level_frame_url,
2536 CONTENT_SETTINGS_TYPE_POPUPS, 2558 CONTENT_SETTINGS_TYPE_POPUPS,
2537 std::string()) != 2559 std::string()) != CONTENT_SETTING_ALLOW) {
2538 CONTENT_SETTING_ALLOW) { 2560 HandleBlockedPopupOnUIThread(blocked_params);
2539 BrowserThread::PostTask(BrowserThread::UI,
2540 FROM_HERE,
2541 base::Bind(&HandleBlockedPopupOnUIThread,
2542 blocked_params));
2543 return false; 2561 return false;
2544 } 2562 }
2545 } 2563 }
2546 2564
2547 #if defined(OS_ANDROID) 2565 #if defined(OS_ANDROID)
2548 if (SingleTabModeTabHelper::IsRegistered(opener_render_process_id, 2566 if (SingleTabModeTabHelper::IsRegistered(opener_render_process_id,
2549 opener_render_frame_id)) { 2567 opener_render_frame_id)) {
2550 BrowserThread::PostTask(BrowserThread::UI, 2568 BrowserThread::PostTask(BrowserThread::UI,
2551 FROM_HERE, 2569 FROM_HERE,
2552 base::Bind(&HandleSingleTabModeBlockOnUIThread, 2570 base::Bind(&HandleSingleTabModeBlockOnUIThread,
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after
3619 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { 3637 RedirectNonUINonIOBrowserThreadsToTaskScheduler() {
3620 return variations::GetVariationParamValue( 3638 return variations::GetVariationParamValue(
3621 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; 3639 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true";
3622 } 3640 }
3623 3641
3624 // static 3642 // static
3625 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( 3643 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
3626 const storage::QuotaSettings* settings) { 3644 const storage::QuotaSettings* settings) {
3627 g_default_quota_settings = settings; 3645 g_default_quota_settings = settings;
3628 } 3646 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698