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

Side by Side Diff: chrome/browser/pdf_unsupported_feature.cc

Issue 6926001: Replace the virtual InfoBarDelegate::InfoBarClosed() function with a non-virtual one. This is a ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
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/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
(...skipping 24 matching lines...) Expand all
35 35
36 // Only launch Adobe Reader X or later. 36 // Only launch Adobe Reader X or later.
37 static const uint16 kMinReaderVersionToUse = 10; 37 static const uint16 kMinReaderVersionToUse = 10;
38 38
39 static const char kReaderUpdateUrl[] = 39 static const char kReaderUpdateUrl[] =
40 "http://www.adobe.com/go/getreader_chrome"; 40 "http://www.adobe.com/go/getreader_chrome";
41 41
42 // The info bar delegate used to ask the user if they want to use Adobe Reader 42 // The info bar delegate used to ask the user if they want to use Adobe Reader
43 // by default. We want the infobar to have [No][Yes], so we swap the text on 43 // by default. We want the infobar to have [No][Yes], so we swap the text on
44 // the buttons, and the meaning of the delegate callbacks. 44 // the buttons, and the meaning of the delegate callbacks.
45 class PDFEnableAdobeReaderConfirmInfoBarDelegate 45 class PDFEnableAdobeReaderInfoBarDelegate : public ConfirmInfoBarDelegate {
46 : public ConfirmInfoBarDelegate {
47 public: 46 public:
48 PDFEnableAdobeReaderConfirmInfoBarDelegate( 47 explicit PDFEnableAdobeReaderInfoBarDelegate(TabContents* tab_contents);
49 TabContents* tab_contents) 48 virtual ~PDFEnableAdobeReaderInfoBarDelegate();
50 : ConfirmInfoBarDelegate(tab_contents),
51 tab_contents_(tab_contents) {
52 UserMetrics::RecordAction(
53 UserMetricsAction("PDF_EnableReaderInfoBarShown"));
54 }
55 49
56 // ConfirmInfoBarDelegate 50 // ConfirmInfoBarDelegate
57 virtual void InfoBarClosed() { 51 virtual void InfoBarDismissed() OVERRIDE;
58 delete this; 52 virtual Type GetInfoBarType() const OVERRIDE;
59 } 53 virtual bool Accept() OVERRIDE;
60 54 virtual bool Cancel() OVERRIDE;
61 virtual void InfoBarDismissed() { 55 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
62 OnNo(); 56 virtual string16 GetMessageText() const OVERRIDE;
63 }
64
65 virtual Type GetInfoBarType() const {
66 return PAGE_ACTION_TYPE;
67 }
68
69 virtual bool Accept() {
70 tab_contents_->profile()->GetPrefs()->SetBoolean(
71 prefs::kPluginsShowSetReaderDefaultInfobar, false);
72 return OnNo();
73 }
74
75 virtual bool Cancel() {
76 return OnYes();
77 }
78
79 virtual int GetButtons() const {
80 return BUTTON_OK | BUTTON_CANCEL;
81 }
82
83 virtual string16 GetButtonLabel(InfoBarButton button) const {
84 switch (button) {
85 case BUTTON_OK:
86 return l10n_util::GetStringUTF16(
87 IDS_PDF_INFOBAR_NEVER_USE_READER_BUTTON);
88 case BUTTON_CANCEL:
89 return l10n_util::GetStringUTF16(
90 IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON);
91 default:
92 // All buttons are labeled above.
93 NOTREACHED() << "Bad button id " << button;
94 return string16();
95 }
96 }
97
98 virtual string16 GetMessageText() const {
99 return l10n_util::GetStringUTF16(
100 IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER);
101 }
102 57
103 private: 58 private:
104 bool OnYes() { 59 void OnYes();
105 UserMetrics::RecordAction( 60 void OnNo();
106 UserMetricsAction("PDF_EnableReaderInfoBarOK"));
107 webkit::npapi::PluginList::Singleton()->EnableGroup(
108 false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName));
109 webkit::npapi::PluginList::Singleton()->EnableGroup(
110 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName));
111 return true;
112 }
113
114 bool OnNo() {
115 UserMetrics::RecordAction(
116 UserMetricsAction("PDF_EnableReaderInfoBarCancel"));
117 return true;
118 }
119 61
120 TabContents* tab_contents_; 62 TabContents* tab_contents_;
121 63
122 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderConfirmInfoBarDelegate); 64 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderInfoBarDelegate);
123 }; 65 };
124 66
67 PDFEnableAdobeReaderInfoBarDelegate::PDFEnableAdobeReaderInfoBarDelegate(
68 TabContents* tab_contents)
69 : ConfirmInfoBarDelegate(tab_contents),
70 tab_contents_(tab_contents) {
71 UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarShown"));
72 }
73
74 PDFEnableAdobeReaderInfoBarDelegate::~PDFEnableAdobeReaderInfoBarDelegate() {
75 }
76
77 void PDFEnableAdobeReaderInfoBarDelegate::InfoBarDismissed() {
78 OnNo();
79 }
80
81 InfoBarDelegate::Type
82 PDFEnableAdobeReaderInfoBarDelegate::GetInfoBarType() const {
83 return PAGE_ACTION_TYPE;
84 }
85
86 bool PDFEnableAdobeReaderInfoBarDelegate::Accept() {
87 tab_contents_->profile()->GetPrefs()->SetBoolean(
88 prefs::kPluginsShowSetReaderDefaultInfobar, false);
89 OnNo();
90 return true;
91 }
92
93 bool PDFEnableAdobeReaderInfoBarDelegate::Cancel() {
94 OnYes();
95 return true;
96 }
97
98 string16 PDFEnableAdobeReaderInfoBarDelegate::GetButtonLabel(
99 InfoBarButton button) const {
100 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
101 IDS_PDF_INFOBAR_NEVER_USE_READER_BUTTON :
102 IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON);
103 }
104
105 string16 PDFEnableAdobeReaderInfoBarDelegate::GetMessageText() const {
106 return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER);
107 }
108
109 void PDFEnableAdobeReaderInfoBarDelegate::OnYes() {
110 UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK"));
111 webkit::npapi::PluginList::Singleton()->EnableGroup(false,
112 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName));
113 webkit::npapi::PluginList::Singleton()->EnableGroup(true,
114 ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName));
115 }
116
117 void PDFEnableAdobeReaderInfoBarDelegate::OnNo() {
118 UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel"));
119 }
120
125 // Launch the url to get the latest Adbobe Reader installer. 121 // Launch the url to get the latest Adbobe Reader installer.
126 void OpenReaderUpdateURL(TabContents* tab) { 122 void OpenReaderUpdateURL(TabContents* tab) {
127 tab->OpenURL(GURL(kReaderUpdateUrl), GURL(), CURRENT_TAB, 123 tab->OpenURL(GURL(kReaderUpdateUrl), GURL(), CURRENT_TAB,
128 PageTransition::LINK); 124 PageTransition::LINK);
129 } 125 }
130 126
131 // Opens the PDF using Adobe Reader. 127 // Opens the PDF using Adobe Reader.
132 void OpenUsingReader(TabContents* tab, 128 void OpenUsingReader(TabContents* tab,
133 const WebPluginInfo& reader_plugin, 129 const WebPluginInfo& reader_plugin,
134 InfoBarDelegate* old_delegate, 130 InfoBarDelegate* old_delegate,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 218 }
223 219
224 private: 220 private:
225 WebPluginInfo reader_webplugininfo_; 221 WebPluginInfo reader_webplugininfo_;
226 222
227 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); 223 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial);
228 }; 224 };
229 225
230 // The info bar delegate used to inform the user that we don't support a feature 226 // The info bar delegate used to inform the user that we don't support a feature
231 // in the PDF. See the comment about how we swap buttons for 227 // in the PDF. See the comment about how we swap buttons for
232 // PDFEnableAdobeReaderConfirmInfoBarDelegate. 228 // PDFEnableAdobeReaderInfoBarDelegate.
233 class PDFUnsupportedFeatureConfirmInfoBarDelegate 229 class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate {
234 : public ConfirmInfoBarDelegate {
235 public: 230 public:
236 PDFUnsupportedFeatureConfirmInfoBarDelegate( 231 // |reader_group| is NULL if Adobe Reader isn't installed.
237 TabContents* tab_contents, 232 PDFUnsupportedFeatureInfoBarDelegate(TabContents* tab_contents,
238 PluginGroup* reader_group) // NULL if Adobe Reader isn't installed. 233 PluginGroup* reader_group);
239 : ConfirmInfoBarDelegate(tab_contents), 234 virtual ~PDFUnsupportedFeatureInfoBarDelegate();
240 tab_contents_(tab_contents),
241 reader_installed_(!!reader_group),
242 reader_vulnerable_(false) {
243 if (reader_installed_) {
244 UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown"));
245 std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos();
246 DCHECK_EQ(plugins.size(), 1u);
247 reader_webplugininfo_ = plugins[0];
248
249 reader_vulnerable_ = reader_group->IsVulnerable();
250 if (!reader_vulnerable_) {
251 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString(
252 reader_webplugininfo_.version));
253 if (version.get()) {
254 if (version->components()[0] < kMinReaderVersionToUse)
255 reader_vulnerable_ = true;
256 }
257 }
258 } else {
259 UserMetrics::RecordAction(
260 UserMetricsAction("PDF_InstallReaderInfoBarShown"));
261 }
262 }
263 235
264 // ConfirmInfoBarDelegate 236 // ConfirmInfoBarDelegate
265 virtual void InfoBarClosed() { 237 virtual void InfoBarDismissed() OVERRIDE;
266 delete this; 238 virtual Type GetInfoBarType() const OVERRIDE;
267 } 239 virtual bool Accept() OVERRIDE;
268 240 virtual bool Cancel() OVERRIDE;
269 virtual void InfoBarDismissed() { 241 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
270 OnNo(); 242 virtual string16 GetMessageText() const OVERRIDE;
271 }
272
273 virtual Type GetInfoBarType() const {
274 return PAGE_ACTION_TYPE;
275 }
276
277 virtual bool Accept() {
278 return OnNo();
279 }
280
281 virtual bool Cancel() {
282 return OnYes();
283 }
284
285 virtual int GetButtons() const {
286 return BUTTON_OK | BUTTON_CANCEL;
287 }
288
289 virtual string16 GetButtonLabel(InfoBarButton button) const {
290 switch (button) {
291 case BUTTON_OK:
292 return l10n_util::GetStringUTF16(
293 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL);
294 case BUTTON_CANCEL:
295 return l10n_util::GetStringUTF16(
296 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL);
297 default:
298 // All buttons are labeled above.
299 NOTREACHED() << "Bad button id " << button;
300 return string16();
301 }
302 }
303
304 virtual string16 GetMessageText() const {
305 return l10n_util::GetStringUTF16(reader_installed_ ?
306 IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED :
307 IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED);
308 }
309 243
310 private: 244 private:
311 bool OnYes() { 245 bool OnYes();
312 if (!reader_installed_) { 246 void OnNo();
313 UserMetrics::RecordAction(
314 UserMetricsAction("PDF_InstallReaderInfoBarOK"));
315 OpenReaderUpdateURL(tab_contents_);
316 return true;
317 }
318
319 UserMetrics::RecordAction(
320 UserMetricsAction("PDF_UseReaderInfoBarOK"));
321
322 if (reader_vulnerable_) {
323 PDFUnsupportedFeatureInterstitial* interstitial = new
324 PDFUnsupportedFeatureInterstitial(
325 tab_contents_, reader_webplugininfo_);
326 interstitial->Show();
327 return true;
328 }
329
330 InfoBarDelegate* bar = NULL;
331 if (tab_contents_->profile()->GetPrefs()->GetBoolean(
332 prefs::kPluginsShowSetReaderDefaultInfobar)) {
333 bar = new PDFEnableAdobeReaderConfirmInfoBarDelegate(tab_contents_);
334 }
335
336 if (bar) {
337 OpenUsingReader(tab_contents_, reader_webplugininfo_, this, bar);
338 return false;
339 } else {
340 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL);
341 return true;
342 }
343 }
344
345 bool OnNo() {
346 if (reader_installed_) {
347 UserMetrics::RecordAction(
348 UserMetricsAction("PDF_UseReaderInfoBarCancel"));
349 } else {
350 UserMetrics::RecordAction(
351 UserMetricsAction("PDF_InstallReaderInfoBarCancel"));
352 }
353 return true;
354 }
355 247
356 TabContents* tab_contents_; 248 TabContents* tab_contents_;
357 bool reader_installed_; 249 bool reader_installed_;
358 bool reader_vulnerable_; 250 bool reader_vulnerable_;
359 WebPluginInfo reader_webplugininfo_; 251 WebPluginInfo reader_webplugininfo_;
360 252
361 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureConfirmInfoBarDelegate); 253 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureInfoBarDelegate);
362 }; 254 };
363 255
256 PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate(
257 TabContents* tab_contents,
258 PluginGroup* reader_group)
259 : ConfirmInfoBarDelegate(tab_contents),
260 tab_contents_(tab_contents),
261 reader_installed_(!!reader_group),
262 reader_vulnerable_(false) {
263 if (!reader_installed_) {
264 UserMetrics::RecordAction(
265 UserMetricsAction("PDF_InstallReaderInfoBarShown"));
266 return;
267 }
268
269 UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown"));
270 std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos();
271 DCHECK_EQ(plugins.size(), 1u);
272 reader_webplugininfo_ = plugins[0];
273
274 reader_vulnerable_ = reader_group->IsVulnerable();
275 if (!reader_vulnerable_) {
276 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString(
277 reader_webplugininfo_.version));
278 reader_vulnerable_ =
279 version.get() && (version->components()[0] < kMinReaderVersionToUse);
280 }
281 }
282
283 PDFUnsupportedFeatureInfoBarDelegate::~PDFUnsupportedFeatureInfoBarDelegate() {
284 }
285
286 void PDFUnsupportedFeatureInfoBarDelegate::InfoBarDismissed() {
287 OnNo();
288 }
289
290 InfoBarDelegate::Type
291 PDFUnsupportedFeatureInfoBarDelegate::GetInfoBarType() const {
292 return PAGE_ACTION_TYPE;
293 }
294
295 bool PDFUnsupportedFeatureInfoBarDelegate::Accept() {
296 OnNo();
297 return true;
298 }
299
300 bool PDFUnsupportedFeatureInfoBarDelegate::Cancel() {
301 return OnYes();
302 }
303
304 string16 PDFUnsupportedFeatureInfoBarDelegate::GetButtonLabel(
305 InfoBarButton button) const {
306 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
307 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL :
308 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL);
309 }
310
311 string16 PDFUnsupportedFeatureInfoBarDelegate::GetMessageText() const {
312 return l10n_util::GetStringUTF16(reader_installed_ ?
313 IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED :
314 IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED);
315 }
316
317 bool PDFUnsupportedFeatureInfoBarDelegate::OnYes() {
318 if (!reader_installed_) {
319 UserMetrics::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK"));
320 OpenReaderUpdateURL(tab_contents_);
321 return true;
322 }
323
324 UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK"));
325
326 if (reader_vulnerable_) {
327 PDFUnsupportedFeatureInterstitial* interstitial =
328 new PDFUnsupportedFeatureInterstitial(tab_contents_,
329 reader_webplugininfo_);
330 interstitial->Show();
331 return true;
332 }
333
334 if (tab_contents_->profile()->GetPrefs()->GetBoolean(
335 prefs::kPluginsShowSetReaderDefaultInfobar)) {
336 InfoBarDelegate* bar =
337 new PDFEnableAdobeReaderInfoBarDelegate(tab_contents_);
338 OpenUsingReader(tab_contents_, reader_webplugininfo_, this, bar);
339 return false;
340 }
341
342 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL);
343 return true;
344 }
345
346 void PDFUnsupportedFeatureInfoBarDelegate::OnNo() {
347 UserMetrics::RecordAction(UserMetricsAction(reader_installed_ ?
348 "PDF_UseReaderInfoBarCancel" : "PDF_InstallReaderInfoBarCancel"));
349 }
350
364 } // namespace 351 } // namespace
365 352
366 void PDFHasUnsupportedFeature(TabContents* tab) { 353 void PDFHasUnsupportedFeature(TabContents* tab) {
367 #if !defined(OS_WIN) 354 #if !defined(OS_WIN)
368 // Only works for Windows for now. For Mac, we'll have to launch the file 355 // Only works for Windows for now. For Mac, we'll have to launch the file
369 // externally since Adobe Reader doesn't work inside Chrome. 356 // externally since Adobe Reader doesn't work inside Chrome.
370 return; 357 return;
371 #endif 358 #endif
372 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); 359 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName));
373 360
374 // If the Reader plugin is disabled by policy, don't prompt them. 361 // If the Reader plugin is disabled by policy, don't prompt them.
375 if (PluginGroup::IsPluginNameDisabledByPolicy(reader_group_name)) 362 if (PluginGroup::IsPluginNameDisabledByPolicy(reader_group_name))
376 return; 363 return;
377 364
378 PluginGroup* reader_group = NULL; 365 PluginGroup* reader_group = NULL;
379 std::vector<PluginGroup> plugin_groups; 366 std::vector<PluginGroup> plugin_groups;
380 PluginList::Singleton()->GetPluginGroups( 367 PluginList::Singleton()->GetPluginGroups(
381 false, &plugin_groups); 368 false, &plugin_groups);
382 for (size_t i = 0; i < plugin_groups.size(); ++i) { 369 for (size_t i = 0; i < plugin_groups.size(); ++i) {
383 if (plugin_groups[i].GetGroupName() == reader_group_name) { 370 if (plugin_groups[i].GetGroupName() == reader_group_name) {
384 reader_group = &plugin_groups[i]; 371 reader_group = &plugin_groups[i];
385 break; 372 break;
386 } 373 }
387 } 374 }
388 375
389 tab->AddInfoBar(new PDFUnsupportedFeatureConfirmInfoBarDelegate( 376 tab->AddInfoBar(new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group));
390 tab, reader_group));
391 } 377 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager_delegate_impl.cc ('k') | chrome/browser/plugin_installer_infobar_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698