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

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: Move over to render frame (but not WebFrameClient yet) + a bunch of cleanups 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 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 761
762 return -1; 762 return -1;
763 } 763 }
764 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 764 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
765 765
766 void SetApplicationLocaleOnIOThread(const std::string& locale) { 766 void SetApplicationLocaleOnIOThread(const std::string& locale) {
767 DCHECK_CURRENTLY_ON(BrowserThread::IO); 767 DCHECK_CURRENTLY_ON(BrowserThread::IO);
768 g_io_thread_application_locale.Get() = locale; 768 g_io_thread_application_locale.Get() = locale;
769 } 769 }
770 770
771 void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) { 771 void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params,
772 RenderFrameHost* render_frame_host = RenderFrameHost::FromID( 772 RenderFrameHost* render_frame_host,
773 params.render_process_id(), params.opener_render_frame_id()); 773 WebContents* tab) {
774 if (!render_frame_host) 774 DCHECK(tab);
775 return; 775 DCHECK(render_frame_host->GetParent() ||
776 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host); 776 tab->GetMainFrame() == render_frame_host);
777 // The tab might already have navigated away. We only need to do this check
778 // for main frames, since the RenderFrameHost for a subframe opener will have
779 // already been deleted if the main frame navigates away.
780 if (!tab ||
781 (!render_frame_host->GetParent() &&
782 tab->GetMainFrame() != render_frame_host))
783 return;
784
785 prerender::PrerenderContents* prerender_contents = 777 prerender::PrerenderContents* prerender_contents =
786 prerender::PrerenderContents::FromWebContents(tab); 778 prerender::PrerenderContents::FromWebContents(tab);
787 if (prerender_contents) { 779 if (prerender_contents) {
788 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW); 780 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
789 return; 781 return;
790 } 782 }
791 783
792 PopupBlockerTabHelper* popup_helper = 784 PopupBlockerTabHelper* popup_helper =
793 PopupBlockerTabHelper::FromWebContents(tab); 785 PopupBlockerTabHelper::FromWebContents(tab);
794 if (!popup_helper) 786 if (!popup_helper)
795 return; 787 return;
796 popup_helper->AddBlockedPopup(params); 788 popup_helper->AddBlockedPopup(params);
797 } 789 }
798 790
799 #if BUILDFLAG(ENABLE_PLUGINS)
800 void HandleFlashDownloadActionOnUIThread(int render_process_id,
801 int render_frame_id,
802 const GURL& source_url) {
803 DCHECK_CURRENTLY_ON(BrowserThread::UI);
804 RenderFrameHost* render_frame_host =
805 RenderFrameHost::FromID(render_process_id, render_frame_id);
806 if (!render_frame_host)
807 return;
808 WebContents* web_contents =
809 WebContents::FromRenderFrameHost(render_frame_host);
810 FlashDownloadInterception::InterceptFlashDownloadNavigation(web_contents,
811 source_url);
812 }
813 #endif // BUILDFLAG(ENABLE_PLUGINS)
814
815 // An implementation of the SSLCertReporter interface used by 791 // An implementation of the SSLCertReporter interface used by
816 // SSLErrorHandler. Uses CertificateReportingService to send reports. The 792 // SSLErrorHandler. Uses CertificateReportingService to send reports. The
817 // service handles queueing and re-sending of failed reports. Each certificate 793 // service handles queueing and re-sending of failed reports. Each certificate
818 // error creates a new instance of this class. 794 // error creates a new instance of this class.
819 class CertificateReportingServiceCertReporter : public SSLCertReporter { 795 class CertificateReportingServiceCertReporter : public SSLCertReporter {
820 public: 796 public:
821 explicit CertificateReportingServiceCertReporter( 797 explicit CertificateReportingServiceCertReporter(
822 CertificateReportingService* service) 798 CertificateReportingService* service)
823 : service_(service) {} 799 : service_(service) {}
824 ~CertificateReportingServiceCertReporter() override {} 800 ~CertificateReportingServiceCertReporter() override {}
(...skipping 23 matching lines...) Expand all
848 return kMinFSM; 824 return kMinFSM;
849 if (minWidth >= kWidthForMaxFSM) 825 if (minWidth >= kWidthForMaxFSM)
850 return kMaxFSM; 826 return kMaxFSM;
851 827
852 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM. 828 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
853 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) / 829 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
854 (kWidthForMaxFSM - kWidthForMinFSM); 830 (kWidthForMaxFSM - kWidthForMinFSM);
855 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; 831 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
856 } 832 }
857 833
858 void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) {
859 WebContents* web_contents = tab_util::GetWebContentsByFrameID(
860 params.render_process_id(), params.opener_render_frame_id());
861 if (!web_contents)
862 return;
863
864 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params);
865 }
866 #endif // defined(OS_ANDROID) 834 #endif // defined(OS_ANDROID)
867 835
868 #if BUILDFLAG(ENABLE_EXTENSIONS) 836 #if BUILDFLAG(ENABLE_EXTENSIONS)
869 // By default, JavaScript, images and autoplay are enabled in guest content. 837 // By default, JavaScript, images and autoplay are enabled in guest content.
870 void GetGuestViewDefaultContentSettingRules( 838 void GetGuestViewDefaultContentSettingRules(
871 bool incognito, 839 bool incognito,
872 RendererContentSettingRules* rules) { 840 RendererContentSettingRules* rules) {
873 rules->image_rules.push_back( 841 rules->image_rules.push_back(
874 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), 842 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
875 ContentSettingsPattern::Wildcard(), 843 ContentSettingsPattern::Wildcard(),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 base::Closure callback_; 927 base::Closure callback_;
960 int count_; 928 int count_;
961 }; 929 };
962 930
963 WebContents* GetWebContents(int render_process_id, int render_frame_id) { 931 WebContents* GetWebContents(int render_process_id, int render_frame_id) {
964 RenderFrameHost* rfh = 932 RenderFrameHost* rfh =
965 RenderFrameHost::FromID(render_process_id, render_frame_id); 933 RenderFrameHost::FromID(render_process_id, render_frame_id);
966 return WebContents::FromRenderFrameHost(rfh); 934 return WebContents::FromRenderFrameHost(rfh);
967 } 935 }
968 936
937 #if BUILDFLAG(ENABLE_EXTENSIONS)
938 // Returns true if there is exists an extension with the same origin as
939 // |source_origin| in |opener_render_process_id| with
940 // APIPermission::kBackground.
941 bool SecurityOriginHasExtensionBackgroundPermission(
942 extensions::ProcessMap* process_map,
943 extensions::ExtensionRegistry* registry,
944 const GURL& source_origin,
945 int opener_render_process_id) {
946 if (source_origin.SchemeIs(extensions::kExtensionScheme)) {
947 const std::string& id = source_origin.host();
948 const Extension* extension = registry->enabled_extensions().GetByID(id);
949 return extension &&
950 extension->permissions_data()->HasAPIPermission(
951 APIPermission::kBackground) &&
952 process_map->Contains(id, opener_render_process_id);
953 }
954
955 for (const auto& extension_id :
956 process_map->GetExtensionsInProcess(opener_render_process_id)) {
957 const Extension* extension = registry->GetExtensionById(
958 extension_id, extensions::ExtensionRegistry::ENABLED);
959 if (extension->web_extent().MatchesSecurityOrigin(source_origin) &&
960 extension->permissions_data()->HasAPIPermission(
961 APIPermission::kBackground)) {
962 return true;
963 }
964 }
965 return false;
966 }
967 #endif
968
969 } // namespace 969 } // namespace
970 970
971 ChromeContentBrowserClient::ChromeContentBrowserClient() 971 ChromeContentBrowserClient::ChromeContentBrowserClient()
972 : weak_factory_(this) { 972 : weak_factory_(this) {
973 #if BUILDFLAG(ENABLE_PLUGINS) 973 #if BUILDFLAG(ENABLE_PLUGINS)
974 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i) 974 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i)
975 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); 975 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
976 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) 976 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i)
977 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); 977 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
978 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) 978 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
(...skipping 1444 matching lines...) Expand 10 before | Expand all | Expand 10 after
2423 content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { 2423 content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
2424 return MediaCaptureDevicesDispatcher::GetInstance(); 2424 return MediaCaptureDevicesDispatcher::GetInstance();
2425 } 2425 }
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 RenderFrameHost* opener,
2434 int opener_render_frame_id,
2435 const GURL& opener_url, 2434 const GURL& opener_url,
2436 const GURL& opener_top_level_frame_url, 2435 const GURL& opener_top_level_frame_url,
2437 const GURL& source_origin, 2436 const GURL& source_origin,
2438 content::mojom::WindowContainerType container_type, 2437 content::mojom::WindowContainerType container_type,
2439 const GURL& target_url, 2438 const GURL& target_url,
2440 const content::Referrer& referrer, 2439 const content::Referrer& referrer,
2441 const std::string& frame_name, 2440 const std::string& frame_name,
2442 WindowOpenDisposition disposition, 2441 WindowOpenDisposition disposition,
2443 const blink::mojom::WindowFeatures& features, 2442 const blink::mojom::WindowFeatures& features,
2444 bool user_gesture, 2443 bool user_gesture,
2445 bool opener_suppressed, 2444 bool opener_suppressed,
2446 content::ResourceContext* context,
2447 bool* no_javascript_access) { 2445 bool* no_javascript_access) {
2448 DCHECK_CURRENTLY_ON(BrowserThread::IO); 2446 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2447 DCHECK(opener);
2449 2448
2449 content::WebContents* web_contents =
2450 content::WebContents::FromRenderFrameHost(opener);
2451 Profile* profile =
2452 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2453 DCHECK(profile);
2450 *no_javascript_access = false; 2454 *no_javascript_access = false;
2451 2455
2452 // If the opener is trying to create a background window but doesn't have 2456 // If the opener is trying to create a background window but doesn't have
2453 // the appropriate permission, fail the attempt. 2457 // the appropriate permission, fail the attempt.
2454 if (container_type == content::mojom::WindowContainerType::BACKGROUND) { 2458 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
2455 #if BUILDFLAG(ENABLE_EXTENSIONS) 2459 #if BUILDFLAG(ENABLE_EXTENSIONS)
2456 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 2460 auto* process_map = extensions::ProcessMap::Get(profile);
2457 InfoMap* map = io_data->GetExtensionInfoMap(); 2461 auto* registry = extensions::ExtensionRegistry::Get(profile);
2458 if (!map->SecurityOriginHasAPIPermission(source_origin, 2462 if (!SecurityOriginHasExtensionBackgroundPermission(
2459 opener_render_process_id, 2463 process_map, registry, source_origin,
2460 APIPermission::kBackground)) { 2464 opener->GetProcess()->GetID())) {
2461 return false; 2465 return false;
2462 } 2466 }
2463 2467
2464 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may 2468 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2465 // return a recently installed Extension even if this CanCreateWindow call 2469 // 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, 2470 // 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 2471 // 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 2472 // already. We must use the full URL to find hosted apps, though, and not
2469 // just the origin. 2473 // just the origin.
2470 const Extension* extension = 2474 const Extension* extension =
2471 map->extensions().GetExtensionOrAppByURL(opener_url); 2475 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
2472 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) 2476 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
2473 *no_javascript_access = true; 2477 *no_javascript_access = true;
2474 #endif 2478 #endif
2475 2479
2476 return true; 2480 return true;
2477 } 2481 }
2478 2482
2479 #if BUILDFLAG(ENABLE_EXTENSIONS) 2483 #if BUILDFLAG(ENABLE_EXTENSIONS)
2480 if (extensions::WebViewRendererState::GetInstance()->IsGuest( 2484 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
2481 opener_render_process_id)) { 2485 opener->GetProcess()->GetID())) {
2482 return true; 2486 return true;
2483 } 2487 }
2484 2488
2485 if (target_url.SchemeIs(extensions::kExtensionScheme)) { 2489 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
2486 // Intentionally duplicating |io_data| and |map| code from above because we 2490 // Intentionally duplicating |registry| code from above because we want to
2487 // want to reduce calls to retrieve them as this function is a SYNC IPC 2491 // reduce calls to retrieve them as this function is a SYNC IPC handler.
2488 // handler. 2492 auto* registry = extensions::ExtensionRegistry::Get(profile);
2489 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
2490 InfoMap* map = io_data->GetExtensionInfoMap();
2491 const Extension* extension = 2493 const Extension* extension =
2492 map->extensions().GetExtensionOrAppByURL(opener_url); 2494 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
2493 if (extension && extension->is_platform_app()) { 2495 if (extension && extension->is_platform_app()) {
2494 AppLoadedInTabSource source = 2496 AppLoadedInTabSource source =
2495 opener_top_level_frame_url == 2497 opener_top_level_frame_url ==
2496 extensions::BackgroundInfo::GetBackgroundURL(extension) 2498 extensions::BackgroundInfo::GetBackgroundURL(extension)
2497 ? APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE 2499 ? APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE
2498 : APP_LOADED_IN_TAB_SOURCE_APP; 2500 : APP_LOADED_IN_TAB_SOURCE_APP;
2499 // TODO(lazyboy): Remove this UMA once the change below to disallow apps 2501 // TODO(lazyboy): Remove this UMA once the change below to disallow apps
2500 // in tabs has settled in stable branch. 2502 // in tabs has settled in stable branch.
2501 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLoadedInTab", source, 2503 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLoadedInTab", source,
2502 APP_LOADED_IN_TAB_SOURCE_MAX); 2504 APP_LOADED_IN_TAB_SOURCE_MAX);
2503 // Platform apps and their background pages should not be able to call 2505 // Platform apps and their background pages should not be able to call
2504 // window.open() to load v2 apps in regular tab. 2506 // window.open() to load v2 apps in regular tab.
2505 // Simply disallow window.open() calls in this case. 2507 // Simply disallow window.open() calls in this case.
2506 return false; 2508 return false;
2507 } 2509 }
2508 } 2510 }
2509 #endif 2511 #endif
2510 2512
2511 HostContentSettingsMap* content_settings = 2513 HostContentSettingsMap* content_settings =
2512 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap(); 2514 HostContentSettingsMapFactory::GetForProfile(profile);
2513 2515
2514 #if BUILDFLAG(ENABLE_PLUGINS) 2516 #if BUILDFLAG(ENABLE_PLUGINS)
2515 if (FlashDownloadInterception::ShouldStopFlashDownloadAction( 2517 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
2516 content_settings, opener_top_level_frame_url, target_url, 2518 content_settings, opener_top_level_frame_url, target_url,
2517 user_gesture)) { 2519 user_gesture)) {
2518 BrowserThread::PostTask( 2520 FlashDownloadInterception::InterceptFlashDownloadNavigation(
2519 BrowserThread::UI, FROM_HERE, 2521 web_contents, opener_top_level_frame_url);
2520 base::Bind(&HandleFlashDownloadActionOnUIThread,
2521 opener_render_process_id, opener_render_frame_id,
2522 opener_top_level_frame_url));
2523 return false; 2522 return false;
2524 } 2523 }
2525 #endif 2524 #endif
2526 2525
2527 BlockedWindowParams blocked_params(
2528 target_url, referrer, frame_name, disposition, features, user_gesture,
2529 opener_suppressed, opener_render_process_id, opener_render_frame_id);
2530
2531 if (!user_gesture && 2526 if (!user_gesture &&
2532 !base::CommandLine::ForCurrentProcess()->HasSwitch( 2527 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2533 switches::kDisablePopupBlocking)) { 2528 switches::kDisablePopupBlocking)) {
2534 if (content_settings->GetContentSetting(opener_top_level_frame_url, 2529 if (content_settings->GetContentSetting(
2535 opener_top_level_frame_url, 2530 opener_top_level_frame_url, opener_top_level_frame_url,
2536 CONTENT_SETTINGS_TYPE_POPUPS, 2531 CONTENT_SETTINGS_TYPE_POPUPS,
2537 std::string()) != 2532 std::string()) != CONTENT_SETTING_ALLOW) {
2538 CONTENT_SETTING_ALLOW) { 2533 BlockedWindowParams blocked_params(target_url, referrer, frame_name,
2539 BrowserThread::PostTask(BrowserThread::UI, 2534 disposition, features, user_gesture,
2540 FROM_HERE, 2535 opener_suppressed);
2541 base::Bind(&HandleBlockedPopupOnUIThread, 2536 HandleBlockedPopupOnUIThread(blocked_params, opener, web_contents);
2542 blocked_params));
2543 return false; 2537 return false;
2544 } 2538 }
2545 } 2539 }
2546 2540
2547 #if defined(OS_ANDROID) 2541 #if defined(OS_ANDROID)
2548 if (SingleTabModeTabHelper::IsRegistered(opener_render_process_id, 2542 auto* single_tab_mode_helper =
2549 opener_render_frame_id)) { 2543 SingleTabModeTabHelper::FromWebContents(web_contents);
2550 BrowserThread::PostTask(BrowserThread::UI, 2544 if (single_tab_mode_helper->block_all_new_windows()) {
2551 FROM_HERE, 2545 BlockedWindowParams blocked_params(target_url, referrer, frame_name,
2552 base::Bind(&HandleSingleTabModeBlockOnUIThread, 2546 disposition, features, user_gesture,
2553 blocked_params)); 2547 opener_suppressed);
2548 single_tab_mode_helper->HandleOpenUrl(blocked_params);
2554 return false; 2549 return false;
2555 } 2550 }
2556 #endif 2551 #endif
2557 2552
2558 return true; 2553 return true;
2559 } 2554 }
2560 2555
2561 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { 2556 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2562 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2557 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2563 for (size_t i = 0; i < extra_parts_.size(); ++i) 2558 for (size_t i = 0; i < extra_parts_.size(); ++i)
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after
3619 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { 3614 RedirectNonUINonIOBrowserThreadsToTaskScheduler() {
3620 return variations::GetVariationParamValue( 3615 return variations::GetVariationParamValue(
3621 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; 3616 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true";
3622 } 3617 }
3623 3618
3624 // static 3619 // static
3625 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( 3620 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
3626 const storage::QuotaSettings* settings) { 3621 const storage::QuotaSettings* settings) {
3627 g_default_quota_settings = settings; 3622 g_default_quota_settings = settings;
3628 } 3623 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698