OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/chrome_content_browser_client_extensions_par t.h" | 5 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_par t.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 11 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
12 #include "chrome/browser/extensions/browser_permissions_policy_delegate.h" | 12 #include "chrome/browser/extensions/browser_permissions_policy_delegate.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_web_ui.h" | 14 #include "chrome/browser/extensions/extension_web_ui.h" |
15 #include "chrome/browser/extensions/extension_webkit_preferences.h" | 15 #include "chrome/browser/extensions/extension_webkit_preferences.h" |
16 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 16 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_io_data.h" | 18 #include "chrome/browser/profiles/profile_io_data.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/browser/renderer_host/chrome_extension_message_filter.h" | 20 #include "chrome/browser/renderer_host/chrome_extension_message_filter.h" |
21 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" | 21 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
22 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
23 #include "chrome/common/chrome_switches.h" | |
24 #include "chrome/common/chrome_version_info.h" | |
23 #include "chrome/common/extensions/extension_process_policy.h" | 25 #include "chrome/common/extensions/extension_process_policy.h" |
24 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" | 26 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
27 #include "chrome/common/pepper_permission_util.h" | |
25 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/browser_url_handler.h" | 29 #include "content/public/browser/browser_url_handler.h" |
27 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
28 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
29 #include "content/public/browser/site_instance.h" | 32 #include "content/public/browser/site_instance.h" |
30 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
31 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
32 #include "extensions/browser/extension_host.h" | 35 #include "extensions/browser/extension_host.h" |
33 #include "extensions/browser/extension_message_filter.h" | 36 #include "extensions/browser/extension_message_filter.h" |
34 #include "extensions/browser/extension_registry.h" | 37 #include "extensions/browser/extension_registry.h" |
35 #include "extensions/browser/extension_system.h" | 38 #include "extensions/browser/extension_system.h" |
36 #include "extensions/browser/info_map.h" | 39 #include "extensions/browser/info_map.h" |
37 #include "extensions/browser/view_type_utils.h" | 40 #include "extensions/browser/view_type_utils.h" |
38 #include "extensions/common/constants.h" | 41 #include "extensions/common/constants.h" |
39 #include "extensions/common/manifest_handlers/background_info.h" | 42 #include "extensions/common/manifest_handlers/background_info.h" |
40 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" | 43 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
44 #include "extensions/common/permissions/socket_permission.h" | |
41 #include "extensions/common/switches.h" | 45 #include "extensions/common/switches.h" |
42 | 46 |
43 using content::BrowserThread; | 47 using content::BrowserThread; |
44 using content::BrowserURLHandler; | 48 using content::BrowserURLHandler; |
45 using content::RenderViewHost; | 49 using content::RenderViewHost; |
46 using content::SiteInstance; | 50 using content::SiteInstance; |
47 using content::WebContents; | 51 using content::WebContents; |
48 using content::WebPreferences; | 52 using content::WebPreferences; |
49 | 53 |
50 namespace extensions { | 54 namespace extensions { |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 Profile::FromBrowserContext(site_instance->GetBrowserContext()); | 388 Profile::FromBrowserContext(site_instance->GetBrowserContext()); |
385 DCHECK(profile); | 389 DCHECK(profile); |
386 BrowserThread::PostTask( | 390 BrowserThread::PostTask( |
387 BrowserThread::IO, | 391 BrowserThread::IO, |
388 FROM_HERE, | 392 FROM_HERE, |
389 base::Bind(&InfoMap::SetSigninProcess, | 393 base::Bind(&InfoMap::SetSigninProcess, |
390 ExtensionSystem::Get(profile)->info_map(), | 394 ExtensionSystem::Get(profile)->info_map(), |
391 site_instance->GetProcess()->GetID())); | 395 site_instance->GetProcess()->GetID())); |
392 } | 396 } |
393 | 397 |
398 // static | |
399 bool ChromeContentBrowserClientExtensionsPart:: | |
400 IsPluginAllowedToCallRequestOSFileHandle( | |
401 content::BrowserContext* browser_context, | |
402 const GURL& url, | |
403 const std::set<std::string>& allowed_file_handle_origins) { | |
404 Profile* profile = Profile::FromBrowserContext(browser_context); | |
Lei Zhang
2014/09/23 01:15:11
I know you are just cutting+pasting code here, but
| |
405 const extensions::ExtensionSet* extension_set = NULL; | |
406 if (profile) { | |
407 const ExtensionService* ext_service = | |
408 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
409 if (ext_service) { | |
410 extension_set = ext_service->extensions(); | |
411 } | |
412 } | |
413 return chrome::IsExtensionOrSharedModuleWhitelisted( | |
414 url, extension_set, allowed_file_handle_origins) || | |
415 chrome::IsHostAllowedByCommandLine( | |
416 url, extension_set, ::switches::kAllowNaClFileHandleAPI); | |
417 } | |
418 | |
419 bool ChromeContentBrowserClientExtensionsPart::AllowPepperSocketAPI( | |
420 content::BrowserContext* browser_context, | |
421 const GURL& url, | |
422 bool private_api, | |
423 const content::SocketPermissionRequest* params, | |
424 const std::set<std::string>& whitelist) { | |
425 Profile* profile = Profile::FromBrowserContext(browser_context); | |
426 const extensions::ExtensionSet* extension_set = NULL; | |
427 if (profile) { | |
428 const ExtensionService* ext_service = | |
429 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
430 if (ext_service) { | |
431 extension_set = ext_service->extensions(); | |
432 } | |
433 } | |
434 | |
435 if (private_api) { | |
436 // Access to private socket APIs is controlled by the whitelist. | |
437 if (chrome::IsExtensionOrSharedModuleWhitelisted( | |
438 url, extension_set, whitelist)) { | |
439 return true; | |
440 } | |
441 } else { | |
442 // Access to public socket APIs is controlled by extension permissions. | |
443 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) && | |
444 extension_set) { | |
445 const Extension* extension = extension_set->GetByID(url.host()); | |
446 if (extension) { | |
447 const extensions::PermissionsData* permissions_data = | |
448 extension->permissions_data(); | |
449 if (params) { | |
450 extensions::SocketPermission::CheckParam check_params( | |
451 params->type, params->host, params->port); | |
452 if (permissions_data->CheckAPIPermissionWithParam( | |
453 extensions::APIPermission::kSocket, &check_params)) { | |
454 return true; | |
455 } | |
456 } else if (permissions_data->HasAPIPermission( | |
457 extensions::APIPermission::kSocket)) { | |
458 return true; | |
459 } | |
460 } | |
461 } | |
462 } | |
463 | |
464 // Allow both public and private APIs if the command line says so. | |
465 return chrome::IsHostAllowedByCommandLine( | |
466 url, extension_set, ::switches::kAllowNaClSocketAPI); | |
467 } | |
468 | |
469 bool | |
470 ChromeContentBrowserClientExtensionsPart::IsPluginAllowedToUseDevChannelAPIs( | |
471 content::BrowserContext* browser_context, | |
472 const GURL& url, | |
473 const std::set<std::string>& allowed_dev_channel_origins) { | |
474 Profile* profile = Profile::FromBrowserContext(browser_context); | |
475 const extensions::ExtensionSet* extension_set = NULL; | |
476 if (profile) { | |
477 const ExtensionService* ext_service = | |
478 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
479 if (ext_service) { | |
480 extension_set = ext_service->extensions(); | |
481 } | |
482 } | |
483 | |
484 // Allow access for whitelisted applications. | |
485 if (chrome::IsExtensionOrSharedModuleWhitelisted( | |
486 url, extension_set, allowed_dev_channel_origins)) { | |
487 return true; | |
488 } | |
489 | |
490 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | |
491 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown" | |
492 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on | |
493 // Chromium builds as well. | |
494 return channel <= chrome::VersionInfo::CHANNEL_DEV; | |
495 } | |
496 | |
394 void ChromeContentBrowserClientExtensionsPart::RenderProcessWillLaunch( | 497 void ChromeContentBrowserClientExtensionsPart::RenderProcessWillLaunch( |
395 content::RenderProcessHost* host) { | 498 content::RenderProcessHost* host) { |
396 int id = host->GetID(); | 499 int id = host->GetID(); |
397 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | 500 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
398 | 501 |
399 host->AddFilter(new ChromeExtensionMessageFilter(id, profile)); | 502 host->AddFilter(new ChromeExtensionMessageFilter(id, profile)); |
400 host->AddFilter(new ExtensionMessageFilter(id, profile)); | 503 host->AddFilter(new ExtensionMessageFilter(id, profile)); |
401 SendExtensionWebRequestStatusToHost(host); | 504 SendExtensionWebRequestStatusToHost(host); |
402 } | 505 } |
403 | 506 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 DCHECK(profile); | 631 DCHECK(profile); |
529 if (ProcessMap::Get(profile)->Contains(process->GetID())) { | 632 if (ProcessMap::Get(profile)->Contains(process->GetID())) { |
530 command_line->AppendSwitch(switches::kExtensionProcess); | 633 command_line->AppendSwitch(switches::kExtensionProcess); |
531 #if defined(ENABLE_WEBRTC) | 634 #if defined(ENABLE_WEBRTC) |
532 command_line->AppendSwitch(::switches::kEnableWebRtcHWH264Encoding); | 635 command_line->AppendSwitch(::switches::kEnableWebRtcHWH264Encoding); |
533 #endif | 636 #endif |
534 } | 637 } |
535 } | 638 } |
536 | 639 |
537 } // namespace extensions | 640 } // namespace extensions |
OLD | NEW |