Bundle pepper PDF plugin on all platforms (issue #1331).

- Add new libpdf.so library on Linux and PDF.plugin app bundle on OS X.
- Move scaled resources from cef.pak into separate cef_100_percent.pak and cef_200_percent.pak files.
- Password-protected PDF files are not currently supported.
- No fallback is provided for PDF files that contain unsupported features.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1758 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2014-07-07 22:17:33 +00:00
parent 479e69fd4e
commit 81f8883b4a
14 changed files with 315 additions and 34 deletions

37
cef.gyp
View File

@ -734,15 +734,35 @@
'pak_inputs': [ 'pak_inputs': [
'<(SHARED_INTERMEDIATE_DIR)/content/content_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/content/content_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources_100_percent.pak',
'<(SHARED_INTERMEDIATE_DIR)/webkit/blink_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/blink_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_resources_100_percent.pak',
'<(grit_out_dir)/cef_resources.pak', '<(grit_out_dir)/cef_resources.pak',
], ],
'pak_output': '<(PRODUCT_DIR)/cef.pak', 'pak_output': '<(PRODUCT_DIR)/cef.pak',
}, },
'includes': [ '../build/repack_action.gypi' ], 'includes': [ '../build/repack_action.gypi' ],
}, },
{
'action_name': 'repack_cef_100_percent_pack',
'variables': {
'pak_inputs': [
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources_100_percent.pak',
'<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_resources_100_percent.pak',
],
'pak_output': '<(PRODUCT_DIR)/cef_100_percent.pak',
},
'includes': [ '../build/repack_action.gypi' ],
},
{
'action_name': 'repack_cef_200_percent_pack',
'variables': {
'pak_inputs': [
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources_200_percent.pak',
'<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_resources_200_percent.pak',
],
'pak_output': '<(PRODUCT_DIR)/cef_200_percent.pak',
},
'includes': [ '../build/repack_action.gypi' ],
},
{ {
'action_name': 'make_pack_resources_header', 'action_name': 'make_pack_resources_header',
'variables': { 'variables': {
@ -837,8 +857,10 @@
'<(DEPTH)/media/media.gyp:media', '<(DEPTH)/media/media.gyp:media',
'<(DEPTH)/net/net.gyp:net', '<(DEPTH)/net/net.gyp:net',
'<(DEPTH)/net/net.gyp:net_with_v8', '<(DEPTH)/net/net.gyp:net_with_v8',
'<(DEPTH)/pdf/pdf.gyp:pdf',
'<(DEPTH)/skia/skia.gyp:skia', '<(DEPTH)/skia/skia.gyp:skia',
'<(DEPTH)/third_party/libxml/libxml.gyp:libxml', '<(DEPTH)/third_party/libxml/libxml.gyp:libxml',
'<(DEPTH)/third_party/re2/re2.gyp:re2',
'<(DEPTH)/third_party/WebKit/public/blink.gyp:blink', '<(DEPTH)/third_party/WebKit/public/blink.gyp:blink',
'<(DEPTH)/third_party/WebKit/Source/core/core.gyp:webcore', '<(DEPTH)/third_party/WebKit/Source/core/core.gyp:webcore',
'<(DEPTH)/third_party/zlib/zlib.gyp:minizip', '<(DEPTH)/third_party/zlib/zlib.gyp:minizip',
@ -1090,6 +1112,9 @@
# determine the current locale. # determine the current locale.
'<(DEPTH)/chrome/browser/browser_process.cc', '<(DEPTH)/chrome/browser/browser_process.cc',
'<(DEPTH)/chrome/browser/browser_process.h', '<(DEPTH)/chrome/browser/browser_process.h',
# Include sources for pepper PDF plugin support.
'<(DEPTH)/chrome/renderer/pepper/ppb_pdf_impl.cc',
'<(DEPTH)/chrome/renderer/pepper/ppb_pdf_impl.h',
], ],
'conditions': [ 'conditions': [
['OS=="win"', { ['OS=="win"', {
@ -1104,9 +1129,6 @@
], ],
}], }],
['OS=="win" and win_pdf_metafile_for_printing==1', { ['OS=="win" and win_pdf_metafile_for_printing==1', {
'dependencies': [
'<(DEPTH)/pdf/pdf.gyp:pdf',
],
'sources': [ 'sources': [
# Include sources for printing using PDF. # Include sources for printing using PDF.
'libcef/utility/printing_handler.cc', 'libcef/utility/printing_handler.cc',
@ -1195,6 +1217,8 @@
'mac_bundle': 1, 'mac_bundle': 1,
'mac_bundle_resources': [ 'mac_bundle_resources': [
'<(PRODUCT_DIR)/cef.pak', '<(PRODUCT_DIR)/cef.pak',
'<(PRODUCT_DIR)/cef_100_percent.pak',
'<(PRODUCT_DIR)/cef_200_percent.pak',
'<(PRODUCT_DIR)/devtools_resources.pak', '<(PRODUCT_DIR)/devtools_resources.pak',
'<(PRODUCT_DIR)/icudtl.dat', '<(PRODUCT_DIR)/icudtl.dat',
'libcef/resources/framework-Info.plist', 'libcef/resources/framework-Info.plist',
@ -1253,10 +1277,11 @@
], ],
'copies': [ 'copies': [
{ {
# Copy FFmpeg binaries for audio/video support. # Copy binaries for HTML5 audio/video and PDF support.
'destination': '<(PRODUCT_DIR)/$(CONTENTS_FOLDER_PATH)/Libraries', 'destination': '<(PRODUCT_DIR)/$(CONTENTS_FOLDER_PATH)/Libraries',
'files': [ 'files': [
'<(PRODUCT_DIR)/ffmpegsumo.so', '<(PRODUCT_DIR)/ffmpegsumo.so',
'<(PRODUCT_DIR)/PDF.plugin',
], ],
}, },
{ {

View File

@ -35,6 +35,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/gpu/compositor_util.h" #include "content/browser/gpu/compositor_util.h"
#include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/view_messages.h" #include "content/common/view_messages.h"
@ -2431,6 +2432,14 @@ bool CefBrowserHostImpl::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(CefHostMsg_Request, OnRequest) IPC_MESSAGE_HANDLER(CefHostMsg_Request, OnRequest)
IPC_MESSAGE_HANDLER(CefHostMsg_Response, OnResponse) IPC_MESSAGE_HANDLER(CefHostMsg_Response, OnResponse)
IPC_MESSAGE_HANDLER(CefHostMsg_ResponseAck, OnResponseAck) IPC_MESSAGE_HANDLER(CefHostMsg_ResponseAck, OnResponseAck)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature,
OnPDFHasUnsupportedFeature)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFSaveURLAs, OnPDFSaveURLAs)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFUpdateContentRestrictions,
OnPDFUpdateContentRestrictions)
IPC_MESSAGE_HANDLER_DELAY_REPLY(
ChromeViewHostMsg_PDFModalPromptForPassword,
OnPDFModalPromptForPassword)
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
return handled; return handled;
@ -2525,6 +2534,38 @@ void CefBrowserHostImpl::OnResponseAck(int request_id) {
response_manager_->RunAckHandler(request_id); response_manager_->RunAckHandler(request_id);
} }
void CefBrowserHostImpl::OnPDFHasUnsupportedFeature() {
// TODO(cef): Use Adobe PDF plugin instead. See PDFHasUnsupportedFeature in
// chrome/browser/ui/pdf/pdf_unsupported_feature.cc.
}
void CefBrowserHostImpl::OnPDFSaveURLAs(
const GURL& url,
const content::Referrer& referrer) {
web_contents()->SaveFrame(url, referrer);
}
void CefBrowserHostImpl::OnPDFUpdateContentRestrictions(
int content_restrictions) {
// TODO(cef): Add support for communicating PDF content restrictions.
}
void CefBrowserHostImpl::OnPDFModalPromptForPassword(
const std::string& prompt,
IPC::Message* reply_message) {
// TODO(cef): Add support for PDF password prompt.
OnPDFModalPromptForPasswordClosed(reply_message, false, base::string16());
}
void CefBrowserHostImpl::OnPDFModalPromptForPasswordClosed(
IPC::Message* reply_message,
bool success,
const base::string16& actual_value) {
ChromeViewHostMsg_PDFModalPromptForPassword::WriteReplyParams(
reply_message, base::UTF16ToUTF8(actual_value));
Send(reply_message);
}
// content::NotificationObserver methods. // content::NotificationObserver methods.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -331,18 +331,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
// can only be dereferenced on, the UI thread. // can only be dereferenced on, the UI thread.
base::WeakPtr<CefBrowserHostImpl> GetWeakPtr(); base::WeakPtr<CefBrowserHostImpl> GetWeakPtr();
private:
class DevToolsWebContentsObserver;
static CefRefPtr<CefBrowserHostImpl> CreateInternal(
const CefWindowInfo& window_info,
const CefBrowserSettings& settings,
CefRefPtr<CefClient> client,
content::WebContents* web_contents,
scoped_refptr<CefBrowserInfo> browser_info,
CefWindowHandle opener,
CefRefPtr<CefRequestContext> request_context);
// content::WebContentsDelegate methods. // content::WebContentsDelegate methods.
virtual content::WebContents* OpenURLFromTab( virtual content::WebContents* OpenURLFromTab(
content::WebContents* source, content::WebContents* source,
@ -443,6 +431,18 @@ class CefBrowserHostImpl : public CefBrowserHost,
// Override to provide a thread safe implementation. // Override to provide a thread safe implementation.
virtual bool Send(IPC::Message* message) OVERRIDE; virtual bool Send(IPC::Message* message) OVERRIDE;
private:
class DevToolsWebContentsObserver;
static CefRefPtr<CefBrowserHostImpl> CreateInternal(
const CefWindowInfo& window_info,
const CefBrowserSettings& settings,
CefRefPtr<CefClient> client,
content::WebContents* web_contents,
scoped_refptr<CefBrowserInfo> browser_info,
CefWindowHandle opener,
CefRefPtr<CefRequestContext> request_context);
// content::WebContentsObserver::OnMessageReceived() message handlers. // content::WebContentsObserver::OnMessageReceived() message handlers.
void OnFrameIdentified(int64 frame_id, void OnFrameIdentified(int64 frame_id,
int64 parent_frame_id, int64 parent_frame_id,
@ -456,6 +456,16 @@ class CefBrowserHostImpl : public CefBrowserHost,
void OnRequest(const Cef_Request_Params& params); void OnRequest(const Cef_Request_Params& params);
void OnResponse(const Cef_Response_Params& params); void OnResponse(const Cef_Response_Params& params);
void OnResponseAck(int request_id); void OnResponseAck(int request_id);
void OnPDFHasUnsupportedFeature();
void OnPDFSaveURLAs(const GURL& url,
const content::Referrer& referrer);
void OnPDFUpdateContentRestrictions(int content_restrictions);
void OnPDFModalPromptForPassword(const std::string& prompt,
IPC::Message* reply_message);
void OnPDFModalPromptForPasswordClosed(IPC::Message* reply_message,
bool success,
const base::string16& actual_value);
// content::NotificationObserver methods. // content::NotificationObserver methods.
virtual void Observe(int type, virtual void Observe(int type,

View File

@ -202,6 +202,28 @@ IPC_MESSAGE_ROUTED1(CefHostMsg_ResponseAck,
int /* request_id */) int /* request_id */)
// Pepper PDF plugin messages excerpted from chrome/common/render_messages.h.
// Including all of render_messages.h would bring in a number of chrome
// dependencies that are better off avoided.
// The currently displayed PDF has an unsupported feature.
IPC_MESSAGE_ROUTED0(ChromeViewHostMsg_PDFHasUnsupportedFeature)
// Brings up SaveAs... dialog to save specified URL.
IPC_MESSAGE_ROUTED2(ChromeViewHostMsg_PDFSaveURLAs,
GURL /* url */,
content::Referrer /* referrer */)
// Updates the content restrictions, i.e. to disable print/copy.
IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_PDFUpdateContentRestrictions,
int /* restrictions */)
// Brings up a Password... dialog for protected documents.
IPC_SYNC_MESSAGE_ROUTED1_1(ChromeViewHostMsg_PDFModalPromptForPassword,
std::string /* prompt */,
std::string /* actual_value */)
// Singly-included section for struct and custom IPC traits. // Singly-included section for struct and custom IPC traits.
#ifndef CEF_LIBCEF_COMMON_CEF_MESSAGES_H_ #ifndef CEF_LIBCEF_COMMON_CEF_MESSAGES_H_
#define CEF_LIBCEF_COMMON_CEF_MESSAGES_H_ #define CEF_LIBCEF_COMMON_CEF_MESSAGES_H_

View File

@ -10,18 +10,60 @@
#include "libcef/common/scheme_registration.h" #include "libcef/common/scheme_registration.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/pepper_plugin_info.h"
#include "content/public/common/user_agent.h" #include "content/public/common/user_agent.h"
#include "ppapi/shared_impl/ppapi_permissions.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
namespace { namespace {
CefContentClient* g_content_client = NULL; CefContentClient* g_content_client = NULL;
const char kPDFPluginName[] = "Chrome PDF Viewer";
const char kPDFPluginMimeType[] = "application/pdf";
const char kPDFPluginExtension[] = "pdf";
const char kPDFPluginDescription[] = "Portable Document Format";
const uint32 kPDFPluginPermissions = ppapi::PERMISSION_PRIVATE |
ppapi::PERMISSION_DEV;
// Appends the known built-in plugins to the given vector.
// Based on chrome/common/chrome_content_client.cc.
void ComputeBuiltInPlugins(std::vector<content::PepperPluginInfo>* plugins) {
// PDF.
//
// Once we're sandboxed, we can't know if the PDF plugin is available or not;
// but (on Linux) this function is always called once before we're sandboxed.
// So the first time through test if the file is available and then skip the
// check on subsequent calls if yes.
static bool skip_pdf_file_check = false;
base::FilePath path;
if (PathService::Get(chrome::FILE_PDF_PLUGIN, &path)) {
if (skip_pdf_file_check || base::PathExists(path)) {
content::PepperPluginInfo pdf;
pdf.path = path;
pdf.name = kPDFPluginName;
// Only in-process loading is currently supported. See issue #1331.
pdf.is_out_of_process = false;
content::WebPluginMimeType pdf_mime_type(kPDFPluginMimeType,
kPDFPluginExtension,
kPDFPluginDescription);
pdf.mime_types.push_back(pdf_mime_type);
pdf.permissions = kPDFPluginPermissions;
plugins->push_back(pdf);
skip_pdf_file_check = true;
}
}
}
} // namespace } // namespace
CefContentClient::CefContentClient(CefRefPtr<CefApp> application) CefContentClient::CefContentClient(CefRefPtr<CefApp> application)
@ -42,6 +84,11 @@ CefContentClient* CefContentClient::Get() {
return g_content_client; return g_content_client;
} }
void CefContentClient::AddPepperPlugins(
std::vector<content::PepperPluginInfo>* plugins) {
ComputeBuiltInPlugins(plugins);
}
void CefContentClient::AddAdditionalSchemes( void CefContentClient::AddAdditionalSchemes(
std::vector<std::string>* standard_schemes, std::vector<std::string>* standard_schemes,
std::vector<std::string>* savable_schemes) { std::vector<std::string>* savable_schemes) {

View File

@ -26,6 +26,8 @@ class CefContentClient : public content::ContentClient,
static CefContentClient* Get(); static CefContentClient* Get();
// content::ContentClient methods. // content::ContentClient methods.
virtual void AddPepperPlugins(
std::vector<content::PepperPluginInfo>* plugins) OVERRIDE;
virtual void AddAdditionalSchemes( virtual void AddAdditionalSchemes(
std::vector<std::string>* standard_schemes, std::vector<std::string>* standard_schemes,
std::vector<std::string>* savable_schemes) OVERRIDE; std::vector<std::string>* savable_schemes) OVERRIDE;

View File

@ -21,11 +21,13 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_main_runner.h" #include "content/public/browser/browser_main_runner.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h" #include "content/public/common/main_function_params.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h" #include "ui/base/ui_base_paths.h"
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
@ -47,10 +49,6 @@
#include "components/breakpad/app/breakpad_linux.h" #include "components/breakpad/app/breakpad_linux.h"
#endif #endif
#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
#include "chrome/common/chrome_paths.h"
#endif
namespace { namespace {
base::LazyInstance<CefBreakpadClient>::Leaky g_shell_breakpad_client = base::LazyInstance<CefBreakpadClient>::Leaky g_shell_breakpad_client =
@ -119,8 +117,6 @@ base::FilePath GetLibrariesFilePath() {
#endif // !defined(OS_MACOSX) #endif // !defined(OS_MACOSX)
#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
// File name of the internal PDF plugin on different platforms. // File name of the internal PDF plugin on different platforms.
const base::FilePath::CharType kInternalPDFPluginFileName[] = const base::FilePath::CharType kInternalPDFPluginFileName[] =
#if defined(OS_WIN) #if defined(OS_WIN)
@ -137,7 +133,15 @@ void OverridePdfPluginPath() {
PathService::Override(chrome::FILE_PDF_PLUGIN, plugin_path); PathService::Override(chrome::FILE_PDF_PLUGIN, plugin_path);
} }
#endif // defined(WIN_PDF_METAFILE_FOR_PRINTING) // Returns true if |scale_factor| is supported by this platform.
// Same as ResourceBundle::IsScaleFactorSupported.
bool IsScaleFactorSupported(ui::ScaleFactor scale_factor) {
const std::vector<ui::ScaleFactor>& supported_scale_factors =
ui::GetSupportedScaleFactors();
return std::find(supported_scale_factors.begin(),
supported_scale_factors.end(),
scale_factor) != supported_scale_factors.end();
}
// Used to run the UI on a separate thread. // Used to run the UI on a separate thread.
class CefUIThread : public base::Thread { class CefUIThread : public base::Thread {
@ -408,9 +412,7 @@ void CefMainDelegate::PreSandboxStartup() {
} }
#endif #endif
#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
OverridePdfPluginPath(); OverridePdfPluginPath();
#endif
if (command_line.HasSwitch(switches::kDisablePackLoading)) if (command_line.HasSwitch(switches::kDisablePackLoading))
content_client_.set_pack_loading_disabled(true); content_client_.set_pack_loading_disabled(true);
@ -502,7 +504,8 @@ void CefMainDelegate::ShutdownBrowser() {
void CefMainDelegate::InitializeResourceBundle() { void CefMainDelegate::InitializeResourceBundle() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess(); const CommandLine& command_line = *CommandLine::ForCurrentProcess();
base::FilePath cef_pak_file, devtools_pak_file, locales_dir; base::FilePath cef_pak_file, cef_100_percent_pak_file,
cef_200_percent_pak_file, devtools_pak_file, locales_dir;
if (!content_client_.pack_loading_disabled()) { if (!content_client_.pack_loading_disabled()) {
base::FilePath resources_dir; base::FilePath resources_dir;
@ -515,6 +518,10 @@ void CefMainDelegate::InitializeResourceBundle() {
if (!resources_dir.empty()) { if (!resources_dir.empty()) {
cef_pak_file = resources_dir.Append(FILE_PATH_LITERAL("cef.pak")); cef_pak_file = resources_dir.Append(FILE_PATH_LITERAL("cef.pak"));
cef_100_percent_pak_file =
resources_dir.Append(FILE_PATH_LITERAL("cef_100_percent.pak"));
cef_200_percent_pak_file =
resources_dir.Append(FILE_PATH_LITERAL("cef_200_percent.pak"));
devtools_pak_file = devtools_pak_file =
resources_dir.Append(FILE_PATH_LITERAL("devtools_resources.pak")); resources_dir.Append(FILE_PATH_LITERAL("devtools_resources.pak"));
} }
@ -532,20 +539,49 @@ void CefMainDelegate::InitializeResourceBundle() {
const std::string loaded_locale = const std::string loaded_locale =
ui::ResourceBundle::InitSharedInstanceWithLocale(locale, ui::ResourceBundle::InitSharedInstanceWithLocale(locale,
&content_client_); &content_client_);
ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance();
if (!content_client_.pack_loading_disabled()) { if (!content_client_.pack_loading_disabled()) {
CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; if (loaded_locale.empty())
LOG(ERROR) << "Could not load locale pak for " << locale;
content_client_.set_allow_pack_file_load(true); content_client_.set_allow_pack_file_load(true);
if (base::PathExists(cef_pak_file)) { if (base::PathExists(cef_pak_file)) {
ResourceBundle::GetSharedInstance().AddDataPackFromPath( resource_bundle.AddDataPackFromPath(cef_pak_file, ui::SCALE_FACTOR_NONE);
cef_pak_file, ui::SCALE_FACTOR_NONE);
} else { } else {
NOTREACHED() << "Could not load cef.pak"; LOG(ERROR) << "Could not load cef.pak";
}
// On OS X and Linux/Aura always load the 1x data pack first as the 2x data
// pack contains both 1x and 2x images.
const bool load_100_percent =
#if defined(OS_WIN)
IsScaleFactorSupported(ui::SCALE_FACTOR_100P);
#else
true;
#endif
if (load_100_percent) {
if (base::PathExists(cef_100_percent_pak_file)) {
resource_bundle.AddDataPackFromPath(
cef_100_percent_pak_file, ui::SCALE_FACTOR_100P);
} else {
LOG(ERROR) << "Could not load cef_100_percent.pak";
}
}
if (IsScaleFactorSupported(ui::SCALE_FACTOR_200P)) {
if (base::PathExists(cef_200_percent_pak_file)) {
resource_bundle.AddDataPackFromPath(
cef_200_percent_pak_file, ui::SCALE_FACTOR_200P);
} else {
LOG(ERROR) << "Could not load cef_200_percent.pak";
}
} }
if (base::PathExists(devtools_pak_file)) { if (base::PathExists(devtools_pak_file)) {
ResourceBundle::GetSharedInstance().AddDataPackFromPath( resource_bundle.AddDataPackFromPath(
devtools_pak_file, ui::SCALE_FACTOR_NONE); devtools_pak_file, ui::SCALE_FACTOR_NONE);
} }

View File

@ -31,10 +31,13 @@ MSVC_POP_WARNING();
#include "libcef/renderer/webkit_glue.h" #include "libcef/renderer/webkit_glue.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/file_util.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/renderer/loadtimes_extension_bindings.h" #include "chrome/renderer/loadtimes_extension_bindings.h"
#include "chrome/renderer/pepper/ppb_pdf_impl.h"
#include "chrome/renderer/printing/print_web_view_helper.h" #include "chrome/renderer/printing/print_web_view_helper.h"
#include "content/child/child_thread.h" #include "content/child/child_thread.h"
#include "content/child/worker_task_runner.h" #include "content/child/worker_task_runner.h"
@ -48,6 +51,7 @@ MSVC_POP_WARNING();
#include "content/renderer/render_frame_impl.h" #include "content/renderer/render_frame_impl.h"
#include "ipc/ipc_sync_channel.h" #include "ipc/ipc_sync_channel.h"
#include "media/base/media.h" #include "media/base/media.h"
#include "ppapi/c/private/ppb_pdf.h"
#include "third_party/WebKit/public/platform/WebPrerenderingSupport.h" #include "third_party/WebKit/public/platform/WebPrerenderingSupport.h"
#include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h" #include "third_party/WebKit/public/platform/WebURL.h"
@ -64,6 +68,10 @@ MSVC_POP_WARNING();
#include "third_party/WebKit/public/web/WebWorkerInfo.h" #include "third_party/WebKit/public/web/WebWorkerInfo.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
#if defined(OS_WIN)
#include "base/win/iat_patch_function.h"
#endif
namespace { namespace {
// Stub implementation of blink::WebPrerenderingSupport. // Stub implementation of blink::WebPrerenderingSupport.
@ -141,6 +149,43 @@ class CefWebWorkerTaskRunner : public base::SequencedTaskRunner,
int worker_id_; int worker_id_;
}; };
#if defined(OS_WIN)
static base::win::IATPatchFunction g_iat_patch_createdca;
HDC WINAPI CreateDCAPatch(LPCSTR driver_name,
LPCSTR device_name,
LPCSTR output,
const void* init_data) {
DCHECK(std::string("DISPLAY") == std::string(driver_name));
DCHECK(!device_name);
DCHECK(!output);
DCHECK(!init_data);
// CreateDC fails behind the sandbox, but not CreateCompatibleDC.
return CreateCompatibleDC(NULL);
}
static base::win::IATPatchFunction g_iat_patch_get_font_data;
DWORD WINAPI GetFontDataPatch(HDC hdc,
DWORD table,
DWORD offset,
LPVOID buffer,
DWORD length) {
int rv = GetFontData(hdc, table, offset, buffer, length);
if (rv == GDI_ERROR && hdc) {
HFONT font = static_cast<HFONT>(GetCurrentObject(hdc, OBJ_FONT));
LOGFONT logfont;
if (GetObject(font, sizeof(LOGFONT), &logfont)) {
std::vector<char> font_data;
content::RenderThread::Get()->PreCacheFont(logfont);
rv = GetFontData(hdc, table, offset, buffer, length);
content::RenderThread::Get()->ReleaseCachedFonts();
}
}
return rv;
}
#endif // OS_WIN
} // namespace } // namespace
CefContentRendererClient::CefContentRendererClient() CefContentRendererClient::CefContentRendererClient()
@ -212,6 +257,19 @@ void CefContentRendererClient::WebKitInitialized() {
blink::WebRuntimeFeatures::enableMediaStream( blink::WebRuntimeFeatures::enableMediaStream(
command_line.HasSwitch(switches::kEnableMediaStream)); command_line.HasSwitch(switches::kEnableMediaStream));
#if defined(OS_WIN)
// Need to patch a few functions for font loading to work correctly.
// From chrome/renderer/chrome_render_process_observer.cc.
base::FilePath pdf;
if (PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) &&
base::PathExists(pdf)) {
g_iat_patch_createdca.Patch(
pdf.value().c_str(), "gdi32.dll", "CreateDCA", CreateDCAPatch);
g_iat_patch_get_font_data.Patch(
pdf.value().c_str(), "gdi32.dll", "GetFontData", GetFontDataPatch);
}
#endif // defined(OS_WIN)
const CefContentClient::SchemeInfoList* schemes = const CefContentClient::SchemeInfoList* schemes =
CefContentClient::Get()->GetCustomSchemes(); CefContentClient::Get()->GetCustomSchemes();
if (!schemes->empty()) { if (!schemes->empty()) {
@ -608,6 +666,16 @@ void CefContentRendererClient::DidCreateScriptContext(
} }
} }
const void* CefContentRendererClient::CreatePPAPIInterface(
const std::string& interface_name) {
#if defined(ENABLE_PLUGINS)
// Used for in-process PDF plugin.
if (interface_name == PPB_PDF_INTERFACE)
return PPB_PDF_Impl::GetInterface();
#endif
return NULL;
}
void CefContentRendererClient::WillReleaseScriptContext( void CefContentRendererClient::WillReleaseScriptContext(
blink::WebFrame* frame, v8::Handle<v8::Context> context, int world_id) { blink::WebFrame* frame, v8::Handle<v8::Context> context, int world_id) {
// Notify the render process handler. // Notify the render process handler.

View File

@ -93,6 +93,8 @@ class CefContentRendererClient : public content::ContentRendererClient,
v8::Handle<v8::Context> context, v8::Handle<v8::Context> context,
int extension_group, int extension_group,
int world_id) OVERRIDE; int world_id) OVERRIDE;
virtual const void* CreatePPAPIInterface(
const std::string& interface_name) OVERRIDE;
void WillReleaseScriptContext(blink::WebFrame* frame, void WillReleaseScriptContext(blink::WebFrame* frame,
v8::Handle<v8::Context> context, v8::Handle<v8::Context> context,

View File

@ -219,12 +219,15 @@
'destination': '<(PRODUCT_DIR)/', 'destination': '<(PRODUCT_DIR)/',
'files': [ 'files': [
'Resources/cef.pak', 'Resources/cef.pak',
'Resources/cef_100_percent.pak',
'Resources/cef_200_percent.pak',
'Resources/devtools_resources.pak', 'Resources/devtools_resources.pak',
'Resources/icudtl.dat', 'Resources/icudtl.dat',
'Resources/locales/', 'Resources/locales/',
'$(BUILDTYPE)/chrome-sandbox', '$(BUILDTYPE)/chrome-sandbox',
'$(BUILDTYPE)/libcef.so', '$(BUILDTYPE)/libcef.so',
'$(BUILDTYPE)/libffmpegsumo.so', '$(BUILDTYPE)/libffmpegsumo.so',
'$(BUILDTYPE)/libpdf.so',
], ],
}, },
], ],
@ -432,12 +435,15 @@
'destination': '<(PRODUCT_DIR)/', 'destination': '<(PRODUCT_DIR)/',
'files': [ 'files': [
'Resources/cef.pak', 'Resources/cef.pak',
'Resources/cef_100_percent.pak',
'Resources/cef_200_percent.pak',
'Resources/devtools_resources.pak', 'Resources/devtools_resources.pak',
'Resources/icudtl.dat', 'Resources/icudtl.dat',
'Resources/locales/', 'Resources/locales/',
'$(BUILDTYPE)/chrome-sandbox', '$(BUILDTYPE)/chrome-sandbox',
'$(BUILDTYPE)/libcef.so', '$(BUILDTYPE)/libcef.so',
'$(BUILDTYPE)/libffmpegsumo.so', '$(BUILDTYPE)/libffmpegsumo.so',
'$(BUILDTYPE)/libpdf.so',
], ],
}, },
], ],

View File

@ -28,6 +28,8 @@ Optional components:
* Other resources * Other resources
cef.pak cef.pak
cef_100_percent.pak
cef_200_percent.pak
devtools_resources.pak devtools_resources.pak
Note: Contains WebKit image and inspector resources. Pack file loading can be Note: Contains WebKit image and inspector resources. Pack file loading can be
disabled completely using CefSettings.pack_loading_disabled. The resources disabled completely using CefSettings.pack_loading_disabled. The resources
@ -36,3 +38,6 @@ Optional components:
* FFmpeg audio and video support * FFmpeg audio and video support
libffmpegsumo.so libffmpegsumo.so
Note: Without this component HTML5 audio and video will not function. Note: Without this component HTML5 audio and video will not function.
* PDF support
libpdf.so

View File

@ -16,8 +16,12 @@ cefclient.app/
Chromium Embedded Framework <= main application library Chromium Embedded Framework <= main application library
Libraries/ Libraries/
ffmpegsumo.so <= HTML5 audio/video support library ffmpegsumo.so <= HTML5 audio/video support library
PDF.plugin <= Pepper plugin for PDF support
Resources/ Resources/
cef.pak, devtools_resources.pak <= non-localized resources and strings cef.pak <= non-localized resources and strings
cef_100_percent.pak <====^
cef_200_percent.pak <====^
devtools_resources.pak <=^
crash_inspector, crash_report_sender <= breakpad support crash_inspector, crash_report_sender <= breakpad support
icudtl.dat <= unicode support icudtl.dat <= unicode support
en.lproj/, ... <= locale-specific resources and strings en.lproj/, ... <= locale-specific resources and strings
@ -83,6 +87,8 @@ Optional components:
* Other resources * Other resources
Chromium Embedded Framework.framework/Resources/cef.pak Chromium Embedded Framework.framework/Resources/cef.pak
Chromium Embedded Framework.framework/Resources/cef_100_percent.pak
Chromium Embedded Framework.framework/Resources/cef_200_percent.pak
Chromium Embedded Framework.framework/Resources/devtools_resources.pak Chromium Embedded Framework.framework/Resources/devtools_resources.pak
Note: Contains WebKit image and inspector resources. Pack file loading can be Note: Contains WebKit image and inspector resources. Pack file loading can be
disabled completely using CefSettings.pack_loading_disabled. The resources disabled completely using CefSettings.pack_loading_disabled. The resources
@ -92,6 +98,9 @@ Optional components:
Chromium Embedded Framework.framework/Libraries/ffmpegsumo.so Chromium Embedded Framework.framework/Libraries/ffmpegsumo.so
Note: Without this component HTML5 audio and video will not function. Note: Without this component HTML5 audio and video will not function.
* PDF support
Chromium Embedded Framework.framework/Libraries/PDF.plugin
* Breakpad support * Breakpad support
Chromium Embedded Framework.framework/Resources/crash_inspector Chromium Embedded Framework.framework/Resources/crash_inspector
Chromium Embedded Framework.framework/Resources/crash_report_sender Chromium Embedded Framework.framework/Resources/crash_report_sender

View File

@ -27,6 +27,8 @@ Optional components:
* Other resources * Other resources
cef.pak cef.pak
cef_100_percent.pak
cef_200_percent.pak
devtools_resources.pak devtools_resources.pak
Note: Contains WebKit image and inspector resources. Pack file loading can be Note: Contains WebKit image and inspector resources. Pack file loading can be
disabled completely using CefSettings.pack_loading_disabled. The resources disabled completely using CefSettings.pack_loading_disabled. The resources

View File

@ -604,6 +604,8 @@ if platform == 'windows':
dst_dir = os.path.join(output_dir, 'Resources') dst_dir = os.path.join(output_dir, 'Resources')
make_dir(dst_dir, options.quiet) make_dir(dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'cef.pak'), dst_dir, options.quiet) copy_file(os.path.join(build_dir, 'cef.pak'), dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'cef_100_percent.pak'), dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'cef_200_percent.pak'), dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'devtools_resources.pak'), dst_dir, options.quiet) copy_file(os.path.join(build_dir, 'devtools_resources.pak'), dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'icudtl.dat'), dst_dir, options.quiet) copy_file(os.path.join(build_dir, 'icudtl.dat'), dst_dir, options.quiet)
copy_dir(os.path.join(build_dir, 'locales'), os.path.join(dst_dir, 'locales'), options.quiet) copy_dir(os.path.join(build_dir, 'locales'), os.path.join(dst_dir, 'locales'), options.quiet)
@ -734,6 +736,7 @@ elif platform == 'linux':
copy_file(os.path.join(build_dir, 'chrome_sandbox'), os.path.join(dst_dir, 'chrome-sandbox'), options.quiet) copy_file(os.path.join(build_dir, 'chrome_sandbox'), os.path.join(dst_dir, 'chrome-sandbox'), options.quiet)
copy_file(os.path.join(build_dir, lib_dir_name, 'libcef.so'), dst_dir, options.quiet) copy_file(os.path.join(build_dir, lib_dir_name, 'libcef.so'), dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'libffmpegsumo.so'), dst_dir, options.quiet) copy_file(os.path.join(build_dir, 'libffmpegsumo.so'), dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'libpdf.so'), dst_dir, options.quiet)
else: else:
sys.stderr.write("No Debug build files.\n") sys.stderr.write("No Debug build files.\n")
@ -753,6 +756,7 @@ elif platform == 'linux':
copy_file(os.path.join(build_dir, lib_dir_name, 'libcef.so'), dst_dir, options.quiet) copy_file(os.path.join(build_dir, lib_dir_name, 'libcef.so'), dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'chrome_sandbox'), os.path.join(dst_dir, 'chrome-sandbox'), options.quiet) copy_file(os.path.join(build_dir, 'chrome_sandbox'), os.path.join(dst_dir, 'chrome-sandbox'), options.quiet)
copy_file(os.path.join(build_dir, 'libffmpegsumo.so'), dst_dir, options.quiet) copy_file(os.path.join(build_dir, 'libffmpegsumo.so'), dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'libpdf.so'), dst_dir, options.quiet)
else: else:
sys.stderr.write("No Release build files.\n") sys.stderr.write("No Release build files.\n")
@ -766,6 +770,8 @@ elif platform == 'linux':
dst_dir = os.path.join(output_dir, 'Resources') dst_dir = os.path.join(output_dir, 'Resources')
make_dir(dst_dir, options.quiet) make_dir(dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'cef.pak'), dst_dir, options.quiet) copy_file(os.path.join(build_dir, 'cef.pak'), dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'cef_100_percent.pak'), dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'cef_200_percent.pak'), dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'devtools_resources.pak'), dst_dir, options.quiet) copy_file(os.path.join(build_dir, 'devtools_resources.pak'), dst_dir, options.quiet)
copy_file(os.path.join(build_dir, 'icudtl.dat'), dst_dir, options.quiet) copy_file(os.path.join(build_dir, 'icudtl.dat'), dst_dir, options.quiet)
copy_dir(os.path.join(build_dir, 'locales'), os.path.join(dst_dir, 'locales'), options.quiet) copy_dir(os.path.join(build_dir, 'locales'), os.path.join(dst_dir, 'locales'), options.quiet)