listen to ipc messages from plugin to perform SaveAs op
This commit is contained in:
parent
fd8c450ef3
commit
0c7bb72891
9 changed files with 286 additions and 2 deletions
|
@ -7,8 +7,10 @@
|
|||
#include <map>
|
||||
|
||||
#include "atom/browser/ui/webui/pdf_viewer_handler.h"
|
||||
#include "components/pdf/common/pdf_messages.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/url_data_source.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/bindings_policy.h"
|
||||
#include "grit/pdf_viewer_resources_map.h"
|
||||
#include "net/base/mime_util.h"
|
||||
|
@ -82,13 +84,32 @@ const char PdfViewerUI::kHost[] = "pdf-viewer";
|
|||
PdfViewerUI::PdfViewerUI(content::BrowserContext* browser_context,
|
||||
content::WebUI* web_ui,
|
||||
const std::string& view_id)
|
||||
: content::WebUIController(web_ui) {
|
||||
: content::WebUIController(web_ui),
|
||||
content::WebContentsObserver(web_ui->GetWebContents()) {
|
||||
web_ui->AddMessageHandler(new PdfViewerHandler(view_id));
|
||||
content::URLDataSource::Add(browser_context, new BundledDataSource);
|
||||
}
|
||||
|
||||
PdfViewerUI::~PdfViewerUI() {}
|
||||
|
||||
void PdfViewerUI::RenderViewCreated(content::RenderViewHost* rvh) {
|
||||
rvh->AllowBindings(content::BINDINGS_POLICY_WEB_UI);
|
||||
}
|
||||
|
||||
bool PdfViewerUI::OnMessageReceived(
|
||||
const IPC::Message& message,
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
bool handled = true;
|
||||
IPC_BEGIN_MESSAGE_MAP(PdfViewerUI, message)
|
||||
IPC_MESSAGE_HANDLER(PDFHostMsg_PDFSaveURLAs, OnSaveURLAs)
|
||||
IPC_MESSAGE_UNHANDLED(handled = false)
|
||||
IPC_END_MESSAGE_MAP()
|
||||
return handled;
|
||||
}
|
||||
|
||||
void PdfViewerUI::OnSaveURLAs(const GURL& url,
|
||||
const content::Referrer& referrer) {
|
||||
web_contents()->SaveFrame(url, referrer);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
#include <string>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "content/public/browser/web_ui_controller.h"
|
||||
#include "ipc/ipc_message.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
|
@ -16,18 +18,26 @@ class BrowserContext;
|
|||
|
||||
namespace atom {
|
||||
|
||||
class PdfViewerUI : public content::WebUIController {
|
||||
class PdfViewerUI : public content::WebUIController,
|
||||
public content::WebContentsObserver {
|
||||
public:
|
||||
static const char kHost[];
|
||||
|
||||
PdfViewerUI(content::BrowserContext* browser_context,
|
||||
content::WebUI* web_ui,
|
||||
const std::string& view_id);
|
||||
~PdfViewerUI() override;
|
||||
|
||||
// content::WebUIController implementation.
|
||||
void RenderViewCreated(content::RenderViewHost* rvh) override;
|
||||
|
||||
// content::WebContentsObserver:
|
||||
bool OnMessageReceived(const IPC::Message& message,
|
||||
content::RenderFrameHost* render_frame_host) override;
|
||||
|
||||
private:
|
||||
void OnSaveURLAs(const GURL& url, const content::Referrer& referrer);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PdfViewerUI);
|
||||
};
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
#include "chrome/renderer/pepper/chrome_renderer_pepper_host_factory.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "chrome/renderer/pepper/pepper_flash_font_file_host.h"
|
||||
#include "chrome/renderer/pepper/pepper_flash_fullscreen_host.h"
|
||||
#include "chrome/renderer/pepper/pepper_flash_menu_host.h"
|
||||
#include "chrome/renderer/pepper/pepper_flash_renderer_host.h"
|
||||
#include "components/pdf/renderer/pepper_pdf_host.h"
|
||||
#include "content/public/renderer/renderer_ppapi_host.h"
|
||||
#include "ppapi/host/ppapi_host.h"
|
||||
#include "ppapi/host/resource_host.h"
|
||||
|
@ -79,5 +81,14 @@ std::unique_ptr<ResourceHost> ChromeRendererPepperHostFactory::CreateResourceHos
|
|||
}
|
||||
}
|
||||
|
||||
if (host_->GetPpapiHost()->permissions().HasPermission(
|
||||
ppapi::PERMISSION_PRIVATE)) {
|
||||
switch (message.type()) {
|
||||
case PpapiHostMsg_PDF_Create::ID: {
|
||||
return base::MakeUnique<pdf::PepperPDFHost>(host_, instance, resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::unique_ptr<ResourceHost>();
|
||||
}
|
||||
|
|
39
chromium_src/components/pdf/common/pdf_message_generator.cc
Normal file
39
chromium_src/components/pdf/common/pdf_message_generator.cc
Normal file
|
@ -0,0 +1,39 @@
|
|||
// 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.
|
||||
|
||||
// Get basic type definitions.
|
||||
#define IPC_MESSAGE_IMPL
|
||||
#include "components/pdf/common/pdf_message_generator.h"
|
||||
|
||||
// Generate constructors.
|
||||
#include "ipc/struct_constructor_macros.h"
|
||||
#include "components/pdf/common/pdf_message_generator.h"
|
||||
|
||||
// Generate destructors.
|
||||
#include "ipc/struct_destructor_macros.h"
|
||||
#include "components/pdf/common/pdf_message_generator.h"
|
||||
|
||||
// Generate param traits size methods.
|
||||
#include "ipc/param_traits_size_macros.h"
|
||||
namespace IPC {
|
||||
#include "components/pdf/common/pdf_message_generator.h"
|
||||
}
|
||||
|
||||
// Generate param traits write methods.
|
||||
#include "ipc/param_traits_write_macros.h"
|
||||
namespace IPC {
|
||||
#include "components/pdf/common/pdf_message_generator.h"
|
||||
} // namespace IPC
|
||||
|
||||
// Generate param traits read methods.
|
||||
#include "ipc/param_traits_read_macros.h"
|
||||
namespace IPC {
|
||||
#include "components/pdf/common/pdf_message_generator.h"
|
||||
} // namespace IPC
|
||||
|
||||
// Generate param traits log methods.
|
||||
#include "ipc/param_traits_log_macros.h"
|
||||
namespace IPC {
|
||||
#include "components/pdf/common/pdf_message_generator.h"
|
||||
} // namespace IPC
|
|
@ -0,0 +1,7 @@
|
|||
// 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.
|
||||
|
||||
// Multiply-included file, no traditional include guard.
|
||||
|
||||
#include "components/pdf/common/pdf_messages.h"
|
26
chromium_src/components/pdf/common/pdf_messages.h
Normal file
26
chromium_src/components/pdf/common/pdf_messages.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
// 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.
|
||||
|
||||
// Multiply-included file, no traditional include guard.
|
||||
#include <string.h>
|
||||
|
||||
#include "content/public/common/common_param_traits_macros.h"
|
||||
#include "content/public/common/referrer.h"
|
||||
#include "ipc/ipc_message_macros.h"
|
||||
#include "url/gurl.h"
|
||||
#include "url/ipc/url_param_traits.h"
|
||||
|
||||
#define IPC_MESSAGE_START PDFMsgStart
|
||||
|
||||
// Updates the content restrictions, i.e. to disable print/copy.
|
||||
IPC_MESSAGE_ROUTED1(PDFHostMsg_PDFUpdateContentRestrictions,
|
||||
int /* restrictions */)
|
||||
|
||||
// The currently displayed PDF has an unsupported feature.
|
||||
IPC_MESSAGE_ROUTED0(PDFHostMsg_PDFHasUnsupportedFeature)
|
||||
|
||||
// Brings up SaveAs... dialog to save specified URL.
|
||||
IPC_MESSAGE_ROUTED2(PDFHostMsg_PDFSaveURLAs,
|
||||
GURL /* url */,
|
||||
content::Referrer /* referrer */)
|
113
chromium_src/components/pdf/renderer/pepper_pdf_host.cc
Normal file
113
chromium_src/components/pdf/renderer/pepper_pdf_host.cc
Normal file
|
@ -0,0 +1,113 @@
|
|||
// 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.
|
||||
|
||||
#include "components/pdf/renderer/pepper_pdf_host.h"
|
||||
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "components/pdf/common/pdf_messages.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;
|
||||
|
||||
render_frame->DidStartLoading();
|
||||
return PP_OK;
|
||||
}
|
||||
|
||||
int32_t PepperPDFHost::OnHostMsgDidStopLoading(
|
||||
ppapi::host::HostMessageContext* context) {
|
||||
content::RenderFrame* render_frame = GetRenderFrame();
|
||||
if (!render_frame)
|
||||
return PP_ERROR_FAILED;
|
||||
|
||||
render_frame->DidStopLoading();
|
||||
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;
|
||||
referrer.policy = blink::WebReferrerPolicyDefault;
|
||||
referrer = content::Referrer::SanitizeForRequest(url, referrer);
|
||||
render_frame->Send(
|
||||
new PDFHostMsg_PDFSaveURLAs(render_frame->GetRoutingID(), url, referrer));
|
||||
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
|
52
chromium_src/components/pdf/renderer/pepper_pdf_host.h
Normal file
52
chromium_src/components/pdf/renderer/pepper_pdf_host.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
// 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.
|
||||
|
||||
#ifndef COMPONENTS_PDF_RENDERER_PEPPER_PDF_HOST_H_
|
||||
#define COMPONENTS_PDF_RENDERER_PEPPER_PDF_HOST_H_
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/strings/string16.h"
|
||||
#include "ppapi/host/resource_host.h"
|
||||
|
||||
namespace content {
|
||||
class RenderFrame;
|
||||
class RendererPpapiHost;
|
||||
}
|
||||
|
||||
namespace pdf {
|
||||
|
||||
class PdfAccessibilityTree;
|
||||
|
||||
class PepperPDFHost : public ppapi::host::ResourceHost {
|
||||
public:
|
||||
PepperPDFHost(content::RendererPpapiHost* host,
|
||||
PP_Instance instance,
|
||||
PP_Resource resource);
|
||||
~PepperPDFHost() override;
|
||||
|
||||
// ppapi::host::ResourceHost:
|
||||
int32_t OnResourceMessageReceived(
|
||||
const IPC::Message& msg,
|
||||
ppapi::host::HostMessageContext* context) override;
|
||||
|
||||
private:
|
||||
int32_t OnHostMsgDidStartLoading(ppapi::host::HostMessageContext* context);
|
||||
int32_t OnHostMsgDidStopLoading(ppapi::host::HostMessageContext* context);
|
||||
int32_t OnHostMsgSaveAs(ppapi::host::HostMessageContext* context);
|
||||
int32_t OnHostMsgSetSelectedText(ppapi::host::HostMessageContext* context,
|
||||
const base::string16& selected_text);
|
||||
int32_t OnHostMsgSetLinkUnderCursor(ppapi::host::HostMessageContext* context,
|
||||
const std::string& url);
|
||||
|
||||
content::RenderFrame* GetRenderFrame();
|
||||
|
||||
content::RendererPpapiHost* const host_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PepperPDFHost);
|
||||
};
|
||||
|
||||
} // namespace pdf
|
||||
|
||||
#endif // COMPONENTS_PDF_RENDERER_PEPPER_PDF_HOST_H_
|
|
@ -613,6 +613,11 @@
|
|||
'chromium_src/chrome/renderer/tts_dispatcher.cc',
|
||||
'chromium_src/chrome/renderer/tts_dispatcher.h',
|
||||
'chromium_src/chrome/utility/utility_message_handler.h',
|
||||
'chromium_src/components/pdf/common/pdf_message_generator.cc',
|
||||
'chromium_src/components/pdf/common/pdf_message_generator.h',
|
||||
'chromium_src/components/pdf/common/pdf_messages.h',
|
||||
'chromium_src/components/pdf/renderer/pepper_pdf_host.cc',
|
||||
'chromium_src/components/pdf/renderer/pepper_pdf_host.h',
|
||||
'chromium_src/extensions/browser/app_window/size_constraints.cc',
|
||||
'chromium_src/extensions/browser/app_window/size_constraints.h',
|
||||
'chromium_src/extensions/common/url_pattern.cc',
|
||||
|
|
Loading…
Reference in a new issue