| Index: chrome/browser/pdf_unsupported_feature.cc
|
| ===================================================================
|
| --- chrome/browser/pdf_unsupported_feature.cc (revision 84141)
|
| +++ chrome/browser/pdf_unsupported_feature.cc (working copy)
|
| @@ -42,86 +42,82 @@
|
| // 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 PDFEnableAdobeReaderConfirmInfoBarDelegate
|
| - : public ConfirmInfoBarDelegate {
|
| +class PDFEnableAdobeReaderInfoBarDelegate : public ConfirmInfoBarDelegate {
|
| public:
|
| - PDFEnableAdobeReaderConfirmInfoBarDelegate(
|
| - TabContents* tab_contents)
|
| - : ConfirmInfoBarDelegate(tab_contents),
|
| - tab_contents_(tab_contents) {
|
| - UserMetrics::RecordAction(
|
| - UserMetricsAction("PDF_EnableReaderInfoBarShown"));
|
| - }
|
| + explicit PDFEnableAdobeReaderInfoBarDelegate(TabContents* tab_contents);
|
| + virtual ~PDFEnableAdobeReaderInfoBarDelegate();
|
|
|
| // ConfirmInfoBarDelegate
|
| - virtual void InfoBarClosed() {
|
| - delete this;
|
| - }
|
| + virtual void InfoBarDismissed() OVERRIDE;
|
| + virtual Type GetInfoBarType() const OVERRIDE;
|
| + virtual bool Accept() OVERRIDE;
|
| + virtual bool Cancel() OVERRIDE;
|
| + virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
|
| + virtual string16 GetMessageText() const OVERRIDE;
|
|
|
| - virtual void InfoBarDismissed() {
|
| - OnNo();
|
| - }
|
| + private:
|
| + void OnYes();
|
| + void OnNo();
|
|
|
| - virtual Type GetInfoBarType() const {
|
| - return PAGE_ACTION_TYPE;
|
| - }
|
| + TabContents* tab_contents_;
|
|
|
| - virtual bool Accept() {
|
| - tab_contents_->profile()->GetPrefs()->SetBoolean(
|
| - prefs::kPluginsShowSetReaderDefaultInfobar, false);
|
| - return OnNo();
|
| - }
|
| + DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderInfoBarDelegate);
|
| +};
|
|
|
| - virtual bool Cancel() {
|
| - return OnYes();
|
| - }
|
| +PDFEnableAdobeReaderInfoBarDelegate::PDFEnableAdobeReaderInfoBarDelegate(
|
| + TabContents* tab_contents)
|
| + : ConfirmInfoBarDelegate(tab_contents),
|
| + tab_contents_(tab_contents) {
|
| + UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarShown"));
|
| +}
|
|
|
| - virtual int GetButtons() const {
|
| - return BUTTON_OK | BUTTON_CANCEL;
|
| - }
|
| +PDFEnableAdobeReaderInfoBarDelegate::~PDFEnableAdobeReaderInfoBarDelegate() {
|
| +}
|
|
|
| - virtual string16 GetButtonLabel(InfoBarButton button) const {
|
| - switch (button) {
|
| - case BUTTON_OK:
|
| - return l10n_util::GetStringUTF16(
|
| - IDS_PDF_INFOBAR_NEVER_USE_READER_BUTTON);
|
| - case BUTTON_CANCEL:
|
| - return l10n_util::GetStringUTF16(
|
| - IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON);
|
| - default:
|
| - // All buttons are labeled above.
|
| - NOTREACHED() << "Bad button id " << button;
|
| - return string16();
|
| - }
|
| - }
|
| +void PDFEnableAdobeReaderInfoBarDelegate::InfoBarDismissed() {
|
| + OnNo();
|
| +}
|
|
|
| - virtual string16 GetMessageText() const {
|
| - return l10n_util::GetStringUTF16(
|
| - IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER);
|
| - }
|
| +InfoBarDelegate::Type
|
| + PDFEnableAdobeReaderInfoBarDelegate::GetInfoBarType() const {
|
| + return PAGE_ACTION_TYPE;
|
| +}
|
|
|
| - private:
|
| - bool OnYes() {
|
| - UserMetrics::RecordAction(
|
| - UserMetricsAction("PDF_EnableReaderInfoBarOK"));
|
| - webkit::npapi::PluginList::Singleton()->EnableGroup(
|
| - false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName));
|
| - webkit::npapi::PluginList::Singleton()->EnableGroup(
|
| - true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName));
|
| - return true;
|
| - }
|
| +bool PDFEnableAdobeReaderInfoBarDelegate::Accept() {
|
| + tab_contents_->profile()->GetPrefs()->SetBoolean(
|
| + prefs::kPluginsShowSetReaderDefaultInfobar, false);
|
| + OnNo();
|
| + return true;
|
| +}
|
|
|
| - bool OnNo() {
|
| - UserMetrics::RecordAction(
|
| - UserMetricsAction("PDF_EnableReaderInfoBarCancel"));
|
| - return true;
|
| - }
|
| +bool PDFEnableAdobeReaderInfoBarDelegate::Cancel() {
|
| + OnYes();
|
| + return true;
|
| +}
|
|
|
| - TabContents* tab_contents_;
|
| +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);
|
| +}
|
|
|
| - DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderConfirmInfoBarDelegate);
|
| -};
|
| +string16 PDFEnableAdobeReaderInfoBarDelegate::GetMessageText() const {
|
| + return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER);
|
| +}
|
|
|
| +void PDFEnableAdobeReaderInfoBarDelegate::OnYes() {
|
| + UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK"));
|
| + webkit::npapi::PluginList::Singleton()->EnableGroup(false,
|
| + ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName));
|
| + webkit::npapi::PluginList::Singleton()->EnableGroup(true,
|
| + ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName));
|
| +}
|
| +
|
| +void PDFEnableAdobeReaderInfoBarDelegate::OnNo() {
|
| + UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel"));
|
| +}
|
| +
|
| // Launch the url to get the latest Adbobe Reader installer.
|
| void OpenReaderUpdateURL(TabContents* tab) {
|
| tab->OpenURL(GURL(kReaderUpdateUrl), GURL(), CURRENT_TAB,
|
| @@ -229,138 +225,129 @@
|
|
|
| // The info bar delegate used to inform the user that we don't support a feature
|
| // in the PDF. See the comment about how we swap buttons for
|
| -// PDFEnableAdobeReaderConfirmInfoBarDelegate.
|
| -class PDFUnsupportedFeatureConfirmInfoBarDelegate
|
| - : public ConfirmInfoBarDelegate {
|
| +// PDFEnableAdobeReaderInfoBarDelegate.
|
| +class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate {
|
| public:
|
| - PDFUnsupportedFeatureConfirmInfoBarDelegate(
|
| - TabContents* tab_contents,
|
| - PluginGroup* reader_group) // NULL if Adobe Reader isn't installed.
|
| - : ConfirmInfoBarDelegate(tab_contents),
|
| - tab_contents_(tab_contents),
|
| - reader_installed_(!!reader_group),
|
| - reader_vulnerable_(false) {
|
| - if (reader_installed_) {
|
| - UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown"));
|
| - std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos();
|
| - DCHECK_EQ(plugins.size(), 1u);
|
| - reader_webplugininfo_ = plugins[0];
|
| + // |reader_group| is NULL if Adobe Reader isn't installed.
|
| + PDFUnsupportedFeatureInfoBarDelegate(TabContents* tab_contents,
|
| + PluginGroup* reader_group);
|
| + virtual ~PDFUnsupportedFeatureInfoBarDelegate();
|
|
|
| - reader_vulnerable_ = reader_group->IsVulnerable();
|
| - if (!reader_vulnerable_) {
|
| - scoped_ptr<Version> version(PluginGroup::CreateVersionFromString(
|
| - reader_webplugininfo_.version));
|
| - if (version.get()) {
|
| - if (version->components()[0] < kMinReaderVersionToUse)
|
| - reader_vulnerable_ = true;
|
| - }
|
| - }
|
| - } else {
|
| - UserMetrics::RecordAction(
|
| - UserMetricsAction("PDF_InstallReaderInfoBarShown"));
|
| - }
|
| - }
|
| -
|
| // ConfirmInfoBarDelegate
|
| - virtual void InfoBarClosed() {
|
| - delete this;
|
| - }
|
| + virtual void InfoBarDismissed() OVERRIDE;
|
| + virtual Type GetInfoBarType() const OVERRIDE;
|
| + virtual bool Accept() OVERRIDE;
|
| + virtual bool Cancel() OVERRIDE;
|
| + virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
|
| + virtual string16 GetMessageText() const OVERRIDE;
|
|
|
| - virtual void InfoBarDismissed() {
|
| - OnNo();
|
| - }
|
| + private:
|
| + bool OnYes();
|
| + void OnNo();
|
|
|
| - virtual Type GetInfoBarType() const {
|
| - return PAGE_ACTION_TYPE;
|
| - }
|
| + TabContents* tab_contents_;
|
| + bool reader_installed_;
|
| + bool reader_vulnerable_;
|
| + WebPluginInfo reader_webplugininfo_;
|
|
|
| - virtual bool Accept() {
|
| - return OnNo();
|
| - }
|
| + DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureInfoBarDelegate);
|
| +};
|
|
|
| - virtual bool Cancel() {
|
| - return OnYes();
|
| +PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate(
|
| + TabContents* tab_contents,
|
| + PluginGroup* reader_group)
|
| + : ConfirmInfoBarDelegate(tab_contents),
|
| + tab_contents_(tab_contents),
|
| + reader_installed_(!!reader_group),
|
| + reader_vulnerable_(false) {
|
| + if (!reader_installed_) {
|
| + UserMetrics::RecordAction(
|
| + UserMetricsAction("PDF_InstallReaderInfoBarShown"));
|
| + return;
|
| }
|
|
|
| - virtual int GetButtons() const {
|
| - return BUTTON_OK | BUTTON_CANCEL;
|
| - }
|
| + UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown"));
|
| + std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos();
|
| + DCHECK_EQ(plugins.size(), 1u);
|
| + reader_webplugininfo_ = plugins[0];
|
|
|
| - virtual string16 GetButtonLabel(InfoBarButton button) const {
|
| - switch (button) {
|
| - case BUTTON_OK:
|
| - return l10n_util::GetStringUTF16(
|
| - IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL);
|
| - case BUTTON_CANCEL:
|
| - return l10n_util::GetStringUTF16(
|
| - IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL);
|
| - default:
|
| - // All buttons are labeled above.
|
| - NOTREACHED() << "Bad button id " << button;
|
| - return string16();
|
| - }
|
| + reader_vulnerable_ = reader_group->IsVulnerable();
|
| + if (!reader_vulnerable_) {
|
| + scoped_ptr<Version> version(PluginGroup::CreateVersionFromString(
|
| + reader_webplugininfo_.version));
|
| + reader_vulnerable_ =
|
| + version.get() && (version->components()[0] < kMinReaderVersionToUse);
|
| }
|
| +}
|
|
|
| - virtual string16 GetMessageText() const {
|
| - return l10n_util::GetStringUTF16(reader_installed_ ?
|
| - IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED :
|
| - IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED);
|
| - }
|
| +PDFUnsupportedFeatureInfoBarDelegate::~PDFUnsupportedFeatureInfoBarDelegate() {
|
| +}
|
|
|
| - private:
|
| - bool OnYes() {
|
| - if (!reader_installed_) {
|
| - UserMetrics::RecordAction(
|
| - UserMetricsAction("PDF_InstallReaderInfoBarOK"));
|
| - OpenReaderUpdateURL(tab_contents_);
|
| - return true;
|
| - }
|
| +void PDFUnsupportedFeatureInfoBarDelegate::InfoBarDismissed() {
|
| + OnNo();
|
| +}
|
|
|
| - UserMetrics::RecordAction(
|
| - UserMetricsAction("PDF_UseReaderInfoBarOK"));
|
| +InfoBarDelegate::Type
|
| + PDFUnsupportedFeatureInfoBarDelegate::GetInfoBarType() const {
|
| + return PAGE_ACTION_TYPE;
|
| +}
|
|
|
| - if (reader_vulnerable_) {
|
| - PDFUnsupportedFeatureInterstitial* interstitial = new
|
| - PDFUnsupportedFeatureInterstitial(
|
| - tab_contents_, reader_webplugininfo_);
|
| - interstitial->Show();
|
| - return true;
|
| - }
|
| +bool PDFUnsupportedFeatureInfoBarDelegate::Accept() {
|
| + OnNo();
|
| + return true;
|
| +}
|
|
|
| - InfoBarDelegate* bar = NULL;
|
| - if (tab_contents_->profile()->GetPrefs()->GetBoolean(
|
| - prefs::kPluginsShowSetReaderDefaultInfobar)) {
|
| - bar = new PDFEnableAdobeReaderConfirmInfoBarDelegate(tab_contents_);
|
| - }
|
| +bool PDFUnsupportedFeatureInfoBarDelegate::Cancel() {
|
| + return OnYes();
|
| +}
|
|
|
| - if (bar) {
|
| - OpenUsingReader(tab_contents_, reader_webplugininfo_, this, bar);
|
| - return false;
|
| - } else {
|
| - OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL);
|
| - return true;
|
| - }
|
| +string16 PDFUnsupportedFeatureInfoBarDelegate::GetButtonLabel(
|
| + InfoBarButton button) const {
|
| + return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
|
| + IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL :
|
| + IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL);
|
| +}
|
| +
|
| +string16 PDFUnsupportedFeatureInfoBarDelegate::GetMessageText() const {
|
| + return l10n_util::GetStringUTF16(reader_installed_ ?
|
| + IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED :
|
| + IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED);
|
| +}
|
| +
|
| +bool PDFUnsupportedFeatureInfoBarDelegate::OnYes() {
|
| + if (!reader_installed_) {
|
| + UserMetrics::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK"));
|
| + OpenReaderUpdateURL(tab_contents_);
|
| + return true;
|
| }
|
|
|
| - bool OnNo() {
|
| - if (reader_installed_) {
|
| - UserMetrics::RecordAction(
|
| - UserMetricsAction("PDF_UseReaderInfoBarCancel"));
|
| - } else {
|
| - UserMetrics::RecordAction(
|
| - UserMetricsAction("PDF_InstallReaderInfoBarCancel"));
|
| - }
|
| + UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK"));
|
| +
|
| + if (reader_vulnerable_) {
|
| + PDFUnsupportedFeatureInterstitial* interstitial =
|
| + new PDFUnsupportedFeatureInterstitial(tab_contents_,
|
| + reader_webplugininfo_);
|
| + interstitial->Show();
|
| return true;
|
| }
|
|
|
| - TabContents* tab_contents_;
|
| - bool reader_installed_;
|
| - bool reader_vulnerable_;
|
| - WebPluginInfo reader_webplugininfo_;
|
| + if (tab_contents_->profile()->GetPrefs()->GetBoolean(
|
| + prefs::kPluginsShowSetReaderDefaultInfobar)) {
|
| + InfoBarDelegate* bar =
|
| + new PDFEnableAdobeReaderInfoBarDelegate(tab_contents_);
|
| + OpenUsingReader(tab_contents_, reader_webplugininfo_, this, bar);
|
| + return false;
|
| + }
|
|
|
| - DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureConfirmInfoBarDelegate);
|
| -};
|
| + OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL);
|
| + return true;
|
| +}
|
|
|
| +void PDFUnsupportedFeatureInfoBarDelegate::OnNo() {
|
| + UserMetrics::RecordAction(UserMetricsAction(reader_installed_ ?
|
| + "PDF_UseReaderInfoBarCancel" : "PDF_InstallReaderInfoBarCancel"));
|
| +}
|
| +
|
| } // namespace
|
|
|
| void PDFHasUnsupportedFeature(TabContents* tab) {
|
| @@ -386,6 +373,5 @@
|
| }
|
| }
|
|
|
| - tab->AddInfoBar(new PDFUnsupportedFeatureConfirmInfoBarDelegate(
|
| - tab, reader_group));
|
| + tab->AddInfoBar(new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group));
|
| }
|
|
|