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