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:
Marshall Greenblatt
2015-09-09 16:05:39 +02:00
parent 846107b291
commit dc3aae19e8
114 changed files with 4007 additions and 559 deletions

View File

@ -15,6 +15,7 @@
#include "libcef_dll/ctocpp/context_menu_params_ctocpp.h"
#include "libcef_dll/ctocpp/frame_ctocpp.h"
#include "libcef_dll/ctocpp/menu_model_ctocpp.h"
#include "libcef_dll/ctocpp/run_context_menu_callback_ctocpp.h"
namespace {
@ -55,6 +56,49 @@ void CEF_CALLBACK context_menu_handler_on_before_context_menu(
CefMenuModelCToCpp::Wrap(model));
}
int CEF_CALLBACK context_menu_handler_run_context_menu(
struct _cef_context_menu_handler_t* self, cef_browser_t* browser,
struct _cef_frame_t* frame, struct _cef_context_menu_params_t* params,
struct _cef_menu_model_t* model,
cef_run_context_menu_callback_t* callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return 0;
// Verify param: frame; type: refptr_diff
DCHECK(frame);
if (!frame)
return 0;
// Verify param: params; type: refptr_diff
DCHECK(params);
if (!params)
return 0;
// Verify param: model; type: refptr_diff
DCHECK(model);
if (!model)
return 0;
// Verify param: callback; type: refptr_diff
DCHECK(callback);
if (!callback)
return 0;
// Execute
bool _retval = CefContextMenuHandlerCppToC::Get(self)->RunContextMenu(
CefBrowserCToCpp::Wrap(browser),
CefFrameCToCpp::Wrap(frame),
CefContextMenuParamsCToCpp::Wrap(params),
CefMenuModelCToCpp::Wrap(model),
CefRunContextMenuCallbackCToCpp::Wrap(callback));
// Return type: bool
return _retval;
}
int CEF_CALLBACK context_menu_handler_on_context_menu_command(
struct _cef_context_menu_handler_t* self, cef_browser_t* browser,
struct _cef_frame_t* frame, struct _cef_context_menu_params_t* params,
@ -120,6 +164,7 @@ void CEF_CALLBACK context_menu_handler_on_context_menu_dismissed(
CefContextMenuHandlerCppToC::CefContextMenuHandlerCppToC() {
GetStruct()->on_before_context_menu =
context_menu_handler_on_before_context_menu;
GetStruct()->run_context_menu = context_menu_handler_run_context_menu;
GetStruct()->on_context_menu_command =
context_menu_handler_on_context_menu_command;
GetStruct()->on_context_menu_dismissed =

View File

@ -308,6 +308,36 @@ cef_context_menu_edit_state_flags_t CEF_CALLBACK context_menu_params_get_edit_st
return _retval;
}
int CEF_CALLBACK context_menu_params_is_custom_menu(
struct _cef_context_menu_params_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Execute
bool _retval = CefContextMenuParamsCppToC::Get(self)->IsCustomMenu();
// Return type: bool
return _retval;
}
int CEF_CALLBACK context_menu_params_is_pepper_menu(
struct _cef_context_menu_params_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Execute
bool _retval = CefContextMenuParamsCppToC::Get(self)->IsPepperMenu();
// Return type: bool
return _retval;
}
} // namespace
@ -336,6 +366,8 @@ CefContextMenuParamsCppToC::CefContextMenuParamsCppToC() {
GetStruct()->is_spell_check_enabled =
context_menu_params_is_spell_check_enabled;
GetStruct()->get_edit_state_flags = context_menu_params_get_edit_state_flags;
GetStruct()->is_custom_menu = context_menu_params_is_custom_menu;
GetStruct()->is_pepper_menu = context_menu_params_is_pepper_menu;
}
template<> CefRefPtr<CefContextMenuParams> CefCppToC<CefContextMenuParamsCppToC,

View File

@ -12,6 +12,7 @@
#include "libcef_dll/cpptoc/request_context_handler_cpptoc.h"
#include "libcef_dll/ctocpp/cookie_manager_ctocpp.h"
#include "libcef_dll/ctocpp/web_plugin_info_ctocpp.h"
namespace {
@ -34,6 +35,46 @@ cef_cookie_manager_t* CEF_CALLBACK request_context_handler_get_cookie_manager(
return CefCookieManagerCToCpp::Unwrap(_retval);
}
int CEF_CALLBACK request_context_handler_on_before_plugin_load(
struct _cef_request_context_handler_t* self, const cef_string_t* mime_type,
const cef_string_t* plugin_url, const cef_string_t* top_origin_url,
struct _cef_web_plugin_info_t* plugin_info,
cef_plugin_policy_t* plugin_policy) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: mime_type; type: string_byref_const
DCHECK(mime_type);
if (!mime_type)
return 0;
// Verify param: top_origin_url; type: string_byref_const
DCHECK(top_origin_url);
if (!top_origin_url)
return 0;
// Verify param: plugin_info; type: refptr_diff
DCHECK(plugin_info);
if (!plugin_info)
return 0;
// Verify param: plugin_policy; type: simple_byaddr
DCHECK(plugin_policy);
if (!plugin_policy)
return 0;
// Unverified params: plugin_url
// Execute
bool _retval = CefRequestContextHandlerCppToC::Get(self)->OnBeforePluginLoad(
CefString(mime_type),
CefString(plugin_url),
CefString(top_origin_url),
CefWebPluginInfoCToCpp::Wrap(plugin_info),
plugin_policy);
// Return type: bool
return _retval;
}
} // namespace
@ -41,6 +82,8 @@ cef_cookie_manager_t* CEF_CALLBACK request_context_handler_get_cookie_manager(
CefRequestContextHandlerCppToC::CefRequestContextHandlerCppToC() {
GetStruct()->get_cookie_manager = request_context_handler_get_cookie_manager;
GetStruct()->on_before_plugin_load =
request_context_handler_on_before_plugin_load;
}
template<> CefRefPtr<CefRequestContextHandler> CefCppToC<CefRequestContextHandlerCppToC,

View File

@ -19,7 +19,6 @@
#include "libcef_dll/ctocpp/request_callback_ctocpp.h"
#include "libcef_dll/ctocpp/response_ctocpp.h"
#include "libcef_dll/ctocpp/sslinfo_ctocpp.h"
#include "libcef_dll/ctocpp/web_plugin_info_ctocpp.h"
namespace {
@ -389,36 +388,6 @@ int CEF_CALLBACK request_handler_on_certificate_error(
return _retval;
}
int CEF_CALLBACK request_handler_on_before_plugin_load(
struct _cef_request_handler_t* self, cef_browser_t* browser,
const cef_string_t* url, const cef_string_t* policy_url,
struct _cef_web_plugin_info_t* info) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return 0;
// Verify param: info; type: refptr_diff
DCHECK(info);
if (!info)
return 0;
// Unverified params: url, policy_url
// Execute
bool _retval = CefRequestHandlerCppToC::Get(self)->OnBeforePluginLoad(
CefBrowserCToCpp::Wrap(browser),
CefString(url),
CefString(policy_url),
CefWebPluginInfoCToCpp::Wrap(info));
// Return type: bool
return _retval;
}
void CEF_CALLBACK request_handler_on_plugin_crashed(
struct _cef_request_handler_t* self, cef_browser_t* browser,
const cef_string_t* plugin_path) {
@ -495,7 +464,6 @@ CefRequestHandlerCppToC::CefRequestHandlerCppToC() {
GetStruct()->on_quota_request = request_handler_on_quota_request;
GetStruct()->on_protocol_execution = request_handler_on_protocol_execution;
GetStruct()->on_certificate_error = request_handler_on_certificate_error;
GetStruct()->on_before_plugin_load = request_handler_on_before_plugin_load;
GetStruct()->on_plugin_crashed = request_handler_on_plugin_crashed;
GetStruct()->on_render_view_ready = request_handler_on_render_view_ready;
GetStruct()->on_render_process_terminated =

View File

@ -0,0 +1,153 @@
// 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.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/cpptoc/resource_bundle_cpptoc.h"
// GLOBAL FUNCTIONS - Body may be edited by hand.
CEF_EXPORT cef_resource_bundle_t* cef_resource_bundle_get_global() {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
CefRefPtr<CefResourceBundle> _retval = CefResourceBundle::GetGlobal();
// Return type: refptr_same
return CefResourceBundleCppToC::Wrap(_retval);
}
namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
cef_string_userfree_t CEF_CALLBACK resource_bundle_get_localized_string(
struct _cef_resource_bundle_t* self, int string_id) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Execute
CefString _retval = CefResourceBundleCppToC::Get(self)->GetLocalizedString(
string_id);
// Return type: string
return _retval.DetachToUserFree();
}
int CEF_CALLBACK resource_bundle_get_data_resource(
struct _cef_resource_bundle_t* self, int resource_id, void** data,
size_t* data_size) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: data; type: simple_byref
DCHECK(data);
if (!data)
return 0;
// Verify param: data_size; type: simple_byref
DCHECK(data_size);
if (!data_size)
return 0;
// Translate param: data; type: simple_byref
void* dataVal = data?*data:NULL;
// Translate param: data_size; type: simple_byref
size_t data_sizeVal = data_size?*data_size:0;
// Execute
bool _retval = CefResourceBundleCppToC::Get(self)->GetDataResource(
resource_id,
dataVal,
data_sizeVal);
// Restore param: data; type: simple_byref
if (data)
*data = dataVal;
// Restore param: data_size; type: simple_byref
if (data_size)
*data_size = data_sizeVal;
// Return type: bool
return _retval;
}
int CEF_CALLBACK resource_bundle_get_data_resource_for_scale(
struct _cef_resource_bundle_t* self, int resource_id,
cef_scale_factor_t scale_factor, void** data, size_t* data_size) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: data; type: simple_byref
DCHECK(data);
if (!data)
return 0;
// Verify param: data_size; type: simple_byref
DCHECK(data_size);
if (!data_size)
return 0;
// Translate param: data; type: simple_byref
void* dataVal = data?*data:NULL;
// Translate param: data_size; type: simple_byref
size_t data_sizeVal = data_size?*data_size:0;
// Execute
bool _retval = CefResourceBundleCppToC::Get(self)->GetDataResourceForScale(
resource_id,
scale_factor,
dataVal,
data_sizeVal);
// Restore param: data; type: simple_byref
if (data)
*data = dataVal;
// Restore param: data_size; type: simple_byref
if (data_size)
*data_size = data_sizeVal;
// Return type: bool
return _retval;
}
} // namespace
// CONSTRUCTOR - Do not edit by hand.
CefResourceBundleCppToC::CefResourceBundleCppToC() {
GetStruct()->get_localized_string = resource_bundle_get_localized_string;
GetStruct()->get_data_resource = resource_bundle_get_data_resource;
GetStruct()->get_data_resource_for_scale =
resource_bundle_get_data_resource_for_scale;
}
template<> CefRefPtr<CefResourceBundle> CefCppToC<CefResourceBundleCppToC,
CefResourceBundle, cef_resource_bundle_t>::UnwrapDerived(
CefWrapperType type, cef_resource_bundle_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return NULL;
}
#ifndef NDEBUG
template<> base::AtomicRefCount CefCppToC<CefResourceBundleCppToC,
CefResourceBundle, cef_resource_bundle_t>::DebugObjCt = 0;
#endif
template<> CefWrapperType CefCppToC<CefResourceBundleCppToC, CefResourceBundle,
cef_resource_bundle_t>::kWrapperType = WT_RESOURCE_BUNDLE;

