2017-01-21 19:52:23 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2018-03-15 08:51:48 +00:00
|
|
|
#ifndef ENABLE_PDF_VIEWER
|
|
|
|
#error("This header can only be used when enable_pdf_viewer gyp flag is enabled")
|
|
|
|
#endif // defined(ENABLE_PDF_VIEWER)
|
|
|
|
|
2017-01-21 19:52:23 +00:00
|
|
|
#include "components/pdf/renderer/pepper_pdf_host.h"
|
|
|
|
|
2017-11-27 07:00:14 +00:00
|
|
|
#include "atom/common/api/api_messages.h"
|
2017-01-21 19:52:23 +00:00
|
|
|
#include "base/memory/ptr_util.h"
|
|
|
|
#include "content/public/common/referrer.h"
|
|
|
|
#include "content/public/renderer/pepper_plugin_instance.h"
|
|
|
|
#include "content/public/renderer/render_frame.h"
|
|
|
|
#include "content/public/renderer/renderer_ppapi_host.h"
|
|
|
|
#include "ppapi/host/dispatch_host_message.h"
|
|
|
|
#include "ppapi/proxy/ppapi_messages.h"
|
|
|
|
|
|
|
|
namespace pdf {
|
|
|
|
|
|
|
|
PepperPDFHost::PepperPDFHost(content::RendererPpapiHost* host,
|
|
|
|
PP_Instance instance,
|
|
|
|
PP_Resource resource)
|
|
|
|
: ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource),
|
|
|
|
host_(host) {}
|
|
|
|
|
|
|
|
PepperPDFHost::~PepperPDFHost() {}
|
|
|
|
|
|
|
|
int32_t PepperPDFHost::OnResourceMessageReceived(
|
|
|
|
const IPC::Message& msg,
|
|
|
|
ppapi::host::HostMessageContext* context) {
|
|
|
|
PPAPI_BEGIN_MESSAGE_MAP(PepperPDFHost, msg)
|
|
|
|
PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_DidStartLoading,
|
|
|
|
OnHostMsgDidStartLoading)
|
|
|
|
PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_DidStopLoading,
|
|
|
|
OnHostMsgDidStopLoading)
|
|
|
|
PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_SaveAs,
|
|
|
|
OnHostMsgSaveAs)
|
|
|
|
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SetSelectedText,
|
|
|
|
OnHostMsgSetSelectedText)
|
|
|
|
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SetLinkUnderCursor,
|
|
|
|
OnHostMsgSetLinkUnderCursor)
|
|
|
|
PPAPI_END_MESSAGE_MAP()
|
|
|
|
return PP_ERROR_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t PepperPDFHost::OnHostMsgDidStartLoading(
|
|
|
|
ppapi::host::HostMessageContext* context) {
|
|
|
|
content::RenderFrame* render_frame = GetRenderFrame();
|
|
|
|
if (!render_frame)
|
|
|
|
return PP_ERROR_FAILED;
|
|
|
|
|
2017-04-13 10:11:16 +00:00
|
|
|
render_frame->PluginDidStartLoading();
|
2017-01-21 19:52:23 +00:00
|
|
|
return PP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t PepperPDFHost::OnHostMsgDidStopLoading(
|
|
|
|
ppapi::host::HostMessageContext* context) {
|
|
|
|
content::RenderFrame* render_frame = GetRenderFrame();
|
|
|
|
if (!render_frame)
|
|
|
|
return PP_ERROR_FAILED;
|
|
|
|
|
2017-04-13 10:11:16 +00:00
|
|
|
render_frame->PluginDidStopLoading();
|
2017-01-21 19:52:23 +00:00
|
|
|
return PP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t PepperPDFHost::OnHostMsgSaveAs(
|
|
|
|
ppapi::host::HostMessageContext* context) {
|
|
|
|
content::PepperPluginInstance* instance =
|
|
|
|
host_->GetPluginInstance(pp_instance());
|
|
|
|
if (!instance)
|
|
|
|
return PP_ERROR_FAILED;
|
|
|
|
|
|
|
|
content::RenderFrame* render_frame = instance->GetRenderFrame();
|
|
|
|
if (!render_frame)
|
|
|
|
return PP_ERROR_FAILED;
|
|
|
|
|
|
|
|
GURL url = instance->GetPluginURL();
|
|
|
|
content::Referrer referrer;
|
|
|
|
referrer.url = url;
|
2017-06-16 20:42:33 +00:00
|
|
|
referrer.policy = blink::kWebReferrerPolicyDefault;
|
2017-01-21 19:52:23 +00:00
|
|
|
referrer = content::Referrer::SanitizeForRequest(url, referrer);
|
2017-11-27 07:00:14 +00:00
|
|
|
render_frame->Send(new AtomFrameHostMsg_PDFSaveURLAs(
|
|
|
|
render_frame->GetRoutingID(), url, referrer));
|
2017-01-21 19:52:23 +00:00
|
|
|
return PP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t PepperPDFHost::OnHostMsgSetSelectedText(
|
|
|
|
ppapi::host::HostMessageContext* context,
|
|
|
|
const base::string16& selected_text) {
|
|
|
|
content::PepperPluginInstance* instance =
|
|
|
|
host_->GetPluginInstance(pp_instance());
|
|
|
|
if (!instance)
|
|
|
|
return PP_ERROR_FAILED;
|
|
|
|
instance->SetSelectedText(selected_text);
|
|
|
|
return PP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t PepperPDFHost::OnHostMsgSetLinkUnderCursor(
|
|
|
|
ppapi::host::HostMessageContext* context,
|
|
|
|
const std::string& url) {
|
|
|
|
content::PepperPluginInstance* instance =
|
|
|
|
host_->GetPluginInstance(pp_instance());
|
|
|
|
if (!instance)
|
|
|
|
return PP_ERROR_FAILED;
|
|
|
|
instance->SetLinkUnderCursor(url);
|
|
|
|
return PP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::RenderFrame* PepperPDFHost::GetRenderFrame() {
|
|
|
|
content::PepperPluginInstance* instance =
|
|
|
|
host_->GetPluginInstance(pp_instance());
|
|
|
|
return instance ? instance->GetRenderFrame() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace pdf
|