Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "chrome/browser/extensions/extension_service.h" | |
|
Lei Zhang
2014/12/05 06:58:51
Can you put all the extensions includes inside #if
Jitu( very slow this week)
2014/12/05 08:02:43
Done.
| |
| 9 #include "chrome/browser/plugins/plugin_info_message_filter.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory .h" | |
| 12 #include "chrome/common/chrome_switches.h" | |
| 13 #include "chrome/common/chrome_version_info.h" | |
| 14 #include "chrome/common/pepper_permission_util.h" | |
| 15 #include "content/public/browser/render_process_host.h" | |
| 16 #include "extensions/browser/extension_registry.h" | |
| 17 #include "extensions/common/constants.h" | |
| 18 #include "extensions/common/permissions/permissions_data.h" | |
| 19 #include "extensions/common/permissions/socket_permission.h" | |
| 20 #include "ppapi/host/ppapi_host.h" | |
| 21 #include "ppapi/shared_impl/ppapi_switches.h" | |
| 22 | |
| 23 namespace plugins { | |
| 24 | |
| 25 ChromeContentBrowserClientPluginsPart::ChromeContentBrowserClientPluginsPart() { | |
| 26 } | |
| 27 | |
| 28 ChromeContentBrowserClientPluginsPart:: | |
| 29 ~ChromeContentBrowserClientPluginsPart() { | |
| 30 } | |
| 31 | |
| 32 void ChromeContentBrowserClientPluginsPart::RenderProcessWillLaunch( | |
| 33 content::RenderProcessHost* host) { | |
| 34 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | |
| 35 host->AddFilter(new PluginInfoMessageFilter(host->GetID(), profile)); | |
| 36 } | |
| 37 | |
| 38 bool ChromeContentBrowserClientPluginsPart:: | |
| 39 IsPluginAllowedToCallRequestOSFileHandle( | |
| 40 content::BrowserContext* browser_context, | |
| 41 const GURL& url, | |
| 42 const std::set<std::string>& allowed_file_handle_origins) { | |
| 43 #if defined(ENABLE_EXTENSIONS) | |
| 44 Profile* profile = Profile::FromBrowserContext(browser_context); | |
| 45 const extensions::ExtensionSet* extension_set = NULL; | |
| 46 if (profile) { | |
| 47 extension_set = | |
| 48 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | |
| 49 } | |
| 50 | |
| 51 return chrome::IsExtensionOrSharedModuleWhitelisted( | |
| 52 url, extension_set, allowed_file_handle_origins) || | |
| 53 chrome::IsHostAllowedByCommandLine( | |
| 54 url, extension_set, ::switches::kAllowNaClFileHandleAPI); | |
| 55 #else | |
| 56 return false; | |
| 57 #endif | |
| 58 } | |
| 59 | |
| 60 bool ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI( | |
| 61 content::BrowserContext* browser_context, | |
| 62 const GURL& url, | |
| 63 bool private_api, | |
| 64 const content::SocketPermissionRequest* params, | |
| 65 const std::set<std::string>& allowed_socket_origin) { | |
| 66 Profile* profile = Profile::FromBrowserContext(browser_context); | |
| 67 #if defined(ENABLE_EXTENSIONS) | |
| 68 const extensions::ExtensionSet* extension_set = NULL; | |
| 69 if (profile) { | |
| 70 extension_set = | |
| 71 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | |
| 72 } | |
| 73 | |
| 74 if (private_api) { | |
| 75 // Access to private socket APIs is controlled by the whitelist. | |
| 76 if (chrome::IsExtensionOrSharedModuleWhitelisted(url, extension_set, | |
| 77 allowed_socket_origin)) { | |
| 78 return true; | |
| 79 } | |
| 80 } else { | |
| 81 // Access to public socket APIs is controlled by extension permissions. | |
| 82 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) && | |
| 83 extension_set) { | |
| 84 const extensions::Extension* extension = | |
| 85 extension_set->GetByID(url.host()); | |
| 86 if (extension) { | |
| 87 const extensions::PermissionsData* permissions_data = | |
| 88 extension->permissions_data(); | |
| 89 if (params) { | |
| 90 extensions::SocketPermission::CheckParam check_params( | |
| 91 params->type, params->host, params->port); | |
| 92 if (permissions_data->CheckAPIPermissionWithParam( | |
| 93 extensions::APIPermission::kSocket, &check_params)) { | |
| 94 return true; | |
| 95 } | |
| 96 } else if (permissions_data->HasAPIPermission( | |
| 97 extensions::APIPermission::kSocket)) { | |
| 98 return true; | |
| 99 } | |
| 100 } | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 // Allow both public and private APIs if the command line says so. | |
| 105 return chrome::IsHostAllowedByCommandLine(url, extension_set, | |
| 106 ::switches::kAllowNaClSocketAPI); | |
| 107 #else | |
| 108 return false; | |
| 109 #endif | |
| 110 } | |
| 111 | |
| 112 bool ChromeContentBrowserClientPluginsPart::IsPluginAllowedToUseDevChannelAPIs( | |
| 113 content::BrowserContext* browser_context, | |
| 114 const GURL& url, | |
| 115 const std::set<std::string>& allowed_dev_channel_origins) { | |
| 116 // Allow access for tests. | |
| 117 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 118 switches::kEnablePepperTesting)) { | |
| 119 return true; | |
| 120 } | |
| 121 | |
| 122 #if defined(ENABLE_EXTENSIONS) | |
| 123 Profile* profile = Profile::FromBrowserContext(browser_context); | |
| 124 const extensions::ExtensionSet* extension_set = NULL; | |
| 125 if (profile) { | |
| 126 extension_set = | |
| 127 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | |
| 128 } | |
| 129 | |
| 130 // Allow access for whitelisted applications. | |
| 131 if (chrome::IsExtensionOrSharedModuleWhitelisted( | |
| 132 url, extension_set, allowed_dev_channel_origins)) { | |
| 133 return true; | |
| 134 } | |
| 135 #endif | |
|
Jitu( very slow this week)
2014/12/05 06:53:49
While i have tried like here
#else
chrome::Vers
| |
| 136 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | |
| 137 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown" | |
| 138 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on | |
| 139 // Chromium builds as well. | |
| 140 return channel <= chrome::VersionInfo::CHANNEL_DEV; | |
| 141 } | |
| 142 | |
| 143 void ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin( | |
| 144 content::BrowserPpapiHost* browser_host) { | |
| 145 browser_host->GetPpapiHost()->AddHostFactoryFilter( | |
| 146 scoped_ptr<ppapi::host::HostFactory>( | |
| 147 new chrome::ChromeBrowserPepperHostFactory(browser_host))); | |
| 148 } | |
| 149 | |
| 150 } // namespace plugins | |
| OLD | NEW |