mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add plugin placeholder and policy support (issue #1708)
- Default plugin loading policy can be specified using the new `--plugin-policy=[allow|block|detect]` command-line flag. - Move CefRequestHandler::OnBeforePluginLoad to CefRequestContextHandler and add a new policy argument that supports different actions (allow, block, detect, disable) on a per-plugin-instance basis. - Add CefContextMenuHandler::RunContextMenu for providing a custom context menu implementation. - Add CefResourceBundleHandler::GetDataResourceForScale for returning scaled resources (issue #1272). - Add CefResourceBundle for retrieving resources from the resource bundle (*.pak) files loaded by CEF during startup or via the CefResourceBundleHandler. - Linux: Fix Debug build IO access warning with CefGetMimeType. - cef_unittests: Move the refcounting implementation from TestHandler to subclasses in order to support interface inheritance from subclasses.
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
#include "libcef/renderer/extensions/print_web_view_helper_delegate.h"
|
||||
#include "libcef/renderer/media/cef_key_systems.h"
|
||||
#include "libcef/renderer/pepper/pepper_helper.h"
|
||||
#include "libcef/renderer/plugins/cef_plugin_placeholder.h"
|
||||
#include "libcef/renderer/plugins/plugin_preroller.h"
|
||||
#include "libcef/renderer/render_frame_observer.h"
|
||||
#include "libcef/renderer/render_message_filter.h"
|
||||
#include "libcef/renderer/render_process_observer.h"
|
||||
@@ -27,15 +29,20 @@
|
||||
#include "libcef/renderer/webkit_glue.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/metrics/user_metrics_action.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "chrome/common/pepper_permission_util.h"
|
||||
#include "chrome/grit/generated_resources.h"
|
||||
#include "chrome/renderer/content_settings_observer.h"
|
||||
#include "chrome/renderer/loadtimes_extension_bindings.h"
|
||||
#include "chrome/renderer/pepper/chrome_pdf_print_client.h"
|
||||
#include "chrome/renderer/spellchecker/spellcheck.h"
|
||||
#include "chrome/renderer/spellchecker/spellcheck_provider.h"
|
||||
#include "components/content_settings/core/common/content_settings_types.h"
|
||||
#include "components/nacl/common/nacl_constants.h"
|
||||
#include "components/printing/renderer/print_web_view_helper.h"
|
||||
#include "components/web_cache/renderer/web_cache_render_process_observer.h"
|
||||
#include "content/child/worker_task_runner.h"
|
||||
@@ -62,6 +69,7 @@
|
||||
#include "third_party/WebKit/public/platform/WebPrerenderingSupport.h"
|
||||
#include "third_party/WebKit/public/platform/WebString.h"
|
||||
#include "third_party/WebKit/public/platform/WebURL.h"
|
||||
#include "third_party/WebKit/public/web/WebConsoleMessage.h"
|
||||
#include "third_party/WebKit/public/web/WebDocument.h"
|
||||
#include "third_party/WebKit/public/web/WebElement.h"
|
||||
#include "third_party/WebKit/public/web/WebFrame.h"
|
||||
@@ -71,6 +79,7 @@
|
||||
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
|
||||
#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
|
||||
#include "third_party/WebKit/public/web/WebView.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
#include "base/mac/mac_util.h"
|
||||
@@ -186,6 +195,19 @@ void AppendParams(const std::vector<base::string16>& additional_names,
|
||||
existing_values->swap(values);
|
||||
}
|
||||
|
||||
std::string GetPluginInstancePosterAttribute(
|
||||
const blink::WebPluginParams& params) {
|
||||
DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
|
||||
|
||||
for (size_t i = 0; i < params.attributeNames.size(); ++i) {
|
||||
if (params.attributeNames[i].utf8() == "poster" &&
|
||||
!params.attributeValues[i].isEmpty()) {
|
||||
return params.attributeValues[i].utf8();
|
||||
}
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CefContentRendererClient::CefContentRendererClient()
|
||||
@@ -660,6 +682,7 @@ void CefContentRendererClient::WillDestroyCurrentMessageLoop() {
|
||||
single_process_cleanup_complete_ = true;
|
||||
}
|
||||
|
||||
// static
|
||||
bool CefContentRendererClient::IsExtensionOrSharedModuleWhitelisted(
|
||||
const GURL& url, const std::set<std::string>& whitelist) {
|
||||
DCHECK(extensions::ExtensionsEnabled());
|
||||
@@ -669,6 +692,167 @@ bool CefContentRendererClient::IsExtensionOrSharedModuleWhitelisted(
|
||||
whitelist);
|
||||
}
|
||||
|
||||
// static
|
||||
blink::WebPlugin* CefContentRendererClient::CreatePlugin(
|
||||
content::RenderFrame* render_frame,
|
||||
blink::WebLocalFrame* frame,
|
||||
const blink::WebPluginParams& original_params,
|
||||
const CefViewHostMsg_GetPluginInfo_Output& output) {
|
||||
const content::WebPluginInfo& info = output.plugin;
|
||||
const std::string& actual_mime_type = output.actual_mime_type;
|
||||
const base::string16& group_name = output.group_name;
|
||||
const std::string& identifier = output.group_identifier;
|
||||
CefViewHostMsg_GetPluginInfo_Status status = output.status;
|
||||
GURL url(original_params.url);
|
||||
std::string orig_mime_type = original_params.mimeType.utf8();
|
||||
CefPluginPlaceholder* placeholder = NULL;
|
||||
|
||||
// If the browser plugin is to be enabled, this should be handled by the
|
||||
// renderer, so the code won't reach here due to the early exit in
|
||||
// OverrideCreatePlugin.
|
||||
if (status == CefViewHostMsg_GetPluginInfo_Status::kNotFound ||
|
||||
orig_mime_type == content::kBrowserPluginMimeType) {
|
||||
placeholder = CefPluginPlaceholder::CreateLoadableMissingPlugin(
|
||||
render_frame, frame, original_params);
|
||||
} else {
|
||||
// TODO(bauerb): This should be in content/.
|
||||
blink::WebPluginParams params(original_params);
|
||||
for (size_t i = 0; i < info.mime_types.size(); ++i) {
|
||||
if (info.mime_types[i].mime_type == actual_mime_type) {
|
||||
AppendParams(info.mime_types[i].additional_param_names,
|
||||
info.mime_types[i].additional_param_values,
|
||||
¶ms.attributeNames, ¶ms.attributeValues);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (params.mimeType.isNull() && (actual_mime_type.size() > 0)) {
|
||||
// Webkit might say that mime type is null while we already know the
|
||||
// actual mime type via CefViewHostMsg_GetPluginInfo. In that case
|
||||
// we should use what we know since WebpluginDelegateProxy does some
|
||||
// specific initializations based on this information.
|
||||
params.mimeType = blink::WebString::fromUTF8(actual_mime_type.c_str());
|
||||
}
|
||||
|
||||
auto create_blocked_plugin =
|
||||
[&render_frame, &frame, ¶ms, &info, &identifier, &group_name](
|
||||
int template_id, const base::string16& message) {
|
||||
return CefPluginPlaceholder::CreateBlockedPlugin(
|
||||
render_frame, frame, params, info, identifier, group_name,
|
||||
template_id, message, PlaceholderPosterInfo());
|
||||
};
|
||||
switch (status) {
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kNotFound: {
|
||||
NOTREACHED();
|
||||
break;
|
||||
}
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kAllowed:
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kPlayImportantContent: {
|
||||
// Delay loading plugins if prerendering.
|
||||
// TODO(mmenke): In the case of prerendering, feed into
|
||||
// CefContentRendererClient::CreatePlugin instead, to
|
||||
// reduce the chance of future regressions.
|
||||
bool is_prerendering = false;
|
||||
bool power_saver_enabled =
|
||||
status ==
|
||||
CefViewHostMsg_GetPluginInfo_Status::kPlayImportantContent;
|
||||
bool blocked_for_background_tab =
|
||||
render_frame->IsHidden() && power_saver_enabled;
|
||||
|
||||
PlaceholderPosterInfo poster_info;
|
||||
if (power_saver_enabled) {
|
||||
poster_info.poster_attribute =
|
||||
GetPluginInstancePosterAttribute(params);
|
||||
poster_info.base_url = frame->document().url();
|
||||
}
|
||||
|
||||
if (blocked_for_background_tab || is_prerendering ||
|
||||
!poster_info.poster_attribute.empty()) {
|
||||
placeholder = CefPluginPlaceholder::CreateBlockedPlugin(
|
||||
render_frame, frame, params, info, identifier, group_name,
|
||||
poster_info.poster_attribute.empty() ? IDR_BLOCKED_PLUGIN_HTML
|
||||
: IDR_PLUGIN_POSTER_HTML,
|
||||
l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
|
||||
poster_info);
|
||||
placeholder->set_blocked_for_background_tab(
|
||||
blocked_for_background_tab);
|
||||
placeholder->set_blocked_for_prerendering(is_prerendering);
|
||||
placeholder->set_power_saver_enabled(power_saver_enabled);
|
||||
placeholder->AllowLoading();
|
||||
break;
|
||||
}
|
||||
|
||||
scoped_ptr<content::PluginInstanceThrottler> throttler;
|
||||
if (power_saver_enabled) {
|
||||
throttler = content::PluginInstanceThrottler::Create();
|
||||
// PluginPreroller manages its own lifetime.
|
||||
new CefPluginPreroller(
|
||||
render_frame, frame, params, info, identifier, group_name,
|
||||
l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
|
||||
throttler.get());
|
||||
}
|
||||
|
||||
return render_frame->CreatePlugin(frame, info, params,
|
||||
throttler.Pass());
|
||||
}
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported: {
|
||||
content::RenderThread::Get()->RecordAction(
|
||||
base::UserMetricsAction("Plugin_NPAPINotSupported"));
|
||||
placeholder = create_blocked_plugin(
|
||||
IDR_BLOCKED_PLUGIN_HTML,
|
||||
l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED_METRO));
|
||||
break;
|
||||
}
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kDisabled: {
|
||||
// Intentionally using the blocked plugin resources instead of the
|
||||
// disabled plugin resources. This provides better messaging (no link to
|
||||
// chrome://plugins) and adds testing support.
|
||||
placeholder = create_blocked_plugin(
|
||||
IDR_BLOCKED_PLUGIN_HTML,
|
||||
l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED_BY_POLICY,
|
||||
group_name));
|
||||
break;
|
||||
}
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked: {
|
||||
NOTREACHED() << "Plugin installation is not supported.";
|
||||
break;
|
||||
}
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed: {
|
||||
placeholder = create_blocked_plugin(
|
||||
IDR_BLOCKED_PLUGIN_HTML,
|
||||
l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED, group_name));
|
||||
break;
|
||||
}
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kUnauthorized: {
|
||||
placeholder = create_blocked_plugin(
|
||||
IDR_BLOCKED_PLUGIN_HTML,
|
||||
l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, group_name));
|
||||
placeholder->AllowLoading();
|
||||
break;
|
||||
}
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kBlocked: {
|
||||
placeholder = create_blocked_plugin(
|
||||
IDR_BLOCKED_PLUGIN_HTML,
|
||||
l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name));
|
||||
placeholder->AllowLoading();
|
||||
content::RenderThread::Get()->RecordAction(
|
||||
base::UserMetricsAction("Plugin_Blocked"));
|
||||
break;
|
||||
}
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kBlockedByPolicy: {
|
||||
placeholder = create_blocked_plugin(
|
||||
IDR_BLOCKED_PLUGIN_HTML,
|
||||
l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED_BY_POLICY,
|
||||
group_name));
|
||||
content::RenderThread::Get()->RecordAction(
|
||||
base::UserMetricsAction("Plugin_BlockedByPolicy"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
placeholder->SetStatus(status);
|
||||
return placeholder->plugin();
|
||||
}
|
||||
|
||||
void CefContentRendererClient::BrowserCreated(
|
||||
content::RenderView* render_view,
|
||||
content::RenderFrame* render_frame) {
|
||||
@@ -743,57 +927,3 @@ void CefContentRendererClient::RunSingleProcessCleanupOnUIThread() {
|
||||
if (!CefContext::Get()->settings().multi_threaded_message_loop)
|
||||
delete host;
|
||||
}
|
||||
|
||||
blink::WebPlugin* CefContentRendererClient::CreatePlugin(
|
||||
content::RenderFrame* render_frame,
|
||||
blink::WebLocalFrame* frame,
|
||||
const blink::WebPluginParams& original_params,
|
||||
const CefViewHostMsg_GetPluginInfo_Output& output) {
|
||||
const content::WebPluginInfo& info = output.plugin;
|
||||
const std::string& actual_mime_type = output.actual_mime_type;
|
||||
CefViewHostMsg_GetPluginInfo_Status status = output.status;
|
||||
GURL url(original_params.url);
|
||||
std::string orig_mime_type = original_params.mimeType.utf8();
|
||||
|
||||
// If the browser plugin is to be enabled, this should be handled by the
|
||||
// renderer, so the code won't reach here due to the early exit in
|
||||
// OverrideCreatePlugin.
|
||||
if (status == CefViewHostMsg_GetPluginInfo_Status::kNotFound ||
|
||||
orig_mime_type == content::kBrowserPluginMimeType) {
|
||||
return NULL;
|
||||
} else {
|
||||
// TODO(bauerb): This should be in content/.
|
||||
blink::WebPluginParams params(original_params);
|
||||
for (size_t i = 0; i < info.mime_types.size(); ++i) {
|
||||
if (info.mime_types[i].mime_type == actual_mime_type) {
|
||||
AppendParams(info.mime_types[i].additional_param_names,
|
||||
info.mime_types[i].additional_param_values,
|
||||
¶ms.attributeNames, ¶ms.attributeValues);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (params.mimeType.isNull() && (actual_mime_type.size() > 0)) {
|
||||
// Webkit might say that mime type is null while we already know the
|
||||
// actual mime type via CefViewHostMsg_GetPluginInfo. In that case
|
||||
// we should use what we know since WebpluginDelegateProxy does some
|
||||
// specific initializations based on this information.
|
||||
params.mimeType = blink::WebString::fromUTF8(actual_mime_type.c_str());
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kNotFound: {
|
||||
NOTREACHED();
|
||||
break;
|
||||
}
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kAllowed:
|
||||
case CefViewHostMsg_GetPluginInfo_Status::kPlayImportantContent: {
|
||||
// TODO(cef): Maybe supply a throttler based on power settings.
|
||||
return render_frame->CreatePlugin(frame, info, params, nullptr);
|
||||
}
|
||||
default:
|
||||
// TODO(cef): Provide a placeholder for the various failure conditions.
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user