2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium 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/common/content_client.h"
|
|
|
|
#include "include/cef_stream.h"
|
|
|
|
#include "include/cef_version.h"
|
2013-06-04 19:41:37 +02:00
|
|
|
#include "libcef/browser/content_browser_client.h"
|
2012-04-24 20:01:48 +02:00
|
|
|
#include "libcef/common/scheme_registrar_impl.h"
|
2013-06-04 19:41:37 +02:00
|
|
|
#include "libcef/common/scheme_registration.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include "base/command_line.h"
|
2014-07-08 00:17:33 +02:00
|
|
|
#include "base/file_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/logging.h"
|
2014-07-08 00:17:33 +02:00
|
|
|
#include "base/path_service.h"
|
2013-04-16 00:16:01 +02:00
|
|
|
#include "base/strings/string_piece.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/stringprintf.h"
|
2014-07-08 00:17:33 +02:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2013-02-06 21:41:54 +01:00
|
|
|
#include "chrome/common/chrome_switches.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
2014-07-08 00:17:33 +02:00
|
|
|
#include "content/public/common/pepper_plugin_info.h"
|
2014-04-04 18:50:38 +02:00
|
|
|
#include "content/public/common/user_agent.h"
|
2014-07-08 00:17:33 +02:00
|
|
|
#include "ppapi/shared_impl/ppapi_permissions.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
|
2012-09-26 02:09:05 +02:00
|
|
|
namespace {
|
|
|
|
|
2013-04-16 00:16:01 +02:00
|
|
|
CefContentClient* g_content_client = NULL;
|
|
|
|
|
2014-07-08 00:17:33 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 02:09:05 +02:00
|
|
|
} // namespace
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefContentClient::CefContentClient(CefRefPtr<CefApp> application)
|
|
|
|
: application_(application),
|
2012-05-18 17:04:56 +02:00
|
|
|
pack_loading_disabled_(false),
|
2013-06-05 01:37:26 +02:00
|
|
|
allow_pack_file_load_(false),
|
|
|
|
scheme_info_list_locked_(false) {
|
2013-04-16 00:16:01 +02:00
|
|
|
DCHECK(!g_content_client);
|
|
|
|
g_content_client = this;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefContentClient::~CefContentClient() {
|
2013-04-16 00:16:01 +02:00
|
|
|
g_content_client = NULL;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefContentClient* CefContentClient::Get() {
|
2013-04-16 00:16:01 +02:00
|
|
|
return g_content_client;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-07-08 00:17:33 +02:00
|
|
|
void CefContentClient::AddPepperPlugins(
|
|
|
|
std::vector<content::PepperPluginInfo>* plugins) {
|
|
|
|
ComputeBuiltInPlugins(plugins);
|
|
|
|
}
|
|
|
|
|
2012-04-24 20:01:48 +02:00
|
|
|
void CefContentClient::AddAdditionalSchemes(
|
|
|
|
std::vector<std::string>* standard_schemes,
|
|
|
|
std::vector<std::string>* savable_schemes) {
|
2013-06-05 01:37:26 +02:00
|
|
|
DCHECK(!scheme_info_list_locked_);
|
|
|
|
|
2012-04-24 20:01:48 +02:00
|
|
|
if (application_.get()) {
|
|
|
|
CefRefPtr<CefSchemeRegistrarImpl> schemeRegistrar(
|
|
|
|
new CefSchemeRegistrarImpl());
|
|
|
|
application_->OnRegisterCustomSchemes(schemeRegistrar.get());
|
|
|
|
schemeRegistrar->GetStandardSchemes(standard_schemes);
|
|
|
|
|
|
|
|
// No references to the registar should be kept.
|
|
|
|
schemeRegistrar->Detach();
|
|
|
|
DCHECK(schemeRegistrar->VerifyRefCount());
|
|
|
|
}
|
2012-05-18 17:04:56 +02:00
|
|
|
|
2013-06-05 01:37:26 +02:00
|
|
|
scheme::AddInternalSchemes(standard_schemes);
|
2013-06-04 19:41:37 +02:00
|
|
|
|
2013-06-05 01:37:26 +02:00
|
|
|
scheme_info_list_locked_ = true;
|
2012-04-24 20:01:48 +02:00
|
|
|
}
|
|
|
|
|
2012-04-11 20:00:55 +02:00
|
|
|
std::string CefContentClient::GetUserAgent() const {
|
|
|
|
std::string product_version;
|
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
|
2012-04-11 20:00:55 +02:00
|
|
|
if (command_line.HasSwitch(switches::kProductVersion)) {
|
|
|
|
product_version =
|
|
|
|
command_line.GetSwitchValueASCII(switches::kProductVersion);
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
2012-04-11 20:00:55 +02:00
|
|
|
product_version = base::StringPrintf("Chrome/%d.%d.%d.%d",
|
|
|
|
CHROME_VERSION_MAJOR, CHROME_VERSION_MINOR, CHROME_VERSION_BUILD,
|
|
|
|
CHROME_VERSION_PATCH);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2012-04-11 20:00:55 +02:00
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
return content::BuildUserAgentFromProduct(product_version);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
base::string16 CefContentClient::GetLocalizedString(int message_id) const {
|
|
|
|
base::string16 value =
|
2012-05-18 17:04:56 +02:00
|
|
|
ResourceBundle::GetSharedInstance().GetLocalizedString(message_id);
|
2012-04-03 03:34:16 +02:00
|
|
|
if (value.empty())
|
|
|
|
LOG(ERROR) << "No localized string available for id " << message_id;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2012-05-31 17:19:33 +02:00
|
|
|
base::StringPiece CefContentClient::GetDataResource(
|
|
|
|
int resource_id,
|
|
|
|
ui::ScaleFactor scale_factor) const {
|
2012-05-18 17:04:56 +02:00
|
|
|
base::StringPiece value =
|
2012-11-05 21:18:20 +01:00
|
|
|
ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
|
|
|
|
resource_id, scale_factor);
|
2012-04-03 03:34:16 +02:00
|
|
|
if (value.empty())
|
|
|
|
LOG(ERROR) << "No data resource available for id " << resource_id;
|
2012-08-04 02:59:58 +02:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Image& CefContentClient::GetNativeImageNamed(int resource_id) const {
|
|
|
|
gfx::Image& value =
|
|
|
|
ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
|
|
|
|
if (value.IsEmpty())
|
|
|
|
LOG(ERROR) << "No native image available for id " << resource_id;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2013-06-05 01:37:26 +02:00
|
|
|
void CefContentClient::AddCustomScheme(const SchemeInfo& scheme_info) {
|
|
|
|
DCHECK(!scheme_info_list_locked_);
|
|
|
|
scheme_info_list_.push_back(scheme_info);
|
|
|
|
|
|
|
|
if (CefContentBrowserClient::Get()) {
|
|
|
|
CefContentBrowserClient::Get()->RegisterCustomScheme(
|
|
|
|
scheme_info.scheme_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const CefContentClient::SchemeInfoList* CefContentClient::GetCustomSchemes() {
|
|
|
|
DCHECK(scheme_info_list_locked_);
|
|
|
|
return &scheme_info_list_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefContentClient::HasCustomScheme(const std::string& scheme_name) {
|
|
|
|
DCHECK(scheme_info_list_locked_);
|
|
|
|
if (scheme_info_list_.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SchemeInfoList::const_iterator it = scheme_info_list_.begin();
|
|
|
|
for (; it != scheme_info_list_.end(); ++it) {
|
|
|
|
if (it->scheme_name == scheme_name)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath CefContentClient::GetPathForResourcePack(
|
|
|
|
const base::FilePath& pack_path,
|
2012-05-31 17:19:33 +02:00
|
|
|
ui::ScaleFactor scale_factor) {
|
2012-05-18 17:04:56 +02:00
|
|
|
// Only allow the cef pack file to load.
|
|
|
|
if (!pack_loading_disabled_ && allow_pack_file_load_)
|
|
|
|
return pack_path;
|
2013-02-23 01:43:28 +01:00
|
|
|
return base::FilePath();
|
2012-05-18 17:04:56 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath CefContentClient::GetPathForLocalePack(
|
|
|
|
const base::FilePath& pack_path,
|
|
|
|
const std::string& locale) {
|
2012-05-18 17:04:56 +02:00
|
|
|
if (!pack_loading_disabled_)
|
|
|
|
return pack_path;
|
2013-02-23 01:43:28 +01:00
|
|
|
return base::FilePath();
|
2012-05-18 17:04:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Image CefContentClient::GetImageNamed(int resource_id) {
|
|
|
|
return gfx::Image();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Image CefContentClient::GetNativeImageNamed(
|
|
|
|
int resource_id,
|
|
|
|
ui::ResourceBundle::ImageRTL rtl) {
|
|
|
|
return gfx::Image();
|
|
|
|
}
|
|
|
|
|
|
|
|
base::RefCountedStaticMemory* CefContentClient::LoadDataResourceBytes(
|
2012-05-31 17:19:33 +02:00
|
|
|
int resource_id,
|
|
|
|
ui::ScaleFactor scale_factor) {
|
2012-05-18 17:04:56 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefContentClient::GetRawDataResource(int resource_id,
|
2012-05-31 17:19:33 +02:00
|
|
|
ui::ScaleFactor scale_factor,
|
2012-05-18 17:04:56 +02:00
|
|
|
base::StringPiece* value) {
|
|
|
|
if (application_.get()) {
|
|
|
|
CefRefPtr<CefResourceBundleHandler> handler =
|
|
|
|
application_->GetResourceBundleHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
void* data = NULL;
|
|
|
|
size_t data_size = 0;
|
|
|
|
if (handler->GetDataResource(resource_id, data, data_size))
|
|
|
|
*value = base::StringPiece(static_cast<char*>(data), data_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (pack_loading_disabled_ || !value->empty());
|
|
|
|
}
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
bool CefContentClient::GetLocalizedString(int message_id,
|
|
|
|
base::string16* value) {
|
2012-05-18 17:04:56 +02:00
|
|
|
if (application_.get()) {
|
|
|
|
CefRefPtr<CefResourceBundleHandler> handler =
|
|
|
|
application_->GetResourceBundleHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefString cef_str;
|
|
|
|
if (handler->GetLocalizedString(message_id, cef_str))
|
|
|
|
*value = cef_str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (pack_loading_disabled_ || !value->empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_ptr<gfx::Font> CefContentClient::GetFont(
|
|
|
|
ui::ResourceBundle::FontStyle style) {
|
|
|
|
return scoped_ptr<gfx::Font>();
|
|
|
|
}
|