View File

@ -0,0 +1,35 @@
// 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.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef CEF_LIBCEF_DLL_CPPTOC_RESOURCE_BUNDLE_CPPTOC_H_
#define CEF_LIBCEF_DLL_CPPTOC_RESOURCE_BUNDLE_CPPTOC_H_
#pragma once
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "include/cef_resource_bundle.h"
#include "include/capi/cef_resource_bundle_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed DLL-side only.
class CefResourceBundleCppToC
: public CefCppToC<CefResourceBundleCppToC, CefResourceBundle,
cef_resource_bundle_t> {
public:
CefResourceBundleCppToC();
};
#endif // BUILDING_CEF_SHARED
#endif // CEF_LIBCEF_DLL_CPPTOC_RESOURCE_BUNDLE_CPPTOC_H_

View File

@ -18,7 +18,7 @@ namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
int CEF_CALLBACK resource_bundle_handler_get_localized_string(
struct _cef_resource_bundle_handler_t* self, int message_id,
struct _cef_resource_bundle_handler_t* self, int string_id,
cef_string_t* string) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
@ -35,7 +35,7 @@ int CEF_CALLBACK resource_bundle_handler_get_localized_string(
// Execute
bool _retval = CefResourceBundleHandlerCppToC::Get(self)->GetLocalizedString(
message_id,
string_id,
stringStr);
// Return type: bool
@ -81,6 +81,47 @@ int CEF_CALLBACK resource_bundle_handler_get_data_resource(
return _retval;
}
int CEF_CALLBACK resource_bundle_handler_get_data_resource_for_scale(
struct _cef_resource_bundle_handler_t* self, int resource_id,
cef_scale_factor_t scale_factor, void** data, size_t* data_size) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: data; type: simple_byref
DCHECK(data);
if (!data)
return 0;
// Verify param: data_size; type: simple_byref
DCHECK(data_size);
if (!data_size)
return 0;
// Translate param: data; type: simple_byref
void* dataVal = data?*data:NULL;
// Translate param: data_size; type: simple_byref
size_t data_sizeVal = data_size?*data_size:0;
// Execute
bool _retval = CefResourceBundleHandlerCppToC::Get(
self)->GetDataResourceForScale(
resource_id,
scale_factor,
dataVal,
data_sizeVal);
// Restore param: data; type: simple_byref
if (data)
*data = dataVal;
// Restore param: data_size; type: simple_byref
if (data_size)
*data_size = data_sizeVal;
// Return type: bool
return _retval;
}
} // namespace
@ -90,6 +131,8 @@ CefResourceBundleHandlerCppToC::CefResourceBundleHandlerCppToC() {
GetStruct()->get_localized_string =
resource_bundle_handler_get_localized_string;
GetStruct()->get_data_resource = resource_bundle_handler_get_data_resource;
GetStruct()->get_data_resource_for_scale =
resource_bundle_handler_get_data_resource_for_scale;
}
template<> CefRefPtr<CefResourceBundleHandler> CefCppToC<CefResourceBundleHandlerCppToC,

