OLD | NEW |
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 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 | 769 |
770 return -1; | 770 return -1; |
771 } | 771 } |
772 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 772 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
773 | 773 |
774 void SetApplicationLocaleOnIOThread(const std::string& locale) { | 774 void SetApplicationLocaleOnIOThread(const std::string& locale) { |
775 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 775 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
776 g_io_thread_application_locale.Get() = locale; | 776 g_io_thread_application_locale.Get() = locale; |
777 } | 777 } |
778 | 778 |
779 void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) { | 779 void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params, |
780 RenderFrameHost* render_frame_host = RenderFrameHost::FromID( | 780 RenderFrameHost* opener, |
781 params.render_process_id(), params.opener_render_frame_id()); | 781 WebContents* tab) { |
782 if (!render_frame_host) | 782 DCHECK(tab); |
783 return; | 783 DCHECK(opener); |
784 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host); | |
785 // The tab might already have navigated away. We only need to do this check | |
786 // for main frames, since the RenderFrameHost for a subframe opener will have | |
787 // already been deleted if the main frame navigates away. | |
788 if (!tab || | |
789 (!render_frame_host->GetParent() && | |
790 tab->GetMainFrame() != render_frame_host)) | |
791 return; | |
792 | |
793 prerender::PrerenderContents* prerender_contents = | 784 prerender::PrerenderContents* prerender_contents = |
794 prerender::PrerenderContents::FromWebContents(tab); | 785 prerender::PrerenderContents::FromWebContents(tab); |
795 if (prerender_contents) { | 786 if (prerender_contents) { |
796 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW); | 787 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW); |
797 return; | 788 return; |
798 } | 789 } |
799 | 790 |
800 PopupBlockerTabHelper* popup_helper = | 791 PopupBlockerTabHelper* popup_helper = |
801 PopupBlockerTabHelper::FromWebContents(tab); | 792 PopupBlockerTabHelper::FromWebContents(tab); |
802 if (!popup_helper) | 793 if (!popup_helper) |
803 return; | 794 return; |
804 popup_helper->AddBlockedPopup(params); | 795 popup_helper->AddBlockedPopup(params); |
805 } | 796 } |
806 | 797 |
807 #if BUILDFLAG(ENABLE_PLUGINS) | |
808 void HandleFlashDownloadActionOnUIThread(int render_process_id, | |
809 int render_frame_id, | |
810 const GURL& source_url) { | |
811 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
812 RenderFrameHost* render_frame_host = | |
813 RenderFrameHost::FromID(render_process_id, render_frame_id); | |
814 if (!render_frame_host) | |
815 return; | |
816 WebContents* web_contents = | |
817 WebContents::FromRenderFrameHost(render_frame_host); | |
818 FlashDownloadInterception::InterceptFlashDownloadNavigation(web_contents, | |
819 source_url); | |
820 } | |
821 #endif // BUILDFLAG(ENABLE_PLUGINS) | |
822 | |
823 // An implementation of the SSLCertReporter interface used by | 798 // An implementation of the SSLCertReporter interface used by |
824 // SSLErrorHandler. Uses CertificateReportingService to send reports. The | 799 // SSLErrorHandler. Uses CertificateReportingService to send reports. The |
825 // service handles queueing and re-sending of failed reports. Each certificate | 800 // service handles queueing and re-sending of failed reports. Each certificate |
826 // error creates a new instance of this class. | 801 // error creates a new instance of this class. |
827 class CertificateReportingServiceCertReporter : public SSLCertReporter { | 802 class CertificateReportingServiceCertReporter : public SSLCertReporter { |
828 public: | 803 public: |
829 explicit CertificateReportingServiceCertReporter( | 804 explicit CertificateReportingServiceCertReporter( |
830 CertificateReportingService* service) | 805 CertificateReportingService* service) |
831 : service_(service) {} | 806 : service_(service) {} |
832 ~CertificateReportingServiceCertReporter() override {} | 807 ~CertificateReportingServiceCertReporter() override {} |
(...skipping 23 matching lines...) Expand all Loading... |
856 return kMinFSM; | 831 return kMinFSM; |
857 if (minWidth >= kWidthForMaxFSM) | 832 if (minWidth >= kWidthForMaxFSM) |
858 return kMaxFSM; | 833 return kMaxFSM; |
859 | 834 |
860 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM. | 835 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM. |
861 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) / | 836 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) / |
862 (kWidthForMaxFSM - kWidthForMinFSM); | 837 (kWidthForMaxFSM - kWidthForMinFSM); |
863 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; | 838 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; |
864 } | 839 } |
865 | 840 |
866 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) { | |
867 WebContents* web_contents = tab_util::GetWebContentsByFrameID( | |
868 params.render_process_id(), params.opener_render_frame_id()); | |
869 if (!web_contents) | |
870 return; | |
871 | |
872 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params); | |
873 } | |
874 #endif // defined(OS_ANDROID) | 841 #endif // defined(OS_ANDROID) |
875 | 842 |
876 #if BUILDFLAG(ENABLE_EXTENSIONS) | 843 #if BUILDFLAG(ENABLE_EXTENSIONS) |
877 // By default, JavaScript, images and autoplay are enabled in guest content. | 844 // By default, JavaScript, images and autoplay are enabled in guest content. |
878 void GetGuestViewDefaultContentSettingRules( | 845 void GetGuestViewDefaultContentSettingRules( |
879 bool incognito, | 846 bool incognito, |
880 RendererContentSettingRules* rules) { | 847 RendererContentSettingRules* rules) { |
881 rules->image_rules.push_back( | 848 rules->image_rules.push_back( |
882 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 849 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), |
883 ContentSettingsPattern::Wildcard(), | 850 ContentSettingsPattern::Wildcard(), |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 base::Closure callback_; | 956 base::Closure callback_; |
990 int count_; | 957 int count_; |
991 }; | 958 }; |
992 | 959 |
993 WebContents* GetWebContents(int render_process_id, int render_frame_id) { | 960 WebContents* GetWebContents(int render_process_id, int render_frame_id) { |
994 RenderFrameHost* rfh = | 961 RenderFrameHost* rfh = |
995 RenderFrameHost::FromID(render_process_id, render_frame_id); | 962 RenderFrameHost::FromID(render_process_id, render_frame_id); |
996 return WebContents::FromRenderFrameHost(rfh); | 963 return WebContents::FromRenderFrameHost(rfh); |
997 } | 964 } |
998 | 965 |
| 966 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 967 // Returns true if there is is an extension with the same origin as |
| 968 // |source_origin| in |opener_render_process_id| with |
| 969 // APIPermission::kBackground. |
| 970 bool SecurityOriginHasExtensionBackgroundPermission( |
| 971 extensions::ProcessMap* process_map, |
| 972 extensions::ExtensionRegistry* registry, |
| 973 const GURL& source_origin, |
| 974 int opener_render_process_id) { |
| 975 // Note: includes web URLs that are part of an extension's web extent. |
| 976 const Extension* extension = |
| 977 registry->enabled_extensions().GetExtensionOrAppByURL(source_origin); |
| 978 return extension && |
| 979 extension->permissions_data()->HasAPIPermission( |
| 980 APIPermission::kBackground) && |
| 981 process_map->Contains(extension->id(), opener_render_process_id); |
| 982 } |
| 983 #endif |
| 984 |
999 } // namespace | 985 } // namespace |
1000 | 986 |
1001 ChromeContentBrowserClient::ChromeContentBrowserClient() | 987 ChromeContentBrowserClient::ChromeContentBrowserClient() |
1002 : weak_factory_(this) { | 988 : weak_factory_(this) { |
1003 #if BUILDFLAG(ENABLE_PLUGINS) | 989 #if BUILDFLAG(ENABLE_PLUGINS) |
1004 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i) | 990 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i) |
1005 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); | 991 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); |
1006 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) | 992 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) |
1007 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); | 993 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); |
1008 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) | 994 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) |
(...skipping 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2448 content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { | 2434 content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { |
2449 return MediaCaptureDevicesDispatcher::GetInstance(); | 2435 return MediaCaptureDevicesDispatcher::GetInstance(); |
2450 } | 2436 } |
2451 | 2437 |
2452 content::PlatformNotificationService* | 2438 content::PlatformNotificationService* |
2453 ChromeContentBrowserClient::GetPlatformNotificationService() { | 2439 ChromeContentBrowserClient::GetPlatformNotificationService() { |
2454 return PlatformNotificationServiceImpl::GetInstance(); | 2440 return PlatformNotificationServiceImpl::GetInstance(); |
2455 } | 2441 } |
2456 | 2442 |
2457 bool ChromeContentBrowserClient::CanCreateWindow( | 2443 bool ChromeContentBrowserClient::CanCreateWindow( |
2458 int opener_render_process_id, | 2444 RenderFrameHost* opener, |
2459 int opener_render_frame_id, | |
2460 const GURL& opener_url, | 2445 const GURL& opener_url, |
2461 const GURL& opener_top_level_frame_url, | 2446 const GURL& opener_top_level_frame_url, |
2462 const GURL& source_origin, | 2447 const GURL& source_origin, |
2463 content::mojom::WindowContainerType container_type, | 2448 content::mojom::WindowContainerType container_type, |
2464 const GURL& target_url, | 2449 const GURL& target_url, |
2465 const content::Referrer& referrer, | 2450 const content::Referrer& referrer, |
2466 const std::string& frame_name, | 2451 const std::string& frame_name, |
2467 WindowOpenDisposition disposition, | 2452 WindowOpenDisposition disposition, |
2468 const blink::mojom::WindowFeatures& features, | 2453 const blink::mojom::WindowFeatures& features, |
2469 bool user_gesture, | 2454 bool user_gesture, |
2470 bool opener_suppressed, | 2455 bool opener_suppressed, |
2471 content::ResourceContext* context, | |
2472 bool* no_javascript_access) { | 2456 bool* no_javascript_access) { |
2473 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2457 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2458 DCHECK(opener); |
2474 | 2459 |
| 2460 content::WebContents* web_contents = |
| 2461 content::WebContents::FromRenderFrameHost(opener); |
| 2462 Profile* profile = |
| 2463 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 2464 DCHECK(profile); |
2475 *no_javascript_access = false; | 2465 *no_javascript_access = false; |
2476 | 2466 |
2477 // If the opener is trying to create a background window but doesn't have | 2467 // If the opener is trying to create a background window but doesn't have |
2478 // the appropriate permission, fail the attempt. | 2468 // the appropriate permission, fail the attempt. |
2479 if (container_type == content::mojom::WindowContainerType::BACKGROUND) { | 2469 if (container_type == content::mojom::WindowContainerType::BACKGROUND) { |
2480 #if BUILDFLAG(ENABLE_EXTENSIONS) | 2470 #if BUILDFLAG(ENABLE_EXTENSIONS) |
2481 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); | 2471 auto* process_map = extensions::ProcessMap::Get(profile); |
2482 InfoMap* map = io_data->GetExtensionInfoMap(); | 2472 auto* registry = extensions::ExtensionRegistry::Get(profile); |
2483 if (!map->SecurityOriginHasAPIPermission(source_origin, | 2473 if (!SecurityOriginHasExtensionBackgroundPermission( |
2484 opener_render_process_id, | 2474 process_map, registry, source_origin, |
2485 APIPermission::kBackground)) { | 2475 opener->GetProcess()->GetID())) { |
2486 return false; | 2476 return false; |
2487 } | 2477 } |
2488 | 2478 |
2489 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may | 2479 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may |
2490 // return a recently installed Extension even if this CanCreateWindow call | 2480 // return a recently installed Extension even if this CanCreateWindow call |
2491 // was made by an old copy of the page in a normal web process. That's ok, | 2481 // was made by an old copy of the page in a normal web process. That's ok, |
2492 // because the permission check above would have caused an early return | 2482 // because the permission check above would have caused an early return |
2493 // already. We must use the full URL to find hosted apps, though, and not | 2483 // already. We must use the full URL to find hosted apps, though, and not |
2494 // just the origin. | 2484 // just the origin. |
2495 const Extension* extension = | 2485 const Extension* extension = |
2496 map->extensions().GetExtensionOrAppByURL(opener_url); | 2486 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url); |
2497 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) | 2487 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) |
2498 *no_javascript_access = true; | 2488 *no_javascript_access = true; |
2499 #endif | 2489 #endif |
2500 | 2490 |
2501 return true; | 2491 return true; |
2502 } | 2492 } |
2503 | 2493 |
2504 #if BUILDFLAG(ENABLE_EXTENSIONS) | 2494 #if BUILDFLAG(ENABLE_EXTENSIONS) |
2505 if (extensions::WebViewRendererState::GetInstance()->IsGuest( | 2495 if (extensions::WebViewRendererState::GetInstance()->IsGuest( |
2506 opener_render_process_id)) { | 2496 opener->GetProcess()->GetID())) { |
2507 return true; | 2497 return true; |
2508 } | 2498 } |
2509 | 2499 |
2510 if (target_url.SchemeIs(extensions::kExtensionScheme)) { | 2500 if (target_url.SchemeIs(extensions::kExtensionScheme)) { |
2511 // Intentionally duplicating |io_data| and |map| code from above because we | 2501 // Intentionally duplicating |registry| code from above because we want to |
2512 // want to reduce calls to retrieve them as this function is a SYNC IPC | 2502 // reduce calls to retrieve them as this function is a SYNC IPC handler. |
2513 // handler. | 2503 auto* registry = extensions::ExtensionRegistry::Get(profile); |
2514 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); | |
2515 InfoMap* map = io_data->GetExtensionInfoMap(); | |
2516 const Extension* extension = | 2504 const Extension* extension = |
2517 map->extensions().GetExtensionOrAppByURL(target_url); | 2505 registry->enabled_extensions().GetExtensionOrAppByURL(target_url); |
2518 if (extension && extension->is_platform_app()) { | 2506 if (extension && extension->is_platform_app()) { |
2519 UMA_HISTOGRAM_ENUMERATION( | 2507 UMA_HISTOGRAM_ENUMERATION( |
2520 "Extensions.AppLoadedInTab", | 2508 "Extensions.AppLoadedInTab", |
2521 ClassifyAppLoadedInTabSource(opener_url, extension), | 2509 ClassifyAppLoadedInTabSource(opener_url, extension), |
2522 APP_LOADED_IN_TAB_SOURCE_MAX); | 2510 APP_LOADED_IN_TAB_SOURCE_MAX); |
2523 | 2511 |
2524 // window.open() may not be used to load v2 apps in a regular tab. | 2512 // window.open() may not be used to load v2 apps in a regular tab. |
2525 return false; | 2513 return false; |
2526 } | 2514 } |
2527 } | 2515 } |
2528 #endif | 2516 #endif |
2529 | 2517 |
2530 HostContentSettingsMap* content_settings = | 2518 HostContentSettingsMap* content_settings = |
2531 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap(); | 2519 HostContentSettingsMapFactory::GetForProfile(profile); |
2532 | 2520 |
2533 #if BUILDFLAG(ENABLE_PLUGINS) | 2521 #if BUILDFLAG(ENABLE_PLUGINS) |
2534 if (FlashDownloadInterception::ShouldStopFlashDownloadAction( | 2522 if (FlashDownloadInterception::ShouldStopFlashDownloadAction( |
2535 content_settings, opener_top_level_frame_url, target_url, | 2523 content_settings, opener_top_level_frame_url, target_url, |
2536 user_gesture)) { | 2524 user_gesture)) { |
2537 BrowserThread::PostTask( | 2525 FlashDownloadInterception::InterceptFlashDownloadNavigation( |
2538 BrowserThread::UI, FROM_HERE, | 2526 web_contents, opener_top_level_frame_url); |
2539 base::BindOnce(&HandleFlashDownloadActionOnUIThread, | |
2540 opener_render_process_id, opener_render_frame_id, | |
2541 opener_top_level_frame_url)); | |
2542 return false; | 2527 return false; |
2543 } | 2528 } |
2544 #endif | 2529 #endif |
2545 | 2530 |
2546 BlockedWindowParams blocked_params( | |
2547 target_url, referrer, frame_name, disposition, features, user_gesture, | |
2548 opener_suppressed, opener_render_process_id, opener_render_frame_id); | |
2549 | |
2550 if (!user_gesture && | 2531 if (!user_gesture && |
2551 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 2532 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
2552 switches::kDisablePopupBlocking)) { | 2533 switches::kDisablePopupBlocking)) { |
2553 if (content_settings->GetContentSetting(opener_top_level_frame_url, | 2534 if (content_settings->GetContentSetting( |
2554 opener_top_level_frame_url, | 2535 opener_top_level_frame_url, opener_top_level_frame_url, |
2555 CONTENT_SETTINGS_TYPE_POPUPS, | 2536 CONTENT_SETTINGS_TYPE_POPUPS, |
2556 std::string()) != | 2537 std::string()) != CONTENT_SETTING_ALLOW) { |
2557 CONTENT_SETTING_ALLOW) { | 2538 BlockedWindowParams blocked_params(target_url, referrer, frame_name, |
2558 BrowserThread::PostTask( | 2539 disposition, features, user_gesture, |
2559 BrowserThread::UI, FROM_HERE, | 2540 opener_suppressed); |
2560 base::BindOnce(&HandleBlockedPopupOnUIThread, blocked_params)); | 2541 HandleBlockedPopupOnUIThread(blocked_params, opener, web_contents); |
2561 return false; | 2542 return false; |
2562 } | 2543 } |
2563 } | 2544 } |
2564 | 2545 |
2565 #if defined(OS_ANDROID) | 2546 #if defined(OS_ANDROID) |
2566 if (SingleTabModeTabHelper::IsRegistered(opener_render_process_id, | 2547 auto* single_tab_mode_helper = |
2567 opener_render_frame_id)) { | 2548 SingleTabModeTabHelper::FromWebContents(web_contents); |
2568 BrowserThread::PostTask(BrowserThread::UI, | 2549 if (single_tab_mode_helper->block_all_new_windows()) { |
2569 FROM_HERE, | 2550 if (TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents)) { |
2570 base::Bind(&HandleSingleTabModeBlockOnUIThread, | 2551 BlockedWindowParams blocked_params(target_url, referrer, frame_name, |
2571 blocked_params)); | 2552 disposition, features, user_gesture, |
| 2553 opener_suppressed); |
| 2554 chrome::NavigateParams nav_params = |
| 2555 blocked_params.CreateNavigateParams(web_contents); |
| 2556 tab_android->HandlePopupNavigation(&nav_params); |
| 2557 } |
2572 return false; | 2558 return false; |
2573 } | 2559 } |
2574 #endif | 2560 #endif |
2575 | 2561 |
2576 return true; | 2562 return true; |
2577 } | 2563 } |
2578 | 2564 |
2579 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { | 2565 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { |
2580 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2566 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
2581 for (size_t i = 0; i < extra_parts_.size(); ++i) | 2567 for (size_t i = 0; i < extra_parts_.size(); ++i) |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3625 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { | 3611 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { |
3626 return variations::GetVariationParamValue( | 3612 return variations::GetVariationParamValue( |
3627 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; | 3613 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; |
3628 } | 3614 } |
3629 | 3615 |
3630 // static | 3616 // static |
3631 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( | 3617 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( |
3632 const storage::QuotaSettings* settings) { | 3618 const storage::QuotaSettings* settings) { |
3633 g_default_quota_settings = settings; | 3619 g_default_quota_settings = settings; |
3634 } | 3620 } |
OLD | NEW |