Call OnBeforePluginLoad when building the plugin list (issue #1708)

This commit is contained in:
Marshall Greenblatt
2015-09-25 14:59:30 +03:00
parent a33720558e
commit 4149192d81
23 changed files with 421 additions and 161 deletions

View File

@@ -52,7 +52,8 @@ void CefBrowserContext::Initialize() {
resource_context_.reset(new CefResourceContext(
IsOffTheRecord(),
extensions_enabled ? extension_system_->info_map() : NULL));
extensions_enabled ? extension_system_->info_map() : NULL,
GetHandler()));
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
this);

View File

@@ -19,12 +19,12 @@
#include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/pepper/browser_pepper_host_factory.h"
#include "libcef/browser/plugins/plugin_info_message_filter.h"
#include "libcef/browser/plugins/plugin_service_filter.h"
#include "libcef/browser/printing/printing_message_filter.h"
#include "libcef/browser/resource_dispatcher_host_delegate.h"
#include "libcef/browser/speech_recognition_manager_delegate.h"
#include "libcef/browser/ssl_info_impl.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/web_plugin_impl.h"
#include "libcef/common/cef_messages.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/command_line_impl.h"
@@ -38,6 +38,7 @@
#include "base/path_service.h"
#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
#include "chrome/common/chrome_switches.h"
#include "content/browser/plugin_service_impl.h"
#include "content/public/browser/access_token_store.h"
#include "content/public/browser/browser_ppapi_host.h"
#include "content/public/browser/browser_url_handler.h"
@@ -358,6 +359,10 @@ int GetCrashSignalFD(const base::CommandLine& command_line) {
CefContentBrowserClient::CefContentBrowserClient()
: browser_main_parts_(NULL),
next_browser_id_(0) {
plugin_service_filter_.reset(new CefPluginServiceFilter);
content::PluginServiceImpl::GetInstance()->SetFilter(
plugin_service_filter_.get());
last_create_window_params_.opener_process_id = MSG_ROUTING_NONE;
}

View File

@@ -32,6 +32,7 @@ class CefResourceDispatcherHostDelegate;
class PrefService;
namespace content {
class PluginServiceFilter;
class SiteInstance;
}
@@ -173,6 +174,7 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
CefBrowserMainParts* browser_main_parts_;
scoped_ptr<content::PluginServiceFilter> plugin_service_filter_;
scoped_ptr<CefResourceDispatcherHostDelegate>
resource_dispatcher_host_delegate_;

View File

@@ -6,9 +6,9 @@
#include "libcef/browser/plugins/plugin_info_message_filter.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/plugins/plugin_service_filter.h"
#include "libcef/browser/web_plugin_impl.h"
#include "libcef/common/cef_messages.h"
#include "libcef/common/content_client.h"
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
@@ -243,83 +243,15 @@ void CefPluginInfoMessageFilter::PluginsLoaded(
IPC::Message* reply_msg,
const std::vector<WebPluginInfo>& plugins) {
CefViewHostMsg_GetPluginInfo_Output output;
CefRefPtr<CefRequestContextHandler> handler =
browser_context_->GetHandler();
// This also fills in |actual_mime_type|.
scoped_ptr<PluginMetadata> plugin_metadata;
if (context_.FindEnabledPlugin(params.render_frame_id, params.url,
params.top_origin_url, params.mime_type,
&output.status, &output.plugin,
&output.actual_mime_type,
&plugin_metadata)) {
context_.DecidePluginStatus(params, output.plugin, plugin_metadata.get(),
&output.status);
const bool is_found =
output.status != CefViewHostMsg_GetPluginInfo_Status::kNotFound &&
output.status != CefViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported;
const bool is_internal_pdf_plugin =
is_found &&
(output.plugin.path == CefString(CefContentClient::kPDFPluginPath));
if (is_internal_pdf_plugin &&
output.status != CefViewHostMsg_GetPluginInfo_Status::kAllowed) {
// Always allow the internal PDF plugin to load if it exists.
output.status = CefViewHostMsg_GetPluginInfo_Status::kAllowed;
}
// Give the handler an opportunity to modify the policy.
CefRefPtr<CefRequestContextHandler> handler =
browser_context_->GetHandler();
if (handler.get() &&
is_found &&
!is_internal_pdf_plugin) {
cef_plugin_policy_t plugin_policy = PLUGIN_POLICY_DISABLE;
switch (output.status) {
case CefViewHostMsg_GetPluginInfo_Status::kAllowed:
plugin_policy = PLUGIN_POLICY_ALLOW;
break;
case CefViewHostMsg_GetPluginInfo_Status::kBlocked:
case CefViewHostMsg_GetPluginInfo_Status::kBlockedByPolicy:
case CefViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked:
case CefViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed:
case CefViewHostMsg_GetPluginInfo_Status::kUnauthorized:
plugin_policy = PLUGIN_POLICY_BLOCK;
break;
case CefViewHostMsg_GetPluginInfo_Status::kDisabled:
plugin_policy = PLUGIN_POLICY_DISABLE;
break;
case CefViewHostMsg_GetPluginInfo_Status::kPlayImportantContent:
plugin_policy = PLUGIN_POLICY_DETECT_IMPORTANT;
break;
default:
NOTREACHED();
break;
}
CefRefPtr<CefWebPluginInfoImpl> pluginInfo(
new CefWebPluginInfoImpl(output.plugin));
if (handler->OnBeforePluginLoad(output.actual_mime_type,
params.url.spec(),
params.top_origin_url.spec(),
pluginInfo.get(),
&plugin_policy)) {
switch (plugin_policy) {
case PLUGIN_POLICY_ALLOW:
output.status = CefViewHostMsg_GetPluginInfo_Status::kAllowed;
break;
case PLUGIN_POLICY_DETECT_IMPORTANT:
output.status =
CefViewHostMsg_GetPluginInfo_Status::kPlayImportantContent;
break;
case PLUGIN_POLICY_BLOCK:
output.status = CefViewHostMsg_GetPluginInfo_Status::kBlocked;
break;
case PLUGIN_POLICY_DISABLE:
output.status = CefViewHostMsg_GetPluginInfo_Status::kDisabled;
break;
}
}
}
}
context_.FindEnabledPlugin(params, handler.get(),
&output.status, &output.plugin,
&output.actual_mime_type,
&plugin_metadata);
if (plugin_metadata) {
output.group_identifier = plugin_metadata->identifier();
@@ -488,10 +420,8 @@ void CefPluginInfoMessageFilter::Context::DecidePluginStatus(
}
bool CefPluginInfoMessageFilter::Context::FindEnabledPlugin(
int render_frame_id,
const GURL& url,
const GURL& top_origin_url,
const std::string& mime_type,
const GetPluginInfo_Params& params,
CefRequestContextHandler* handler,
CefViewHostMsg_GetPluginInfo_Status* status,
WebPluginInfo* plugin,
std::string* actual_mime_type,
@@ -502,7 +432,8 @@ bool CefPluginInfoMessageFilter::Context::FindEnabledPlugin(
std::vector<WebPluginInfo> matching_plugins;
std::vector<std::string> mime_types;
PluginService::GetInstance()->GetPluginInfoArray(
url, mime_type, allow_wildcard, &matching_plugins, &mime_types);
params.url, params.mime_type, allow_wildcard, &matching_plugins,
&mime_types);
if (matching_plugins.empty()) {
*status = CefViewHostMsg_GetPluginInfo_Status::kNotFound;
#if defined(OS_WIN) || defined(OS_MACOSX)
@@ -511,39 +442,48 @@ bool CefPluginInfoMessageFilter::Context::FindEnabledPlugin(
// could be a not-yet-installed Pepper plugin. To avoid notifying on
// these types, bail early based on a blacklist of pepper mime types.
for (auto pepper_mime_type : kPepperPluginMimeTypes)
if (pepper_mime_type == mime_type)
if (pepper_mime_type == params.mime_type)
return false;
}
#endif
return false;
}
content::PluginServiceFilter* filter =
PluginService::GetInstance()->GetFilter();
CefPluginServiceFilter* filter = static_cast<CefPluginServiceFilter*>(
PluginService::GetInstance()->GetFilter());
DCHECK(filter);
CefViewHostMsg_GetPluginInfo_Status first_status = *status;
size_t i = 0;
for (; i < matching_plugins.size(); ++i) {
if (!filter || filter->IsPluginAvailable(render_process_id_,
render_frame_id,
resource_context_,
url,
top_origin_url,
&matching_plugins[i])) {
*plugin = matching_plugins[i];
*actual_mime_type = mime_types[i];
*plugin_metadata = PluginFinder::GetInstance()->GetPluginMetadata(*plugin);
DecidePluginStatus(params, *plugin, (*plugin_metadata).get(), status);
if (filter->IsPluginAvailable(handler,
params.url,
params.top_origin_url,
plugin,
status)) {
break;
}
if (i == 0)
first_status = *status;
}
// If we broke out of the loop, we have found an enabled plugin.
bool enabled = i < matching_plugins.size();
if (!enabled) {
// Otherwise, we only found disabled plugins, so we take the first one.
i = 0;
*status = CefViewHostMsg_GetPluginInfo_Status::kDisabled;
}
*plugin = matching_plugins[i];
*actual_mime_type = mime_types[i];
if (plugin_metadata)
// Otherwise, we only found disabled/not-found plugins, so we take the first
// one.
*plugin = matching_plugins[0];
*actual_mime_type = mime_types[0];
*plugin_metadata = PluginFinder::GetInstance()->GetPluginMetadata(*plugin);
*status = first_status;
}
return enabled;
}

View File

@@ -20,6 +20,7 @@
#include "content/public/browser/browser_message_filter.h"
class CefBrowserContext;
class CefRequestContextHandler;
struct CefViewHostMsg_GetPluginInfo_Output;
enum class CefViewHostMsg_GetPluginInfo_Status;
class GURL;
@@ -50,10 +51,8 @@ class CefPluginInfoMessageFilter : public content::BrowserMessageFilter {
const content::WebPluginInfo& plugin,
const PluginMetadata* plugin_metadata,
CefViewHostMsg_GetPluginInfo_Status* status) const;
bool FindEnabledPlugin(int render_frame_id,
const GURL& url,
const GURL& top_origin_url,
const std::string& mime_type,
bool FindEnabledPlugin(const GetPluginInfo_Params& params,
CefRequestContextHandler* handler,
CefViewHostMsg_GetPluginInfo_Status* status,
content::WebPluginInfo* plugin,
std::string* actual_mime_type,

View File

@@ -0,0 +1,106 @@
// Copyright (c) 2015 The Chromium Embedded Framework 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 "libcef/browser/plugins/plugin_service_filter.h"
#include "include/cef_request_context_handler.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/resource_context.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/web_plugin_impl.h"
#include "libcef/common/cef_messages.h"
#include "libcef/common/content_client.h"
CefPluginServiceFilter::CefPluginServiceFilter() {
}
bool CefPluginServiceFilter::IsPluginAvailable(
int render_process_id,
int render_frame_id,
const void* context,
const GURL& url,
const GURL& policy_url,
content::WebPluginInfo* plugin) {
CefRefPtr<CefRequestContextHandler> handler =
reinterpret_cast<const CefResourceContext*>(context)->GetHandler();
CefViewHostMsg_GetPluginInfo_Status status =
CefViewHostMsg_GetPluginInfo_Status::kAllowed;
return IsPluginAvailable(handler.get(), url, policy_url, plugin, &status);
}
bool CefPluginServiceFilter::CanLoadPlugin(int render_process_id,
const base::FilePath& path) {
return true;
}
bool CefPluginServiceFilter::IsPluginAvailable(
CefRequestContextHandler* handler,
const GURL& url,
const GURL& policy_url,
content::WebPluginInfo* plugin,
CefViewHostMsg_GetPluginInfo_Status* status) {
if (*status == CefViewHostMsg_GetPluginInfo_Status::kNotFound ||
*status == CefViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported) {
// The plugin does not exist so no need to query the handler.
return false;
}
if (plugin->path == CefString(CefContentClient::kPDFPluginPath)) {
// Always allow the internal PDF plugin to load.
*status = CefViewHostMsg_GetPluginInfo_Status::kAllowed;
return true;
}
if (handler) {
CefRefPtr<CefWebPluginInfoImpl> pluginInfo(
new CefWebPluginInfoImpl(*plugin));
cef_plugin_policy_t plugin_policy = PLUGIN_POLICY_ALLOW;
switch (*status) {
case CefViewHostMsg_GetPluginInfo_Status::kAllowed:
plugin_policy = PLUGIN_POLICY_ALLOW;
break;
case CefViewHostMsg_GetPluginInfo_Status::kBlocked:
case CefViewHostMsg_GetPluginInfo_Status::kBlockedByPolicy:
case CefViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked:
case CefViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed:
case CefViewHostMsg_GetPluginInfo_Status::kUnauthorized:
plugin_policy = PLUGIN_POLICY_BLOCK;
break;
case CefViewHostMsg_GetPluginInfo_Status::kDisabled:
plugin_policy = PLUGIN_POLICY_DISABLE;
break;
case CefViewHostMsg_GetPluginInfo_Status::kPlayImportantContent:
plugin_policy = PLUGIN_POLICY_DETECT_IMPORTANT;
break;
default:
NOTREACHED();
break;
}
if (handler->OnBeforePluginLoad(plugin->mime_types[0].mime_type,
url.possibly_invalid_spec(),
policy_url.possibly_invalid_spec(),
pluginInfo.get(),
&plugin_policy)) {
switch (plugin_policy) {
case PLUGIN_POLICY_ALLOW:
*status = CefViewHostMsg_GetPluginInfo_Status::kAllowed;
break;
case PLUGIN_POLICY_DETECT_IMPORTANT:
*status = CefViewHostMsg_GetPluginInfo_Status::kPlayImportantContent;
break;
case PLUGIN_POLICY_BLOCK:
*status = CefViewHostMsg_GetPluginInfo_Status::kBlocked;
break;
case PLUGIN_POLICY_DISABLE:
*status = CefViewHostMsg_GetPluginInfo_Status::kDisabled;
break;
}
}
}
return (*status != CefViewHostMsg_GetPluginInfo_Status::kDisabled);
}

View File

@@ -0,0 +1,46 @@
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_PLUGINS_PLUGIN_SERVICE_FILTER_H_
#define CEF_LIBCEF_BROWSER_PLUGINS_PLUGIN_SERVICE_FILTER_H_
#include "content/public/browser/plugin_service_filter.h"
#include "include/internal/cef_types.h"
#include "base/macros.h"
class CefRequestContextHandler;
enum class CefViewHostMsg_GetPluginInfo_Status;
class CefPluginServiceFilter : public content::PluginServiceFilter {
public:
CefPluginServiceFilter();
// Called whenever the plugin list is queried. For example, when choosing the
// plugin to handle a mime type or when determining the plugins that will be
// exposed to JavaScript via 'navigator.plugins'.
bool IsPluginAvailable(int render_process_id,
int render_frame_id,
const void* context,
const GURL& url,
const GURL& policy_url,
content::WebPluginInfo* plugin) override;
bool CanLoadPlugin(int render_process_id,
const base::FilePath& path) override;
// Returns false if the plugin is not found or disabled. May call
// CefRequestContextHandler::OnBeforePluginLoad if possible/necessary.
bool IsPluginAvailable(CefRequestContextHandler* handler,
const GURL& url,
const GURL& policy_url,
content::WebPluginInfo* plugin,
CefViewHostMsg_GetPluginInfo_Status* status);
private:
DISALLOW_COPY_AND_ASSIGN(CefPluginServiceFilter);
};
#endif // CEF_LIBCEF_BROWSER_PLUGINS_PLUGIN_SERVICE_FILTER_H_

View File

@@ -9,8 +9,10 @@
#include "libcef/browser/context.h"
#include "libcef/browser/cookie_manager_impl.h"
#include "libcef/browser/thread_util.h"
#include "base/atomic_sequence_num.h"
#include "base/logging.h"
#include "content/public/browser/plugin_service.h"
using content::BrowserThread;
@@ -283,6 +285,13 @@ bool CefRequestContextImpl::ClearSchemeHandlerFactories() {
return true;
}
void CefRequestContextImpl::PurgePluginListCache(bool reload_pages) {
GetBrowserContext(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
base::Bind(&CefRequestContextImpl::PurgePluginListCacheInternal,
this, reload_pages));
}
CefRequestContextImpl::CefRequestContextImpl(
scoped_refptr<CefBrowserContext> browser_context)
: browser_context_(browser_context),
@@ -375,3 +384,11 @@ void CefRequestContextImpl::ClearSchemeHandlerFactoriesInternal(
CEF_REQUIRE_IOT();
request_context->request_manager()->ClearFactories();
}
void CefRequestContextImpl::PurgePluginListCacheInternal(
bool reload_pages,
scoped_refptr<CefBrowserContext> browser_context) {
CEF_REQUIRE_UIT();
content::PluginService::GetInstance()->PurgePluginListCache(
browser_context.get(), false);
}

View File

@@ -60,6 +60,7 @@ class CefRequestContextImpl : public CefRequestContext {
const CefString& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory) override;
bool ClearSchemeHandlerFactories() override;
void PurgePluginListCache(bool reload_pages) override;
const CefRequestContextSettings& settings() const { return settings_; }
@@ -85,9 +86,12 @@ class CefRequestContextImpl : public CefRequestContext {
const CefString& scheme_name,
const CefString& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory,
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
void ClearSchemeHandlerFactoriesInternal(
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
void PurgePluginListCacheInternal(
bool reload_pages,
scoped_refptr<CefBrowserContext> browser_context);
scoped_refptr<CefBrowserContext> browser_context_;
CefRequestContextSettings settings_;

View File

@@ -22,9 +22,11 @@
CefResourceContext::CefResourceContext(
bool is_off_the_record,
extensions::InfoMap* extension_info_map)
extensions::InfoMap* extension_info_map,
CefRefPtr<CefRequestContextHandler> handler)
: is_off_the_record_(is_off_the_record),
extension_info_map_(extension_info_map) {
extension_info_map_(extension_info_map),
handler_(handler) {
}
CefResourceContext::~CefResourceContext() {

View File

@@ -6,6 +6,8 @@
#define CEF_LIBCEF_BROWSER_RESOURCE_CONTEXT_H_
#pragma once
#include "include/cef_request_context_handler.h"
#include "content/public/browser/resource_context.h"
#include "extensions/browser/info_map.h"
@@ -22,7 +24,8 @@ class CefURLRequestContextGetter;
class CefResourceContext : public content::ResourceContext {
public:
CefResourceContext(bool is_off_the_record,
extensions::InfoMap* extension_info_map);
extensions::InfoMap* extension_info_map,
CefRefPtr<CefRequestContextHandler> handler);
~CefResourceContext() override;
// ResourceContext implementation.
@@ -38,12 +41,14 @@ class CefResourceContext : public content::ResourceContext {
const extensions::InfoMap* GetExtensionInfoMap() const {
return extension_info_map_.get();
}
CefRefPtr<CefRequestContextHandler> GetHandler() const { return handler_; }
private:
scoped_refptr<CefURLRequestContextGetter> getter_;
bool is_off_the_record_;
scoped_refptr<extensions::InfoMap> extension_info_map_;
CefRefPtr<CefRequestContextHandler> handler_;
DISALLOW_COPY_AND_ASSIGN(CefResourceContext);
};