View File

@ -0,0 +1,72 @@
// 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.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/cpptoc/run_context_menu_callback_cpptoc.h"
namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
void CEF_CALLBACK run_context_menu_callback_cont(
struct _cef_run_context_menu_callback_t* self, int command_id,
cef_event_flags_t event_flags) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Execute
CefRunContextMenuCallbackCppToC::Get(self)->Continue(
command_id,
event_flags);
}
void CEF_CALLBACK run_context_menu_callback_cancel(
struct _cef_run_context_menu_callback_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Execute
CefRunContextMenuCallbackCppToC::Get(self)->Cancel();
}
} // namespace
// CONSTRUCTOR - Do not edit by hand.
CefRunContextMenuCallbackCppToC::CefRunContextMenuCallbackCppToC() {
GetStruct()->cont = run_context_menu_callback_cont;
GetStruct()->cancel = run_context_menu_callback_cancel;
}
template<> CefRefPtr<CefRunContextMenuCallback> CefCppToC<CefRunContextMenuCallbackCppToC,
CefRunContextMenuCallback, cef_run_context_menu_callback_t>::UnwrapDerived(
CefWrapperType type, cef_run_context_menu_callback_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return NULL;
}
#ifndef NDEBUG
template<> base::AtomicRefCount CefCppToC<CefRunContextMenuCallbackCppToC,
CefRunContextMenuCallback, cef_run_context_menu_callback_t>::DebugObjCt =
0;
#endif
template<> CefWrapperType CefCppToC<CefRunContextMenuCallbackCppToC,
CefRunContextMenuCallback, cef_run_context_menu_callback_t>::kWrapperType =
WT_RUN_CONTEXT_MENU_CALLBACK;

