diff options
author | Sadrul Habib Chowdhury <sadrul@chromium.org> | 2014-08-27 23:50:36 -0400 |
---|---|---|
committer | Sadrul Habib Chowdhury <sadrul@chromium.org> | 2014-08-28 03:51:28 +0000 |
commit | 2f8807f697e2c043c857ec37c43d45573d239d8f (patch) | |
tree | 3e067a88970845d20d703c94d8ca7afbdc1445e9 | |
parent | 99492bedc3bd5ac3a26b12fbf7599a55086a998e (diff) | |
download | chromium_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}
51 files changed, 840 insertions, 331 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 3670008..d8d9246 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -47,6 +47,7 @@ include_rules = [ "+components/omnibox", "+components/os_crypt", "+components/password_manager", + "+components/pdf/browser", "+components/policy", "+components/power", "+components/precache", diff --git a/chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.cc b/chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.cc index e9c3024..30c5c20 100644 --- a/chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.cc +++ b/chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.cc @@ -9,9 +9,10 @@ #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" #include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" -#include "chrome/browser/ui/pdf/pdf_tab_helper.h" +#include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h" #include "chrome/browser/ui/zoom/zoom_controller.h" #include "chrome/common/chrome_version_info.h" +#include "components/pdf/browser/pdf_web_contents_helper.h" #include "components/renderer_context_menu/context_menu_delegate.h" #include "content/public/common/page_zoom.h" #include "extensions/browser/guest_view/web_view/web_view_constants.h" @@ -120,7 +121,10 @@ void ChromeWebViewGuestDelegate::OnAttachWebViewHelpers( printing::PrintViewManagerBasic::CreateForWebContents(contents); #endif // defined(ENABLE_FULL_PRINTING) #endif // defined(ENABLE_PRINTING) - PDFTabHelper::CreateForWebContents(contents); + pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( + contents, + scoped_ptr<pdf::PDFWebContentsHelperClient>( + new ChromePDFWebContentsHelperClient())); } void ChromeWebViewGuestDelegate::OnEmbedderDestroyed() { diff --git a/chrome/browser/ui/cocoa/pdf_password_dialog.mm b/chrome/browser/ui/cocoa/pdf_password_dialog.mm index fc14353..bfde5a8 100644 --- a/chrome/browser/ui/cocoa/pdf_password_dialog.mm +++ b/chrome/browser/ui/cocoa/pdf_password_dialog.mm @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/pdf/pdf_tab_helper.h" - #import <Cocoa/Cocoa.h> #include "base/mac/scoped_nsobject.h" @@ -15,6 +13,7 @@ #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" #include "chrome/grit/generated_resources.h" +#include "components/pdf/browser/pdf_web_contents_helper_client.h" #include "ui/base/l10n/l10n_util.h" @class PDFPasswordDialogMac; @@ -39,7 +38,7 @@ class PDFPasswordDialogMacBridge : public ConstrainedWindowMacDelegate { @private content::WebContents* webContents_; base::string16 prompt_; - PasswordDialogClosedCallback callback_; + pdf::PasswordDialogClosedCallback callback_; base::scoped_nsobject<NSSecureTextField> passwordField_; @@ -49,7 +48,7 @@ class PDFPasswordDialogMacBridge : public ConstrainedWindowMacDelegate { } - (id)initWithWebContents:(content::WebContents*)webContents prompt:(base::string16)prompt - callback:(PasswordDialogClosedCallback)callback; + callback:(pdf::PasswordDialogClosedCallback)callback; - (void)onOKButton:(id)sender; - (void)onCancelButton:(id)sender; @end @@ -74,7 +73,7 @@ void PDFPasswordDialogMacBridge::OnConstrainedWindowClosed( - (id)initWithWebContents:(content::WebContents*)webContents prompt:(base::string16)prompt - callback:(PasswordDialogClosedCallback)callback { + callback:(pdf::PasswordDialogClosedCallback)callback { if ((self = [super init])) { webContents_ = webContents; prompt_ = prompt; @@ -135,7 +134,7 @@ void PDFPasswordDialogMacBridge::OnConstrainedWindowClosed( void ShowPDFPasswordDialog(content::WebContents* web_contents, const base::string16& prompt, - const PasswordDialogClosedCallback& callback) { + const pdf::PasswordDialogClosedCallback& callback) { [[PDFPasswordDialogMac alloc] initWithWebContents:web_contents prompt:prompt callback:callback]; diff --git a/chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.cc b/chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.cc new file mode 100644 index 0000000..dc5c1dcf --- /dev/null +++ b/chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.cc @@ -0,0 +1,62 @@ +// 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 "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h" + +#include "chrome/browser/download/download_stats.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_finder.h" +#include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/location_bar/location_bar.h" +#include "chrome/browser/ui/pdf/pdf_unsupported_feature.h" +#include "chrome/browser/ui/tab_contents/core_tab_helper.h" + +ChromePDFWebContentsHelperClient::ChromePDFWebContentsHelperClient() { +} + +ChromePDFWebContentsHelperClient::~ChromePDFWebContentsHelperClient() { +} + +void ChromePDFWebContentsHelperClient::UpdateLocationBar( + content::WebContents* contents) { + Browser* browser = chrome::FindBrowserWithWebContents(contents); + if (!browser) + return; + + BrowserWindow* window = browser->window(); + if (!window) + return; + + LocationBar* location_bar = window->GetLocationBar(); + if (!location_bar) + return; + + location_bar->UpdateOpenPDFInReaderPrompt(); +} + +void ChromePDFWebContentsHelperClient::UpdateContentRestrictions( + content::WebContents* contents, + int content_restrictions) { + CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents); + // |core_tab_helper| is NULL for WebViewGuest. + if (core_tab_helper) + core_tab_helper->UpdateContentRestrictions(content_restrictions); +} + +void ChromePDFWebContentsHelperClient::OnPDFHasUnsupportedFeature( + content::WebContents* contents) { + PDFHasUnsupportedFeature(contents); +} + +void ChromePDFWebContentsHelperClient::OnSaveURL( + content::WebContents* contents) { + RecordDownloadSource(DOWNLOAD_INITIATED_BY_PDF_SAVE); +} + +void ChromePDFWebContentsHelperClient::OnShowPDFPasswordDialog( + content::WebContents* contents, + const base::string16& prompt, + const pdf::PasswordDialogClosedCallback& callback) { + ShowPDFPasswordDialog(contents, prompt, callback); +} diff --git a/chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h b/chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h new file mode 100644 index 0000000..f8c9f96e --- /dev/null +++ b/chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h @@ -0,0 +1,41 @@ +// 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 CHROME_BROWSER_UI_PDF_CHROME_PDF_WEB_CONTENTS_HELPER_CLIENT_H_ +#define CHROME_BROWSER_UI_PDF_CHROME_PDF_WEB_CONTENTS_HELPER_CLIENT_H_ + +#include "base/macros.h" +#include "components/pdf/browser/pdf_web_contents_helper_client.h" + +class ChromePDFWebContentsHelperClient + : public pdf::PDFWebContentsHelperClient { + public: + ChromePDFWebContentsHelperClient(); + virtual ~ChromePDFWebContentsHelperClient(); + + private: + // pdf::PDFWebContentsHelperClient: + virtual void UpdateLocationBar(content::WebContents* contents) OVERRIDE; + + virtual void UpdateContentRestrictions(content::WebContents* contents, + int content_restrictions) OVERRIDE; + + virtual void OnPDFHasUnsupportedFeature( + content::WebContents* contents) OVERRIDE; + + virtual void OnSaveURL(content::WebContents* contents) OVERRIDE; + + virtual void OnShowPDFPasswordDialog( + content::WebContents* contents, + const base::string16& prompt, + const pdf::PasswordDialogClosedCallback& callback) OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(ChromePDFWebContentsHelperClient); +}; + +void ShowPDFPasswordDialog(content::WebContents* web_contents, + const base::string16& prompt, + const pdf::PasswordDialogClosedCallback& callback); + +#endif // CHROME_BROWSER_UI_PDF_CHROME_PDF_WEB_CONTENTS_HELPER_CLIENT_H_ diff --git a/chrome/browser/ui/pdf/pdf_tab_helper.cc b/chrome/browser/ui/pdf/pdf_tab_helper.cc deleted file mode 100644 index 71edc67..0000000 --- a/chrome/browser/ui/pdf/pdf_tab_helper.cc +++ /dev/null @@ -1,108 +0,0 @@ -// 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 "chrome/browser/ui/pdf/pdf_tab_helper.h" - -#include "base/strings/utf_string_conversions.h" -#include "chrome/browser/download/download_stats.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/location_bar/location_bar.h" -#include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" -#include "chrome/browser/ui/pdf/pdf_unsupported_feature.h" -#include "chrome/browser/ui/tab_contents/core_tab_helper.h" -#include "chrome/common/render_messages.h" -#include "content/public/browser/navigation_details.h" - -DEFINE_WEB_CONTENTS_USER_DATA_KEY(PDFTabHelper); - -PDFTabHelper::PDFTabHelper(content::WebContents* web_contents) - : content::WebContentsObserver(web_contents) { -} - -PDFTabHelper::~PDFTabHelper() { -} - -void PDFTabHelper::ShowOpenInReaderPrompt( - scoped_ptr<OpenPDFInReaderPromptDelegate> prompt) { - open_in_reader_prompt_ = prompt.Pass(); - UpdateLocationBar(); -} - -bool PDFTabHelper::OnMessageReceived(const IPC::Message& message) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(PDFTabHelper, message) - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature, - OnHasUnsupportedFeature) - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFSaveURLAs, OnSaveURLAs) - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFUpdateContentRestrictions, - OnUpdateContentRestrictions) - IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_PDFModalPromptForPassword, - OnModalPromptForPassword) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void PDFTabHelper::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 PDFTabHelper::UpdateLocationBar() { - Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); - if (!browser) - return; - - BrowserWindow* window = browser->window(); - if (!window) - return; - - LocationBar* location_bar = window->GetLocationBar(); - if (!location_bar) - return; - - location_bar->UpdateOpenPDFInReaderPrompt(); -} - -void PDFTabHelper::OnHasUnsupportedFeature() { - PDFHasUnsupportedFeature(web_contents()); -} - -void PDFTabHelper::OnSaveURLAs(const GURL& url, - const content::Referrer& referrer) { - RecordDownloadSource(DOWNLOAD_INITIATED_BY_PDF_SAVE); - web_contents()->SaveFrame(url, referrer); -} - -void PDFTabHelper::OnUpdateContentRestrictions(int content_restrictions) { - CoreTabHelper* core_tab_helper = - CoreTabHelper::FromWebContents(web_contents()); - // |core_tab_helper| is NULL for WebViewGuest. - if (core_tab_helper) - core_tab_helper->UpdateContentRestrictions(content_restrictions); -} - -void PDFTabHelper::OnModalPromptForPasswordClosed( - IPC::Message* reply_message, - bool success, - const base::string16& actual_value) { - ChromeViewHostMsg_PDFModalPromptForPassword::WriteReplyParams( - reply_message, base::UTF16ToUTF8(actual_value)); - Send(reply_message); -} - -void PDFTabHelper::OnModalPromptForPassword(const std::string& prompt, - IPC::Message* reply_message) { - base::Callback<void(bool, const base::string16&)> callback = - base::Bind(&PDFTabHelper::OnModalPromptForPasswordClosed, - base::Unretained(this), reply_message); - ShowPDFPasswordDialog(web_contents(), base::UTF8ToUTF16(prompt), callback); -} diff --git a/chrome/browser/ui/pdf/pdf_unsupported_feature.cc b/chrome/browser/ui/pdf/pdf_unsupported_feature.cc index 2874f37..d1a351d 100644 --- a/chrome/browser/ui/pdf/pdf_unsupported_feature.cc +++ b/chrome/browser/ui/pdf/pdf_unsupported_feature.cc @@ -14,10 +14,10 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/renderer_preferences_util.h" #include "chrome/browser/tab_contents/tab_util.h" -#include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" -#include "chrome/browser/ui/pdf/pdf_tab_helper.h" #include "chrome/common/chrome_content_client.h" #include "chrome/grit/generated_resources.h" +#include "components/pdf/browser/open_pdf_in_reader_prompt_client.h" +#include "components/pdf/browser/pdf_web_contents_helper.h" #include "content/public/browser/interstitial_page.h" #include "content/public/browser/interstitial_page_delegate.h" #include "content/public/browser/navigation_details.h" @@ -52,13 +52,13 @@ const char kAdobeReaderUpdateUrl[] = "http://www.adobe.com/go/getreader_chrome"; // The prompt delegate used to ask the user if they want to use Adobe Reader // by default. -class PDFEnableAdobeReaderPromptDelegate - : public OpenPDFInReaderPromptDelegate { +class PDFEnableAdobeReaderPromptClient + : public pdf::OpenPDFInReaderPromptClient { public: - explicit PDFEnableAdobeReaderPromptDelegate(Profile* profile); - virtual ~PDFEnableAdobeReaderPromptDelegate(); + explicit PDFEnableAdobeReaderPromptClient(Profile* profile); + virtual ~PDFEnableAdobeReaderPromptClient(); - // OpenPDFInReaderPromptDelegate + // pdf::OpenPDFInReaderPromptClient virtual base::string16 GetMessageText() const OVERRIDE; virtual base::string16 GetAcceptButtonText() const OVERRIDE; virtual base::string16 GetCancelButtonText() const OVERRIDE; @@ -73,19 +73,19 @@ class PDFEnableAdobeReaderPromptDelegate Profile* profile_; - DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderPromptDelegate); + DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderPromptClient); }; -PDFEnableAdobeReaderPromptDelegate::PDFEnableAdobeReaderPromptDelegate( +PDFEnableAdobeReaderPromptClient::PDFEnableAdobeReaderPromptClient( Profile* profile) : profile_(profile) { content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarShown")); } -PDFEnableAdobeReaderPromptDelegate::~PDFEnableAdobeReaderPromptDelegate() { +PDFEnableAdobeReaderPromptClient::~PDFEnableAdobeReaderPromptClient() { } -bool PDFEnableAdobeReaderPromptDelegate::ShouldExpire( +bool PDFEnableAdobeReaderPromptClient::ShouldExpire( const content::LoadCommittedDetails& details) const { content::PageTransition transition = content::PageTransitionStripQualifier(details.entry->GetTransitionType()); @@ -94,7 +94,7 @@ bool PDFEnableAdobeReaderPromptDelegate::ShouldExpire( return !details.is_in_page && transition != content::PAGE_TRANSITION_RELOAD; } -void PDFEnableAdobeReaderPromptDelegate::Accept() { +void PDFEnableAdobeReaderPromptClient::Accept() { content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK")); PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile_).get(); plugin_prefs->EnablePluginGroup( @@ -103,19 +103,19 @@ void PDFEnableAdobeReaderPromptDelegate::Accept() { false, base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName)); } -void PDFEnableAdobeReaderPromptDelegate::Cancel() { +void PDFEnableAdobeReaderPromptClient::Cancel() { content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel")); } -base::string16 PDFEnableAdobeReaderPromptDelegate::GetAcceptButtonText() const { +base::string16 PDFEnableAdobeReaderPromptClient::GetAcceptButtonText() const { return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON); } -base::string16 PDFEnableAdobeReaderPromptDelegate::GetCancelButtonText() const { +base::string16 PDFEnableAdobeReaderPromptClient::GetCancelButtonText() const { return l10n_util::GetStringUTF16(IDS_DONE); } -base::string16 PDFEnableAdobeReaderPromptDelegate::GetMessageText() const { +base::string16 PDFEnableAdobeReaderPromptClient::GetMessageText() const { return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); } @@ -130,7 +130,7 @@ void OpenReaderUpdateURL(WebContents* web_contents) { // Opens the PDF using Adobe Reader. void OpenUsingReader(WebContents* web_contents, const WebPluginInfo& reader_plugin, - OpenPDFInReaderPromptDelegate* delegate) { + pdf::OpenPDFInReaderPromptClient* client) { ChromePluginServiceFilter::GetInstance()->OverridePluginForFrame( web_contents->GetRenderProcessHost()->GetID(), web_contents->GetMainFrame()->GetRoutingID(), @@ -138,9 +138,10 @@ void OpenUsingReader(WebContents* web_contents, reader_plugin); web_contents->ReloadFocusedFrame(false); - PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); - if (delegate) - pdf_tab_helper->ShowOpenInReaderPrompt(make_scoped_ptr(delegate)); + pdf::PDFWebContentsHelper* pdf_tab_helper = + pdf::PDFWebContentsHelper::FromWebContents(web_contents); + if (client) + pdf_tab_helper->ShowOpenInReaderPrompt(make_scoped_ptr(client)); } // An interstitial to be used when the user chooses to open a PDF using Adobe @@ -230,15 +231,14 @@ class PDFUnsupportedFeatureInterstitial // The delegate for the bubble used to inform the user that we don't support a // feature in the PDF. -class PDFUnsupportedFeaturePromptDelegate - : public OpenPDFInReaderPromptDelegate { +class PDFUnsupportedFeaturePromptClient + : public pdf::OpenPDFInReaderPromptClient { public: - PDFUnsupportedFeaturePromptDelegate( - WebContents* web_contents, - const AdobeReaderPluginInfo& reader_info); - virtual ~PDFUnsupportedFeaturePromptDelegate(); + PDFUnsupportedFeaturePromptClient(WebContents* web_contents, + const AdobeReaderPluginInfo& reader_info); + virtual ~PDFUnsupportedFeaturePromptClient(); - // OpenPDFInReaderPromptDelegate: + // pdf::OpenPDFInReaderPromptClient: virtual base::string16 GetMessageText() const OVERRIDE; virtual base::string16 GetAcceptButtonText() const OVERRIDE; virtual base::string16 GetCancelButtonText() const OVERRIDE; @@ -251,28 +251,26 @@ class PDFUnsupportedFeaturePromptDelegate WebContents* web_contents_; const AdobeReaderPluginInfo reader_info_; - DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeaturePromptDelegate); + DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeaturePromptClient); }; -PDFUnsupportedFeaturePromptDelegate::PDFUnsupportedFeaturePromptDelegate( +PDFUnsupportedFeaturePromptClient::PDFUnsupportedFeaturePromptClient( WebContents* web_contents, const AdobeReaderPluginInfo& reader_info) - : web_contents_(web_contents), - reader_info_(reader_info) { + : web_contents_(web_contents), reader_info_(reader_info) { content::RecordAction(reader_info_.is_installed ? UserMetricsAction("PDF_UseReaderInfoBarShown") : UserMetricsAction("PDF_InstallReaderInfoBarShown")); } -PDFUnsupportedFeaturePromptDelegate::~PDFUnsupportedFeaturePromptDelegate() { +PDFUnsupportedFeaturePromptClient::~PDFUnsupportedFeaturePromptClient() { } -base::string16 PDFUnsupportedFeaturePromptDelegate::GetMessageText() const { +base::string16 PDFUnsupportedFeaturePromptClient::GetMessageText() const { return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_MESSAGE); } -base::string16 PDFUnsupportedFeaturePromptDelegate::GetAcceptButtonText() - const { +base::string16 PDFUnsupportedFeaturePromptClient::GetAcceptButtonText() const { if (base::win::IsMetroProcess()) return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_METRO_MODE_LINK); @@ -281,17 +279,16 @@ base::string16 PDFUnsupportedFeaturePromptDelegate::GetAcceptButtonText() : IDS_PDF_BUBBLE_INSTALL_READER_LINK); } -base::string16 PDFUnsupportedFeaturePromptDelegate::GetCancelButtonText() - const { +base::string16 PDFUnsupportedFeaturePromptClient::GetCancelButtonText() const { return l10n_util::GetStringUTF16(IDS_DONE); } -bool PDFUnsupportedFeaturePromptDelegate::ShouldExpire( +bool PDFUnsupportedFeaturePromptClient::ShouldExpire( const content::LoadCommittedDetails& details) const { return !details.is_in_page; } -void PDFUnsupportedFeaturePromptDelegate::Accept() { +void PDFUnsupportedFeaturePromptClient::Accept() { if (base::win::IsMetroProcess()) { chrome::AttemptRestartWithModeSwitch(); return; @@ -313,13 +310,13 @@ void PDFUnsupportedFeaturePromptDelegate::Accept() { Profile* profile = Profile::FromBrowserContext(web_contents_->GetBrowserContext()); - OpenPDFInReaderPromptDelegate* delegate = - new PDFEnableAdobeReaderPromptDelegate(profile); + pdf::OpenPDFInReaderPromptClient* client = + new PDFEnableAdobeReaderPromptClient(profile); - OpenUsingReader(web_contents_, reader_info_.plugin_info, delegate); + OpenUsingReader(web_contents_, reader_info_.plugin_info, client); } -void PDFUnsupportedFeaturePromptDelegate::Cancel() { +void PDFUnsupportedFeaturePromptClient::Cancel() { content::RecordAction(reader_info_.is_installed ? UserMetricsAction("PDF_UseReaderInfoBarCancel") : UserMetricsAction("PDF_InstallReaderInfoBarCancel")); @@ -331,9 +328,10 @@ void MaybeShowOpenPDFInReaderPrompt(WebContents* web_contents, if (!reader_info.is_installed || !reader_info.is_enabled) return; - scoped_ptr<OpenPDFInReaderPromptDelegate> prompt( - new PDFUnsupportedFeaturePromptDelegate(web_contents, reader_info)); - PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); + scoped_ptr<pdf::OpenPDFInReaderPromptClient> prompt( + new PDFUnsupportedFeaturePromptClient(web_contents, reader_info)); + pdf::PDFWebContentsHelper* pdf_tab_helper = + pdf::PDFWebContentsHelper::FromWebContents(web_contents); pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass()); } diff --git a/chrome/browser/ui/tab_helpers.cc b/chrome/browser/ui/tab_helpers.cc index 7e73f74..797bb3a 100644 --- a/chrome/browser/ui/tab_helpers.cc +++ b/chrome/browser/ui/tab_helpers.cc @@ -21,6 +21,7 @@ #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" #include "chrome/browser/ui/find_bar/find_tab_helper.h" #include "chrome/browser/ui/navigation_correction_tab_observer.h" +#include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h" #include "chrome/browser/ui/prefs/prefs_tab_helper.h" #include "chrome/browser/ui/search/search_tab_helper.h" #include "chrome/browser/ui/tab_contents/core_tab_helper.h" @@ -43,12 +44,12 @@ #include "chrome/browser/thumbnails/thumbnail_tab_helper.h" #include "chrome/browser/ui/hung_plugin_tab_helper.h" #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" -#include "chrome/browser/ui/pdf/pdf_tab_helper.h" #include "chrome/browser/ui/sad_tab_helper.h" #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" #include "chrome/browser/ui/zoom/zoom_controller.h" +#include "components/pdf/browser/pdf_web_contents_helper.h" #include "components/web_modal/web_contents_modal_dialog_manager.h" #endif // defined(OS_ANDROID) @@ -164,7 +165,10 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) { ExternalProtocolObserver::CreateForWebContents(web_contents); HungPluginTabHelper::CreateForWebContents(web_contents); ManagePasswordsUIController::CreateForWebContents(web_contents); - PDFTabHelper::CreateForWebContents(web_contents); + pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( + web_contents, + scoped_ptr<pdf::PDFWebContentsHelperClient>( + new ChromePDFWebContentsHelperClient())); PermissionBubbleManager::CreateForWebContents(web_contents); PluginObserver::CreateForWebContents(web_contents); SadTabHelper::CreateForWebContents(web_contents); diff --git a/chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.cc b/chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.cc index 19a270a..2be219f6 100644 --- a/chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.cc +++ b/chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.cc @@ -4,9 +4,10 @@ #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" -#include "chrome/browser/ui/pdf/pdf_tab_helper.h" #include "chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h" #include "chrome/grit/generated_resources.h" +#include "components/pdf/browser/open_pdf_in_reader_prompt_client.h" +#include "components/pdf/browser/pdf_web_contents_helper.h" #include "grit/theme_resources.h" #include "ui/accessibility/ax_view_state.h" #include "ui/base/l10n/l10n_util.h" @@ -28,7 +29,8 @@ OpenPDFInReaderView::~OpenPDFInReaderView() { void OpenPDFInReaderView::Update(content::WebContents* web_contents) { model_ = NULL; if (web_contents) { - PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); + pdf::PDFWebContentsHelper* pdf_tab_helper = + pdf::PDFWebContentsHelper::FromWebContents(web_contents); model_ = pdf_tab_helper->open_in_reader_prompt(); } diff --git a/chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h b/chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h index 3bb25b0..a883216 100644 --- a/chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h +++ b/chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h @@ -9,12 +9,15 @@ #include "ui/views/widget/widget_observer.h" class OpenPDFInReaderBubbleView; -class OpenPDFInReaderPromptDelegate; namespace content { class WebContents; } +namespace pdf { +class OpenPDFInReaderPromptClient; +} + // A Page Action image view for the "Open PDF in Reader" bubble. class OpenPDFInReaderView : public views::ImageView, public views::WidgetObserver { @@ -38,8 +41,9 @@ class OpenPDFInReaderView : public views::ImageView, OpenPDFInReaderBubbleView* bubble_; - // Weak pointer; owned by the PDFTabHelper of the currently active tab. - OpenPDFInReaderPromptDelegate* model_; + // Weak pointer; owned by the PDFWebContentsHelper of the currently active + // tab. + pdf::OpenPDFInReaderPromptClient* model_; DISALLOW_COPY_AND_ASSIGN(OpenPDFInReaderView); }; diff --git a/chrome/browser/ui/views/open_pdf_in_reader_bubble_view.cc b/chrome/browser/ui/views/open_pdf_in_reader_bubble_view.cc index e72bb1c..9ae0edc 100644 --- a/chrome/browser/ui/views/open_pdf_in_reader_bubble_view.cc +++ b/chrome/browser/ui/views/open_pdf_in_reader_bubble_view.cc @@ -4,7 +4,7 @@ #include "chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h" -#include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" +#include "components/pdf/browser/open_pdf_in_reader_prompt_client.h" #include "ui/views/controls/button/label_button.h" #include "ui/views/controls/label.h" #include "ui/views/controls/link.h" @@ -16,7 +16,7 @@ OpenPDFInReaderBubbleView::~OpenPDFInReaderBubbleView() {} OpenPDFInReaderBubbleView::OpenPDFInReaderBubbleView( views::View* anchor_view, - OpenPDFInReaderPromptDelegate* model) + pdf::OpenPDFInReaderPromptClient* model) : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), model_(model), open_in_reader_link_(NULL), diff --git a/chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h b/chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h index cde20b1..ecf66c5 100644 --- a/chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h +++ b/chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h @@ -9,7 +9,9 @@ #include "ui/views/controls/button/button.h" #include "ui/views/controls/link_listener.h" -class OpenPDFInReaderPromptDelegate; +namespace pdf { +class OpenPDFInReaderPromptClient; +} namespace views { class LabelButton; @@ -20,7 +22,7 @@ class OpenPDFInReaderBubbleView : public views::BubbleDelegateView, public views::LinkListener { public: OpenPDFInReaderBubbleView(views::View* anchor_view, - OpenPDFInReaderPromptDelegate* model); + pdf::OpenPDFInReaderPromptClient* model); virtual ~OpenPDFInReaderBubbleView(); protected: @@ -35,8 +37,9 @@ class OpenPDFInReaderBubbleView : public views::BubbleDelegateView, virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; private: - // Weak pointer; owned by the PDFTabHelper of the currently active tab. - OpenPDFInReaderPromptDelegate* model_; + // Weak pointer; owned by the PDFWebContentsHelper of the currently active + // tab. + pdf::OpenPDFInReaderPromptClient* model_; views::Link* open_in_reader_link_; views::LabelButton* close_button_; diff --git a/chrome/browser/ui/views/pdf_password_dialog.cc b/chrome/browser/ui/views/pdf_password_dialog.cc index cb5b287..f444fab 100644 --- a/chrome/browser/ui/views/pdf_password_dialog.cc +++ b/chrome/browser/ui/views/pdf_password_dialog.cc @@ -2,10 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/pdf/pdf_tab_helper.h" - #include "chrome/browser/ui/views/constrained_window_views.h" #include "chrome/grit/generated_resources.h" +#include "components/pdf/browser/pdf_web_contents_helper_client.h" #include "content/public/browser/web_contents.h" #include "ui/base/l10n/l10n_util.h" #include "ui/views/controls/message_box_view.h" @@ -21,7 +20,7 @@ class PDFPasswordDialogViews : public views::DialogDelegate { public: PDFPasswordDialogViews(content::WebContents* web_contents, const base::string16& prompt, - const PasswordDialogClosedCallback& callback); + const pdf::PasswordDialogClosedCallback& callback); virtual ~PDFPasswordDialogViews(); // views::DialogDelegate: @@ -43,7 +42,7 @@ class PDFPasswordDialogViews : public views::DialogDelegate { // The message box view whose commands we handle. views::MessageBoxView* message_box_view_; - PasswordDialogClosedCallback callback_; + pdf::PasswordDialogClosedCallback callback_; DISALLOW_COPY_AND_ASSIGN(PDFPasswordDialogViews); }; @@ -51,9 +50,8 @@ class PDFPasswordDialogViews : public views::DialogDelegate { PDFPasswordDialogViews::PDFPasswordDialogViews( content::WebContents* web_contents, const base::string16& prompt, - const PasswordDialogClosedCallback& callback) - : message_box_view_(NULL), - callback_(callback) { + const pdf::PasswordDialogClosedCallback& callback) + : message_box_view_(NULL), callback_(callback) { views::MessageBoxView::InitParams init_params(prompt); init_params.options = views::MessageBoxView::HAS_PROMPT_FIELD; init_params.inter_row_vertical_spacing = @@ -130,6 +128,6 @@ ui::ModalType PDFPasswordDialogViews::GetModalType() const { void ShowPDFPasswordDialog(content::WebContents* web_contents, const base::string16& prompt, - const PasswordDialogClosedCallback& callback) { + const pdf::PasswordDialogClosedCallback& callback) { new PDFPasswordDialogViews(web_contents, prompt, callback); } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index f4f3848..3613e45 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3089,6 +3089,7 @@ }], ['enable_plugins==1', { 'dependencies': [ + '../components/components.gyp:pdf_browser', '../ppapi/ppapi_internal.gyp:ppapi_ipc', '../third_party/adobe/flash/flash_player.gyp:flapper_version_h', ], diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 0eb1440..c64d05f 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -1509,9 +1509,8 @@ 'browser/ui/panels/stacked_panel_drag_handler.h', 'browser/ui/pdf/adobe_reader_info_win.cc', 'browser/ui/pdf/adobe_reader_info_win.h', - 'browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h', - 'browser/ui/pdf/pdf_tab_helper.cc', - 'browser/ui/pdf/pdf_tab_helper.h', + 'browser/ui/pdf/chrome_pdf_web_contents_helper_client.cc', + 'browser/ui/pdf/chrome_pdf_web_contents_helper_client.h', 'browser/ui/pdf/pdf_unsupported_feature.cc', 'browser/ui/pdf/pdf_unsupported_feature.h', 'browser/ui/sad_tab.cc', diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index 737d1f6..1d4c6f6c 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -208,8 +208,6 @@ 'renderer/pepper/pepper_shared_memory_message_filter.h', 'renderer/pepper/pepper_uma_host.cc', 'renderer/pepper/pepper_uma_host.h', - 'renderer/pepper/ppb_pdf_impl.cc', - 'renderer/pepper/ppb_pdf_impl.h', ], # For safe_browsing==1 or safe_browsing==2. 'chrome_renderer_basic_safe_browsing_sources': [ @@ -261,6 +259,10 @@ 'renderer/printing/print_web_view_helper_linux.cc', 'renderer/printing/print_web_view_helper_mac.mm', ], + 'chrome_renderer_full_printing_sources': [ + 'renderer/pepper/chrome_pdf_print_client.cc', + 'renderer/pepper/chrome_pdf_print_client.h', + ], }, 'targets': [ { @@ -320,6 +322,7 @@ '<@(chrome_renderer_plugin_sources)', ], 'dependencies': [ + '../components/components.gyp:pdf_renderer', '../ppapi/ppapi_internal.gyp:ppapi_host', '../ppapi/ppapi_internal.gyp:ppapi_proxy', '../ppapi/ppapi_internal.gyp:ppapi_ipc', @@ -382,7 +385,12 @@ ], 'sources': [ '<@(chrome_renderer_printing_sources)', - ] + ], + }], + ['enable_printing==1', { + 'sources': [ + '<@(chrome_renderer_full_printing_sources)', + ], }], ['win_pdf_metafile_for_printing==1', { 'sources': [ diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index d4a209c..271ab71 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -572,23 +572,6 @@ IPC_MESSAGE_ROUTED4(ChromeViewHostMsg_DidRetrieveMetaTagContent, GURL /* expected_url */) #endif // defined(OS_ANDROID) -// The currently displayed PDF has an unsupported feature. -IPC_MESSAGE_ROUTED0(ChromeViewHostMsg_PDFHasUnsupportedFeature) - -// Brings up SaveAs... dialog to save specified URL. -IPC_MESSAGE_ROUTED2(ChromeViewHostMsg_PDFSaveURLAs, - GURL /* url */, - content::Referrer /* referrer */) - -// Updates the content restrictions, i.e. to disable print/copy. -IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_PDFUpdateContentRestrictions, - int /* restrictions */) - -// Brings up a Password... dialog for protected documents. -IPC_SYNC_MESSAGE_ROUTED1_1(ChromeViewHostMsg_PDFModalPromptForPassword, - std::string /* prompt */, - std::string /* actual_value */) - // This message indicates the error appeared in the frame. IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_FrameLoadingError, int /* error */) diff --git a/chrome/renderer/BUILD.gn b/chrome/renderer/BUILD.gn index 33bb0fe..fef9507 100644 --- a/chrome/renderer/BUILD.gn +++ b/chrome/renderer/BUILD.gn @@ -124,8 +124,10 @@ static_library("renderer") { if (printing_mode > 0) { deps += [ "//printing" ] + sources += rebase_path(gypi_values.chrome_renderer_printing_sources, + ".", "..") if (printing_mode == 1) { - sources += rebase_path(gypi_values.chrome_renderer_printing_sources, + sources += rebase_path(gypi_values.chrome_renderer_full_printing_sources, ".", "..") } } diff --git a/chrome/renderer/DEPS b/chrome/renderer/DEPS index 83f3464..9437474 100644 --- a/chrome/renderer/DEPS +++ b/chrome/renderer/DEPS @@ -12,6 +12,8 @@ include_rules = [ "+components/nacl/common", "+components/nacl/renderer", "+components/password_manager/content/renderer", + "+components/pdf/common", + "+components/pdf/renderer", "+components/plugins/renderer", "+components/signin/core/common", "+components/translate/content/common", diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index b122262..212784d 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -51,7 +51,6 @@ #include "chrome/renderer/net_benchmarking_extension.h" #include "chrome/renderer/page_load_histograms.h" #include "chrome/renderer/pepper/pepper_helper.h" -#include "chrome/renderer/pepper/ppb_pdf_impl.h" #include "chrome/renderer/playback_extension.h" #include "chrome/renderer/plugins/chrome_plugin_placeholder.h" #include "chrome/renderer/plugins/plugin_uma.h" @@ -75,6 +74,7 @@ #include "components/dom_distiller/core/url_constants.h" #include "components/nacl/renderer/ppb_nacl_private_impl.h" #include "components/password_manager/content/renderer/credential_manager_client.h" +#include "components/pdf/renderer/ppb_pdf_impl.h" #include "components/plugins/renderer/mobile_youtube_plugin.h" #include "components/signin/core/common/profile_management_switches.h" #include "components/visitedlink/renderer/visitedlink_slave.h" @@ -123,6 +123,10 @@ #include "extensions/renderer/extensions_render_frame_observer.h" #endif +#if defined(ENABLE_FULL_PRINTING) +#include "chrome/renderer/pepper/chrome_pdf_print_client.h" +#endif + #if defined(ENABLE_SPELLCHECK) #include "chrome/renderer/spellchecker/spellcheck.h" #include "chrome/renderer/spellchecker/spellcheck_provider.h" @@ -421,6 +425,10 @@ void ChromeContentRendererClient::RenderThreadStarted() { if (blacklist::IsBlacklistInitialized()) UMA_HISTOGRAM_BOOLEAN("Blacklist.PatchedInRenderer", true); #endif +#if defined(ENABLE_FULL_PRINTING) + pdf_print_client_.reset(new ChromePDFPrintClient()); + pdf::PPB_PDF_Impl::SetPrintClient(pdf_print_client_.get()); +#endif } void ChromeContentRendererClient::RenderFrameCreated( @@ -1394,7 +1402,7 @@ const void* ChromeContentRendererClient::CreatePPAPIInterface( return nacl::GetNaClPrivateInterface(); #endif // DISABLE_NACL if (interface_name == PPB_PDF_INTERFACE) - return PPB_PDF_Impl::GetInterface(); + return pdf::PPB_PDF_Impl::GetInterface(); #endif return NULL; } diff --git a/chrome/renderer/chrome_content_renderer_client.h b/chrome/renderer/chrome_content_renderer_client.h index 748c7df..7b06cbc 100644 --- a/chrome/renderer/chrome_content_renderer_client.h +++ b/chrome/renderer/chrome_content_renderer_client.h @@ -17,6 +17,9 @@ class ChromeExtensionsDispatcherDelegate; class ChromeRenderProcessObserver; +#if defined(ENABLE_FULL_PRINTING) +class ChromePDFPrintClient; +#endif class PrescientNetworkingDispatcher; class RendererNetPredictor; class SearchBouncer; @@ -207,6 +210,9 @@ class ChromeContentRendererClient : public content::ContentRendererClient { scoped_refptr<WebRtcLoggingMessageFilter> webrtc_logging_message_filter_; #endif scoped_ptr<SearchBouncer> search_bouncer_; +#if defined(ENABLE_FULL_PRINTING) + scoped_ptr<ChromePDFPrintClient> pdf_print_client_; +#endif #if defined(ENABLE_PLUGINS) std::set<std::string> allowed_compositor_origins_; std::set<std::string> allowed_video_decode_origins_; diff --git a/chrome/renderer/pepper/chrome_pdf_print_client.cc b/chrome/renderer/pepper/chrome_pdf_print_client.cc new file mode 100644 index 0000000..32d1e09 --- /dev/null +++ b/chrome/renderer/pepper/chrome_pdf_print_client.cc @@ -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. + +#include "chrome/renderer/pepper/chrome_pdf_print_client.h" + +#include "chrome/renderer/printing/print_web_view_helper.h" +#include "content/public/renderer/pepper_plugin_instance.h" +#include "content/public/renderer/render_view.h" +#include "third_party/WebKit/public/web/WebDocument.h" +#include "third_party/WebKit/public/web/WebElement.h" +#include "third_party/WebKit/public/web/WebLocalFrame.h" +#include "third_party/WebKit/public/web/WebPluginContainer.h" + +namespace { + +blink::WebElement GetWebElement(PP_Instance instance_id) { + content::PepperPluginInstance* instance = + content::PepperPluginInstance::Get(instance_id); + if (!instance) + return blink::WebElement(); + return instance->GetContainer()->element(); +} + +printing::PrintWebViewHelper* GetPrintWebViewHelper( + const blink::WebElement& element) { + if (element.isNull()) + return NULL; + blink::WebView* view = element.document().frame()->view(); + content::RenderView* render_view = content::RenderView::FromWebView(view); + return printing::PrintWebViewHelper::Get(render_view); +} + +} // namespace + +ChromePDFPrintClient::ChromePDFPrintClient() { +} +ChromePDFPrintClient::~ChromePDFPrintClient() { +} + +bool ChromePDFPrintClient::IsPrintingEnabled(PP_Instance instance_id) { + blink::WebElement element = GetWebElement(instance_id); + printing::PrintWebViewHelper* helper = GetPrintWebViewHelper(element); + return helper && helper->IsPrintingEnabled(); +} + +void ChromePDFPrintClient::Print(PP_Instance instance_id) { + blink::WebElement element = GetWebElement(instance_id); + printing::PrintWebViewHelper* helper = GetPrintWebViewHelper(element); + if (helper) + helper->PrintNode(element); +} diff --git a/chrome/renderer/pepper/chrome_pdf_print_client.h b/chrome/renderer/pepper/chrome_pdf_print_client.h new file mode 100644 index 0000000..0ae3224 --- /dev/null +++ b/chrome/renderer/pepper/chrome_pdf_print_client.h @@ -0,0 +1,24 @@ +// 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 CHROME_RENDERER_PEPPER_CHROME_PDF_PRINT_CLIENT_H_ +#define CHROME_RENDERER_PEPPER_CHROME_PDF_PRINT_CLIENT_H_ + +#include "base/macros.h" +#include "components/pdf/renderer/ppb_pdf_impl.h" + +class ChromePDFPrintClient : public pdf::PPB_PDF_Impl::PrintClient { + public: + ChromePDFPrintClient(); + virtual ~ChromePDFPrintClient(); + + private: + // pdf::PPB_PDF_Impl::PrintClient: + virtual bool IsPrintingEnabled(PP_Instance instance_id) OVERRIDE; + virtual void Print(PP_Instance instance_id) OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(ChromePDFPrintClient); +}; + +#endif // CHROME_RENDERER_PEPPER_CHROME_PDF_PRINT_CLIENT_H_ diff --git a/chrome/renderer/pepper/pepper_flash_renderer_host.cc b/chrome/renderer/pepper/pepper_flash_renderer_host.cc index 85aa804..fbb1007 100644 --- a/chrome/renderer/pepper/pepper_flash_renderer_host.cc +++ b/chrome/renderer/pepper/pepper_flash_renderer_host.cc @@ -10,7 +10,7 @@ #include "base/lazy_instance.h" #include "base/metrics/histogram.h" #include "base/strings/string_util.h" -#include "chrome/renderer/pepper/ppb_pdf_impl.h" +#include "components/pdf/renderer/ppb_pdf_impl.h" #include "content/public/renderer/pepper_plugin_instance.h" #include "content/public/renderer/render_thread.h" #include "content/public/renderer/renderer_ppapi_host.h" @@ -377,6 +377,6 @@ int32_t PepperFlashRendererHost::OnIsRectTopmost( int32_t PepperFlashRendererHost::OnInvokePrinting( ppapi::host::HostMessageContext* host_context) { - PPB_PDF_Impl::InvokePrintingForInstance(pp_instance()); + pdf::PPB_PDF_Impl::InvokePrintingForInstance(pp_instance()); return PP_OK; } diff --git a/chrome/renderer/pepper/pepper_pdf_host.cc b/chrome/renderer/pepper/pepper_pdf_host.cc index bacec43..0c22c92 100644 --- a/chrome/renderer/pepper/pepper_pdf_host.cc +++ b/chrome/renderer/pepper/pepper_pdf_host.cc @@ -5,8 +5,8 @@ #include "chrome/renderer/pepper/pepper_pdf_host.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/common/render_messages.h" #include "chrome/renderer/printing/print_web_view_helper.h" +#include "components/pdf/common/pdf_messages.h" #include "content/app/resources/grit/content_resources.h" #include "content/app/strings/grit/content_strings.h" #include "content/public/common/referrer.h" @@ -184,9 +184,8 @@ int32_t PepperPDFHost::OnHostMsgSetContentRestriction( host_->GetPluginInstance(pp_instance()); if (!instance) return PP_ERROR_FAILED; - instance->GetRenderView()->Send( - new ChromeViewHostMsg_PDFUpdateContentRestrictions( - instance->GetRenderView()->GetRoutingID(), restrictions)); + instance->GetRenderView()->Send(new PDFHostMsg_PDFUpdateContentRestrictions( + instance->GetRenderView()->GetRoutingID(), restrictions)); return PP_OK; } @@ -209,8 +208,8 @@ int32_t PepperPDFHost::OnHostMsgHasUnsupportedFeature( blink::WebView* view = instance->GetContainer()->element().document().frame()->view(); content::RenderView* render_view = content::RenderView::FromWebView(view); - render_view->Send(new ChromeViewHostMsg_PDFHasUnsupportedFeature( - render_view->GetRoutingID())); + render_view->Send( + new PDFHostMsg_PDFHasUnsupportedFeature(render_view->GetRoutingID())); return PP_OK; } @@ -248,8 +247,8 @@ int32_t PepperPDFHost::OnHostMsgSaveAs( render_view->GetWebView()->mainFrame()->toWebLocalFrame(); content::Referrer referrer(frame->document().url(), frame->document().referrerPolicy()); - render_view->Send(new ChromeViewHostMsg_PDFSaveURLAs( - render_view->GetRoutingID(), url, referrer)); + render_view->Send( + new PDFHostMsg_PDFSaveURLAs(render_view->GetRoutingID(), url, referrer)); return PP_OK; } diff --git a/chrome/renderer/pepper/ppb_pdf_impl.h b/chrome/renderer/pepper/ppb_pdf_impl.h deleted file mode 100644 index 1b88f47..0000000 --- a/chrome/renderer/pepper/ppb_pdf_impl.h +++ /dev/null @@ -1,23 +0,0 @@ -// 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 CHROME_RENDERER_PEPPER_PPB_PDF_IMPL_H_ -#define CHROME_RENDERER_PEPPER_PPB_PDF_IMPL_H_ - -#include "ppapi/c/pp_instance.h" - -struct PPB_PDF; - -class PPB_PDF_Impl { - public: - // Returns a pointer to the interface implementing PPB_PDF that is exposed - // to the plugin. - static const PPB_PDF* GetInterface(); - - // Invokes the "Print" command for the given instance as if the user right - // clicked on it and selected "Print". - static void InvokePrintingForInstance(PP_Instance instance); -}; - -#endif // CHROME_RENDERER_PEPPER_PPB_PDF_IMPL_H_ diff --git a/components/BUILD.gn b/components/BUILD.gn index afb2e63..3f05d34 100644 --- a/components/BUILD.gn +++ b/components/BUILD.gn @@ -2,6 +2,8 @@ # 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") + # Collection of all components. You wouldn't link to this, but this is rather # to reference the files so they can be compiled by the build system. group("all_components") { @@ -56,6 +58,9 @@ group("all_components") { "//components/password_manager/content/browser", "//components/password_manager/core/browser", "//components/password_manager/core/common", + "//components/pdf/browser", + "//components/pdf/common", + "//components/pdf/renderer", "//components/plugins/renderer", "//components/policy", "//components/power", @@ -105,6 +110,14 @@ group("all_components") { deps -= [ "//components/keyed_service/content" ] } + if (!enable_plugins) { + deps -= [ + "//components/pdf/browser", + "//components/pdf/common", + "//components/pdf/renderer", + ] + } + if (is_android) { deps -= [ "//components/autofill/content/browser", # Blocked on content/blink. diff --git a/components/OWNERS b/components/OWNERS index 8a394c1..75a219b 100644 --- a/components/OWNERS +++ b/components/OWNERS @@ -122,6 +122,11 @@ per-file password_manager*=stuartmorgan@chromium.org per-file password_manager*=tim@chromium.org per-file password_manager*=vabr@chromium.org +per-file pdf.gypi=gene@chromium.org +per-file pdf.gypi=jam@chromium.org +per-file pdf.gypi=raymes@chromium.org +per-file pdf.gypi=thestig@chromium.org + per-file precache*=bengr@chromium.org per-file precache*=sclittle@chromium.org diff --git a/components/components.gyp b/components/components.gyp index e19c1a8..3b36cc8 100644 --- a/components/components.gyp +++ b/components/components.gyp @@ -110,5 +110,10 @@ 'invalidation.gypi', ], }], + ['enable_plugins==1', { + 'includes': [ + 'pdf.gypi', + ], + }], ], } diff --git a/components/pdf.gypi b/components/pdf.gypi new file mode 100644 index 0000000..80061c6 --- /dev/null +++ b/components/pdf.gypi @@ -0,0 +1,60 @@ +# 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. + +{ + 'variables': { + 'chromium_code': 1, + }, + 'targets': [{ + 'target_name': 'pdf_common', + 'type': 'static_library', + 'dependencies': [ + '<(DEPTH)/base/base.gyp:base', + '<(DEPTH)/content/content.gyp:content_common', + '<(DEPTH)/ipc/ipc.gyp:ipc', + '<(DEPTH)/url/url.gyp:url_lib', + ], + 'sources': [ + 'pdf/common/pdf_message_generator.cc', + 'pdf/common/pdf_message_generator.h', + 'pdf/common/pdf_messages.h', + ], + }, { + 'target_name': 'pdf_browser', + 'type': 'static_library', + 'dependencies': [ + '<(DEPTH)/content/content.gyp:content_browser', + 'pdf_common', + ], + 'sources': [ + 'pdf/browser/open_pdf_in_reader_prompt_client.h', + 'pdf/browser/pdf_web_contents_helper.cc', + 'pdf/browser/pdf_web_contents_helper.h', + 'pdf/browser/pdf_web_contents_helper_client.h', + ], + }, { + 'target_name': 'pdf_renderer', + 'type': 'static_library', + 'dependencies': [ + '<(DEPTH)/content/content.gyp:content_renderer', + '<(DEPTH)/ppapi/ppapi_internal.gyp:ppapi_shared', + '<(DEPTH)/third_party/icu/icu.gyp:icuuc', + '<(DEPTH)/third_party/icu/icu.gyp:icui18n', + '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', + '<(DEPTH)/third_party/WebKit/public/blink.gyp:blink', + 'pdf_common', + ], + 'sources': [ + 'pdf/renderer/ppb_pdf_impl.cc', + 'pdf/renderer/ppb_pdf_impl.h', + ], + 'conditions': [ + ['OS=="win"', { + # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. + 'msvs_disabled_warnings': [4267, ], + }, + ], + ], + }], +} diff --git a/components/pdf/DEPS b/components/pdf/DEPS new file mode 100644 index 0000000..745ee50 --- /dev/null +++ b/components/pdf/DEPS @@ -0,0 +1,10 @@ +include_rules = [ + "+content/app", + "+content/public", + "+grit/webkit_resources.h", + "+ipc", + "+ppapi", + "+third_party/skia/include", + "+third_party/WebKit/public", + "+ui/base", +] diff --git a/components/pdf/OWNERS b/components/pdf/OWNERS new file mode 100644 index 0000000..fb5f2d2 --- /dev/null +++ b/components/pdf/OWNERS @@ -0,0 +1,4 @@ +gene@chromium.org +jam@chromium.org +raymes@chromium.org +thestig@chromium.org diff --git a/components/pdf/README b/components/pdf/README new file mode 100644 index 0000000..da0b817 --- /dev/null +++ b/components/pdf/README @@ -0,0 +1,4 @@ +The PDF component contains code necessary for using the PDF plugin in +content-based clients. It provides an implementation for the PPB_PDF ppapi +interface, and the necessary browser and renderer-side code for processing the +relevant IPC mesages. 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/chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h b/components/pdf/browser/open_pdf_in_reader_prompt_client.h index c39d66a..854e6f4 100644 --- a/chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h +++ b/components/pdf/browser/open_pdf_in_reader_prompt_client.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_UI_PDF_OPEN_PDF_IN_READER_PROMPT_DELEGATE_H_ -#define CHROME_BROWSER_UI_PDF_OPEN_PDF_IN_READER_PROMPT_DELEGATE_H_ +#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" @@ -11,9 +11,11 @@ namespace content { struct LoadCommittedDetails; } -class OpenPDFInReaderPromptDelegate { +namespace pdf { + +class OpenPDFInReaderPromptClient { public: - virtual ~OpenPDFInReaderPromptDelegate() {} + virtual ~OpenPDFInReaderPromptClient() {} virtual base::string16 GetMessageText() const = 0; @@ -29,4 +31,6 @@ class OpenPDFInReaderPromptDelegate { virtual void Cancel() = 0; }; -#endif // CHROME_BROWSER_UI_PDF_OPEN_PDF_IN_READER_PROMPT_DELEGATE_H_ +} // 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/chrome/browser/ui/pdf/pdf_tab_helper.h b/components/pdf/browser/pdf_web_contents_helper.h index 5dca4a6..d37b57f 100644 --- a/chrome/browser/ui/pdf/pdf_tab_helper.h +++ b/components/pdf/browser/pdf_web_contents_helper.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_UI_PDF_PDF_TAB_HELPER_H_ -#define CHROME_BROWSER_UI_PDF_PDF_TAB_HELPER_H_ +#ifndef COMPONENTS_PDF_BROWSER_PDF_WEB_CONTENTS_HELPER_H_ +#define COMPONENTS_PDF_BROWSER_PDF_WEB_CONTENTS_HELPER_H_ #include <string> @@ -13,27 +13,35 @@ #include "content/public/browser/web_contents_user_data.h" #include "ipc/ipc_message.h" -class OpenPDFInReaderPromptDelegate; - namespace content { class WebContents; } -// Per-tab class to handle PDF messages. -class PDFTabHelper : public content::WebContentsObserver, - public content::WebContentsUserData<PDFTabHelper> { - public: +namespace pdf { + +class OpenPDFInReaderPromptClient; +class PDFWebContentsHelperClient; - explicit PDFTabHelper(content::WebContents* web_contents); - virtual ~PDFTabHelper(); +// 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); - OpenPDFInReaderPromptDelegate* open_in_reader_prompt() const { + OpenPDFInReaderPromptClient* open_in_reader_prompt() const { return open_in_reader_prompt_.get(); } - void ShowOpenInReaderPrompt(scoped_ptr<OpenPDFInReaderPromptDelegate> prompt); + 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( @@ -49,25 +57,18 @@ class PDFTabHelper : public content::WebContentsObserver, // Message handlers. void OnHasUnsupportedFeature(); - void OnSaveURLAs(const GURL& url, - const content::Referrer& referrer); + 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<OpenPDFInReaderPromptDelegate> open_in_reader_prompt_; + scoped_ptr<OpenPDFInReaderPromptClient> open_in_reader_prompt_; + scoped_ptr<PDFWebContentsHelperClient> client_; - DISALLOW_COPY_AND_ASSIGN(PDFTabHelper); + DISALLOW_COPY_AND_ASSIGN(PDFWebContentsHelper); }; -typedef base::Callback<void(bool /* success */, - const base::string16& /* password */)> - PasswordDialogClosedCallback; - -// Shows a tab-modal dialog to get a password for a PDF document. -void ShowPDFPasswordDialog(content::WebContents* web_contents, - const base::string16& prompt, - const PasswordDialogClosedCallback& callback); +} // namespace pdf -#endif // CHROME_BROWSER_UI_PDF_PDF_TAB_HELPER_H_ +#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_ diff --git a/components/pdf/common/BUILD.gn b/components/pdf/common/BUILD.gn new file mode 100644 index 0000000..adff35e --- /dev/null +++ b/components/pdf/common/BUILD.gn @@ -0,0 +1,20 @@ +# 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("common") { + sources = [ + "pdf_message_generator.cc", + "pdf_message_generator.h", + "pdf_messages.h", + ] + + deps = [ + "//base", + "//content/public/common", + "//ipc", + "//url", + ] +} diff --git a/components/pdf/common/OWNERS b/components/pdf/common/OWNERS new file mode 100644 index 0000000..faa1757 --- /dev/null +++ b/components/pdf/common/OWNERS @@ -0,0 +1,11 @@ +# Changes to IPC messages require a security review to avoid introducing +# new sandbox escapes. +per-file *_messages*.h=set noparent +per-file *_messages*.h=cevans@chromium.org +per-file *_messages*.h=dcheng@chromium.org +per-file *_messages*.h=inferno@chromium.org +per-file *_messages*.h=jln@chromium.org +per-file *_messages*.h=jschuh@chromium.org +per-file *_messages*.h=kenrb@chromium.org +per-file *_messages*.h=nasko@chromium.org +per-file *_messages*.h=tsepez@chromium.org diff --git a/components/pdf/common/pdf_message_generator.cc b/components/pdf/common/pdf_message_generator.cc new file mode 100644 index 0000000..025d94c --- /dev/null +++ b/components/pdf/common/pdf_message_generator.cc @@ -0,0 +1,33 @@ +// 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 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 diff --git a/components/pdf/common/pdf_message_generator.h b/components/pdf/common/pdf_message_generator.h new file mode 100644 index 0000000..c55d672 --- /dev/null +++ b/components/pdf/common/pdf_message_generator.h @@ -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" diff --git a/components/pdf/common/pdf_messages.h b/components/pdf/common/pdf_messages.h new file mode 100644 index 0000000..0973923 --- /dev/null +++ b/components/pdf/common/pdf_messages.h @@ -0,0 +1,31 @@ +// 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.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" + +#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 */) + +// Brings up a Password... dialog for protected documents. +IPC_SYNC_MESSAGE_ROUTED1_1(PDFHostMsg_PDFModalPromptForPassword, + std::string /* prompt */, + std::string /* actual_value */) diff --git a/components/pdf/renderer/BUILD.gn b/components/pdf/renderer/BUILD.gn new file mode 100644 index 0000000..e2cfaeb --- /dev/null +++ b/components/pdf/renderer/BUILD.gn @@ -0,0 +1,28 @@ +# 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("renderer") { + sources = [ + "ppb_pdf_impl.cc", + "ppb_pdf_impl.h", + ] + + deps = [ + "//base", + "//components/pdf/common", + "//content/public/renderer", + "//ppapi:ppapi_shared", + "//third_party/icu", + "//v8", + "//third_party/WebKit/public:blink_minimal", + ] + + if (is_win) { + cflags += [ + "/wd4267" # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. + ] + } +} diff --git a/components/pdf/renderer/OWNERS b/components/pdf/renderer/OWNERS new file mode 100644 index 0000000..d998f46 --- /dev/null +++ b/components/pdf/renderer/OWNERS @@ -0,0 +1,5 @@ +per-file ppb_pdf_impl.*=bbudge@chromium.org +per-file ppb_pdf_impl.*=dmichael@chromium.org +per-file ppb_pdf_impl.*=raymes@chromium.org +per-file ppb_pdf_impl.*=teravest@chromium.org +per-file ppb_pdf_impl.*=yzshen@chromium.org diff --git a/chrome/renderer/pepper/ppb_pdf_impl.cc b/components/pdf/renderer/ppb_pdf_impl.cc index 516178c..716ff9a 100644 --- a/chrome/renderer/pepper/ppb_pdf_impl.cc +++ b/components/pdf/renderer/ppb_pdf_impl.cc @@ -2,15 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/renderer/pepper/ppb_pdf_impl.h" +#include "components/pdf/renderer/ppb_pdf_impl.h" #include "base/files/scoped_file.h" #include "base/metrics/histogram.h" #include "base/numerics/safe_conversions.h" #include "base/strings/utf_string_conversions.h" #include "build/build_config.h" -#include "chrome/common/render_messages.h" -#include "chrome/renderer/printing/print_web_view_helper.h" +#include "components/pdf/common/pdf_messages.h" #include "content/app/resources/grit/content_resources.h" #include "content/app/strings/grit/content_strings.h" #include "content/public/common/child_process_sandbox_support_linux.h" @@ -35,8 +34,11 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +namespace pdf { namespace { +PPB_PDF_Impl::PrintClient* g_print_client = NULL; + #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) class PrivateFontFile : public ppapi::Resource { public: @@ -45,9 +47,11 @@ class PrivateFontFile : public ppapi::Resource { bool GetFontTable(uint32_t table, void* output, uint32_t* output_length) { size_t temp_size = static_cast<size_t>(*output_length); - bool rv = content::GetFontTable( - fd_.get(), table, 0 /* offset */, static_cast<uint8_t*>(output), - &temp_size); + bool rv = content::GetFontTable(fd_.get(), + table, + 0 /* offset */, + static_cast<uint8_t*>(output), + &temp_size); *output_length = base::checked_cast<uint32_t>(temp_size); return rv; } @@ -117,38 +121,8 @@ static const ResourceImageInfo kResourceImageMap[] = { {PP_RESOURCEIMAGE_PDF_PAGE_INDICATOR_BACKGROUND, IDR_PDF_PAGE_INDICATOR_BACKGROUND}, {PP_RESOURCEIMAGE_PDF_PAGE_DROPSHADOW, IDR_PDF_PAGE_DROPSHADOW}, - {PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PAN_SCROLL_ICON}, }; - -#if defined(ENABLE_FULL_PRINTING) - -blink::WebElement GetWebElement(PP_Instance instance_id) { - content::PepperPluginInstance* instance = - content::PepperPluginInstance::Get(instance_id); - if (!instance) - return blink::WebElement(); - return instance->GetContainer()->element(); -} - -printing::PrintWebViewHelper* GetPrintWebViewHelper( - const blink::WebElement& element) { - if (element.isNull()) - return NULL; - blink::WebView* view = element.document().frame()->view(); - content::RenderView* render_view = content::RenderView::FromWebView(view); - return printing::PrintWebViewHelper::Get(render_view); -} - -bool IsPrintingEnabled(PP_Instance instance_id) { - blink::WebElement element = GetWebElement(instance_id); - printing::PrintWebViewHelper* helper = GetPrintWebViewHelper(element); - return helper && helper->IsPrintingEnabled(); -} - -#else // ENABLE_FULL_PRINTING - -bool IsPrintingEnabled(PP_Instance instance_id) { return false; } - -#endif // ENABLE_FULL_PRINTING + {PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PAN_SCROLL_ICON}, +}; PP_Var GetLocalizedString(PP_Instance instance_id, PP_ResourceString string_id) { @@ -300,9 +274,8 @@ void SetContentRestriction(PP_Instance instance_id, int restrictions) { content::PepperPluginInstance::Get(instance_id); if (!instance) return; - instance->GetRenderView()->Send( - new ChromeViewHostMsg_PDFUpdateContentRestrictions( - instance->GetRenderView()->GetRoutingID(), restrictions)); + instance->GetRenderView()->Send(new PDFHostMsg_PDFUpdateContentRestrictions( + instance->GetRenderView()->GetRoutingID(), restrictions)); } void HistogramPDFPageCount(PP_Instance instance, int count) { @@ -329,8 +302,8 @@ void HasUnsupportedFeature(PP_Instance instance_id) { blink::WebView* view = instance->GetContainer()->element().document().frame()->view(); content::RenderView* render_view = content::RenderView::FromWebView(view); - render_view->Send(new ChromeViewHostMsg_PDFHasUnsupportedFeature( - render_view->GetRoutingID())); + render_view->Send( + new PDFHostMsg_PDFHasUnsupportedFeature(render_view->GetRoutingID())); } void SaveAs(PP_Instance instance_id) { @@ -345,8 +318,8 @@ void SaveAs(PP_Instance instance_id) { render_view->GetWebView()->mainFrame()->toWebLocalFrame(); content::Referrer referrer(frame->document().url(), frame->document().referrerPolicy()); - render_view->Send(new ChromeViewHostMsg_PDFSaveURLAs( - render_view->GetRoutingID(), url, referrer)); + render_view->Send( + new PDFHostMsg_PDFSaveURLAs(render_view->GetRoutingID(), url, referrer)); } PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) { @@ -354,7 +327,9 @@ PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) { case PP_PDFFEATURE_HIDPI: return PP_TRUE; case PP_PDFFEATURE_PRINTING: - return IsPrintingEnabled(instance) ? PP_TRUE : PP_FALSE; + return (g_print_client && g_print_client->IsPrintingEnabled(instance)) + ? PP_TRUE + : PP_FALSE; } return PP_FALSE; } @@ -402,7 +377,7 @@ PP_Var ModalPromptForPassword(PP_Instance instance_id, PP_Var message) { scoped_refptr<ppapi::StringVar> message_string( ppapi::StringVar::FromPPVar(message)); - IPC::SyncMessage* msg = new ChromeViewHostMsg_PDFModalPromptForPassword( + IPC::SyncMessage* msg = new PDFHostMsg_PDFModalPromptForPassword( instance->GetRenderView()->GetRoutingID(), message_string->value(), &actual_value); @@ -412,7 +387,9 @@ PP_Var ModalPromptForPassword(PP_Instance instance_id, PP_Var message) { return ppapi::StringVar::StringToPPVar(actual_value); } -PP_Bool IsOutOfProcess(PP_Instance instance_id) { return PP_FALSE; } +PP_Bool IsOutOfProcess(PP_Instance instance_id) { + return PP_FALSE; +} void SetSelectedText(PP_Instance instance_id, const char* selected_text) { // This function is intended for out of process PDF plugin. @@ -451,14 +428,19 @@ const PPB_PDF ppb_pdf = { // } // namespace // static -const PPB_PDF* PPB_PDF_Impl::GetInterface() { return &ppb_pdf; } +const PPB_PDF* PPB_PDF_Impl::GetInterface() { + return &ppb_pdf; +} // static void PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { -#if defined(ENABLE_FULL_PRINTING) - blink::WebElement element = GetWebElement(instance_id); - printing::PrintWebViewHelper* helper = GetPrintWebViewHelper(element); - if (helper) - helper->PrintNode(element); -#endif // ENABLE_FULL_PRINTING + if (g_print_client) + g_print_client->Print(instance_id); } + +void PPB_PDF_Impl::SetPrintClient(PPB_PDF_Impl::PrintClient* client) { + CHECK(!g_print_client) << "There should only be a single PrintClient."; + g_print_client = client; +} + +} // namespace pdf diff --git a/components/pdf/renderer/ppb_pdf_impl.h b/components/pdf/renderer/ppb_pdf_impl.h new file mode 100644 index 0000000..2cd5a44 --- /dev/null +++ b/components/pdf/renderer/ppb_pdf_impl.h @@ -0,0 +1,45 @@ +// 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 COMPONENT_PDF_RENDERER_PPB_PDF_IMPL_H_ +#define COMPONENT_PDF_RENDERER_PPB_PDF_IMPL_H_ + +#include "ppapi/c/pp_instance.h" + +struct PPB_PDF; + +namespace pdf { + +class PPB_PDF_Impl { + public: + class PrintClient { + public: + virtual ~PrintClient() {} + + // Returns whether printing is enabled for the plugin instance identified by + // |instance_id|. + virtual bool IsPrintingEnabled(PP_Instance instance_id) = 0; + + // Invokes the "Print" command for the plugin instance identified by + // |instance_id|. + virtual void Print(PP_Instance instance_id) = 0; + }; + + // Returns a pointer to the interface implementing PPB_PDF that is exposed + // to the plugin. + static const PPB_PDF* GetInterface(); + + // Invokes the "Print" command for the given instance as if the user right + // clicked on it and selected "Print". + static void InvokePrintingForInstance(PP_Instance instance); + + // The caller retains the ownership of |print_client|. The client is + // allowed to be set only once, and when set, the client must outlive the + // PPB_PDF_Impl instance. + static void SetPrintClient(PrintClient* print_client); +}; + +} // namespace pdf + +#endif // COMPONENT_PDF_RENDERER_PPB_PDF_IMPL_H_ diff --git a/ipc/ipc_message_start.h b/ipc/ipc_message_start.h index 57f6dcc..5acf8c1 100644 --- a/ipc/ipc_message_start.h +++ b/ipc/ipc_message_start.h @@ -107,6 +107,7 @@ enum IPCMessageStart { ChromeUtilityExtensionsMsgStart, PlatformNotificationMsgStart, CredentialManagerMsgStart, + PDFMsgStart, LastIPCMsgStart // Must come last. }; diff --git a/ppapi/c/private/ppb_pdf.h b/ppapi/c/private/ppb_pdf.h index c0b570b..fdd62fe 100644 --- a/ppapi/c/private/ppb_pdf.h +++ b/ppapi/c/private/ppb_pdf.h @@ -158,11 +158,11 @@ struct PPB_PDF { float scale); // Invoke password dialog for plugin. - struct PP_Var (*ModalPromptForPassword)(PP_Instance instance, - struct PP_Var message); + struct PP_Var (*ModalPromptForPassword)(PP_Instance instance, + struct PP_Var message); - // Returns PP_TRUE if the plugin is out of process. - PP_Bool(*IsOutOfProcess)(PP_Instance instance); + // Returns PP_TRUE if the plugin is out of process. + PP_Bool (*IsOutOfProcess)(PP_Instance instance); // Sets the selected text of the plugin. void(*SetSelectedText)(PP_Instance instance, const char* selected_text); diff --git a/tools/ipc_fuzzer/message_lib/DEPS b/tools/ipc_fuzzer/message_lib/DEPS index ab7d2d5..525a002 100644 --- a/tools/ipc_fuzzer/message_lib/DEPS +++ b/tools/ipc_fuzzer/message_lib/DEPS @@ -2,6 +2,7 @@ include_rules = [ "+chrome/common", "+components/autofill/content/common", "+components/nacl/common", + "+components/pdf/common", "+components/tracing", "+components/translate", "+components/visitedlink/common", diff --git a/tools/ipc_fuzzer/message_lib/all_messages.h b/tools/ipc_fuzzer/message_lib/all_messages.h index 46d88b1..afc6455 100644 --- a/tools/ipc_fuzzer/message_lib/all_messages.h +++ b/tools/ipc_fuzzer/message_lib/all_messages.h @@ -16,6 +16,7 @@ #include "chrome/common/all_messages.h" #include "components/autofill/content/common/autofill_messages.h" #include "components/nacl/common/nacl_host_messages.h" +#include "components/pdf/common/pdf_messages.h" #include "components/tracing/tracing_messages.h" #include "components/translate/content/common/translate_messages.h" #include "components/visitedlink/common/visitedlink_messages.h" |