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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/tools/chromeactions.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/pdf_unsupported_feature.h" 5 #include "chrome/browser/pdf_unsupported_feature.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "base/version.h" 9 #include "base/version.h"
10 #include "chrome/browser/metrics/user_metrics.h"
10 #include "chrome/browser/plugin_service.h" 11 #include "chrome/browser/plugin_service.h"
11 #include "chrome/browser/renderer_host/render_process_host.h" 12 #include "chrome/browser/renderer_host/render_process_host.h"
12 #include "chrome/browser/renderer_host/render_view_host.h" 13 #include "chrome/browser/renderer_host/render_view_host.h"
13 #include "chrome/browser/tab_contents/infobar_delegate.h" 14 #include "chrome/browser/tab_contents/infobar_delegate.h"
14 #include "chrome/browser/tab_contents/interstitial_page.h" 15 #include "chrome/browser/tab_contents/interstitial_page.h"
15 #include "chrome/browser/tab_contents/tab_contents.h" 16 #include "chrome/browser/tab_contents/tab_contents.h"
16 #include "chrome/common/jstemplate_builder.h" 17 #include "chrome/common/jstemplate_builder.h"
18 #include "chrome/common/pepper_plugin_registry.h"
17 #include "grit/browser_resources.h" 19 #include "grit/browser_resources.h"
18 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
21 #include "webkit/plugins/npapi/plugin_group.h" 23 #include "webkit/plugins/npapi/plugin_group.h"
22 #include "webkit/plugins/npapi/plugin_list.h" 24 #include "webkit/plugins/npapi/plugin_list.h"
23 #include "webkit/plugins/npapi/webplugininfo.h" 25 #include "webkit/plugins/npapi/webplugininfo.h"
24 26
25 using webkit::npapi::PluginGroup; 27 using webkit::npapi::PluginGroup;
26 using webkit::npapi::PluginList; 28 using webkit::npapi::PluginList;
27 using webkit::npapi::WebPluginInfo; 29 using webkit::npapi::WebPluginInfo;
28 30
29 // Only launch Adobe Reader X or later. 31 // Only launch Adobe Reader X or later.
30 static const uint16 kMinReaderVersionToUse = 10; 32 static const uint16 kMinReaderVersionToUse = 10;
31 33
32 namespace { 34 namespace {
33 35
36 // The info bar delegate used to ask the user if they want to use Adobe Reader
37 // by default.
38 class PDFEnableAdobeReaderConfirmInfoBarDelegate
39 : public ConfirmInfoBarDelegate {
40 public:
41 PDFEnableAdobeReaderConfirmInfoBarDelegate(
42 TabContents* tab_contents)
43 : ConfirmInfoBarDelegate(tab_contents) {
44 UserMetrics::RecordAction(
45 UserMetricsAction("PDF_EnableReaderInfoBarShown"));
46 }
47
48 // ConfirmInfoBarDelegate
49 virtual void InfoBarClosed() {
Chris Evans 2011/01/27 00:03:27 I still think this is a different user action (use
jam 2011/01/27 00:31:02 ah, I thought Cancel() would get closed in that ca
50 delete this;
51 }
52
53 virtual Type GetInfoBarType() const {
54 return PAGE_ACTION_TYPE;
55 }
56
57 virtual bool Accept() {
58 UserMetrics::RecordAction(
59 UserMetricsAction("PDF_EnableReaderInfoBarOK"));
Chris Evans 2011/01/27 00:03:27 I'm not sure which way around the buttons are. Can
jam 2011/01/27 00:31:02 Yes No X
60 webkit::npapi::PluginList::Singleton()->EnableGroup(
61 false, ASCIIToUTF16(PepperPluginRegistry::kPDFPluginName));
62 webkit::npapi::PluginList::Singleton()->EnableGroup(
63 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName));
64 return true;
65 }
66
67 virtual bool Cancel() {
68 UserMetrics::RecordAction(
69 UserMetricsAction("PDF_EnableReaderInfoBarCancel"));
70 return true;
71 }
72
73 virtual int GetButtons() const {
74 return BUTTON_OK | BUTTON_CANCEL;
75 }
76
77 virtual string16 GetButtonLabel(InfoBarButton button) const {
78 switch (button) {
79 case BUTTON_OK:
80 return l10n_util::GetStringUTF16(
81 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL);
82 case BUTTON_CANCEL:
83 return l10n_util::GetStringUTF16(
84 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL);
85 default:
86 // All buttons are labeled above.
87 NOTREACHED() << "Bad button id " << button;
88 return string16();
89 }
90 }
Chris Evans 2011/01/27 00:03:27 Newline
jam 2011/01/27 00:31:02 Done.
91 virtual string16 GetMessageText() const {
92 return l10n_util::GetStringUTF16(
93 IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER);
Chris Evans 2011/01/27 00:03:27 "Always use Adobe Reader to open PDF files?" -- as
jam 2011/01/27 00:31:02 Sorry I don't think this is the place to change th
94 }
95
96 private:
97 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderConfirmInfoBarDelegate);
98 };
99
34 // Launch the url to get the latest Adbobe Reader installer. 100 // Launch the url to get the latest Adbobe Reader installer.
35 void OpenReaderUpdateURL(TabContents* tab) { 101 void OpenReaderUpdateURL(TabContents* tab) {
36 tab->OpenURL(GURL(PluginGroup::kAdobeReaderUpdateURL), GURL(), CURRENT_TAB, 102 tab->OpenURL(GURL(PluginGroup::kAdobeReaderUpdateURL), GURL(), CURRENT_TAB,
37 PageTransition::LINK); 103 PageTransition::LINK);
38 } 104 }
39 105
40 // Opens the PDF using Adobe Reader. 106 // Opens the PDF using Adobe Reader.
41 void OpenUsingReader(TabContents* tab, const WebPluginInfo& reader_plugin) { 107 void OpenUsingReader(TabContents* tab,
108 const WebPluginInfo& reader_plugin,
109 InfoBarDelegate* old_delegate) {
42 PluginService::OverriddenPlugin plugin; 110 PluginService::OverriddenPlugin plugin;
43 plugin.render_process_id = tab->GetRenderProcessHost()->id(); 111 plugin.render_process_id = tab->GetRenderProcessHost()->id();
44 plugin.render_view_id = tab->render_view_host()->routing_id(); 112 plugin.render_view_id = tab->render_view_host()->routing_id();
45 plugin.url = tab->GetURL(); 113 plugin.url = tab->GetURL();
46 plugin.plugin = reader_plugin; 114 plugin.plugin = reader_plugin;
115 // The plugin is disabled, so enable it to get around the renderer check.
116 // Also give it a new version so that the renderer doesn't show the blocked
117 // plugin UI if it's vulnerable, since we already went through the
118 // interstitial.
119 plugin.plugin.enabled = WebPluginInfo::USER_ENABLED;
120 plugin.plugin.version = ASCIIToUTF16("11.0.0.0");
Chris Evans 2011/01/27 00:03:27 One day, that will be a vulnerable version in the
jam 2011/01/27 00:31:02 Once that happens, we'll know pretty quickly (i.e.
47 121
48 PluginService::GetInstance()->OverridePluginForTab(plugin); 122 PluginService::GetInstance()->OverridePluginForTab(plugin);
49 tab->render_view_host()->ReloadFrame(); 123 tab->render_view_host()->ReloadFrame();
124
125 InfoBarDelegate* bar = new PDFEnableAdobeReaderConfirmInfoBarDelegate(tab);
126 if (old_delegate) {
127 tab->ReplaceInfoBar(old_delegate, bar);
128 } else {
129 tab->AddInfoBar(bar);
130 }
50 } 131 }
51 132
52 // An interstitial to be used when the user chooses to open a PDF using Adobe 133 // An interstitial to be used when the user chooses to open a PDF using Adobe
53 // Reader, but it is out of date. 134 // Reader, but it is out of date.
54 class PDFUnsupportedFeatureInterstitial : public InterstitialPage { 135 class PDFUnsupportedFeatureInterstitial : public InterstitialPage {
55 public: 136 public:
56 PDFUnsupportedFeatureInterstitial( 137 PDFUnsupportedFeatureInterstitial(
57 TabContents* tab, 138 TabContents* tab,
58 const WebPluginInfo& reader_webplugininfo) 139 const WebPluginInfo& reader_webplugininfo)
59 : InterstitialPage(tab, false, tab->GetURL()), 140 : InterstitialPage(tab, false, tab->GetURL()),
60 reader_webplugininfo_(reader_webplugininfo) { 141 reader_webplugininfo_(reader_webplugininfo) {
142 UserMetrics::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown"));
61 } 143 }
62 144
63 protected: 145 protected:
64 // InterstitialPage implementation. 146 // InterstitialPage implementation.
65 virtual std::string GetHTMLContents() { 147 virtual std::string GetHTMLContents() {
66 DictionaryValue strings; 148 DictionaryValue strings;
67 strings.SetString( 149 strings.SetString(
68 "title", 150 "title",
69 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_TITLE)); 151 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_TITLE));
70 strings.SetString( 152 strings.SetString(
(...skipping 14 matching lines...) Expand all
85 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_CANCEL)); 167 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_CANCEL));
86 168
87 base::StringPiece html(ResourceBundle::GetSharedInstance(). 169 base::StringPiece html(ResourceBundle::GetSharedInstance().
88 GetRawDataResource(IDR_READER_OUT_OF_DATE_HTML)); 170 GetRawDataResource(IDR_READER_OUT_OF_DATE_HTML));
89 171
90 return jstemplate_builder::GetI18nTemplateHtml(html, &strings); 172 return jstemplate_builder::GetI18nTemplateHtml(html, &strings);
91 } 173 }
92 174
93 virtual void CommandReceived(const std::string& command) { 175 virtual void CommandReceived(const std::string& command) {
94 if (command == "0") { 176 if (command == "0") {
177 UserMetrics::RecordAction(
178 UserMetricsAction("PDF_ReaderInterstitialCancel"));
95 DontProceed(); 179 DontProceed();
96 return; 180 return;
97 } 181 }
98 182
99 if (command == "1") { 183 if (command == "1") {
184 UserMetrics::RecordAction(
185 UserMetricsAction("PDF_ReaderInterstitialUpdate"));
100 OpenReaderUpdateURL(tab()); 186 OpenReaderUpdateURL(tab());
101 } else if (command == "2") { 187 } else if (command == "2") {
102 OpenUsingReader(tab(), reader_webplugininfo_); 188 UserMetrics::RecordAction(
189 UserMetricsAction("PDF_ReaderInterstitialIgnore"));
190 OpenUsingReader(tab(), reader_webplugininfo_, NULL);
103 } else { 191 } else {
104 NOTREACHED(); 192 NOTREACHED();
105 } 193 }
106 Proceed(); 194 Proceed();
107 } 195 }
108 196
109 private: 197 private:
110 WebPluginInfo reader_webplugininfo_; 198 WebPluginInfo reader_webplugininfo_;
111 199
112 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); 200 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial);
113 }; 201 };
114 202
115 // The info bar delegate used to inform the user that we don't support a feature 203 // The info bar delegate used to inform the user that we don't support a feature
116 // in the PDF. 204 // in the PDF.
117 class PDFUnsupportedFeatureConfirmInfoBarDelegate 205 class PDFUnsupportedFeatureConfirmInfoBarDelegate
118 : public ConfirmInfoBarDelegate { 206 : public ConfirmInfoBarDelegate {
119 public: 207 public:
120 PDFUnsupportedFeatureConfirmInfoBarDelegate( 208 PDFUnsupportedFeatureConfirmInfoBarDelegate(
121 TabContents* tab_contents, 209 TabContents* tab_contents,
122 PluginGroup* reader_group) // NULL if Adobe Reader isn't installed. 210 PluginGroup* reader_group) // NULL if Adobe Reader isn't installed.
123 : ConfirmInfoBarDelegate(tab_contents), 211 : ConfirmInfoBarDelegate(tab_contents),
124 tab_contents_(tab_contents), 212 tab_contents_(tab_contents),
125 reader_installed_(!!reader_group), 213 reader_installed_(!!reader_group),
126 reader_vulnerable_(false) { 214 reader_vulnerable_(false) {
127 if (reader_installed_) { 215 if (reader_installed_) {
216 UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown"));
128 std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos(); 217 std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos();
129 DCHECK_EQ(plugins.size(), 1u); 218 DCHECK_EQ(plugins.size(), 1u);
130 reader_webplugininfo_ = plugins[0]; 219 reader_webplugininfo_ = plugins[0];
131 220
132 reader_vulnerable_ = reader_group->IsVulnerable(); 221 reader_vulnerable_ = reader_group->IsVulnerable();
133 if (!reader_vulnerable_) { 222 if (!reader_vulnerable_) {
134 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString( 223 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString(
135 reader_webplugininfo_.version)); 224 reader_webplugininfo_.version));
136 if (version.get()) { 225 if (version.get()) {
137 if (version->components()[0] < kMinReaderVersionToUse) 226 if (version->components()[0] < kMinReaderVersionToUse)
138 reader_vulnerable_ = true; 227 reader_vulnerable_ = true;
139 } 228 }
140 } 229 }
230 } else {
231 UserMetrics::RecordAction(
232 UserMetricsAction("PDF_InstallReaderInfoBarShown"));
141 } 233 }
142 } 234 }
143 235
144 // ConfirmInfoBarDelegate 236 // ConfirmInfoBarDelegate
145 virtual void InfoBarClosed() { 237 virtual void InfoBarClosed() {
146 delete this; 238 delete this;
147 } 239 }
148 virtual Type GetInfoBarType() { 240
241 virtual Type GetInfoBarType() const {
149 return PAGE_ACTION_TYPE; 242 return PAGE_ACTION_TYPE;
150 } 243 }
244
151 virtual bool Accept() { 245 virtual bool Accept() {
Chris Evans 2011/01/27 00:03:27 As per the other infobar, please can we make sure
jam 2011/01/27 00:31:02 ditto
152 LaunchReader(); 246 if (!reader_installed_) {
247 UserMetrics::RecordAction(
248 UserMetricsAction("PDF_InstallReaderInfoBarOK"));
249 OpenReaderUpdateURL(tab_contents_);
250 return true;
251 }
252
253 UserMetrics::RecordAction(
254 UserMetricsAction("PDF_UseReaderInfoBarOK"));
255
256 if (reader_vulnerable_) {
257 PDFUnsupportedFeatureInterstitial* interstitial = new
258 PDFUnsupportedFeatureInterstitial(
259 tab_contents_, reader_webplugininfo_);
260 interstitial->Show();
261 return true;
262 }
263
264 OpenUsingReader(tab_contents_, reader_webplugininfo_, this);
265 return false;
266 }
267
268 virtual bool Cancel() {
269 if (reader_installed_) {
270 UserMetrics::RecordAction(
271 UserMetricsAction("PDF_UseReaderInfoBarCancel"));
272 } else {
273 UserMetrics::RecordAction(
274 UserMetricsAction("PDF_InstallReaderInfoBarCancel"));
275 }
153 return true; 276 return true;
154 } 277 }
278
155 virtual int GetButtons() const { 279 virtual int GetButtons() const {
156 return BUTTON_OK | BUTTON_CANCEL; 280 return BUTTON_OK | BUTTON_CANCEL;
157 } 281 }
282
158 virtual string16 GetButtonLabel(InfoBarButton button) const { 283 virtual string16 GetButtonLabel(InfoBarButton button) const {
159 switch (button) { 284 switch (button) {
160 case BUTTON_OK: 285 case BUTTON_OK:
161 return l10n_util::GetStringUTF16( 286 return l10n_util::GetStringUTF16(
162 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); 287 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL);
163 case BUTTON_CANCEL: 288 case BUTTON_CANCEL:
164 return l10n_util::GetStringUTF16( 289 return l10n_util::GetStringUTF16(
165 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); 290 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL);
166 default: 291 default:
167 // All buttons are labeled above. 292 // All buttons are labeled above.
168 NOTREACHED() << "Bad button id " << button; 293 NOTREACHED() << "Bad button id " << button;
169 return string16(); 294 return string16();
170 } 295 }
171 } 296 }
297
172 virtual string16 GetMessageText() const { 298 virtual string16 GetMessageText() const {
173 return l10n_util::GetStringUTF16(reader_installed_ ? 299 return l10n_util::GetStringUTF16(reader_installed_ ?
174 IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED : 300 IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED :
175 IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED); 301 IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED);
176 } 302 }
177 303
178 private: 304 private:
179 void LaunchReader() {
180 if (!reader_installed_) {
181 OpenReaderUpdateURL(tab_contents_);
182 return;
183 }
184
185 if (reader_vulnerable_) {
186 PDFUnsupportedFeatureInterstitial* interstitial = new
187 PDFUnsupportedFeatureInterstitial(
188 tab_contents_, reader_webplugininfo_);
189 interstitial->Show();
190 return;
191 }
192
193 OpenUsingReader(tab_contents_, reader_webplugininfo_);
194 }
195
196 TabContents* tab_contents_; 305 TabContents* tab_contents_;
197 bool reader_installed_; 306 bool reader_installed_;
198 bool reader_vulnerable_; 307 bool reader_vulnerable_;
199 WebPluginInfo reader_webplugininfo_; 308 WebPluginInfo reader_webplugininfo_;
200 309
201 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureConfirmInfoBarDelegate); 310 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureConfirmInfoBarDelegate);
202 }; 311 };
203 312
204 } // namespace 313 } // namespace
205 314
206 void PDFHasUnsupportedFeature(TabContents* tab) { 315 void PDFHasUnsupportedFeature(TabContents* tab) {
207 #if !defined(OS_WIN) 316 #if !defined(OS_WIN)
208 // Only works for Windows for now. For Mac, we'll have to launch the file 317 // Only works for Windows for now. For Mac, we'll have to launch the file
209 // externally since Adobe Reader doesn't work inside Chrome. 318 // externally since Adobe Reader doesn't work inside Chrome.
210 return; 319 return;
211 #endif 320 #endif
321 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName));
322
323 // If the Reader plugin is disabled by policy, don't prompt them.
324 if (PluginGroup::IsPluginNameDisabledByPolicy(reader_group_name))
325 return;
Chris Evans 2011/01/27 00:03:27 I guess what I was hoping for is some command line
jam 2011/01/27 00:31:02 I guess I don't see the scenario where a company w
212 326
213 PluginGroup* reader_group = NULL; 327 PluginGroup* reader_group = NULL;
214 std::vector<PluginGroup> plugin_groups; 328 std::vector<PluginGroup> plugin_groups;
215 PluginList::Singleton()->GetPluginGroups( 329 PluginList::Singleton()->GetPluginGroups(
216 false, &plugin_groups); 330 false, &plugin_groups);
217 string16 reader_group_name(UTF8ToUTF16(PluginGroup::kAdobeReaderGroupName));
218 for (size_t i = 0; i < plugin_groups.size(); ++i) { 331 for (size_t i = 0; i < plugin_groups.size(); ++i) {
219 if (plugin_groups[i].GetGroupName() == reader_group_name) { 332 if (plugin_groups[i].GetGroupName() == reader_group_name) {
220 reader_group = &plugin_groups[i]; 333 reader_group = &plugin_groups[i];
221 break; 334 break;
222 } 335 }
223 } 336 }
224 337
225 // If the plugin is disabled by policy or by the user, don't prompt them.
226 if (reader_group && !reader_group->Enabled())
227 return;
228
229 tab->AddInfoBar(new PDFUnsupportedFeatureConfirmInfoBarDelegate( 338 tab->AddInfoBar(new PDFUnsupportedFeatureConfirmInfoBarDelegate(
230 tab, reader_group)); 339 tab, reader_group));
231 } 340 }
OLDNEW
« 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