diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-27 01:16:30 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-27 01:16:30 +0000 |
commit | f9597714f543497fdafabde1a0df9073f113840d (patch) | |
tree | 90f84260198abe059f7a6df065847c646cabbbeb /chrome | |
parent | 3bdd51b06b25a4cb4c88f0e14040bc3846f242d3 (diff) | |
download | chromium_src-f9597714f543497fdafabde1a0df9073f113840d.zip chromium_src-f9597714f543497fdafabde1a0df9073f113840d.tar.gz chromium_src-f9597714f543497fdafabde1a0df9073f113840d.tar.bz2 |
If a user chooses to open a PDF with Reader, ask them if they want to do so always.
Review URL: http://codereview.chromium.org/6278017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72735 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/pdf_unsupported_feature.cc | 170 | ||||
-rw-r--r-- | chrome/tools/chromeactions.txt | 13 |
2 files changed, 157 insertions, 26 deletions
diff --git a/chrome/browser/pdf_unsupported_feature.cc b/chrome/browser/pdf_unsupported_feature.cc index 6c8f217..66a9122 100644 --- a/chrome/browser/pdf_unsupported_feature.cc +++ b/chrome/browser/pdf_unsupported_feature.cc @@ -7,6 +7,7 @@ #include "base/utf_string_conversions.h" #include "base/values.h" #include "base/version.h" +#include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/plugin_service.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" @@ -14,6 +15,7 @@ #include "chrome/browser/tab_contents/interstitial_page.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/jstemplate_builder.h" +#include "chrome/common/pepper_plugin_registry.h" #include "grit/browser_resources.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -31,6 +33,75 @@ static const uint16 kMinReaderVersionToUse = 10; namespace { +// The info bar delegate used to ask the user if they want to use Adobe Reader +// by default. +class PDFEnableAdobeReaderConfirmInfoBarDelegate + : public ConfirmInfoBarDelegate { + public: + PDFEnableAdobeReaderConfirmInfoBarDelegate( + TabContents* tab_contents) + : ConfirmInfoBarDelegate(tab_contents) { + UserMetrics::RecordAction( + UserMetricsAction("PDF_EnableReaderInfoBarShown")); + } + + // ConfirmInfoBarDelegate + virtual void InfoBarClosed() { + delete this; + } + + virtual void InfoBarDismissed() { + Cancel(); + } + + virtual Type GetInfoBarType() const { + return PAGE_ACTION_TYPE; + } + + virtual bool Accept() { + UserMetrics::RecordAction( + UserMetricsAction("PDF_EnableReaderInfoBarOK")); + webkit::npapi::PluginList::Singleton()->EnableGroup( + false, ASCIIToUTF16(PepperPluginRegistry::kPDFPluginName)); + webkit::npapi::PluginList::Singleton()->EnableGroup( + true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); + return true; + } + + virtual bool Cancel() { + UserMetrics::RecordAction( + UserMetricsAction("PDF_EnableReaderInfoBarCancel")); + return true; + } + + virtual int GetButtons() const { + return BUTTON_OK | BUTTON_CANCEL; + } + + virtual string16 GetButtonLabel(InfoBarButton button) const { + switch (button) { + case BUTTON_OK: + return l10n_util::GetStringUTF16( + IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); + case BUTTON_CANCEL: + return l10n_util::GetStringUTF16( + IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); + default: + // All buttons are labeled above. + NOTREACHED() << "Bad button id " << button; + return string16(); + } + } + + virtual string16 GetMessageText() const { + return l10n_util::GetStringUTF16( + IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); + } + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderConfirmInfoBarDelegate); +}; + // Launch the url to get the latest Adbobe Reader installer. void OpenReaderUpdateURL(TabContents* tab) { tab->OpenURL(GURL(PluginGroup::kAdobeReaderUpdateURL), GURL(), CURRENT_TAB, @@ -38,15 +109,30 @@ void OpenReaderUpdateURL(TabContents* tab) { } // Opens the PDF using Adobe Reader. -void OpenUsingReader(TabContents* tab, const WebPluginInfo& reader_plugin) { +void OpenUsingReader(TabContents* tab, + const WebPluginInfo& reader_plugin, + InfoBarDelegate* old_delegate) { PluginService::OverriddenPlugin plugin; plugin.render_process_id = tab->GetRenderProcessHost()->id(); plugin.render_view_id = tab->render_view_host()->routing_id(); plugin.url = tab->GetURL(); plugin.plugin = reader_plugin; + // The plugin is disabled, so enable it to get around the renderer check. + // Also give it a new version so that the renderer doesn't show the blocked + // plugin UI if it's vulnerable, since we already went through the + // interstitial. + plugin.plugin.enabled = WebPluginInfo::USER_ENABLED; + plugin.plugin.version = ASCIIToUTF16("11.0.0.0"); PluginService::GetInstance()->OverridePluginForTab(plugin); tab->render_view_host()->ReloadFrame(); + + InfoBarDelegate* bar = new PDFEnableAdobeReaderConfirmInfoBarDelegate(tab); + if (old_delegate) { + tab->ReplaceInfoBar(old_delegate, bar); + } else { + tab->AddInfoBar(bar); + } } // An interstitial to be used when the user chooses to open a PDF using Adobe @@ -58,6 +144,7 @@ class PDFUnsupportedFeatureInterstitial : public InterstitialPage { const WebPluginInfo& reader_webplugininfo) : InterstitialPage(tab, false, tab->GetURL()), reader_webplugininfo_(reader_webplugininfo) { + UserMetrics::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); } protected: @@ -92,14 +179,20 @@ class PDFUnsupportedFeatureInterstitial : public InterstitialPage { virtual void CommandReceived(const std::string& command) { if (command == "0") { + UserMetrics::RecordAction( + UserMetricsAction("PDF_ReaderInterstitialCancel")); DontProceed(); return; } if (command == "1") { + UserMetrics::RecordAction( + UserMetricsAction("PDF_ReaderInterstitialUpdate")); OpenReaderUpdateURL(tab()); } else if (command == "2") { - OpenUsingReader(tab(), reader_webplugininfo_); + UserMetrics::RecordAction( + UserMetricsAction("PDF_ReaderInterstitialIgnore")); + OpenUsingReader(tab(), reader_webplugininfo_, NULL); } else { NOTREACHED(); } @@ -125,6 +218,7 @@ class PDFUnsupportedFeatureConfirmInfoBarDelegate 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]; @@ -138,6 +232,9 @@ class PDFUnsupportedFeatureConfirmInfoBarDelegate reader_vulnerable_ = true; } } + } else { + UserMetrics::RecordAction( + UserMetricsAction("PDF_InstallReaderInfoBarShown")); } } @@ -145,16 +242,53 @@ class PDFUnsupportedFeatureConfirmInfoBarDelegate virtual void InfoBarClosed() { delete this; } - virtual Type GetInfoBarType() { + + virtual void InfoBarDismissed() { + Cancel(); + } + + virtual Type GetInfoBarType() const { return PAGE_ACTION_TYPE; } + virtual bool Accept() { - LaunchReader(); + if (!reader_installed_) { + UserMetrics::RecordAction( + UserMetricsAction("PDF_InstallReaderInfoBarOK")); + OpenReaderUpdateURL(tab_contents_); + return true; + } + + UserMetrics::RecordAction( + UserMetricsAction("PDF_UseReaderInfoBarOK")); + + if (reader_vulnerable_) { + PDFUnsupportedFeatureInterstitial* interstitial = new + PDFUnsupportedFeatureInterstitial( + tab_contents_, reader_webplugininfo_); + interstitial->Show(); + return true; + } + + OpenUsingReader(tab_contents_, reader_webplugininfo_, this); + return false; + } + + virtual bool Cancel() { + if (reader_installed_) { + UserMetrics::RecordAction( + UserMetricsAction("PDF_UseReaderInfoBarCancel")); + } else { + UserMetrics::RecordAction( + UserMetricsAction("PDF_InstallReaderInfoBarCancel")); + } return true; } + virtual int GetButtons() const { return BUTTON_OK | BUTTON_CANCEL; } + virtual string16 GetButtonLabel(InfoBarButton button) const { switch (button) { case BUTTON_OK: @@ -169,6 +303,7 @@ class PDFUnsupportedFeatureConfirmInfoBarDelegate return string16(); } } + virtual string16 GetMessageText() const { return l10n_util::GetStringUTF16(reader_installed_ ? IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED : @@ -176,23 +311,6 @@ class PDFUnsupportedFeatureConfirmInfoBarDelegate } private: - void LaunchReader() { - if (!reader_installed_) { - OpenReaderUpdateURL(tab_contents_); - return; - } - - if (reader_vulnerable_) { - PDFUnsupportedFeatureInterstitial* interstitial = new - PDFUnsupportedFeatureInterstitial( - tab_contents_, reader_webplugininfo_); - interstitial->Show(); - return; - } - - OpenUsingReader(tab_contents_, reader_webplugininfo_); - } - TabContents* tab_contents_; bool reader_installed_; bool reader_vulnerable_; @@ -209,12 +327,16 @@ void PDFHasUnsupportedFeature(TabContents* tab) { // externally since Adobe Reader doesn't work inside Chrome. return; #endif + string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); + + // If the Reader plugin is disabled by policy, don't prompt them. + if (PluginGroup::IsPluginNameDisabledByPolicy(reader_group_name)) + return; PluginGroup* reader_group = NULL; std::vector<PluginGroup> plugin_groups; PluginList::Singleton()->GetPluginGroups( false, &plugin_groups); - string16 reader_group_name(UTF8ToUTF16(PluginGroup::kAdobeReaderGroupName)); for (size_t i = 0; i < plugin_groups.size(); ++i) { if (plugin_groups[i].GetGroupName() == reader_group_name) { reader_group = &plugin_groups[i]; @@ -222,10 +344,6 @@ void PDFHasUnsupportedFeature(TabContents* tab) { } } - // If the plugin is disabled by policy or by the user, don't prompt them. - if (reader_group && !reader_group->Enabled()) - return; - tab->AddInfoBar(new PDFUnsupportedFeatureConfirmInfoBarDelegate( tab, reader_group)); } diff --git a/chrome/tools/chromeactions.txt b/chrome/tools/chromeactions.txt index bf10b32..d58c665 100644 --- a/chrome/tools/chromeactions.txt +++ b/chrome/tools/chromeactions.txt @@ -947,6 +947,16 @@ 0x99ed44568e5ff51a PDF.ZoomFromBrowser 0x1d57434947820665 PDF.ZoomInButton 0x40ca10ced9d81d17 PDF.ZoomOutButton +0xcf6b6026dc11987b PDF_EnableReaderInfoBarCancel +0x00a3a874d94e0ae5 PDF_EnableReaderInfoBarOK +0x8cae37cf015a06ba PDF_EnableReaderInfoBarShown +0x1f8608be3f132d3f PDF_InstallReaderInfoBarCancel +0x020d4194a7e4b5e1 PDF_InstallReaderInfoBarOK +0xe8d7c93dac04f552 PDF_InstallReaderInfoBarShown +0xbd058843faaa1507 PDF_ReaderInterstitialCancel +0x673c5fad6fc74eac PDF_ReaderInterstitialIgnore +0xe1cd8e7ef514360d PDF_ReaderInterstitialShown +0x4bde610f2543fbd7 PDF_ReaderInterstitialUpdate 0x0b951f22f9dff291 PDF_Unsupported_3D 0x3c012d5822815c63 PDF_Unsupported_Attachment 0x75035f67192c6952 PDF_Unsupported_Digital_Signature @@ -959,6 +969,9 @@ 0xb7474a7496f9a77e PDF_Unsupported_Shared_Review 0x6efe497913838ea5 PDF_Unsupported_Sound 0x08640e2d5578cf94 PDF_Unsupported_XFA +0xde70e21d95b52c83 PDF_UseReaderInfoBarCancel +0xc35f4595bbf2a0fa PDF_UseReaderInfoBarOK +0xb7334d4097ba87ef PDF_UseReaderInfoBarShown 0xee3677bcca83ece9 PageDown 0x9b869c510c75c582 PageUp 0x9ba3ff80fde405cd PasswordManager_Disabled |