| OLD | NEW |
| 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/metrics/user_metrics.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 using webkit::npapi::PluginGroup; | 27 using webkit::npapi::PluginGroup; |
| 28 using webkit::npapi::PluginList; | 28 using webkit::npapi::PluginList; |
| 29 using webkit::npapi::WebPluginInfo; | 29 using webkit::npapi::WebPluginInfo; |
| 30 | 30 |
| 31 // Only launch Adobe Reader X or later. | 31 // Only launch Adobe Reader X or later. |
| 32 static const uint16 kMinReaderVersionToUse = 10; | 32 static const uint16 kMinReaderVersionToUse = 10; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // The info bar delegate used to ask the user if they want to use Adobe Reader | 36 // The info bar delegate used to ask the user if they want to use Adobe Reader |
| 37 // by default. | 37 // by default. We want the infobar to have [No][Yes], so we swap the text on |
| 38 // the buttons, and the meaning of the delegate callbacks. |
| 38 class PDFEnableAdobeReaderConfirmInfoBarDelegate | 39 class PDFEnableAdobeReaderConfirmInfoBarDelegate |
| 39 : public ConfirmInfoBarDelegate { | 40 : public ConfirmInfoBarDelegate { |
| 40 public: | 41 public: |
| 41 PDFEnableAdobeReaderConfirmInfoBarDelegate( | 42 PDFEnableAdobeReaderConfirmInfoBarDelegate( |
| 42 TabContents* tab_contents) | 43 TabContents* tab_contents) |
| 43 : ConfirmInfoBarDelegate(tab_contents) { | 44 : ConfirmInfoBarDelegate(tab_contents) { |
| 44 UserMetrics::RecordAction( | 45 UserMetrics::RecordAction( |
| 45 UserMetricsAction("PDF_EnableReaderInfoBarShown")); | 46 UserMetricsAction("PDF_EnableReaderInfoBarShown")); |
| 46 } | 47 } |
| 47 | 48 |
| 48 // ConfirmInfoBarDelegate | 49 // ConfirmInfoBarDelegate |
| 49 virtual void InfoBarClosed() { | 50 virtual void InfoBarClosed() { |
| 50 delete this; | 51 delete this; |
| 51 } | 52 } |
| 52 | 53 |
| 53 virtual void InfoBarDismissed() { | 54 virtual void InfoBarDismissed() { |
| 54 Cancel(); | 55 OnNo(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 virtual Type GetInfoBarType() const { | 58 virtual Type GetInfoBarType() const { |
| 58 return PAGE_ACTION_TYPE; | 59 return PAGE_ACTION_TYPE; |
| 59 } | 60 } |
| 60 | 61 |
| 61 virtual bool Accept() { | 62 virtual bool Accept() { |
| 62 UserMetrics::RecordAction( | 63 return OnNo(); |
| 63 UserMetricsAction("PDF_EnableReaderInfoBarOK")); | |
| 64 webkit::npapi::PluginList::Singleton()->EnableGroup( | |
| 65 false, ASCIIToUTF16(PepperPluginRegistry::kPDFPluginName)); | |
| 66 webkit::npapi::PluginList::Singleton()->EnableGroup( | |
| 67 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); | |
| 68 return true; | |
| 69 } | 64 } |
| 70 | 65 |
| 71 virtual bool Cancel() { | 66 virtual bool Cancel() { |
| 72 UserMetrics::RecordAction( | 67 return OnYes(); |
| 73 UserMetricsAction("PDF_EnableReaderInfoBarCancel")); | |
| 74 return true; | |
| 75 } | 68 } |
| 76 | 69 |
| 77 virtual int GetButtons() const { | 70 virtual int GetButtons() const { |
| 78 return BUTTON_OK | BUTTON_CANCEL; | 71 return BUTTON_OK | BUTTON_CANCEL; |
| 79 } | 72 } |
| 80 | 73 |
| 81 virtual string16 GetButtonLabel(InfoBarButton button) const { | 74 virtual string16 GetButtonLabel(InfoBarButton button) const { |
| 82 switch (button) { | 75 switch (button) { |
| 83 case BUTTON_OK: | 76 case BUTTON_OK: |
| 84 return l10n_util::GetStringUTF16( | 77 return l10n_util::GetStringUTF16( |
| 85 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); | 78 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); |
| 86 case BUTTON_CANCEL: | 79 case BUTTON_CANCEL: |
| 87 return l10n_util::GetStringUTF16( | 80 return l10n_util::GetStringUTF16( |
| 88 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); | 81 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); |
| 89 default: | 82 default: |
| 90 // All buttons are labeled above. | 83 // All buttons are labeled above. |
| 91 NOTREACHED() << "Bad button id " << button; | 84 NOTREACHED() << "Bad button id " << button; |
| 92 return string16(); | 85 return string16(); |
| 93 } | 86 } |
| 94 } | 87 } |
| 95 | 88 |
| 96 virtual string16 GetMessageText() const { | 89 virtual string16 GetMessageText() const { |
| 97 return l10n_util::GetStringUTF16( | 90 return l10n_util::GetStringUTF16( |
| 98 IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); | 91 IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); |
| 99 } | 92 } |
| 100 | 93 |
| 101 private: | 94 private: |
| 95 bool OnYes() { |
| 96 UserMetrics::RecordAction( |
| 97 UserMetricsAction("PDF_EnableReaderInfoBarOK")); |
| 98 webkit::npapi::PluginList::Singleton()->EnableGroup( |
| 99 false, ASCIIToUTF16(PepperPluginRegistry::kPDFPluginName)); |
| 100 webkit::npapi::PluginList::Singleton()->EnableGroup( |
| 101 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); |
| 102 return true; |
| 103 } |
| 104 |
| 105 bool OnNo() { |
| 106 UserMetrics::RecordAction( |
| 107 UserMetricsAction("PDF_EnableReaderInfoBarCancel")); |
| 108 return true; |
| 109 } |
| 110 |
| 102 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderConfirmInfoBarDelegate); | 111 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderConfirmInfoBarDelegate); |
| 103 }; | 112 }; |
| 104 | 113 |
| 105 // Launch the url to get the latest Adbobe Reader installer. | 114 // Launch the url to get the latest Adbobe Reader installer. |
| 106 void OpenReaderUpdateURL(TabContents* tab) { | 115 void OpenReaderUpdateURL(TabContents* tab) { |
| 107 tab->OpenURL(GURL(PluginGroup::kAdobeReaderUpdateURL), GURL(), CURRENT_TAB, | 116 tab->OpenURL(GURL(PluginGroup::kAdobeReaderUpdateURL), GURL(), CURRENT_TAB, |
| 108 PageTransition::LINK); | 117 PageTransition::LINK); |
| 109 } | 118 } |
| 110 | 119 |
| 111 // Opens the PDF using Adobe Reader. | 120 // Opens the PDF using Adobe Reader. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 Proceed(); | 208 Proceed(); |
| 200 } | 209 } |
| 201 | 210 |
| 202 private: | 211 private: |
| 203 WebPluginInfo reader_webplugininfo_; | 212 WebPluginInfo reader_webplugininfo_; |
| 204 | 213 |
| 205 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); | 214 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); |
| 206 }; | 215 }; |
| 207 | 216 |
| 208 // The info bar delegate used to inform the user that we don't support a feature | 217 // The info bar delegate used to inform the user that we don't support a feature |
| 209 // in the PDF. | 218 // in the PDF. See the comment about how we swap buttons for |
| 219 // PDFEnableAdobeReaderConfirmInfoBarDelegate. |
| 210 class PDFUnsupportedFeatureConfirmInfoBarDelegate | 220 class PDFUnsupportedFeatureConfirmInfoBarDelegate |
| 211 : public ConfirmInfoBarDelegate { | 221 : public ConfirmInfoBarDelegate { |
| 212 public: | 222 public: |
| 213 PDFUnsupportedFeatureConfirmInfoBarDelegate( | 223 PDFUnsupportedFeatureConfirmInfoBarDelegate( |
| 214 TabContents* tab_contents, | 224 TabContents* tab_contents, |
| 215 PluginGroup* reader_group) // NULL if Adobe Reader isn't installed. | 225 PluginGroup* reader_group) // NULL if Adobe Reader isn't installed. |
| 216 : ConfirmInfoBarDelegate(tab_contents), | 226 : ConfirmInfoBarDelegate(tab_contents), |
| 217 tab_contents_(tab_contents), | 227 tab_contents_(tab_contents), |
| 218 reader_installed_(!!reader_group), | 228 reader_installed_(!!reader_group), |
| 219 reader_vulnerable_(false) { | 229 reader_vulnerable_(false) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 237 UserMetricsAction("PDF_InstallReaderInfoBarShown")); | 247 UserMetricsAction("PDF_InstallReaderInfoBarShown")); |
| 238 } | 248 } |
| 239 } | 249 } |
| 240 | 250 |
| 241 // ConfirmInfoBarDelegate | 251 // ConfirmInfoBarDelegate |
| 242 virtual void InfoBarClosed() { | 252 virtual void InfoBarClosed() { |
| 243 delete this; | 253 delete this; |
| 244 } | 254 } |
| 245 | 255 |
| 246 virtual void InfoBarDismissed() { | 256 virtual void InfoBarDismissed() { |
| 247 Cancel(); | 257 OnNo(); |
| 248 } | 258 } |
| 249 | 259 |
| 250 virtual Type GetInfoBarType() const { | 260 virtual Type GetInfoBarType() const { |
| 251 return PAGE_ACTION_TYPE; | 261 return PAGE_ACTION_TYPE; |
| 252 } | 262 } |
| 253 | 263 |
| 254 virtual bool Accept() { | 264 virtual bool Accept() { |
| 255 if (!reader_installed_) { | 265 return OnNo(); |
| 266 } |
| 267 |
| 268 virtual bool Cancel() { |
| 269 return OnYes(); |
| 270 } |
| 271 |
| 272 virtual int GetButtons() const { |
| 273 return BUTTON_OK | BUTTON_CANCEL; |
| 274 } |
| 275 |
| 276 virtual string16 GetButtonLabel(InfoBarButton button) const { |
| 277 switch (button) { |
| 278 case BUTTON_OK: |
| 279 return l10n_util::GetStringUTF16( |
| 280 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); |
| 281 case BUTTON_CANCEL: |
| 282 return l10n_util::GetStringUTF16( |
| 283 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); |
| 284 default: |
| 285 // All buttons are labeled above. |
| 286 NOTREACHED() << "Bad button id " << button; |
| 287 return string16(); |
| 288 } |
| 289 } |
| 290 |
| 291 virtual string16 GetMessageText() const { |
| 292 return l10n_util::GetStringUTF16(reader_installed_ ? |
| 293 IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED : |
| 294 IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED); |
| 295 } |
| 296 |
| 297 private: |
| 298 bool OnYes() { |
| 299 if (!reader_installed_) { |
| 256 UserMetrics::RecordAction( | 300 UserMetrics::RecordAction( |
| 257 UserMetricsAction("PDF_InstallReaderInfoBarOK")); | 301 UserMetricsAction("PDF_InstallReaderInfoBarOK")); |
| 258 OpenReaderUpdateURL(tab_contents_); | 302 OpenReaderUpdateURL(tab_contents_); |
| 259 return true; | 303 return true; |
| 260 } | 304 } |
| 261 | 305 |
| 262 UserMetrics::RecordAction( | 306 UserMetrics::RecordAction( |
| 263 UserMetricsAction("PDF_UseReaderInfoBarOK")); | 307 UserMetricsAction("PDF_UseReaderInfoBarOK")); |
| 264 | 308 |
| 265 if (reader_vulnerable_) { | 309 if (reader_vulnerable_) { |
| 266 PDFUnsupportedFeatureInterstitial* interstitial = new | 310 PDFUnsupportedFeatureInterstitial* interstitial = new |
| 267 PDFUnsupportedFeatureInterstitial( | 311 PDFUnsupportedFeatureInterstitial( |
| 268 tab_contents_, reader_webplugininfo_); | 312 tab_contents_, reader_webplugininfo_); |
| 269 interstitial->Show(); | 313 interstitial->Show(); |
| 270 return true; | 314 return true; |
| 271 } | 315 } |
| 272 | 316 |
| 273 OpenUsingReader(tab_contents_, reader_webplugininfo_, this); | 317 OpenUsingReader(tab_contents_, reader_webplugininfo_, this); |
| 274 return false; | 318 return false; |
| 275 } | 319 } |
| 276 | 320 |
| 277 virtual bool Cancel() { | 321 bool OnNo() { |
| 278 if (reader_installed_) { | 322 if (reader_installed_) { |
| 279 UserMetrics::RecordAction( | 323 UserMetrics::RecordAction( |
| 280 UserMetricsAction("PDF_UseReaderInfoBarCancel")); | 324 UserMetricsAction("PDF_UseReaderInfoBarCancel")); |
| 281 } else { | 325 } else { |
| 282 UserMetrics::RecordAction( | 326 UserMetrics::RecordAction( |
| 283 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); | 327 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); |
| 284 } | 328 } |
| 285 return true; | 329 return true; |
| 286 } | 330 } |
| 287 | 331 |
| 288 virtual int GetButtons() const { | |
| 289 return BUTTON_OK | BUTTON_CANCEL; | |
| 290 } | |
| 291 | |
| 292 virtual string16 GetButtonLabel(InfoBarButton button) const { | |
| 293 switch (button) { | |
| 294 case BUTTON_OK: | |
| 295 return l10n_util::GetStringUTF16( | |
| 296 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); | |
| 297 case BUTTON_CANCEL: | |
| 298 return l10n_util::GetStringUTF16( | |
| 299 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); | |
| 300 default: | |
| 301 // All buttons are labeled above. | |
| 302 NOTREACHED() << "Bad button id " << button; | |
| 303 return string16(); | |
| 304 } | |
| 305 } | |
| 306 | |
| 307 virtual string16 GetMessageText() const { | |
| 308 return l10n_util::GetStringUTF16(reader_installed_ ? | |
| 309 IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED : | |
| 310 IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED); | |
| 311 } | |
| 312 | |
| 313 private: | |
| 314 TabContents* tab_contents_; | 332 TabContents* tab_contents_; |
| 315 bool reader_installed_; | 333 bool reader_installed_; |
| 316 bool reader_vulnerable_; | 334 bool reader_vulnerable_; |
| 317 WebPluginInfo reader_webplugininfo_; | 335 WebPluginInfo reader_webplugininfo_; |
| 318 | 336 |
| 319 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureConfirmInfoBarDelegate); | 337 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureConfirmInfoBarDelegate); |
| 320 }; | 338 }; |
| 321 | 339 |
| 322 } // namespace | 340 } // namespace |
| 323 | 341 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 340 for (size_t i = 0; i < plugin_groups.size(); ++i) { | 358 for (size_t i = 0; i < plugin_groups.size(); ++i) { |
| 341 if (plugin_groups[i].GetGroupName() == reader_group_name) { | 359 if (plugin_groups[i].GetGroupName() == reader_group_name) { |
| 342 reader_group = &plugin_groups[i]; | 360 reader_group = &plugin_groups[i]; |
| 343 break; | 361 break; |
| 344 } | 362 } |
| 345 } | 363 } |
| 346 | 364 |
| 347 tab->AddInfoBar(new PDFUnsupportedFeatureConfirmInfoBarDelegate( | 365 tab->AddInfoBar(new PDFUnsupportedFeatureConfirmInfoBarDelegate( |
| 348 tab, reader_group)); | 366 tab, reader_group)); |
| 349 } | 367 } |
| OLD | NEW |