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

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

Issue 591063003: Split ChromeContentBrowserClient into smaller parts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 27 matching lines...) Expand all
38 #include "chrome/browser/media/cast_transport_host_filter.h" 38 #include "chrome/browser/media/cast_transport_host_filter.h"
39 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 39 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
40 #include "chrome/browser/media/midi_permission_context.h" 40 #include "chrome/browser/media/midi_permission_context.h"
41 #include "chrome/browser/media/midi_permission_context_factory.h" 41 #include "chrome/browser/media/midi_permission_context_factory.h"
42 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" 42 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
43 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h" 43 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
44 #include "chrome/browser/net/chrome_net_log.h" 44 #include "chrome/browser/net/chrome_net_log.h"
45 #include "chrome/browser/notifications/desktop_notification_service.h" 45 #include "chrome/browser/notifications/desktop_notification_service.h"
46 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 46 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
47 #include "chrome/browser/platform_util.h" 47 #include "chrome/browser/platform_util.h"
48 #include "chrome/browser/plugins/plugin_info_message_filter.h"
49 #include "chrome/browser/prerender/prerender_final_status.h" 48 #include "chrome/browser/prerender/prerender_final_status.h"
50 #include "chrome/browser/prerender/prerender_manager.h" 49 #include "chrome/browser/prerender/prerender_manager.h"
51 #include "chrome/browser/prerender/prerender_manager_factory.h" 50 #include "chrome/browser/prerender/prerender_manager_factory.h"
52 #include "chrome/browser/prerender/prerender_message_filter.h" 51 #include "chrome/browser/prerender/prerender_message_filter.h"
53 #include "chrome/browser/prerender/prerender_tracker.h" 52 #include "chrome/browser/prerender/prerender_tracker.h"
54 #include "chrome/browser/printing/printing_message_filter.h" 53 #include "chrome/browser/printing/printing_message_filter.h"
55 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" 54 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
56 #include "chrome/browser/profiles/profile.h" 55 #include "chrome/browser/profiles/profile.h"
57 #include "chrome/browser/profiles/profile_io_data.h" 56 #include "chrome/browser/profiles/profile_io_data.h"
58 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" 57 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 #include "extensions/common/constants.h" 233 #include "extensions/common/constants.h"
235 #include "extensions/common/extension.h" 234 #include "extensions/common/extension.h"
236 #include "extensions/common/extension_set.h" 235 #include "extensions/common/extension_set.h"
237 #include "extensions/common/manifest_handlers/background_info.h" 236 #include "extensions/common/manifest_handlers/background_info.h"
238 #include "extensions/common/manifest_handlers/shared_module_info.h" 237 #include "extensions/common/manifest_handlers/shared_module_info.h"
239 #include "extensions/common/permissions/permissions_data.h" 238 #include "extensions/common/permissions/permissions_data.h"
240 #include "extensions/common/permissions/socket_permission.h" 239 #include "extensions/common/permissions/socket_permission.h"
241 #include "extensions/common/switches.h" 240 #include "extensions/common/switches.h"
242 #endif 241 #endif
243 242
243 #if defined(ENABLE_PLUGINS)
244 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
245 #endif
246
244 #if defined(ENABLE_SPELLCHECK) 247 #if defined(ENABLE_SPELLCHECK)
245 #include "chrome/browser/spellchecker/spellcheck_message_filter.h" 248 #include "chrome/browser/spellchecker/spellcheck_message_filter.h"
246 #endif 249 #endif
247 250
248 #if defined(ENABLE_WEBRTC) 251 #if defined(ENABLE_WEBRTC)
249 #include "chrome/browser/media/webrtc_logging_handler_host.h" 252 #include "chrome/browser/media/webrtc_logging_handler_host.h"
250 #endif 253 #endif
251 254
252 using base::FileDescriptor; 255 using base::FileDescriptor;
253 using blink::WebWindowFeatures; 256 using blink::WebWindowFeatures;
(...skipping 15 matching lines...) Expand all
269 #endif 272 #endif
270 273
271 #if defined(ENABLE_EXTENSIONS) 274 #if defined(ENABLE_EXTENSIONS)
272 using extensions::APIPermission; 275 using extensions::APIPermission;
273 using extensions::ChromeContentBrowserClientExtensionsPart; 276 using extensions::ChromeContentBrowserClientExtensionsPart;
274 using extensions::Extension; 277 using extensions::Extension;
275 using extensions::InfoMap; 278 using extensions::InfoMap;
276 using extensions::Manifest; 279 using extensions::Manifest;
277 #endif 280 #endif
278 281
282 #if defined(ENABLE_PLUGINS)
283 using plugins::ChromeContentBrowserClientPluginsPart;
284 #endif
285
279 namespace { 286 namespace {
280 287
281 // Cached version of the locale so we can return the locale on the I/O 288 // Cached version of the locale so we can return the locale on the I/O
282 // thread. 289 // thread.
283 base::LazyInstance<std::string> g_io_thread_application_locale; 290 base::LazyInstance<std::string> g_io_thread_application_locale;
284 291
285 #if defined(ENABLE_PLUGINS) 292 #if defined(ENABLE_PLUGINS)
286 // TODO(teravest): Add renderer-side API-specific checking for these APIs so 293 // TODO(teravest): Add renderer-side API-specific checking for these APIs so
287 // that blanket permission isn't granted to all dev channel APIs for these. 294 // that blanket permission isn't granted to all dev channel APIs for these.
288 // http://crbug.com/386743 295 // http://crbug.com/386743
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 ChromeContentBrowserClient::ChromeContentBrowserClient() 608 ChromeContentBrowserClient::ChromeContentBrowserClient()
602 : prerender_tracker_(NULL), 609 : prerender_tracker_(NULL),
603 weak_factory_(this) { 610 weak_factory_(this) {
604 #if defined(ENABLE_PLUGINS) 611 #if defined(ENABLE_PLUGINS)
605 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i) 612 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i)
606 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); 613 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
607 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) 614 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i)
608 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); 615 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
609 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) 616 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
610 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); 617 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
618
619 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
611 #endif 620 #endif
612 621
613 #if !defined(OS_ANDROID) 622 #if !defined(OS_ANDROID)
614 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance(); 623 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
615 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine); 624 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine);
616 #endif 625 #endif
617 626
618 #if defined(ENABLE_EXTENSIONS) 627 #if defined(ENABLE_EXTENSIONS)
619 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart); 628 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
620 #endif 629 #endif
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 } 819 }
811 820
812 void ChromeContentBrowserClient::RenderProcessWillLaunch( 821 void ChromeContentBrowserClient::RenderProcessWillLaunch(
813 content::RenderProcessHost* host) { 822 content::RenderProcessHost* host) {
814 int id = host->GetID(); 823 int id = host->GetID();
815 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); 824 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
816 net::URLRequestContextGetter* context = 825 net::URLRequestContextGetter* context =
817 profile->GetRequestContextForRenderProcess(id); 826 profile->GetRequestContextForRenderProcess(id);
818 827
819 host->AddFilter(new ChromeRenderMessageFilter(id, profile)); 828 host->AddFilter(new ChromeRenderMessageFilter(id, profile));
820 #if defined(ENABLE_PLUGINS)
821 host->AddFilter(new PluginInfoMessageFilter(id, profile));
822 #endif
823 host->AddFilter(new cast::CastTransportHostFilter); 829 host->AddFilter(new cast::CastTransportHostFilter);
824 #if defined(ENABLE_PRINTING) 830 #if defined(ENABLE_PRINTING)
825 host->AddFilter(new printing::PrintingMessageFilter(id, profile)); 831 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
826 #endif 832 #endif
827 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile)); 833 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile));
828 #if defined(ENABLE_SPELLCHECK) 834 #if defined(ENABLE_SPELLCHECK)
829 host->AddFilter(new SpellCheckMessageFilter(id)); 835 host->AddFilter(new SpellCheckMessageFilter(id));
830 #endif 836 #endif
831 #if defined(OS_MACOSX) 837 #if defined(OS_MACOSX)
832 host->AddFilter(new SpellCheckMessageFilterMac(id)); 838 host->AddFilter(new SpellCheckMessageFilterMac(id));
(...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after
2325 return DownloadPrefs::GetDefaultDownloadDirectory(); 2331 return DownloadPrefs::GetDefaultDownloadDirectory();
2326 } 2332 }
2327 2333
2328 std::string ChromeContentBrowserClient::GetDefaultDownloadName() { 2334 std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2329 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); 2335 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2330 } 2336 }
2331 2337
2332 void ChromeContentBrowserClient::DidCreatePpapiPlugin( 2338 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2333 content::BrowserPpapiHost* browser_host) { 2339 content::BrowserPpapiHost* browser_host) {
2334 #if defined(ENABLE_PLUGINS) 2340 #if defined(ENABLE_PLUGINS)
2335 browser_host->GetPpapiHost()->AddHostFactoryFilter( 2341 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
2336 scoped_ptr<ppapi::host::HostFactory>(
2337 new ChromeBrowserPepperHostFactory(browser_host)));
2338 #endif 2342 #endif
2339 } 2343 }
2340 2344
2341 content::BrowserPpapiHost* 2345 content::BrowserPpapiHost*
2342 ChromeContentBrowserClient::GetExternalBrowserPpapiHost( 2346 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2343 int plugin_process_id) { 2347 int plugin_process_id) {
2344 #if !defined(DISABLE_NACL) 2348 #if !defined(DISABLE_NACL)
2345 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); 2349 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
2346 while (!iter.Done()) { 2350 while (!iter.Done()) {
2347 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>( 2351 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
2348 iter.GetDelegate()); 2352 iter.GetDelegate());
2349 if (host->process() && 2353 if (host->process() &&
2350 host->process()->GetData().id == plugin_process_id) { 2354 host->process()->GetData().id == plugin_process_id) {
2351 // Found the plugin. 2355 // Found the plugin.
2352 return host->browser_ppapi_host(); 2356 return host->browser_ppapi_host();
2353 } 2357 }
2354 ++iter; 2358 ++iter;
2355 } 2359 }
2356 #endif 2360 #endif
2357 return NULL; 2361 return NULL;
2358 } 2362 }
2359 2363
2360 bool ChromeContentBrowserClient::AllowPepperSocketAPI( 2364 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2361 content::BrowserContext* browser_context, 2365 content::BrowserContext* browser_context,
2362 const GURL& url, 2366 const GURL& url,
2363 bool private_api, 2367 bool private_api,
2364 const content::SocketPermissionRequest* params) { 2368 const content::SocketPermissionRequest* params) {
2365 #if defined(ENABLE_EXTENSIONS) 2369 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2366 Profile* profile = Profile::FromBrowserContext(browser_context); 2370 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
2367 const extensions::ExtensionSet* extension_set = NULL; 2371 browser_context, url, private_api, params, allowed_socket_origins_);
2368 if (profile) {
2369 extension_set =
2370 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
2371 }
2372
2373 if (private_api) {
2374 // Access to private socket APIs is controlled by the whitelist.
2375 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2376 allowed_socket_origins_)) {
2377 return true;
2378 }
2379 } else {
2380 // Access to public socket APIs is controlled by extension permissions.
2381 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2382 extension_set) {
2383 const Extension* extension = extension_set->GetByID(url.host());
2384 if (extension) {
2385 const extensions::PermissionsData* permissions_data =
2386 extension->permissions_data();
2387 if (params) {
2388 extensions::SocketPermission::CheckParam check_params(
2389 params->type, params->host, params->port);
2390 if (permissions_data->CheckAPIPermissionWithParam(
2391 extensions::APIPermission::kSocket, &check_params)) {
2392 return true;
2393 }
2394 } else if (permissions_data->HasAPIPermission(
2395 extensions::APIPermission::kSocket)) {
2396 return true;
2397 }
2398 }
2399 }
2400 }
2401
2402 // Allow both public and private APIs if the command line says so.
2403 return IsHostAllowedByCommandLine(url, extension_set,
2404 switches::kAllowNaClSocketAPI);
2405 #else 2372 #else
2406 return false; 2373 return false;
2407 #endif 2374 #endif
2408 } 2375 }
2409 2376
2410 ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy( 2377 ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2411 WebContents* web_contents) { 2378 WebContents* web_contents) {
2412 return new ChromeSelectFilePolicy(web_contents); 2379 return new ChromeSelectFilePolicy(web_contents);
2413 } 2380 }
2414 2381
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2589 #if defined(OS_ANDROID) 2556 #if defined(OS_ANDROID)
2590 return new DevToolsManagerDelegateAndroid(); 2557 return new DevToolsManagerDelegateAndroid();
2591 #else 2558 #else
2592 return new ChromeDevToolsManagerDelegate(); 2559 return new ChromeDevToolsManagerDelegate();
2593 #endif 2560 #endif
2594 } 2561 }
2595 2562
2596 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle( 2563 bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2597 content::BrowserContext* browser_context, 2564 content::BrowserContext* browser_context,
2598 const GURL& url) { 2565 const GURL& url) {
2599 #if defined(ENABLE_EXTENSIONS) 2566 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2600 Profile* profile = Profile::FromBrowserContext(browser_context); 2567 return ChromeContentBrowserClientPluginsPart::
2601 const extensions::ExtensionSet* extension_set = NULL; 2568 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url,
2602 if (profile) { 2569 allowed_file_handle_origins_);
2603 extension_set =
2604 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
2605 }
2606 return IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2607 allowed_file_handle_origins_) ||
2608 IsHostAllowedByCommandLine(url, extension_set,
2609 switches::kAllowNaClFileHandleAPI);
2610 #else 2570 #else
2611 return false; 2571 return false;
2612 #endif 2572 #endif
2613 } 2573 }
2614 2574
2615 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs( 2575 bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
2616 content::BrowserContext* browser_context, 2576 content::BrowserContext* browser_context,
2617 const GURL& url) { 2577 const GURL& url) {
2618 #if defined(ENABLE_EXTENSIONS) 2578 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
2619 // Allow access for tests. 2579 // Allow access for tests.
2620 if (CommandLine::ForCurrentProcess()->HasSwitch( 2580 if (CommandLine::ForCurrentProcess()->HasSwitch(
Lei Zhang 2014/12/04 22:59:43 Move this into chrome_content_browser_client_plugi
Jitu( very slow this week) 2014/12/05 05:39:30 Done.
2621 switches::kEnablePepperTesting)) { 2581 switches::kEnablePepperTesting)) {
2622 return true; 2582 return true;
2623 } 2583 }
2624 2584 return ChromeContentBrowserClientPluginsPart::
2625 Profile* profile = Profile::FromBrowserContext(browser_context); 2585 IsPluginAllowedToUseDevChannelAPIs(browser_context, url,
2626 const extensions::ExtensionSet* extension_set = NULL; 2586 allowed_dev_channel_origins_);
2627 if (profile) {
2628 extension_set =
2629 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
2630 }
2631
2632 // Allow access for whitelisted applications.
2633 if (IsExtensionOrSharedModuleWhitelisted(url,
2634 extension_set,
2635 allowed_dev_channel_origins_)) {
2636 return true;
2637 }
2638
2639 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
2640 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
2641 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
2642 // Chromium builds as well.
2643 return channel <= chrome::VersionInfo::CHANNEL_DEV;
2644 #else 2587 #else
2645 return false; 2588 return false;
2646 #endif 2589 #endif
2647 } 2590 }
2648 2591
2649 net::CookieStore* 2592 net::CookieStore*
2650 ChromeContentBrowserClient::OverrideCookieStoreForRenderProcess( 2593 ChromeContentBrowserClient::OverrideCookieStoreForRenderProcess(
2651 int render_process_id) { 2594 int render_process_id) {
2652 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 2595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2653 if (!prerender_tracker_) 2596 if (!prerender_tracker_)
(...skipping 19 matching lines...) Expand all
2673 switches::kDisableWebRtcEncryption, 2616 switches::kDisableWebRtcEncryption,
2674 }; 2617 };
2675 to_command_line->CopySwitchesFrom(from_command_line, 2618 to_command_line->CopySwitchesFrom(from_command_line,
2676 kWebRtcDevSwitchNames, 2619 kWebRtcDevSwitchNames,
2677 arraysize(kWebRtcDevSwitchNames)); 2620 arraysize(kWebRtcDevSwitchNames));
2678 } 2621 }
2679 } 2622 }
2680 #endif // defined(ENABLE_WEBRTC) 2623 #endif // defined(ENABLE_WEBRTC)
2681 2624
2682 } // namespace chrome 2625 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698