| Index: chrome/browser/ui/pdf/pdf_unsupported_feature.cc
|
| diff --git a/chrome/browser/ui/pdf/pdf_unsupported_feature.cc b/chrome/browser/ui/pdf/pdf_unsupported_feature.cc
|
| index 1618988dea59a3ad921994bc5d7e40b820690df6..5a59f58bf1f8bb18e3418c9b16aa8e5c0a1ae2e1 100644
|
| --- a/chrome/browser/ui/pdf/pdf_unsupported_feature.cc
|
| +++ b/chrome/browser/ui/pdf/pdf_unsupported_feature.cc
|
| @@ -8,9 +8,7 @@
|
| #include "base/utf_string_conversions.h"
|
| #include "base/values.h"
|
| #include "base/version.h"
|
| -#include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
|
| #include "chrome/browser/chrome_plugin_service_filter.h"
|
| -#include "chrome/browser/infobars/infobar_tab_helper.h"
|
| #include "chrome/browser/lifetime/application_lifetime.h"
|
| #include "chrome/browser/plugin_finder.h"
|
| #include "chrome/browser/plugin_installer.h"
|
| @@ -27,11 +25,14 @@
|
| #include "chrome/common/pref_names.h"
|
| #include "content/public/browser/interstitial_page.h"
|
| #include "content/public/browser/interstitial_page_delegate.h"
|
| +#include "content/public/browser/navigation_details.h"
|
| +#include "content/public/browser/navigation_entry.h"
|
| #include "content/public/browser/plugin_service.h"
|
| #include "content/public/browser/render_process_host.h"
|
| #include "content/public/browser/render_view_host.h"
|
| #include "content/public/browser/user_metrics.h"
|
| #include "content/public/browser/web_contents.h"
|
| +#include "content/public/common/page_transition_types.h"
|
| #include "grit/browser_resources.h"
|
| #include "grit/generated_resources.h"
|
| #include "grit/theme_resources.h"
|
| @@ -60,23 +61,22 @@ static const char kAdobeReaderIdentifier[] = "adobe-reader";
|
| static const char kAdobeReaderUpdateUrl[] =
|
| "http://www.adobe.com/go/getreader_chrome";
|
|
|
| -// The info bar delegate used to ask the user if they want to use Adobe Reader
|
| -// by default. We want the infobar to have [No][Yes], so we swap the text on
|
| -// the buttons, and the meaning of the delegate callbacks.
|
| -class PDFEnableAdobeReaderInfoBarDelegate : public ConfirmInfoBarDelegate {
|
| +// The prompt delegate used to ask the user if they want to use Adobe Reader
|
| +// by default.
|
| +class PDFEnableAdobeReaderPromptDelegate
|
| + : public OpenPDFInReaderPromptDelegate {
|
| public:
|
| - explicit PDFEnableAdobeReaderInfoBarDelegate(
|
| - InfoBarTabHelper* infobar_helper,
|
| - Profile* profile);
|
| - virtual ~PDFEnableAdobeReaderInfoBarDelegate();
|
| -
|
| - // ConfirmInfoBarDelegate
|
| - virtual void InfoBarDismissed() OVERRIDE;
|
| - virtual Type GetInfoBarType() const OVERRIDE;
|
| - virtual bool Accept() OVERRIDE;
|
| - virtual bool Cancel() OVERRIDE;
|
| - virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
|
| + explicit PDFEnableAdobeReaderPromptDelegate(Profile* profile);
|
| + virtual ~PDFEnableAdobeReaderPromptDelegate();
|
| +
|
| + // OpenPDFInReaderPromptDelegate
|
| virtual string16 GetMessageText() const OVERRIDE;
|
| + virtual string16 GetAcceptButtonText() const OVERRIDE;
|
| + virtual string16 GetCancelButtonText() const OVERRIDE;
|
| + virtual bool ShouldExpire(
|
| + const content::LoadCommittedDetails& details) const OVERRIDE;
|
| + virtual void Accept() OVERRIDE;
|
| + virtual void Cancel() OVERRIDE;
|
|
|
| private:
|
| void OnYes();
|
| @@ -84,52 +84,28 @@ class PDFEnableAdobeReaderInfoBarDelegate : public ConfirmInfoBarDelegate {
|
|
|
| Profile* profile_;
|
|
|
| - DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderInfoBarDelegate);
|
| + DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderPromptDelegate);
|
| };
|
|
|
| -PDFEnableAdobeReaderInfoBarDelegate::PDFEnableAdobeReaderInfoBarDelegate(
|
| - InfoBarTabHelper* infobar_helper, Profile* profile)
|
| - : ConfirmInfoBarDelegate(infobar_helper),
|
| - profile_(profile) {
|
| +PDFEnableAdobeReaderPromptDelegate::PDFEnableAdobeReaderPromptDelegate(
|
| + Profile* profile)
|
| + : profile_(profile) {
|
| content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarShown"));
|
| }
|
|
|
| -PDFEnableAdobeReaderInfoBarDelegate::~PDFEnableAdobeReaderInfoBarDelegate() {
|
| -}
|
| -
|
| -void PDFEnableAdobeReaderInfoBarDelegate::InfoBarDismissed() {
|
| - OnNo();
|
| +PDFEnableAdobeReaderPromptDelegate::~PDFEnableAdobeReaderPromptDelegate() {
|
| }
|
|
|
| -InfoBarDelegate::Type
|
| - PDFEnableAdobeReaderInfoBarDelegate::GetInfoBarType() const {
|
| - return PAGE_ACTION_TYPE;
|
| +bool PDFEnableAdobeReaderPromptDelegate::ShouldExpire(
|
| + const content::LoadCommittedDetails& details) const {
|
| + content::PageTransition transition =
|
| + content::PageTransitionStripQualifier(details.entry->GetTransitionType());
|
| + // We don't want to expire on a reload, because that is how we open the PDF in
|
| + // Reader.
|
| + return !details.is_in_page && transition != content::PAGE_TRANSITION_RELOAD;
|
| }
|
|
|
| -bool PDFEnableAdobeReaderInfoBarDelegate::Accept() {
|
| - profile_->GetPrefs()->SetBoolean(
|
| - prefs::kPluginsShowSetReaderDefaultInfobar, false);
|
| - OnNo();
|
| - return true;
|
| -}
|
| -
|
| -bool PDFEnableAdobeReaderInfoBarDelegate::Cancel() {
|
| - OnYes();
|
| - return true;
|
| -}
|
| -
|
| -string16 PDFEnableAdobeReaderInfoBarDelegate::GetButtonLabel(
|
| - InfoBarButton button) const {
|
| - return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
|
| - IDS_PDF_INFOBAR_NEVER_USE_READER_BUTTON :
|
| - IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON);
|
| -}
|
| -
|
| -string16 PDFEnableAdobeReaderInfoBarDelegate::GetMessageText() const {
|
| - return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER);
|
| -}
|
| -
|
| -void PDFEnableAdobeReaderInfoBarDelegate::OnYes() {
|
| +void PDFEnableAdobeReaderPromptDelegate::Accept() {
|
| content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK"));
|
| PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile_);
|
| plugin_prefs->EnablePluginGroup(
|
| @@ -138,10 +114,24 @@ void PDFEnableAdobeReaderInfoBarDelegate::OnYes() {
|
| false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName));
|
| }
|
|
|
| -void PDFEnableAdobeReaderInfoBarDelegate::OnNo() {
|
| +void PDFEnableAdobeReaderPromptDelegate::Cancel() {
|
| + // profile_->GetPrefs()->SetBoolean(
|
| + // prefs::kPluginsShowSetReaderDefaultInfobar, false);
|
| content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel"));
|
| }
|
|
|
| +string16 PDFEnableAdobeReaderPromptDelegate::GetAcceptButtonText() const {
|
| + return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON);
|
| +}
|
| +
|
| +string16 PDFEnableAdobeReaderPromptDelegate::GetCancelButtonText() const {
|
| + return l10n_util::GetStringUTF16(IDS_DONE);
|
| +}
|
| +
|
| +string16 PDFEnableAdobeReaderPromptDelegate::GetMessageText() const {
|
| + return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER);
|
| +}
|
| +
|
| // Launch the url to get the latest Adbobe Reader installer.
|
| void OpenReaderUpdateURL(WebContents* tab) {
|
| OpenURLParams params(
|
| @@ -153,7 +143,7 @@ void OpenReaderUpdateURL(WebContents* tab) {
|
| // Opens the PDF using Adobe Reader.
|
| void OpenUsingReader(WebContents* web_contents,
|
| const WebPluginInfo& reader_plugin,
|
| - InfoBarDelegate* delegate) {
|
| + OpenPDFInReaderPromptDelegate* delegate) {
|
| ChromePluginServiceFilter::GetInstance()->OverridePluginForTab(
|
| web_contents->GetRenderProcessHost()->GetID(),
|
| web_contents->GetRenderViewHost()->GetRoutingID(),
|
| @@ -161,8 +151,9 @@ void OpenUsingReader(WebContents* web_contents,
|
| reader_plugin);
|
| web_contents->GetRenderViewHost()->ReloadFrame();
|
|
|
| + PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents);
|
| if (delegate)
|
| - tab->infobar_tab_helper()->AddInfoBar(delegate);
|
| + pdf_tab_helper->ShowOpenInReaderPrompt(make_scoped_ptr(delegate));
|
| }
|
|
|
| // An interstitial to be used when the user chooses to open a PDF using Adobe
|
| @@ -266,6 +257,8 @@ class PDFUnsupportedFeaturePromptDelegate
|
| virtual string16 GetMessageText() const OVERRIDE;
|
| virtual string16 GetAcceptButtonText() const OVERRIDE;
|
| virtual string16 GetCancelButtonText() const OVERRIDE;
|
| + virtual bool ShouldExpire(
|
| + const content::LoadCommittedDetails& details) const OVERRIDE;
|
| virtual void Accept() OVERRIDE;
|
| virtual void Cancel() OVERRIDE;
|
|
|
| @@ -329,6 +322,11 @@ string16 PDFUnsupportedFeaturePromptDelegate::GetCancelButtonText() const {
|
| return l10n_util::GetStringUTF16(IDS_DONE);
|
| }
|
|
|
| +bool PDFUnsupportedFeaturePromptDelegate::ShouldExpire(
|
| + const content::LoadCommittedDetails& details) const {
|
| + return !details.is_in_page;
|
| +}
|
| +
|
| void PDFUnsupportedFeaturePromptDelegate::Accept() {
|
| #if defined(OS_WIN)
|
| if (base::win::IsMetroProcess()) {
|
| @@ -350,15 +348,15 @@ void PDFUnsupportedFeaturePromptDelegate::Accept() {
|
| return;
|
| }
|
|
|
| + OpenPDFInReaderPromptDelegate* delegate = NULL;
|
| if (tab_contents_->profile()->GetPrefs()->GetBoolean(
|
| prefs::kPluginsShowSetReaderDefaultInfobar)) {
|
| - InfoBarDelegate* bar = new PDFEnableAdobeReaderInfoBarDelegate(
|
| - tab_contents_->infobar_tab_helper(), tab_contents_->profile());
|
| - OpenUsingReader(tab_contents_, reader_webplugininfo_, bar);
|
| - return;
|
| + delegate =
|
| + new PDFEnableAdobeReaderPromptDelegate(tab_contents_->profile());
|
| }
|
|
|
| - OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL);
|
| + OpenUsingReader(tab_contents_->web_contents(), reader_webplugininfo_,
|
| + delegate);
|
| }
|
|
|
| void PDFUnsupportedFeaturePromptDelegate::Cancel() {
|
|
|