summaryrefslogtreecommitdiffstats
path: root/components/pdf/browser
diff options
context:
space:
mode:
authorSadrul Habib Chowdhury <sadrul@chromium.org>2014-08-27 23:50:36 -0400
committerSadrul Habib Chowdhury <sadrul@chromium.org>2014-08-28 03:51:28 +0000
commit2f8807f697e2c043c857ec37c43d45573d239d8f (patch)
tree3e067a88970845d20d703c94d8ca7afbdc1445e9 /components/pdf/browser
parent99492bedc3bd5ac3a26b12fbf7599a55086a998e (diff)
downloadchromium_src-2f8807f697e2c043c857ec37c43d45573d239d8f.zip
chromium_src-2f8807f697e2c043c857ec37c43d45573d239d8f.tar.gz
chromium_src-2f8807f697e2c043c857ec37c43d45573d239d8f.tar.bz2
pdf: Create a separate component for using the pdf pepper plugin.
Create a component necessary for showing PDF in a content-based client. Much of the relevant code currently lives in //chrome/, and is usable by chrome. Moving this code into a separate component in //components/pdf/ allows it to be easily used by other content-clients (e.g. app-shell, athena, etc.). This patch moves PPB_PDF_Impl (implementation for the PPB_PDF interface in ppapi) and the relevant IPC messages in the pdf component. A short summary of the changes in this patch: . Move ppb_pdf_impl.cc|h into //components/pdf from //chrome/renderer/pepper . Put this code in the 'pdf' namespace. This code lives in 'pdf_renderer' target. 'chrome_renderer' depends on this target. . Move the following IPC messages from render_messages.h to pdf_messages.h: - PDFUpdateContentRestrictions - PDFHasUnsupportedFeature - PDFSaveURLAs - PDFModalPromptForPassword Change the prefix of these messages from ChromeViewHostMsg_ to PDFHostMsg_ . Move PDFTabHelper into //components/pdf from //chrome/browser/ui/pdf. Put this code in the 'pdf' namespace. This code lives in 'pdf_browser' target. 'chrome_browser' depends on this target. BUG=401242 R=blundell@chromium.org, raymes@chromium.org, thestig@chromium.org, tsepez@chromium.org TBR=darin@chromium.org for DEPS Review URL: https://codereview.chromium.org/477263003 Cr-Commit-Position: refs/heads/master@{#292313}
Diffstat (limited to 'components/pdf/browser')
-rw-r--r--components/pdf/browser/BUILD.gn19
-rw-r--r--components/pdf/browser/open_pdf_in_reader_prompt_client.h36
-rw-r--r--components/pdf/browser/pdf_web_contents_helper.cc107
-rw-r--r--components/pdf/browser/pdf_web_contents_helper.h74
-rw-r--r--components/pdf/browser/pdf_web_contents_helper_client.h43
5 files changed, 279 insertions, 0 deletions
diff --git a/components/pdf/browser/BUILD.gn b/components/pdf/browser/BUILD.gn
new file mode 100644
index 0000000..7434a8f
--- /dev/null
+++ b/components/pdf/browser/BUILD.gn
@@ -0,0 +1,19 @@
+# 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.
+
+import("//build/config/features.gni")
+
+static_library("browser") {
+ sources = [
+ "open_pdf_in_reader_prompt_client.h",
+ "pdf_web_contents_helper.cc",
+ "pdf_web_contents_helper.h",
+ "pdf_web_contents_helper_client.h",
+ ]
+
+ deps = [
+ "//components/pdf/common",
+ "//content/public/browser",
+ ]
+}
diff --git a/components/pdf/browser/open_pdf_in_reader_prompt_client.h b/components/pdf/browser/open_pdf_in_reader_prompt_client.h
new file mode 100644
index 0000000..854e6f4
--- /dev/null
+++ b/components/pdf/browser/open_pdf_in_reader_prompt_client.h
@@ -0,0 +1,36 @@
+// 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.
+
+#ifndef COMPONENTS_PDF_BROWSER_OPEN_PDF_IN_READER_PROMPT_CLIENT_H_
+#define COMPONENTS_PDF_BROWSER_OPEN_PDF_IN_READER_PROMPT_CLIENT_H_
+
+#include "base/strings/string16.h"
+
+namespace content {
+struct LoadCommittedDetails;
+}
+
+namespace pdf {
+
+class OpenPDFInReaderPromptClient {
+ public:
+ virtual ~OpenPDFInReaderPromptClient() {}
+
+ virtual base::string16 GetMessageText() const = 0;
+
+ virtual base::string16 GetAcceptButtonText() const = 0;
+
+ virtual base::string16 GetCancelButtonText() const = 0;
+
+ virtual bool ShouldExpire(
+ const content::LoadCommittedDetails& details) const = 0;
+
+ virtual void Accept() = 0;
+
+ virtual void Cancel() = 0;
+};
+
+} // namespace pdf
+
+#endif // COMPONENTS_PDF_BROWSER_OPEN_PDF_IN_READER_PROMPT_CLIENT_H_
diff --git a/components/pdf/browser/pdf_web_contents_helper.cc b/components/pdf/browser/pdf_web_contents_helper.cc
new file mode 100644
index 0000000..59a17a8
--- /dev/null
+++ b/components/pdf/browser/pdf_web_contents_helper.cc
@@ -0,0 +1,107 @@
+// 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 "components/pdf/browser/pdf_web_contents_helper.h"
+
+#include "base/bind.h"
+#include "base/strings/utf_string_conversions.h"
+#include "components/pdf/browser/open_pdf_in_reader_prompt_client.h"
+#include "components/pdf/browser/pdf_web_contents_helper_client.h"
+#include "components/pdf/common/pdf_messages.h"
+#include "content/public/browser/navigation_details.h"
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(pdf::PDFWebContentsHelper);
+
+namespace pdf {
+
+// static
+void PDFWebContentsHelper::CreateForWebContentsWithClient(
+ content::WebContents* contents,
+ scoped_ptr<PDFWebContentsHelperClient> client) {
+ if (FromWebContents(contents))
+ return;
+ contents->SetUserData(UserDataKey(),
+ new PDFWebContentsHelper(contents, client.Pass()));
+}
+
+PDFWebContentsHelper::PDFWebContentsHelper(
+ content::WebContents* web_contents,
+ scoped_ptr<PDFWebContentsHelperClient> client)
+ : content::WebContentsObserver(web_contents), client_(client.Pass()) {
+}
+
+PDFWebContentsHelper::~PDFWebContentsHelper() {
+}
+
+void PDFWebContentsHelper::ShowOpenInReaderPrompt(
+ scoped_ptr<OpenPDFInReaderPromptClient> prompt) {
+ open_in_reader_prompt_ = prompt.Pass();
+ UpdateLocationBar();
+}
+
+bool PDFWebContentsHelper::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(PDFWebContentsHelper, message)
+ IPC_MESSAGE_HANDLER(PDFHostMsg_PDFHasUnsupportedFeature,
+ OnHasUnsupportedFeature)
+ IPC_MESSAGE_HANDLER(PDFHostMsg_PDFSaveURLAs, OnSaveURLAs)
+ IPC_MESSAGE_HANDLER(PDFHostMsg_PDFUpdateContentRestrictions,
+ OnUpdateContentRestrictions)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(PDFHostMsg_PDFModalPromptForPassword,
+ OnModalPromptForPassword)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void PDFWebContentsHelper::DidNavigateMainFrame(
+ const content::LoadCommittedDetails& details,
+ const content::FrameNavigateParams& params) {
+ if (open_in_reader_prompt_.get() &&
+ open_in_reader_prompt_->ShouldExpire(details)) {
+ open_in_reader_prompt_.reset();
+ UpdateLocationBar();
+ }
+}
+
+void PDFWebContentsHelper::UpdateLocationBar() {
+ client_->UpdateLocationBar(web_contents());
+}
+
+void PDFWebContentsHelper::OnHasUnsupportedFeature() {
+ client_->OnPDFHasUnsupportedFeature(web_contents());
+}
+
+void PDFWebContentsHelper::OnSaveURLAs(const GURL& url,
+ const content::Referrer& referrer) {
+ client_->OnSaveURL(web_contents());
+ web_contents()->SaveFrame(url, referrer);
+}
+
+void PDFWebContentsHelper::OnUpdateContentRestrictions(
+ int content_restrictions) {
+ client_->UpdateContentRestrictions(web_contents(), content_restrictions);
+}
+
+void PDFWebContentsHelper::OnModalPromptForPasswordClosed(
+ IPC::Message* reply_message,
+ bool success,
+ const base::string16& actual_value) {
+ PDFHostMsg_PDFModalPromptForPassword::WriteReplyParams(
+ reply_message, base::UTF16ToUTF8(actual_value));
+ Send(reply_message);
+}
+
+void PDFWebContentsHelper::OnModalPromptForPassword(
+ const std::string& prompt,
+ IPC::Message* reply_message) {
+ base::Callback<void(bool, const base::string16&)> callback =
+ base::Bind(&PDFWebContentsHelper::OnModalPromptForPasswordClosed,
+ base::Unretained(this),
+ reply_message);
+ client_->OnShowPDFPasswordDialog(
+ web_contents(), base::UTF8ToUTF16(prompt), callback);
+}
+
+} // namespace pdf
diff --git a/components/pdf/browser/pdf_web_contents_helper.h b/components/pdf/browser/pdf_web_contents_helper.h
new file mode 100644
index 0000000..d37b57f
--- /dev/null
+++ b/components/pdf/browser/pdf_web_contents_helper.h
@@ -0,0 +1,74 @@
+// 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.
+
+#ifndef COMPONENTS_PDF_BROWSER_PDF_WEB_CONTENTS_HELPER_H_
+#define COMPONENTS_PDF_BROWSER_PDF_WEB_CONTENTS_HELPER_H_
+
+#include <string>
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
+#include "ipc/ipc_message.h"
+
+namespace content {
+class WebContents;
+}
+
+namespace pdf {
+
+class OpenPDFInReaderPromptClient;
+class PDFWebContentsHelperClient;
+
+// Per-WebContents class to handle PDF messages.
+class PDFWebContentsHelper
+ : public content::WebContentsObserver,
+ public content::WebContentsUserData<PDFWebContentsHelper> {
+ public:
+ static void CreateForWebContentsWithClient(
+ content::WebContents* contents,
+ scoped_ptr<PDFWebContentsHelperClient> client);
+
+ OpenPDFInReaderPromptClient* open_in_reader_prompt() const {
+ return open_in_reader_prompt_.get();
+ }
+
+ void ShowOpenInReaderPrompt(scoped_ptr<OpenPDFInReaderPromptClient> prompt);
+
+ private:
+ PDFWebContentsHelper(content::WebContents* web_contents,
+ scoped_ptr<PDFWebContentsHelperClient> client);
+ virtual ~PDFWebContentsHelper();
+
+ // content::WebContentsObserver overrides:
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+ virtual void DidNavigateMainFrame(
+ const content::LoadCommittedDetails& details,
+ const content::FrameNavigateParams& params) OVERRIDE;
+
+ // Internal helpers ----------------------------------------------------------
+
+ void UpdateLocationBar();
+ void OnModalPromptForPasswordClosed(IPC::Message* reply_message,
+ bool success,
+ const base::string16& actual_value);
+
+ // Message handlers.
+ void OnHasUnsupportedFeature();
+ void OnSaveURLAs(const GURL& url, const content::Referrer& referrer);
+ void OnUpdateContentRestrictions(int content_restrictions);
+ void OnModalPromptForPassword(const std::string& prompt,
+ IPC::Message* reply_message);
+
+ // The model for the confirmation prompt to open a PDF in Adobe Reader.
+ scoped_ptr<OpenPDFInReaderPromptClient> open_in_reader_prompt_;
+ scoped_ptr<PDFWebContentsHelperClient> client_;
+
+ DISALLOW_COPY_AND_ASSIGN(PDFWebContentsHelper);
+};
+
+} // namespace pdf
+
+#endif // COMPONENTS_PDF_BROWSER_PDF_WEB_CONTENTS_HELPER_H_
diff --git a/components/pdf/browser/pdf_web_contents_helper_client.h b/components/pdf/browser/pdf_web_contents_helper_client.h
new file mode 100644
index 0000000..17dfb4e
--- /dev/null
+++ b/components/pdf/browser/pdf_web_contents_helper_client.h
@@ -0,0 +1,43 @@
+// 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_BROWSER_PDF_WEB_CONTENTS_HELPER_CLIENT_H_
+#define COMPONENTS_PDF_BROWSER_PDF_WEB_CONTENTS_HELPER_CLIENT_H_
+
+#include "base/callback.h"
+#include "base/strings/string16.h"
+#include "ipc/ipc_message.h"
+
+namespace content {
+class WebContents;
+}
+
+namespace pdf {
+
+typedef base::Callback<
+ void(bool /* success */, const base::string16& /* password */)>
+ PasswordDialogClosedCallback;
+
+class PDFWebContentsHelperClient {
+ public:
+ virtual ~PDFWebContentsHelperClient() {}
+
+ virtual void UpdateLocationBar(content::WebContents* contents) = 0;
+
+ virtual void UpdateContentRestrictions(content::WebContents* contents,
+ int content_restrictions) = 0;
+
+ virtual void OnPDFHasUnsupportedFeature(content::WebContents* contents) = 0;
+
+ virtual void OnSaveURL(content::WebContents* contents) = 0;
+
+ virtual void OnShowPDFPasswordDialog(
+ content::WebContents* contents,
+ const base::string16& prompt,
+ const PasswordDialogClosedCallback& callback) = 0;
+};
+
+} // namespace pdf
+
+#endif // COMPONENTS_PDF_BROWSER_PDF_WEB_CONTENTS_HELPER_CLIENT_H_