mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
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:
@@ -202,6 +202,28 @@ IPC_MESSAGE_ROUTED1(CefHostMsg_ResponseAck,
|
||||
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.
|
||||
#ifndef CEF_LIBCEF_COMMON_CEF_MESSAGES_H_
|
||||
#define CEF_LIBCEF_COMMON_CEF_MESSAGES_H_
|
||||
|
@@ -10,18 +10,60 @@
|
||||
#include "libcef/common/scheme_registration.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/file_util.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "chrome/common/chrome_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 "ppapi/shared_impl/ppapi_permissions.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
|
||||
namespace {
|
||||
|
||||
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
|
||||
|
||||
CefContentClient::CefContentClient(CefRefPtr<CefApp> application)
|
||||
@@ -42,6 +84,11 @@ CefContentClient* CefContentClient::Get() {
|
||||
return g_content_client;
|
||||
}
|
||||
|
||||
void CefContentClient::AddPepperPlugins(
|
||||
std::vector<content::PepperPluginInfo>* plugins) {
|
||||
ComputeBuiltInPlugins(plugins);
|
||||
}
|
||||
|
||||
void CefContentClient::AddAdditionalSchemes(
|
||||
std::vector<std::string>* standard_schemes,
|
||||
std::vector<std::string>* savable_schemes) {
|
||||
|
@@ -26,6 +26,8 @@ class CefContentClient : public content::ContentClient,
|
||||
static CefContentClient* Get();
|
||||
|
||||
// content::ContentClient methods.
|
||||
virtual void AddPepperPlugins(
|
||||
std::vector<content::PepperPluginInfo>* plugins) OVERRIDE;
|
||||
virtual void AddAdditionalSchemes(
|
||||
std::vector<std::string>* standard_schemes,
|
||||
std::vector<std::string>* savable_schemes) OVERRIDE;
|
||||
|
@@ -21,11 +21,13 @@
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/synchronization/waitable_event.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "content/public/browser/browser_main_runner.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
#include "ui/base/layout.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
#include "ui/base/ui_base_paths.h"
|
||||
#include "ui/base/ui_base_switches.h"
|
||||
@@ -47,10 +49,6 @@
|
||||
#include "components/breakpad/app/breakpad_linux.h"
|
||||
#endif
|
||||
|
||||
#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
base::LazyInstance<CefBreakpadClient>::Leaky g_shell_breakpad_client =
|
||||
@@ -119,8 +117,6 @@ base::FilePath GetLibrariesFilePath() {
|
||||
|
||||
#endif // !defined(OS_MACOSX)
|
||||
|
||||
#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
|
||||
|
||||
// File name of the internal PDF plugin on different platforms.
|
||||
const base::FilePath::CharType kInternalPDFPluginFileName[] =
|
||||
#if defined(OS_WIN)
|
||||
@@ -137,7 +133,15 @@ void OverridePdfPluginPath() {
|
||||
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.
|
||||
class CefUIThread : public base::Thread {
|
||||
@@ -408,9 +412,7 @@ void CefMainDelegate::PreSandboxStartup() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
|
||||
OverridePdfPluginPath();
|
||||
#endif
|
||||
|
||||
if (command_line.HasSwitch(switches::kDisablePackLoading))
|
||||
content_client_.set_pack_loading_disabled(true);
|
||||
@@ -502,7 +504,8 @@ void CefMainDelegate::ShutdownBrowser() {
|
||||
|
||||
void CefMainDelegate::InitializeResourceBundle() {
|
||||
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()) {
|
||||
base::FilePath resources_dir;
|
||||
@@ -515,6 +518,10 @@ void CefMainDelegate::InitializeResourceBundle() {
|
||||
|
||||
if (!resources_dir.empty()) {
|
||||
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 =
|
||||
resources_dir.Append(FILE_PATH_LITERAL("devtools_resources.pak"));
|
||||
}
|
||||
@@ -532,20 +539,49 @@ void CefMainDelegate::InitializeResourceBundle() {
|
||||
const std::string loaded_locale =
|
||||
ui::ResourceBundle::InitSharedInstanceWithLocale(locale,
|
||||
&content_client_);
|
||||
ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance();
|
||||
|
||||
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);
|
||||
|
||||
if (base::PathExists(cef_pak_file)) {
|
||||
ResourceBundle::GetSharedInstance().AddDataPackFromPath(
|
||||
cef_pak_file, ui::SCALE_FACTOR_NONE);
|
||||
resource_bundle.AddDataPackFromPath(cef_pak_file, ui::SCALE_FACTOR_NONE);
|
||||
} 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)) {
|
||||
ResourceBundle::GetSharedInstance().AddDataPackFromPath(
|
||||
resource_bundle.AddDataPackFromPath(
|
||||
devtools_pak_file, ui::SCALE_FACTOR_NONE);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user