Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
|
Lei Zhang
2014/12/04 22:59:43
ditto, no (c)
Jitu( very slow this week)
2014/12/05 05:39:31
Done.
| |
| 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 "chrome/browser/extensions/extension_service.h" | |
| 8 #include "chrome/browser/plugins/plugin_info_message_filter.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory .h" | |
| 11 #include "chrome/common/chrome_switches.h" | |
| 12 #include "chrome/common/chrome_version_info.h" | |
| 13 #include "chrome/common/pepper_permission_util.h" | |
| 14 #include "content/public/browser/render_process_host.h" | |
| 15 #include "extensions/browser/extension_registry.h" | |
| 16 #include "extensions/common/constants.h" | |
| 17 #include "extensions/common/permissions/permissions_data.h" | |
| 18 #include "extensions/common/permissions/socket_permission.h" | |
| 19 #include "ppapi/host/ppapi_host.h" | |
| 20 | |
| 21 using namespace extensions; | |
|
Lei Zhang
2014/12/04 22:59:43
Please don't do this, it's against the style guide
Jitu( very slow this week)
2014/12/05 05:39:31
Thanks
Done
| |
| 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 int id = host->GetID(); | |
|
Lei Zhang
2014/12/04 22:59:43
You can just put this in line 36, since the variou
Jitu( very slow this week)
2014/12/05 05:39:31
Done.
| |
| 35 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | |
| 36 host->AddFilter(new PluginInfoMessageFilter(id, profile)); | |
| 37 } | |
| 38 | |
| 39 bool ChromeContentBrowserClientPluginsPart:: | |
| 40 IsPluginAllowedToCallRequestOSFileHandle( | |
| 41 content::BrowserContext* browser_context, | |
| 42 const GURL& url, | |
| 43 const std::set<std::string>& allowed_file_handle_origins) { | |
| 44 Profile* profile = Profile::FromBrowserContext(browser_context); | |
| 45 const extensions::ExtensionSet* extension_set = NULL; | |
|
Lei Zhang
2014/12/04 22:59:43
I don't think there's any standard build configura
Jitu( very slow this week)
2014/12/05 05:39:31
So for in this function you mean to say if extensi
Lei Zhang
2014/12/05 05:45:47
Sure, and you need to look through the other funct
| |
| 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 } | |
| 56 | |
| 57 bool ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI( | |
| 58 content::BrowserContext* browser_context, | |
| 59 const GURL& url, | |
| 60 bool private_api, | |
| 61 const content::SocketPermissionRequest* params, | |
| 62 const std::set<std::string>& allowed_socket_origin) { | |
| 63 Profile* profile = Profile::FromBrowserContext(browser_context); | |
| 64 const extensions::ExtensionSet* extension_set = NULL; | |
| 65 if (profile) { | |
| 66 extension_set = | |
| 67 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | |
| 68 } | |
| 69 | |
| 70 if (private_api) { | |
| 71 // Access to private socket APIs is controlled by the whitelist. | |
| 72 if (chrome::IsExtensionOrSharedModuleWhitelisted(url, extension_set, | |
| 73 allowed_socket_origin)) { | |
| 74 return true; | |
| 75 } | |
| 76 } else { | |
| 77 // Access to public socket APIs is controlled by extension permissions. | |
| 78 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) && | |
| 79 extension_set) { | |
| 80 const Extension* extension = extension_set->GetByID(url.host()); | |
| 81 if (extension) { | |
| 82 const extensions::PermissionsData* permissions_data = | |
| 83 extension->permissions_data(); | |
| 84 if (params) { | |
| 85 extensions::SocketPermission::CheckParam check_params( | |
| 86 params->type, params->host, params->port); | |
| 87 if (permissions_data->CheckAPIPermissionWithParam( | |
| 88 extensions::APIPermission::kSocket, &check_params)) { | |
| 89 return true; | |
| 90 } | |
| 91 } else if (permissions_data->HasAPIPermission( | |
| 92 extensions::APIPermission::kSocket)) { | |
| 93 return true; | |
| 94 } | |
| 95 } | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 // Allow both public and private APIs if the command line says so. | |
| 100 return chrome::IsHostAllowedByCommandLine(url, extension_set, | |
| 101 ::switches::kAllowNaClSocketAPI); | |
| 102 } | |
| 103 | |
| 104 bool ChromeContentBrowserClientPluginsPart::IsPluginAllowedToUseDevChannelAPIs( | |
| 105 content::BrowserContext* browser_context, | |
| 106 const GURL& url, | |
| 107 const std::set<std::string>& allowed_dev_channel_origins) { | |
| 108 Profile* profile = Profile::FromBrowserContext(browser_context); | |
| 109 const extensions::ExtensionSet* extension_set = NULL; | |
| 110 if (profile) { | |
| 111 extension_set = | |
| 112 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | |
| 113 } | |
| 114 | |
| 115 // Allow access for whitelisted applications. | |
| 116 if (chrome::IsExtensionOrSharedModuleWhitelisted( | |
| 117 url, extension_set, allowed_dev_channel_origins)) { | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 121 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | |
| 122 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown" | |
| 123 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on | |
| 124 // Chromium builds as well. | |
| 125 return channel <= chrome::VersionInfo::CHANNEL_DEV; | |
| 126 } | |
| 127 | |
| 128 void ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin( | |
| 129 content::BrowserPpapiHost* browser_host) { | |
| 130 browser_host->GetPpapiHost()->AddHostFactoryFilter( | |
| 131 scoped_ptr<ppapi::host::HostFactory>( | |
| 132 new chrome::ChromeBrowserPepperHostFactory(browser_host))); | |
| 133 } | |
| 134 | |
| 135 } // namespace plugins | |
| OLD | NEW |