| Index: chrome/browser/plugins/chrome_content_browser_client_plugins_part.cc
|
| diff --git a/chrome/browser/plugins/chrome_content_browser_client_plugins_part.cc b/chrome/browser/plugins/chrome_content_browser_client_plugins_part.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3b8fe77ca302aa8b25998cafb2aeb01ecd249ce9
|
| --- /dev/null
|
| +++ b/chrome/browser/plugins/chrome_content_browser_client_plugins_part.cc
|
| @@ -0,0 +1,153 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
|
| +
|
| +#include "base/command_line.h"
|
| +#include "chrome/browser/plugins/plugin_info_message_filter.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| +#include "chrome/common/chrome_version_info.h"
|
| +#include "chrome/common/pepper_permission_util.h"
|
| +#include "content/public/browser/render_process_host.h"
|
| +#include "ppapi/host/ppapi_host.h"
|
| +#include "ppapi/shared_impl/ppapi_switches.h"
|
| +
|
| +#if defined(ENABLE_EXTENSIONS)
|
| +#include "chrome/browser/extensions/extension_service.h"
|
| +#include "extensions/browser/extension_registry.h"
|
| +#include "extensions/common/constants.h"
|
| +#include "extensions/common/permissions/permissions_data.h"
|
| +#include "extensions/common/permissions/socket_permission.h"
|
| +#endif
|
| +
|
| +namespace plugins {
|
| +
|
| +ChromeContentBrowserClientPluginsPart::ChromeContentBrowserClientPluginsPart() {
|
| +}
|
| +
|
| +ChromeContentBrowserClientPluginsPart::
|
| + ~ChromeContentBrowserClientPluginsPart() {
|
| +}
|
| +
|
| +void ChromeContentBrowserClientPluginsPart::RenderProcessWillLaunch(
|
| + content::RenderProcessHost* host) {
|
| + Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
|
| + host->AddFilter(new PluginInfoMessageFilter(host->GetID(), profile));
|
| +}
|
| +
|
| +bool ChromeContentBrowserClientPluginsPart::
|
| + IsPluginAllowedToCallRequestOSFileHandle(
|
| + content::BrowserContext* browser_context,
|
| + const GURL& url,
|
| + const std::set<std::string>& allowed_file_handle_origins) {
|
| +#if defined(ENABLE_EXTENSIONS)
|
| + Profile* profile = Profile::FromBrowserContext(browser_context);
|
| + const extensions::ExtensionSet* extension_set = NULL;
|
| + if (profile) {
|
| + extension_set =
|
| + &extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
|
| + }
|
| +
|
| + return chrome::IsExtensionOrSharedModuleWhitelisted(
|
| + url, extension_set, allowed_file_handle_origins) ||
|
| + chrome::IsHostAllowedByCommandLine(
|
| + url, extension_set, ::switches::kAllowNaClFileHandleAPI);
|
| +#else
|
| + return false;
|
| +#endif
|
| +}
|
| +
|
| +bool ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
|
| + content::BrowserContext* browser_context,
|
| + const GURL& url,
|
| + bool private_api,
|
| + const content::SocketPermissionRequest* params,
|
| + const std::set<std::string>& allowed_socket_origin) {
|
| + Profile* profile = Profile::FromBrowserContext(browser_context);
|
| +#if defined(ENABLE_EXTENSIONS)
|
| + const extensions::ExtensionSet* extension_set = NULL;
|
| + if (profile) {
|
| + extension_set =
|
| + &extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
|
| + }
|
| +
|
| + if (private_api) {
|
| + // Access to private socket APIs is controlled by the whitelist.
|
| + if (chrome::IsExtensionOrSharedModuleWhitelisted(url, extension_set,
|
| + allowed_socket_origin)) {
|
| + return true;
|
| + }
|
| + } else {
|
| + // Access to public socket APIs is controlled by extension permissions.
|
| + if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
|
| + extension_set) {
|
| + const extensions::Extension* extension =
|
| + extension_set->GetByID(url.host());
|
| + if (extension) {
|
| + const extensions::PermissionsData* permissions_data =
|
| + extension->permissions_data();
|
| + if (params) {
|
| + extensions::SocketPermission::CheckParam check_params(
|
| + params->type, params->host, params->port);
|
| + if (permissions_data->CheckAPIPermissionWithParam(
|
| + extensions::APIPermission::kSocket, &check_params)) {
|
| + return true;
|
| + }
|
| + } else if (permissions_data->HasAPIPermission(
|
| + extensions::APIPermission::kSocket)) {
|
| + return true;
|
| + }
|
| + }
|
| + }
|
| + }
|
| +
|
| + // Allow both public and private APIs if the command line says so.
|
| + return chrome::IsHostAllowedByCommandLine(url, extension_set,
|
| + ::switches::kAllowNaClSocketAPI);
|
| +#else
|
| + return false;
|
| +#endif
|
| +}
|
| +
|
| +bool ChromeContentBrowserClientPluginsPart::IsPluginAllowedToUseDevChannelAPIs(
|
| + content::BrowserContext* browser_context,
|
| + const GURL& url,
|
| + const std::set<std::string>& allowed_dev_channel_origins) {
|
| + // Allow access for tests.
|
| + if (CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kEnablePepperTesting)) {
|
| + return true;
|
| + }
|
| +
|
| +#if defined(ENABLE_EXTENSIONS)
|
| + Profile* profile = Profile::FromBrowserContext(browser_context);
|
| + const extensions::ExtensionSet* extension_set = NULL;
|
| + if (profile) {
|
| + extension_set =
|
| + &extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
|
| + }
|
| +
|
| + // Allow access for whitelisted applications.
|
| + if (chrome::IsExtensionOrSharedModuleWhitelisted(
|
| + url, extension_set, allowed_dev_channel_origins)) {
|
| + return true;
|
| + }
|
| +#endif
|
| + chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
|
| + // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
|
| + // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
|
| + // Chromium builds as well.
|
| + return channel <= chrome::VersionInfo::CHANNEL_DEV;
|
| +}
|
| +
|
| +void ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(
|
| + content::BrowserPpapiHost* browser_host) {
|
| + browser_host->GetPpapiHost()->AddHostFactoryFilter(
|
| + scoped_ptr<ppapi::host::HostFactory>(
|
| + new chrome::ChromeBrowserPepperHostFactory(browser_host)));
|
| +}
|
| +
|
| +} // namespace plugins
|
|
|