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

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: 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 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 2425 matching lines...) Expand 10 before | Expand all | Expand 10 after
2436 const GURL& opener_top_level_frame_url, 2436 const GURL& opener_top_level_frame_url,
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
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.
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)) {
2467 const std::string& id = source_origin.host();
2468 const Extension* extension = registry->GetExtensionById(
2469 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.
2470 bool extension_has_api_permission =
2471 extension &&
2472 extension->permissions_data()->HasAPIPermission(
2473 APIPermission::kBackground) &&
2474 process_map->Contains(id, opener_render_process_id);
2475 if (!extension_has_api_permission)
2476 return false;
2477 }
2478 bool has_permission = false;
2479 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.
2480 process_map->GetExtensionsInProcess(opener_render_process_id)) {
2481 const Extension* extension = registry->GetExtensionById(
2482 extension_id, extensions::ExtensionRegistry::ENABLED);
2483 if (extension->web_extent().MatchesSecurityOrigin(source_origin) &&
2484 extension->permissions_data()->HasAPIPermission(
2485 APIPermission::kBackground)) {
2486 has_permission = true;
2487 break;
2488 }
2489 }
2490 if (!has_permission)
2461 return false; 2491 return false;
2462 }
2463 2492
2464 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may 2493 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2465 // return a recently installed Extension even if this CanCreateWindow call 2494 // 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, 2495 // 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 2496 // 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 2497 // already. We must use the full URL to find hosted apps, though, and not
2469 // just the origin. 2498 // just the origin.
2470 const Extension* extension = 2499 const Extension* extension =
2471 map->extensions().GetExtensionOrAppByURL(opener_url); 2500 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
2472 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) 2501 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
2473 *no_javascript_access = true; 2502 *no_javascript_access = true;
2474 #endif 2503 #endif
2475 2504
2476 return true; 2505 return true;
2477 } 2506 }
2478 2507
2479 #if BUILDFLAG(ENABLE_EXTENSIONS) 2508 #if BUILDFLAG(ENABLE_EXTENSIONS)
2480 if (extensions::WebViewRendererState::GetInstance()->IsGuest( 2509 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
2481 opener_render_process_id)) { 2510 opener_render_process_id)) {
2482 return true; 2511 return true;
2483 } 2512 }
2484 2513
2485 if (target_url.SchemeIs(extensions::kExtensionScheme)) { 2514 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
2486 // Intentionally duplicating |io_data| and |map| code from above because we 2515 // 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 2516 // want to reduce calls to retrieve them as this function is a SYNC IPC
2488 // handler. 2517 // handler.
2489 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 2518 auto* registry = extensions::ExtensionRegistry::Get(profile);
2490 InfoMap* map = io_data->GetExtensionInfoMap();
2491 const Extension* extension = 2519 const Extension* extension =
2492 map->extensions().GetExtensionOrAppByURL(opener_url); 2520 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
2493 if (extension && extension->is_platform_app()) { 2521 if (extension && extension->is_platform_app()) {
2494 AppLoadedInTabSource source = 2522 AppLoadedInTabSource source =
2495 opener_top_level_frame_url == 2523 opener_top_level_frame_url ==
2496 extensions::BackgroundInfo::GetBackgroundURL(extension) 2524 extensions::BackgroundInfo::GetBackgroundURL(extension)
2497 ? APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE 2525 ? APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE
2498 : APP_LOADED_IN_TAB_SOURCE_APP; 2526 : APP_LOADED_IN_TAB_SOURCE_APP;
2499 // TODO(lazyboy): Remove this UMA once the change below to disallow apps 2527 // TODO(lazyboy): Remove this UMA once the change below to disallow apps
2500 // in tabs has settled in stable branch. 2528 // in tabs has settled in stable branch.
2501 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLoadedInTab", source, 2529 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLoadedInTab", source,
2502 APP_LOADED_IN_TAB_SOURCE_MAX); 2530 APP_LOADED_IN_TAB_SOURCE_MAX);
2503 // Platform apps and their background pages should not be able to call 2531 // Platform apps and their background pages should not be able to call
2504 // window.open() to load v2 apps in regular tab. 2532 // window.open() to load v2 apps in regular tab.
2505 // Simply disallow window.open() calls in this case. 2533 // Simply disallow window.open() calls in this case.
2506 return false; 2534 return false;
2507 } 2535 }
2508 } 2536 }
2509 #endif 2537 #endif
2510 2538
2511 HostContentSettingsMap* content_settings = 2539 HostContentSettingsMap* content_settings =
2512 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap(); 2540 HostContentSettingsMapFactory::GetForProfile(profile);
2513 2541
2514 #if BUILDFLAG(ENABLE_PLUGINS) 2542 #if BUILDFLAG(ENABLE_PLUGINS)
2515 if (FlashDownloadInterception::ShouldStopFlashDownloadAction( 2543 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
2516 content_settings, opener_top_level_frame_url, target_url, 2544 content_settings, opener_top_level_frame_url, target_url,
2517 user_gesture)) { 2545 user_gesture)) {
2518 BrowserThread::PostTask( 2546 HandleFlashDownloadActionOnUIThread(opener_render_process_id,
2519 BrowserThread::UI, FROM_HERE, 2547 opener_render_frame_id,
2520 base::Bind(&HandleFlashDownloadActionOnUIThread, 2548 opener_top_level_frame_url);
2521 opener_render_process_id, opener_render_frame_id,
2522 opener_top_level_frame_url));
2523 return false; 2549 return false;
2524 } 2550 }
2525 #endif 2551 #endif
2526 2552
2527 BlockedWindowParams blocked_params( 2553 BlockedWindowParams blocked_params(
2528 target_url, referrer, frame_name, disposition, features, user_gesture, 2554 target_url, referrer, frame_name, disposition, features, user_gesture,
2529 opener_suppressed, opener_render_process_id, opener_render_frame_id); 2555 opener_suppressed, opener_render_process_id, opener_render_frame_id);
2530 2556
2531 if (!user_gesture && 2557 if (!user_gesture &&
2532 !base::CommandLine::ForCurrentProcess()->HasSwitch( 2558 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2533 switches::kDisablePopupBlocking)) { 2559 switches::kDisablePopupBlocking)) {
2534 if (content_settings->GetContentSetting(opener_top_level_frame_url, 2560 if (content_settings->GetContentSetting(
2535 opener_top_level_frame_url, 2561 opener_top_level_frame_url, opener_top_level_frame_url,
2536 CONTENT_SETTINGS_TYPE_POPUPS, 2562 CONTENT_SETTINGS_TYPE_POPUPS,
2537 std::string()) != 2563 std::string()) != CONTENT_SETTING_ALLOW) {
2538 CONTENT_SETTING_ALLOW) { 2564 HandleBlockedPopupOnUIThread(blocked_params);
2539 BrowserThread::PostTask(BrowserThread::UI,
2540 FROM_HERE,
2541 base::Bind(&HandleBlockedPopupOnUIThread,
2542 blocked_params));
2543 return false; 2565 return false;
2544 } 2566 }
2545 } 2567 }
2546 2568
2547 #if defined(OS_ANDROID) 2569 #if defined(OS_ANDROID)
2548 if (SingleTabModeTabHelper::IsRegistered(opener_render_process_id, 2570 if (SingleTabModeTabHelper::IsRegistered(opener_render_process_id,
2549 opener_render_frame_id)) { 2571 opener_render_frame_id)) {
2550 BrowserThread::PostTask(BrowserThread::UI, 2572 BrowserThread::PostTask(BrowserThread::UI,
2551 FROM_HERE, 2573 FROM_HERE,
2552 base::Bind(&HandleSingleTabModeBlockOnUIThread, 2574 base::Bind(&HandleSingleTabModeBlockOnUIThread,
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after
3619 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { 3641 RedirectNonUINonIOBrowserThreadsToTaskScheduler() {
3620 return variations::GetVariationParamValue( 3642 return variations::GetVariationParamValue(
3621 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; 3643 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true";
3622 } 3644 }
3623 3645
3624 // static 3646 // static
3625 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( 3647 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
3626 const storage::QuotaSettings* settings) { 3648 const storage::QuotaSettings* settings) {
3627 g_default_quota_settings = settings; 3649 g_default_quota_settings = settings;
3628 } 3650 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698