Chromium Code Reviews| Index: chrome/browser/pdf_unsupported_feature.cc |
| =================================================================== |
| --- chrome/browser/pdf_unsupported_feature.cc (revision 72573) |
| +++ chrome/browser/pdf_unsupported_feature.cc (working copy) |
| @@ -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,65 @@ |
| 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")); |
|
Chris Evans
2011/01/26 23:31:30
Will this style of linebreak match the regex in ex
jam
2011/01/26 23:45:57
ah, good point. i forgot to run the script to ver
|
| + } |
| + |
| + // ConfirmInfoBarDelegate |
| + virtual void InfoBarClosed() { |
|
Chris Evans
2011/01/26 23:31:30
Do you want to UMA the act of closing this bar?
jam
2011/01/26 23:45:57
that's done in virtual bool Cancel() {
|
| + delete this; |
| + } |
|
Chris Evans
2011/01/26 23:31:30
Style: newline here?
jam
2011/01/26 23:45:57
Done.
|
| + virtual Type GetInfoBarType() { |
|
Chris Evans
2011/01/26 23:31:30
I think you're missing a const -- wrong overload?
jam
2011/01/26 23:45:57
good catch, done
|
| + 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); |
|
Chris Evans
2011/01/26 23:31:30
This does not seem be to be defined in this CL?
We
jam
2011/01/26 23:45:57
it was checked in earlier.
|
| + } |
| + |
| + 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 +99,30 @@ |
| } |
| // 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(); |
| + |
| + if (old_delegate) { |
| + tab->ReplaceInfoBar( |
| + old_delegate, new PDFEnableAdobeReaderConfirmInfoBarDelegate(tab)); |
|
Chris Evans
2011/01/26 23:31:30
Do the common construction of that object once, ou
jam
2011/01/26 23:45:57
Done.
|
| + } else { |
| + tab->AddInfoBar(new PDFEnableAdobeReaderConfirmInfoBarDelegate(tab)); |
| + } |
| } |
| // An interstitial to be used when the user chooses to open a PDF using Adobe |
| @@ -58,6 +134,7 @@ |
| const WebPluginInfo& reader_webplugininfo) |
| : InterstitialPage(tab, false, tab->GetURL()), |
| reader_webplugininfo_(reader_webplugininfo) { |
| + UserMetrics::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); |
| } |
| protected: |
| @@ -92,14 +169,20 @@ |
| 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 +208,7 @@ |
| 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 +222,9 @@ |
| reader_vulnerable_ = true; |
| } |
| } |
| + } else { |
| + UserMetrics::RecordAction(UserMetricsAction( |
| + "PDF_InstallReaderInfoBarShown")); |
| } |
| } |
| @@ -149,7 +236,35 @@ |
| 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 { |
| @@ -176,23 +291,6 @@ |
| } |
| 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 +307,16 @@ |
| // 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; |
|
Chris Evans
2011/01/26 23:31:30
Is there a command line flag for disabling this? I
jam
2011/01/26 23:45:57
this code is doing exactly what you're asking for
|
| + |
| 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 +324,6 @@ |
| } |
| } |
| - // 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)); |
| } |