Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1421)

Unified Diff: chrome/browser/pdf_unsupported_feature.cc

Issue 6278017: If a user chooses to open a PDF with Reader, ask them if they want to do so a... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/tools/chromeactions.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,75 @@
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 @@
}
// 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 @@
const WebPluginInfo& reader_webplugininfo)
: InterstitialPage(tab, false, tab->GetURL()),
reader_webplugininfo_(reader_webplugininfo) {
+ UserMetrics::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown"));
}
protected:
@@ -92,14 +179,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 +218,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 +232,9 @@
reader_vulnerable_ = true;
}
}
+ } else {
+ UserMetrics::RecordAction(
+ UserMetricsAction("PDF_InstallReaderInfoBarShown"));
}
}
@@ -145,16 +242,53 @@
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 @@
return string16();
}
}
+
virtual string16 GetMessageText() const {
return l10n_util::GetStringUTF16(reader_installed_ ?
IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED :
@@ -176,23 +311,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 +327,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;
+
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 @@
}
}
- // 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));
}
« no previous file with comments | « no previous file | chrome/tools/chromeactions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698