View File

@ -0,0 +1,35 @@
// 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.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef CEF_LIBCEF_DLL_CPPTOC_RUN_CONTEXT_MENU_CALLBACK_CPPTOC_H_
#define CEF_LIBCEF_DLL_CPPTOC_RUN_CONTEXT_MENU_CALLBACK_CPPTOC_H_
#pragma once
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "include/cef_context_menu_handler.h"
#include "include/capi/cef_context_menu_handler_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed DLL-side only.
class CefRunContextMenuCallbackCppToC
: public CefCppToC<CefRunContextMenuCallbackCppToC,
CefRunContextMenuCallback, cef_run_context_menu_callback_t> {
public:
CefRunContextMenuCallbackCppToC();
};
#endif // BUILDING_CEF_SHARED
#endif // CEF_LIBCEF_DLL_CPPTOC_RUN_CONTEXT_MENU_CALLBACK_CPPTOC_H_

View File

@ -20,6 +20,8 @@
#include "include/cef_web_plugin.h"
#include "include/capi/cef_web_plugin_capi.h"
#include "include/cef_browser.h"
#include "include/capi/cef_browser_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.

View File

@ -20,6 +20,8 @@
#include "include/cef_web_plugin.h"
#include "include/capi/cef_web_plugin_capi.h"
#include "include/cef_browser.h"
#include "include/capi/cef_browser_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.

View File

@ -20,6 +20,8 @@
#include "include/cef_web_plugin.h"
#include "include/capi/cef_web_plugin_capi.h"
#include "include/cef_browser.h"
#include "include/capi/cef_browser_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.