mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Update to Chromium revision 47fb4821 (#318735).
- Remove the in-process PDF plugin implementation. A new implementation is now required (issue #1565). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@2043 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -36,10 +36,8 @@
|
||||
#include "base/bind.h"
|
||||
#include "base/bind_helpers.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "chrome/browser/spellchecker/spellcheck_factory.h"
|
||||
#include "chrome/browser/spellchecker/spellcheck_service.h"
|
||||
#include "components/pdf/common/pdf_messages.h"
|
||||
#include "content/browser/gpu/compositor_util.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
||||
#include "content/common/view_messages.h"
|
||||
@@ -2558,13 +2556,6 @@ bool CefBrowserHostImpl::OnMessageReceived(const IPC::Message& message) {
|
||||
IPC_MESSAGE_HANDLER(CefHostMsg_Request, OnRequest)
|
||||
IPC_MESSAGE_HANDLER(CefHostMsg_Response, OnResponse)
|
||||
IPC_MESSAGE_HANDLER(CefHostMsg_ResponseAck, OnResponseAck)
|
||||
IPC_MESSAGE_HANDLER(PDFHostMsg_PDFHasUnsupportedFeature,
|
||||
OnPDFHasUnsupportedFeature)
|
||||
IPC_MESSAGE_HANDLER(PDFHostMsg_PDFSaveURLAs, OnPDFSaveURLAs)
|
||||
IPC_MESSAGE_HANDLER(PDFHostMsg_PDFUpdateContentRestrictions,
|
||||
OnPDFUpdateContentRestrictions)
|
||||
IPC_MESSAGE_HANDLER_DELAY_REPLY(PDFHostMsg_PDFModalPromptForPassword,
|
||||
OnPDFModalPromptForPassword)
|
||||
IPC_MESSAGE_UNHANDLED(handled = false)
|
||||
IPC_END_MESSAGE_MAP()
|
||||
return handled;
|
||||
@@ -2659,38 +2650,6 @@ void CefBrowserHostImpl::OnResponseAck(int 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) {
|
||||
PDFHostMsg_PDFModalPromptForPassword::WriteReplyParams(
|
||||
reply_message, base::UTF16ToUTF8(actual_value));
|
||||
Send(reply_message);
|
||||
}
|
||||
|
||||
|
||||
// content::NotificationObserver methods.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@@ -478,16 +478,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
||||
void OnRequest(const Cef_Request_Params& params);
|
||||
void OnResponse(const Cef_Response_Params& params);
|
||||
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.
|
||||
void Observe(int type,
|
||||
|
@@ -24,7 +24,6 @@
|
||||
#include "content/public/browser/web_ui_controller_factory.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "net/base/net_module.h"
|
||||
#include "net/proxy/proxy_resolver_v8.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
|
||||
#if defined(USE_AURA)
|
||||
@@ -115,9 +114,6 @@ int CefBrowserMainParts::PreCreateThreads() {
|
||||
pref_store_->SetInitializationCompleted();
|
||||
pref_service_ = pref_store_->CreateService().Pass();
|
||||
|
||||
// Initialize the V8 proxy integration.
|
||||
net::ProxyResolverV8::EnsureIsolateCreated();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -239,6 +239,12 @@ component_updater::PnaclComponentInstaller*
|
||||
return NULL;
|
||||
}
|
||||
|
||||
component_updater::SupervisedUserWhitelistInstaller*
|
||||
ChromeBrowserProcessStub::supervised_user_whitelist_installer() {
|
||||
NOTIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MediaFileSystemRegistry*
|
||||
ChromeBrowserProcessStub::media_file_system_registry() {
|
||||
NOTIMPLEMENTED();
|
||||
|
@@ -86,6 +86,8 @@ class ChromeBrowserProcessStub : public BrowserProcess {
|
||||
CRLSetFetcher* crl_set_fetcher() override;
|
||||
component_updater::PnaclComponentInstaller*
|
||||
pnacl_component_installer() override;
|
||||
component_updater::SupervisedUserWhitelistInstaller*
|
||||
supervised_user_whitelist_installer() override;
|
||||
MediaFileSystemRegistry*
|
||||
media_file_system_registry() override;
|
||||
bool created_local_state() const override;
|
||||
|
@@ -932,7 +932,6 @@ void CefContentBrowserClient::ResourceDispatcherHostCreated() {
|
||||
|
||||
void CefContentBrowserClient::OverrideWebkitPrefs(
|
||||
content::RenderViewHost* rvh,
|
||||
const GURL& url,
|
||||
content::WebPreferences* prefs) {
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
|
@@ -132,7 +132,6 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
|
||||
bool* no_javascript_access) override;
|
||||
void ResourceDispatcherHostCreated() override;
|
||||
void OverrideWebkitPrefs(content::RenderViewHost* rvh,
|
||||
const GURL& url,
|
||||
content::WebPreferences* prefs) override;
|
||||
SkColor GetBaseBackgroundColor(content::RenderViewHost* rvh) override;
|
||||
void BrowserURLHandlerCreated(
|
||||
|
@@ -545,6 +545,7 @@ void CefCookieManagerImpl::SetCookieInternal(
|
||||
expiration_time,
|
||||
cookie.secure ? true : false,
|
||||
cookie.httponly ? true : false,
|
||||
false, // First-party only.
|
||||
net::COOKIE_PRIORITY_DEFAULT,
|
||||
base::Bind(SetCookieCallbackImpl, callback));
|
||||
}
|
||||
|
@@ -12,19 +12,80 @@
|
||||
#include "base/command_line.h"
|
||||
#include "base/json/json_reader.h"
|
||||
#include "base/json/json_writer.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/values.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/devtools_http_handler.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
#include "net/base/net_util.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "net/base/io_buffer.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/http/http_response_headers.h"
|
||||
#include "net/url_request/url_fetcher.h"
|
||||
#include "net/url_request/url_fetcher_response_writer.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
// ResponseWriter -------------------------------------------------------------
|
||||
|
||||
class ResponseWriter : public net::URLFetcherResponseWriter {
|
||||
public:
|
||||
ResponseWriter(base::WeakPtr<CefDevToolsFrontend> devtools_,
|
||||
int stream_id);
|
||||
~ResponseWriter() override;
|
||||
|
||||
// URLFetcherResponseWriter overrides:
|
||||
int Initialize(const net::CompletionCallback& callback) override;
|
||||
int Write(net::IOBuffer* buffer,
|
||||
int num_bytes,
|
||||
const net::CompletionCallback& callback) override;
|
||||
int Finish(const net::CompletionCallback& callback) override;
|
||||
|
||||
private:
|
||||
base::WeakPtr<CefDevToolsFrontend> devtools_;
|
||||
int stream_id_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ResponseWriter);
|
||||
};
|
||||
|
||||
ResponseWriter::ResponseWriter(
|
||||
base::WeakPtr<CefDevToolsFrontend> devtools,
|
||||
int stream_id)
|
||||
: devtools_(devtools),
|
||||
stream_id_(stream_id) {
|
||||
}
|
||||
|
||||
ResponseWriter::~ResponseWriter() {
|
||||
}
|
||||
|
||||
int ResponseWriter::Initialize(const net::CompletionCallback& callback) {
|
||||
return net::OK;
|
||||
}
|
||||
|
||||
int ResponseWriter::Write(net::IOBuffer* buffer,
|
||||
int num_bytes,
|
||||
const net::CompletionCallback& callback) {
|
||||
base::FundamentalValue* id = new base::FundamentalValue(stream_id_);
|
||||
base::StringValue* chunk =
|
||||
new base::StringValue(std::string(buffer->data(), num_bytes));
|
||||
|
||||
content::BrowserThread::PostTask(
|
||||
content::BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&CefDevToolsFrontend::CallClientFunction,
|
||||
devtools_, "DevToolsAPI.streamWrite",
|
||||
base::Owned(id), base::Owned(chunk), nullptr));
|
||||
return num_bytes;
|
||||
}
|
||||
|
||||
int ResponseWriter::Finish(const net::CompletionCallback& callback) {
|
||||
return net::OK;
|
||||
}
|
||||
|
||||
// This constant should be in sync with
|
||||
// the constant at devtools_ui_bindings.cc.
|
||||
const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4;
|
||||
@@ -82,21 +143,36 @@ void CefDevToolsFrontend::Focus() {
|
||||
web_contents()->Focus();
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::InspectElementAt(int x, int y) {
|
||||
if (agent_host_)
|
||||
agent_host_->InspectElement(x, y);
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::Close() {
|
||||
CEF_POST_TASK(CEF_UIT,
|
||||
base::Bind(&CefBrowserHostImpl::CloseBrowser, frontend_browser_.get(),
|
||||
true));
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::DisconnectFromTarget() {
|
||||
if (!agent_host_)
|
||||
return;
|
||||
agent_host_->DetachClient();
|
||||
agent_host_ = NULL;
|
||||
}
|
||||
|
||||
CefDevToolsFrontend::CefDevToolsFrontend(
|
||||
CefRefPtr<CefBrowserHostImpl> frontend_browser,
|
||||
content::DevToolsAgentHost* agent_host)
|
||||
: WebContentsObserver(frontend_browser->GetWebContents()),
|
||||
frontend_browser_(frontend_browser),
|
||||
agent_host_(agent_host) {
|
||||
agent_host_(agent_host),
|
||||
weak_factory_(this) {
|
||||
}
|
||||
|
||||
CefDevToolsFrontend::~CefDevToolsFrontend() {
|
||||
for (const auto& pair : pending_requests_)
|
||||
delete pair.first;
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::RenderViewCreated(
|
||||
@@ -105,19 +181,27 @@ void CefDevToolsFrontend::RenderViewCreated(
|
||||
frontend_host_.reset(
|
||||
content::DevToolsFrontendHost::Create(
|
||||
web_contents()->GetMainFrame(), this));
|
||||
agent_host_->AttachClient(this);
|
||||
}
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::DidNavigateMainFrame(
|
||||
const content::LoadCommittedDetails& details,
|
||||
const content::FrameNavigateParams& params) {
|
||||
if (agent_host_)
|
||||
agent_host_->AttachClient(this);
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::WebContentsDestroyed() {
|
||||
agent_host_->DetachClient();
|
||||
if (agent_host_)
|
||||
agent_host_->DetachClient();
|
||||
delete this;
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
|
||||
const std::string& message) {
|
||||
if (!agent_host_)
|
||||
return;
|
||||
std::string method;
|
||||
int id = 0;
|
||||
base::ListValue* params = NULL;
|
||||
base::DictionaryValue* dict = NULL;
|
||||
scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
|
||||
@@ -126,6 +210,8 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
|
||||
!dict->GetString("method", &method)) {
|
||||
return;
|
||||
}
|
||||
int request_id = 0;
|
||||
dict->GetInteger("id", &request_id);
|
||||
dict->GetList("params", ¶ms);
|
||||
|
||||
std::string browser_message;
|
||||
@@ -135,22 +221,47 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
|
||||
} else if (method == "loadCompleted") {
|
||||
web_contents()->GetMainFrame()->ExecuteJavaScript(
|
||||
base::ASCIIToUTF16("DevToolsAPI.setUseSoftMenu(true);"));
|
||||
} else if (method == "loadNetworkResource" && params->GetSize() == 3) {
|
||||
// TODO(pfeldman): handle some of the embedder messages in content.
|
||||
std::string url;
|
||||
std::string headers;
|
||||
int stream_id;
|
||||
if (!params->GetString(0, &url) ||
|
||||
!params->GetString(1, &headers) ||
|
||||
!params->GetInteger(2, &stream_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GURL gurl(url);
|
||||
if (!gurl.is_valid()) {
|
||||
base::DictionaryValue response;
|
||||
response.SetInteger("statusCode", 404);
|
||||
SendMessageAck(request_id, &response);
|
||||
return;
|
||||
}
|
||||
|
||||
net::URLFetcher* fetcher =
|
||||
net::URLFetcher::Create(gurl, net::URLFetcher::GET, this);
|
||||
pending_requests_[fetcher] = request_id;
|
||||
fetcher->SetRequestContext(web_contents()->GetBrowserContext()->
|
||||
GetRequestContext());
|
||||
fetcher->SetExtraRequestHeaders(headers);
|
||||
fetcher->SaveResponseWithWriter(scoped_ptr<net::URLFetcherResponseWriter>(
|
||||
new ResponseWriter(weak_factory_.GetWeakPtr(), stream_id)));
|
||||
fetcher->Start();
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
dict->GetInteger("id", &id);
|
||||
if (id) {
|
||||
std::string code = "DevToolsAPI.embedderMessageAck(" +
|
||||
base::IntToString(id) + ",\"\");";
|
||||
base::string16 javascript = base::UTF8ToUTF16(code);
|
||||
web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
|
||||
}
|
||||
if (request_id)
|
||||
SendMessageAck(request_id, nullptr);
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend(
|
||||
const std::string& message) {
|
||||
agent_host_->DispatchProtocolMessage(message);
|
||||
if (agent_host_)
|
||||
agent_host_->DispatchProtocolMessage(message);
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::DispatchProtocolMessage(
|
||||
@@ -174,6 +285,66 @@ void CefDevToolsFrontend::DispatchProtocolMessage(
|
||||
}
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) {
|
||||
// TODO(pfeldman): this is a copy of chrome's devtools_ui_bindings.cc.
|
||||
// We should handle some of the commands including this one in content.
|
||||
DCHECK(source);
|
||||
PendingRequestsMap::iterator it = pending_requests_.find(source);
|
||||
DCHECK(it != pending_requests_.end());
|
||||
|
||||
base::DictionaryValue response;
|
||||
base::DictionaryValue* headers = new base::DictionaryValue();
|
||||
net::HttpResponseHeaders* rh = source->GetResponseHeaders();
|
||||
response.SetInteger("statusCode", rh ? rh->response_code() : 200);
|
||||
response.Set("headers", headers);
|
||||
|
||||
void* iterator = NULL;
|
||||
std::string name;
|
||||
std::string value;
|
||||
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value))
|
||||
headers->SetString(name, value);
|
||||
|
||||
SendMessageAck(it->second, &response);
|
||||
pending_requests_.erase(it);
|
||||
delete source;
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::CallClientFunction(
|
||||
const std::string& function_name,
|
||||
const base::Value* arg1,
|
||||
const base::Value* arg2,
|
||||
const base::Value* arg3) {
|
||||
std::string javascript = function_name + "(";
|
||||
if (arg1) {
|
||||
std::string json;
|
||||
base::JSONWriter::Write(arg1, &json);
|
||||
javascript.append(json);
|
||||
if (arg2) {
|
||||
base::JSONWriter::Write(arg2, &json);
|
||||
javascript.append(", ").append(json);
|
||||
if (arg3) {
|
||||
base::JSONWriter::Write(arg3, &json);
|
||||
javascript.append(", ").append(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
javascript.append(");");
|
||||
web_contents()->GetMainFrame()->ExecuteJavaScript(
|
||||
base::UTF8ToUTF16(javascript));
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::SendMessageAck(int request_id,
|
||||
const base::Value* arg) {
|
||||
base::FundamentalValue id_value(request_id);
|
||||
CallClientFunction("DevToolsAPI.embedderMessageAck",
|
||||
&id_value, arg, nullptr);
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::AttachTo(content::WebContents* inspected_contents) {
|
||||
DisconnectFromTarget();
|
||||
agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(inspected_contents);
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::AgentHostClosed(
|
||||
content::DevToolsAgentHost* agent_host,
|
||||
bool replaced) {
|
||||
|
@@ -11,9 +11,15 @@
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "content/public/browser/devtools_agent_host.h"
|
||||
#include "content/public/browser/devtools_frontend_host.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "net/url_request/url_fetcher_delegate.h"
|
||||
|
||||
namespace base {
|
||||
class Value;
|
||||
}
|
||||
|
||||
namespace content {
|
||||
class RenderViewHost;
|
||||
@@ -22,7 +28,8 @@ class WebContents;
|
||||
|
||||
class CefDevToolsFrontend : public content::WebContentsObserver,
|
||||
public content::DevToolsFrontendHost::Delegate,
|
||||
public content::DevToolsAgentHostClient {
|
||||
public content::DevToolsAgentHostClient,
|
||||
public net::URLFetcherDelegate {
|
||||
public:
|
||||
static CefDevToolsFrontend* Show(
|
||||
CefRefPtr<CefBrowserHostImpl> inspected_browser,
|
||||
@@ -33,39 +40,56 @@ class CefDevToolsFrontend : public content::WebContentsObserver,
|
||||
|
||||
void Activate();
|
||||
void Focus();
|
||||
void InspectElementAt(int x, int y);
|
||||
void Close();
|
||||
|
||||
void DisconnectFromTarget();
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> frontend_browser() const {
|
||||
return frontend_browser_;
|
||||
}
|
||||
|
||||
void CallClientFunction(const std::string& function_name,
|
||||
const base::Value* arg1,
|
||||
const base::Value* arg2,
|
||||
const base::Value* arg3);
|
||||
|
||||
private:
|
||||
CefDevToolsFrontend(CefRefPtr<CefBrowserHostImpl> frontend_browser,
|
||||
content::DevToolsAgentHost* agent_host);
|
||||
~CefDevToolsFrontend() override;
|
||||
|
||||
// WebContentsObserver overrides.
|
||||
void RenderViewCreated(
|
||||
content::RenderViewHost* render_view_host) override;
|
||||
// content::DevToolsAgentHostClient implementation.
|
||||
void AgentHostClosed(content::DevToolsAgentHost* agent_host,
|
||||
bool replaced) override;
|
||||
void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
|
||||
const std::string& message) override;
|
||||
void AttachTo(content::WebContents* inspected_contents);
|
||||
|
||||
// WebContentsObserver overrides
|
||||
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
|
||||
void DidNavigateMainFrame(
|
||||
const content::LoadCommittedDetails& details,
|
||||
const content::FrameNavigateParams& params) override;
|
||||
void WebContentsDestroyed() override;
|
||||
|
||||
// content::DevToolsFrontendHost::Delegate implementation.
|
||||
void HandleMessageFromDevToolsFrontend(
|
||||
const std::string& message) override;
|
||||
void HandleMessageFromDevToolsFrontend(const std::string& message) override;
|
||||
void HandleMessageFromDevToolsFrontendToBackend(
|
||||
const std::string& message) override;
|
||||
|
||||
// content::DevToolsAgentHostClient implementation.
|
||||
void DispatchProtocolMessage(
|
||||
content::DevToolsAgentHost* agent_host,
|
||||
const std::string& message) override;
|
||||
void AgentHostClosed(
|
||||
content::DevToolsAgentHost* agent_host,
|
||||
bool replaced) override;
|
||||
// net::URLFetcherDelegate overrides.
|
||||
void OnURLFetchComplete(const net::URLFetcher* source) override;
|
||||
|
||||
void SendMessageAck(int request_id,
|
||||
const base::Value* arg1);
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> frontend_browser_;
|
||||
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
||||
scoped_ptr<content::DevToolsFrontendHost> frontend_host_;
|
||||
using PendingRequestsMap = std::map<const net::URLFetcher*, int>;
|
||||
PendingRequestsMap pending_requests_;
|
||||
base::WeakPtrFactory<CefDevToolsFrontend> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CefDevToolsFrontend);
|
||||
};
|
||||
|
@@ -6,8 +6,8 @@
|
||||
#include "include/cef_trace.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
|
||||
#include "base/debug/trace_event.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "content/public/browser/tracing_controller.h"
|
||||
|
||||
namespace {
|
||||
@@ -57,8 +57,8 @@ bool CefTraceSubscriber::BeginTracing(
|
||||
}
|
||||
|
||||
TracingController::GetInstance()->EnableRecording(
|
||||
base::debug::CategoryFilter(categories),
|
||||
base::debug::TraceOptions(),
|
||||
base::trace_event::CategoryFilter(categories),
|
||||
base::trace_event::TraceOptions(),
|
||||
done_callback);
|
||||
return true;
|
||||
}
|
||||
|
@@ -6,9 +6,9 @@
|
||||
#include "include/internal/cef_logging_internal.h"
|
||||
#include "include/internal/cef_thread_internal.h"
|
||||
|
||||
#include "base/debug/trace_event.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/threading/platform_thread.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
|
||||
// The contents of this file are a compilation unit that is not called by other
|
||||
// functions in the the library. Consiquently MSVS will exclude it during the
|
||||
|
@@ -10,60 +10,18 @@
|
||||
#include "libcef/common/scheme_registration.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/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)
|
||||
@@ -84,11 +42,6 @@ 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,8 +26,6 @@ class CefContentClient : public content::ContentClient,
|
||||
static CefContentClient* Get();
|
||||
|
||||
// content::ContentClient methods.
|
||||
void AddPepperPlugins(
|
||||
std::vector<content::PepperPluginInfo>* plugins) override;
|
||||
void AddAdditionalSchemes(
|
||||
std::vector<std::string>* standard_schemes,
|
||||
std::vector<std::string>* savable_schemes) override;
|
||||
|
@@ -84,10 +84,6 @@ base::FilePath GetResourcesFilePath() {
|
||||
return GetFrameworkBundlePath().Append(FILE_PATH_LITERAL("Resources"));
|
||||
}
|
||||
|
||||
base::FilePath GetLibrariesFilePath() {
|
||||
return GetFrameworkBundlePath().Append(FILE_PATH_LITERAL("Libraries"));
|
||||
}
|
||||
|
||||
void OverrideFrameworkBundlePath() {
|
||||
base::mac::SetOverrideFrameworkBundlePath(GetFrameworkBundlePath());
|
||||
}
|
||||
@@ -116,10 +112,6 @@ base::FilePath GetResourcesFilePath() {
|
||||
return pak_dir;
|
||||
}
|
||||
|
||||
base::FilePath GetLibrariesFilePath() {
|
||||
return GetResourcesFilePath();
|
||||
}
|
||||
|
||||
#endif // !defined(OS_MACOSX)
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
@@ -180,22 +172,6 @@ base::FilePath GetUserDataPath() {
|
||||
return result;
|
||||
}
|
||||
|
||||
// File name of the internal PDF plugin on different platforms.
|
||||
const base::FilePath::CharType kInternalPDFPluginFileName[] =
|
||||
#if defined(OS_WIN)
|
||||
FILE_PATH_LITERAL("pdf.dll");
|
||||
#elif defined(OS_MACOSX)
|
||||
FILE_PATH_LITERAL("PDF.plugin");
|
||||
#else // Linux and Chrome OS
|
||||
FILE_PATH_LITERAL("libpdf.so");
|
||||
#endif
|
||||
|
||||
void OverridePdfPluginPath() {
|
||||
base::FilePath plugin_path = GetLibrariesFilePath();
|
||||
plugin_path = plugin_path.Append(kInternalPDFPluginFileName);
|
||||
PathService::Override(chrome::FILE_PDF_PLUGIN, plugin_path);
|
||||
}
|
||||
|
||||
// Returns true if |scale_factor| is supported by this platform.
|
||||
// Same as ResourceBundle::IsScaleFactorSupported.
|
||||
bool IsScaleFactorSupported(ui::ScaleFactor scale_factor) {
|
||||
@@ -489,17 +465,10 @@ void CefMainDelegate::PreSandboxStartup() {
|
||||
true); // Create if necessary.
|
||||
}
|
||||
|
||||
OverridePdfPluginPath();
|
||||
|
||||
if (command_line->HasSwitch(switches::kDisablePackLoading))
|
||||
content_client_.set_pack_loading_disabled(true);
|
||||
|
||||
InitializeResourceBundle();
|
||||
|
||||
if (process_type == switches::kUtilityProcess ||
|
||||
process_type == switches::kZygoteProcess) {
|
||||
CefContentUtilityClient::PreSandboxStartup();
|
||||
}
|
||||
}
|
||||
|
||||
int CefMainDelegate::RunProcess(
|
||||
|
@@ -31,23 +31,19 @@ MSVC_POP_WARNING();
|
||||
#include "libcef/renderer/webkit_glue.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/string_number_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/pepper/chrome_pdf_print_client.h"
|
||||
#include "chrome/renderer/spellchecker/spellcheck.h"
|
||||
#include "chrome/renderer/spellchecker/spellcheck_provider.h"
|
||||
#include "components/pdf/renderer/ppb_pdf_impl.h"
|
||||
#include "components/printing/renderer/print_web_view_helper.h"
|
||||
#include "components/web_cache/renderer/web_cache_render_process_observer.h"
|
||||
#include "content/child/child_thread.h"
|
||||
#include "content/child/worker_task_runner.h"
|
||||
#include "content/common/frame_messages.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/child/child_thread.h"
|
||||
#include "content/public/common/content_constants.h"
|
||||
#include "content/public/common/content_paths.h"
|
||||
#include "content/public/renderer/plugin_instance_throttler.h"
|
||||
@@ -57,11 +53,9 @@ MSVC_POP_WARNING();
|
||||
#include "content/renderer/render_frame_impl.h"
|
||||
#include "ipc/ipc_sync_channel.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/WebString.h"
|
||||
#include "third_party/WebKit/public/platform/WebURL.h"
|
||||
#include "third_party/WebKit/public/platform/WebWorkerRunLoop.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"
|
||||
@@ -74,10 +68,6 @@ MSVC_POP_WARNING();
|
||||
#include "third_party/WebKit/public/web/WebView.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "base/win/iat_patch_function.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
// Stub implementation of blink::WebPrerenderingSupport.
|
||||
@@ -182,43 +172,6 @@ class CefPrintWebViewHelperDelegate :
|
||||
DISALLOW_COPY_AND_ASSIGN(CefPrintWebViewHelperDelegate);
|
||||
};
|
||||
|
||||
#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
|
||||
|
||||
CefContentRendererClient::CefContentRendererClient()
|
||||
@@ -288,18 +241,9 @@ void CefContentRendererClient::WebKitInitialized() {
|
||||
// TODO(cef): Enable these once the implementation supports it.
|
||||
blink::WebRuntimeFeatures::enableNotifications(false);
|
||||
|
||||
#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)
|
||||
// TODO(cef): Remove this line once off-screen rendering is fixed to work
|
||||
// with the new popup menu implementation (issue #1566).
|
||||
blink::WebRuntimeFeatures::enableFeatureFromString("HTMLPopupMenu", false);
|
||||
|
||||
const CefContentClient::SchemeInfoList* schemes =
|
||||
CefContentClient::Get()->GetCustomSchemes();
|
||||
@@ -510,9 +454,6 @@ void CefContentRendererClient::RenderThreadStarted() {
|
||||
// Cross-origin entries need to be added after WebKit is initialized.
|
||||
cross_origin_whitelist_entries_ = params.cross_origin_whitelist_entries;
|
||||
|
||||
pdf_print_client_.reset(new ChromePDFPrintClient());
|
||||
pdf::PPB_PDF_Impl::SetPrintClient(pdf_print_client_.get());
|
||||
|
||||
// Notify the render process handler.
|
||||
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
||||
if (application.get()) {
|
||||
@@ -710,16 +651,6 @@ 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 pdf::PPB_PDF_Impl::GetInterface();
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CefContentRendererClient::WillReleaseScriptContext(
|
||||
blink::WebLocalFrame* frame,
|
||||
v8::Handle<v8::Context> context,
|
||||
|
@@ -26,7 +26,6 @@ class WebCacheRenderProcessObserver;
|
||||
|
||||
class CefRenderProcessObserver;
|
||||
struct Cef_CrossOriginWhiteListEntry_Params;
|
||||
class ChromePDFPrintClient;
|
||||
class SpellCheck;
|
||||
|
||||
class CefContentRendererClient : public content::ContentRendererClient,
|
||||
@@ -99,8 +98,6 @@ class CefContentRendererClient : public content::ContentRendererClient,
|
||||
v8::Handle<v8::Context> context,
|
||||
int extension_group,
|
||||
int world_id) override;
|
||||
const void* CreatePPAPIInterface(
|
||||
const std::string& interface_name) override;
|
||||
|
||||
void WillReleaseScriptContext(blink::WebLocalFrame* frame,
|
||||
v8::Handle<v8::Context> context,
|
||||
@@ -129,8 +126,6 @@ class CefContentRendererClient : public content::ContentRendererClient,
|
||||
typedef std::vector<Cef_CrossOriginWhiteListEntry_Params> CrossOriginList;
|
||||
CrossOriginList cross_origin_whitelist_entries_;
|
||||
|
||||
scoped_ptr<ChromePDFPrintClient> pdf_print_client_;
|
||||
|
||||
int devtools_agent_count_;
|
||||
int uncaught_exception_stack_size_;
|
||||
|
||||
|
@@ -47,13 +47,6 @@ bool CefContentUtilityClient::OnMessageReceived(
|
||||
return handled;
|
||||
}
|
||||
|
||||
// static
|
||||
void CefContentUtilityClient::PreSandboxStartup() {
|
||||
#if defined(OS_WIN)
|
||||
PrintingHandler::PreSandboxStartup();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CefContentUtilityClient::OnStartupPing() {
|
||||
Send(new ChromeUtilityHostMsg_ProcessStarted);
|
||||
// Don't release the process, we assume further messages are on the way.
|
||||
|
@@ -18,8 +18,6 @@ class CefContentUtilityClient : public content::ContentUtilityClient {
|
||||
|
||||
bool OnMessageReceived(const IPC::Message& message) override;
|
||||
|
||||
static void PreSandboxStartup();
|
||||
|
||||
private:
|
||||
// IPC message handlers.
|
||||
void OnStartupPing();
|
||||
|
@@ -30,225 +30,12 @@ void ReleaseProcessIfNeeded() {
|
||||
content::UtilityThread::Get()->ReleaseProcessIfNeeded();
|
||||
}
|
||||
|
||||
class PdfFunctionsBase {
|
||||
public:
|
||||
PdfFunctionsBase() : render_pdf_to_bitmap_func_(NULL),
|
||||
get_pdf_doc_info_func_(NULL) {}
|
||||
|
||||
bool Init() {
|
||||
base::FilePath pdf_module_path;
|
||||
if (!PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_module_path) ||
|
||||
!base::PathExists(pdf_module_path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pdf_lib_.Reset(base::LoadNativeLibrary(pdf_module_path, NULL));
|
||||
if (!pdf_lib_.is_valid()) {
|
||||
LOG(WARNING) << "Couldn't load PDF plugin";
|
||||
return false;
|
||||
}
|
||||
|
||||
render_pdf_to_bitmap_func_ =
|
||||
reinterpret_cast<RenderPDFPageToBitmapProc>(
|
||||
pdf_lib_.GetFunctionPointer("RenderPDFPageToBitmap"));
|
||||
LOG_IF(WARNING, !render_pdf_to_bitmap_func_) <<
|
||||
"Missing RenderPDFPageToBitmap";
|
||||
|
||||
get_pdf_doc_info_func_ =
|
||||
reinterpret_cast<GetPDFDocInfoProc>(
|
||||
pdf_lib_.GetFunctionPointer("GetPDFDocInfo"));
|
||||
LOG_IF(WARNING, !get_pdf_doc_info_func_) << "Missing GetPDFDocInfo";
|
||||
|
||||
if (!render_pdf_to_bitmap_func_ || !get_pdf_doc_info_func_ ||
|
||||
!PlatformInit(pdf_module_path, pdf_lib_)) {
|
||||
Reset();
|
||||
}
|
||||
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
bool IsValid() const {
|
||||
return pdf_lib_.is_valid();
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
pdf_lib_.Reset(NULL);
|
||||
}
|
||||
|
||||
bool RenderPDFPageToBitmap(const void* pdf_buffer,
|
||||
int pdf_buffer_size,
|
||||
int page_number,
|
||||
void* bitmap_buffer,
|
||||
int bitmap_width,
|
||||
int bitmap_height,
|
||||
int dpi_x,
|
||||
int dpi_y,
|
||||
bool autorotate) {
|
||||
if (!render_pdf_to_bitmap_func_)
|
||||
return false;
|
||||
return render_pdf_to_bitmap_func_(pdf_buffer, pdf_buffer_size, page_number,
|
||||
bitmap_buffer, bitmap_width,
|
||||
bitmap_height, dpi_x, dpi_y, autorotate);
|
||||
}
|
||||
|
||||
bool GetPDFDocInfo(const void* pdf_buffer,
|
||||
int buffer_size,
|
||||
int* page_count,
|
||||
double* max_page_width) {
|
||||
if (!get_pdf_doc_info_func_)
|
||||
return false;
|
||||
return get_pdf_doc_info_func_(pdf_buffer, buffer_size, page_count,
|
||||
max_page_width);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool PlatformInit(
|
||||
const base::FilePath& pdf_module_path,
|
||||
const base::ScopedNativeLibrary& pdf_lib) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
// Exported by PDF plugin.
|
||||
typedef bool (*RenderPDFPageToBitmapProc)(const void* pdf_buffer,
|
||||
int pdf_buffer_size,
|
||||
int page_number,
|
||||
void* bitmap_buffer,
|
||||
int bitmap_width,
|
||||
int bitmap_height,
|
||||
int dpi_x,
|
||||
int dpi_y,
|
||||
bool autorotate);
|
||||
typedef bool (*GetPDFDocInfoProc)(const void* pdf_buffer,
|
||||
int buffer_size, int* page_count,
|
||||
double* max_page_width);
|
||||
|
||||
RenderPDFPageToBitmapProc render_pdf_to_bitmap_func_;
|
||||
GetPDFDocInfoProc get_pdf_doc_info_func_;
|
||||
|
||||
base::ScopedNativeLibrary pdf_lib_;
|
||||
DISALLOW_COPY_AND_ASSIGN(PdfFunctionsBase);
|
||||
};
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// The 2 below IAT patch functions are almost identical to the code in
|
||||
// render_process_impl.cc. This is needed to work around specific Windows APIs
|
||||
// used by the Chrome PDF plugin that will fail in the sandbox.
|
||||
static base::win::IATPatchFunction g_iat_patch_createdca;
|
||||
HDC WINAPI UtilityProcess_CreateDCAPatch(LPCSTR driver_name,
|
||||
LPCSTR device_name,
|
||||
LPCSTR output,
|
||||
const DEVMODEA* init_data) {
|
||||
if (driver_name && (std::string("DISPLAY") == driver_name)) {
|
||||
// CreateDC fails behind the sandbox, but not CreateCompatibleDC.
|
||||
return CreateCompatibleDC(NULL);
|
||||
}
|
||||
|
||||
NOTREACHED();
|
||||
return CreateDCA(driver_name, device_name, output, init_data);
|
||||
}
|
||||
|
||||
static base::win::IATPatchFunction g_iat_patch_get_font_data;
|
||||
DWORD WINAPI UtilityProcess_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)) {
|
||||
content::UtilityThread::Get()->PreCacheFont(logfont);
|
||||
rv = GetFontData(hdc, table, offset, buffer, length);
|
||||
content::UtilityThread::Get()->ReleaseCachedFonts();
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
class PdfFunctionsWin : public PdfFunctionsBase {
|
||||
public:
|
||||
PdfFunctionsWin() : render_pdf_to_dc_func_(NULL) {
|
||||
}
|
||||
|
||||
bool PlatformInit(
|
||||
const base::FilePath& pdf_module_path,
|
||||
const base::ScopedNativeLibrary& pdf_lib) override {
|
||||
// Patch the IAT for handling specific APIs known to fail in the sandbox.
|
||||
if (!g_iat_patch_createdca.is_patched()) {
|
||||
g_iat_patch_createdca.Patch(pdf_module_path.value().c_str(),
|
||||
"gdi32.dll", "CreateDCA",
|
||||
UtilityProcess_CreateDCAPatch);
|
||||
}
|
||||
|
||||
if (!g_iat_patch_get_font_data.is_patched()) {
|
||||
g_iat_patch_get_font_data.Patch(pdf_module_path.value().c_str(),
|
||||
"gdi32.dll", "GetFontData",
|
||||
UtilityProcess_GetFontDataPatch);
|
||||
}
|
||||
render_pdf_to_dc_func_ =
|
||||
reinterpret_cast<RenderPDFPageToDCProc>(
|
||||
pdf_lib.GetFunctionPointer("RenderPDFPageToDC"));
|
||||
LOG_IF(WARNING, !render_pdf_to_dc_func_) << "Missing RenderPDFPageToDC";
|
||||
|
||||
return render_pdf_to_dc_func_ != NULL;
|
||||
}
|
||||
|
||||
bool RenderPDFPageToDC(const void* pdf_buffer,
|
||||
int buffer_size,
|
||||
int page_number,
|
||||
HDC dc,
|
||||
int dpi_x,
|
||||
int dpi_y,
|
||||
int bounds_origin_x,
|
||||
int bounds_origin_y,
|
||||
int bounds_width,
|
||||
int bounds_height,
|
||||
bool fit_to_bounds,
|
||||
bool stretch_to_bounds,
|
||||
bool keep_aspect_ratio,
|
||||
bool center_in_bounds,
|
||||
bool autorotate) {
|
||||
if (!render_pdf_to_dc_func_)
|
||||
return false;
|
||||
return render_pdf_to_dc_func_(pdf_buffer, buffer_size, page_number,
|
||||
dc, dpi_x, dpi_y, bounds_origin_x,
|
||||
bounds_origin_y, bounds_width, bounds_height,
|
||||
fit_to_bounds, stretch_to_bounds,
|
||||
keep_aspect_ratio, center_in_bounds,
|
||||
autorotate);
|
||||
}
|
||||
|
||||
private:
|
||||
// Exported by PDF plugin.
|
||||
typedef bool (*RenderPDFPageToDCProc)(
|
||||
const void* pdf_buffer, int buffer_size, int page_number, HDC dc,
|
||||
int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y,
|
||||
int bounds_width, int bounds_height, bool fit_to_bounds,
|
||||
bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds,
|
||||
bool autorotate);
|
||||
RenderPDFPageToDCProc render_pdf_to_dc_func_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PdfFunctionsWin);
|
||||
};
|
||||
|
||||
typedef PdfFunctionsWin PdfFunctions;
|
||||
#else // OS_WIN
|
||||
typedef PdfFunctionsBase PdfFunctions;
|
||||
#endif // OS_WIN
|
||||
|
||||
base::LazyInstance<PdfFunctions> g_pdf_lib = LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
} // namespace
|
||||
|
||||
PrintingHandler::PrintingHandler() {}
|
||||
|
||||
PrintingHandler::~PrintingHandler() {}
|
||||
|
||||
// static
|
||||
void PrintingHandler::PreSandboxStartup() {
|
||||
g_pdf_lib.Get().Init();
|
||||
}
|
||||
|
||||
bool PrintingHandler::OnMessageReceived(const IPC::Message& message) {
|
||||
bool handled = true;
|
||||
IPC_BEGIN_MESSAGE_MAP(PrintingHandler, message)
|
||||
@@ -292,9 +79,6 @@ void PrintingHandler::OnRenderPDFPagesToMetafileStop() {
|
||||
}
|
||||
|
||||
int PrintingHandler::LoadPDF(base::File pdf_file) {
|
||||
if (!g_pdf_lib.Get().IsValid())
|
||||
return 0;
|
||||
|
||||
int64 length = pdf_file.GetLength();
|
||||
if (length < 0)
|
||||
return 0;
|
||||
@@ -304,7 +88,7 @@ int PrintingHandler::LoadPDF(base::File pdf_file) {
|
||||
return 0;
|
||||
|
||||
int total_page_count = 0;
|
||||
if (!g_pdf_lib.Get().GetPDFDocInfo(
|
||||
if (!chrome_pdf::GetPDFDocInfo(
|
||||
&pdf_data_.front(), pdf_data_.size(), &total_page_count, NULL)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -333,13 +117,12 @@ bool PrintingHandler::RenderPdfPageToMetafile(int page_number,
|
||||
// The underlying metafile is of type Emf and ignores the arguments passed
|
||||
// to StartPage.
|
||||
metafile.StartPage(gfx::Size(), gfx::Rect(), 1);
|
||||
if (!g_pdf_lib.Get().RenderPDFPageToDC(
|
||||
if (!chrome_pdf::RenderPDFPageToDC(
|
||||
&pdf_data_.front(),
|
||||
pdf_data_.size(),
|
||||
page_number,
|
||||
metafile.context(),
|
||||
pdf_rendering_settings_.dpi(),
|
||||
pdf_rendering_settings_.dpi(),
|
||||
pdf_rendering_settings_.area().x(),
|
||||
pdf_rendering_settings_.area().y(),
|
||||
pdf_rendering_settings_.area().width(),
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include "base/macros.h"
|
||||
#include "chrome/utility/utility_message_handler.h"
|
||||
#include "ipc/ipc_platform_file.h"
|
||||
#include "pdf/pdf.h"
|
||||
#include "printing/pdf_render_settings.h"
|
||||
|
||||
#if !defined(OS_WIN)
|
||||
@@ -27,8 +28,6 @@ class PrintingHandler : public UtilityMessageHandler {
|
||||
PrintingHandler();
|
||||
~PrintingHandler() override;
|
||||
|
||||
static void PreSandboxStartup();
|
||||
|
||||
// IPC::Listener:
|
||||
bool OnMessageReceived(const IPC::Message& message) override;
|
||||
|
||||
|
Reference in New Issue
Block a user