| 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/ui/pdf/pdf_unsupported_feature.h" | 5 #include "chrome/browser/ui/pdf/pdf_unsupported_feature.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "base/version.h" | 10 #include "base/version.h" |
| 11 #include "chrome/browser/chrome_plugin_service_filter.h" | 11 #include "chrome/browser/chrome_plugin_service_filter.h" |
| 12 #include "chrome/browser/infobars/infobar_tab_helper.h" | 12 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 13 #include "chrome/browser/plugin_prefs.h" | 13 #include "chrome/browser/plugin_prefs.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" | 16 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" |
| 17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 18 #include "chrome/browser/tab_contents/tab_util.h" | 18 #include "chrome/browser/tab_contents/tab_util.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 20 #include "chrome/common/chrome_content_client.h" | 20 #include "chrome/common/chrome_content_client.h" |
| 21 #include "chrome/common/jstemplate_builder.h" | 21 #include "chrome/common/jstemplate_builder.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "content/browser/plugin_service.h" | 23 #include "content/browser/plugin_service.h" |
| 24 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
| 25 #include "content/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
| 26 #include "grit/browser_resources.h" | 26 #include "grit/browser_resources.h" |
| 27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 28 #include "grit/theme_resources_standard.h" | 28 #include "grit/theme_resources_standard.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/gfx/image/image.h" | 31 #include "ui/gfx/image/image.h" |
| 32 #include "webkit/plugins/npapi/plugin_group.h" | 32 #include "webkit/plugins/npapi/plugin_group.h" |
| 33 | 33 |
| 34 using content::UserMetricsAction; |
| 34 using webkit::npapi::PluginGroup; | 35 using webkit::npapi::PluginGroup; |
| 35 using webkit::WebPluginInfo; | 36 using webkit::WebPluginInfo; |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 // Only launch Adobe Reader X or later. | 40 // Only launch Adobe Reader X or later. |
| 40 static const uint16 kMinReaderVersionToUse = 10; | 41 static const uint16 kMinReaderVersionToUse = 10; |
| 41 | 42 |
| 42 static const char kReaderUpdateUrl[] = | 43 static const char kReaderUpdateUrl[] = |
| 43 "http://www.adobe.com/go/getreader_chrome"; | 44 "http://www.adobe.com/go/getreader_chrome"; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 66 | 67 |
| 67 Profile* profile_; | 68 Profile* profile_; |
| 68 | 69 |
| 69 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderInfoBarDelegate); | 70 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderInfoBarDelegate); |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 PDFEnableAdobeReaderInfoBarDelegate::PDFEnableAdobeReaderInfoBarDelegate( | 73 PDFEnableAdobeReaderInfoBarDelegate::PDFEnableAdobeReaderInfoBarDelegate( |
| 73 InfoBarTabHelper* infobar_helper, Profile* profile) | 74 InfoBarTabHelper* infobar_helper, Profile* profile) |
| 74 : ConfirmInfoBarDelegate(infobar_helper), | 75 : ConfirmInfoBarDelegate(infobar_helper), |
| 75 profile_(profile) { | 76 profile_(profile) { |
| 76 UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarShown")); | 77 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarShown")); |
| 77 } | 78 } |
| 78 | 79 |
| 79 PDFEnableAdobeReaderInfoBarDelegate::~PDFEnableAdobeReaderInfoBarDelegate() { | 80 PDFEnableAdobeReaderInfoBarDelegate::~PDFEnableAdobeReaderInfoBarDelegate() { |
| 80 } | 81 } |
| 81 | 82 |
| 82 void PDFEnableAdobeReaderInfoBarDelegate::InfoBarDismissed() { | 83 void PDFEnableAdobeReaderInfoBarDelegate::InfoBarDismissed() { |
| 83 OnNo(); | 84 OnNo(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 InfoBarDelegate::Type | 87 InfoBarDelegate::Type |
| (...skipping 18 matching lines...) Expand all Loading... |
| 105 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 106 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 106 IDS_PDF_INFOBAR_NEVER_USE_READER_BUTTON : | 107 IDS_PDF_INFOBAR_NEVER_USE_READER_BUTTON : |
| 107 IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON); | 108 IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON); |
| 108 } | 109 } |
| 109 | 110 |
| 110 string16 PDFEnableAdobeReaderInfoBarDelegate::GetMessageText() const { | 111 string16 PDFEnableAdobeReaderInfoBarDelegate::GetMessageText() const { |
| 111 return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); | 112 return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void PDFEnableAdobeReaderInfoBarDelegate::OnYes() { | 115 void PDFEnableAdobeReaderInfoBarDelegate::OnYes() { |
| 115 UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK")); | 116 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK")); |
| 116 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile_); | 117 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile_); |
| 117 plugin_prefs->EnablePluginGroup( | 118 plugin_prefs->EnablePluginGroup( |
| 118 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); | 119 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); |
| 119 plugin_prefs->EnablePluginGroup( | 120 plugin_prefs->EnablePluginGroup( |
| 120 false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); | 121 false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); |
| 121 } | 122 } |
| 122 | 123 |
| 123 void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { | 124 void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { |
| 124 UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel")); | 125 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel")); |
| 125 } | 126 } |
| 126 | 127 |
| 127 // Launch the url to get the latest Adbobe Reader installer. | 128 // Launch the url to get the latest Adbobe Reader installer. |
| 128 void OpenReaderUpdateURL(TabContents* tab) { | 129 void OpenReaderUpdateURL(TabContents* tab) { |
| 129 tab->OpenURL(GURL(kReaderUpdateUrl), GURL(), NEW_FOREGROUND_TAB, | 130 tab->OpenURL(GURL(kReaderUpdateUrl), GURL(), NEW_FOREGROUND_TAB, |
| 130 content::PAGE_TRANSITION_LINK); | 131 content::PAGE_TRANSITION_LINK); |
| 131 } | 132 } |
| 132 | 133 |
| 133 // Opens the PDF using Adobe Reader. | 134 // Opens the PDF using Adobe Reader. |
| 134 void OpenUsingReader(TabContentsWrapper* tab, | 135 void OpenUsingReader(TabContentsWrapper* tab, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 155 // Reader, but it is out of date. | 156 // Reader, but it is out of date. |
| 156 class PDFUnsupportedFeatureInterstitial : public ChromeInterstitialPage { | 157 class PDFUnsupportedFeatureInterstitial : public ChromeInterstitialPage { |
| 157 public: | 158 public: |
| 158 PDFUnsupportedFeatureInterstitial( | 159 PDFUnsupportedFeatureInterstitial( |
| 159 TabContentsWrapper* tab, | 160 TabContentsWrapper* tab, |
| 160 const WebPluginInfo& reader_webplugininfo) | 161 const WebPluginInfo& reader_webplugininfo) |
| 161 : ChromeInterstitialPage( | 162 : ChromeInterstitialPage( |
| 162 tab->tab_contents(), false, tab->tab_contents()->GetURL()), | 163 tab->tab_contents(), false, tab->tab_contents()->GetURL()), |
| 163 tab_contents_(tab), | 164 tab_contents_(tab), |
| 164 reader_webplugininfo_(reader_webplugininfo) { | 165 reader_webplugininfo_(reader_webplugininfo) { |
| 165 UserMetrics::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); | 166 content::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); |
| 166 } | 167 } |
| 167 | 168 |
| 168 protected: | 169 protected: |
| 169 // ChromeInterstitialPage implementation. | 170 // ChromeInterstitialPage implementation. |
| 170 virtual std::string GetHTMLContents() { | 171 virtual std::string GetHTMLContents() { |
| 171 DictionaryValue strings; | 172 DictionaryValue strings; |
| 172 strings.SetString( | 173 strings.SetString( |
| 173 "title", | 174 "title", |
| 174 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_TITLE)); | 175 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_TITLE)); |
| 175 strings.SetString( | 176 strings.SetString( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 190 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_CANCEL)); | 191 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_CANCEL)); |
| 191 | 192 |
| 192 base::StringPiece html(ResourceBundle::GetSharedInstance(). | 193 base::StringPiece html(ResourceBundle::GetSharedInstance(). |
| 193 GetRawDataResource(IDR_READER_OUT_OF_DATE_HTML)); | 194 GetRawDataResource(IDR_READER_OUT_OF_DATE_HTML)); |
| 194 | 195 |
| 195 return jstemplate_builder::GetI18nTemplateHtml(html, &strings); | 196 return jstemplate_builder::GetI18nTemplateHtml(html, &strings); |
| 196 } | 197 } |
| 197 | 198 |
| 198 virtual void CommandReceived(const std::string& command) { | 199 virtual void CommandReceived(const std::string& command) { |
| 199 if (command == "0") { | 200 if (command == "0") { |
| 200 UserMetrics::RecordAction( | 201 content::RecordAction( |
| 201 UserMetricsAction("PDF_ReaderInterstitialCancel")); | 202 UserMetricsAction("PDF_ReaderInterstitialCancel")); |
| 202 DontProceed(); | 203 DontProceed(); |
| 203 return; | 204 return; |
| 204 } | 205 } |
| 205 | 206 |
| 206 if (command == "1") { | 207 if (command == "1") { |
| 207 UserMetrics::RecordAction( | 208 content::RecordAction( |
| 208 UserMetricsAction("PDF_ReaderInterstitialUpdate")); | 209 UserMetricsAction("PDF_ReaderInterstitialUpdate")); |
| 209 OpenReaderUpdateURL(tab()); | 210 OpenReaderUpdateURL(tab()); |
| 210 } else if (command == "2") { | 211 } else if (command == "2") { |
| 211 UserMetrics::RecordAction( | 212 content::RecordAction( |
| 212 UserMetricsAction("PDF_ReaderInterstitialIgnore")); | 213 UserMetricsAction("PDF_ReaderInterstitialIgnore")); |
| 213 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL); | 214 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL); |
| 214 } else { | 215 } else { |
| 215 NOTREACHED(); | 216 NOTREACHED(); |
| 216 } | 217 } |
| 217 Proceed(); | 218 Proceed(); |
| 218 } | 219 } |
| 219 | 220 |
| 220 private: | 221 private: |
| 221 TabContentsWrapper* tab_contents_; | 222 TabContentsWrapper* tab_contents_; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 }; | 257 }; |
| 257 | 258 |
| 258 PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate( | 259 PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate( |
| 259 TabContentsWrapper* tab_contents, | 260 TabContentsWrapper* tab_contents, |
| 260 const PluginGroup* reader_group) | 261 const PluginGroup* reader_group) |
| 261 : ConfirmInfoBarDelegate(tab_contents->infobar_tab_helper()), | 262 : ConfirmInfoBarDelegate(tab_contents->infobar_tab_helper()), |
| 262 tab_contents_(tab_contents), | 263 tab_contents_(tab_contents), |
| 263 reader_installed_(!!reader_group), | 264 reader_installed_(!!reader_group), |
| 264 reader_vulnerable_(false) { | 265 reader_vulnerable_(false) { |
| 265 if (!reader_installed_) { | 266 if (!reader_installed_) { |
| 266 UserMetrics::RecordAction( | 267 content::RecordAction( |
| 267 UserMetricsAction("PDF_InstallReaderInfoBarShown")); | 268 UserMetricsAction("PDF_InstallReaderInfoBarShown")); |
| 268 return; | 269 return; |
| 269 } | 270 } |
| 270 | 271 |
| 271 UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); | 272 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); |
| 272 const std::vector<WebPluginInfo>& plugins = | 273 const std::vector<WebPluginInfo>& plugins = |
| 273 reader_group->web_plugin_infos(); | 274 reader_group->web_plugin_infos(); |
| 274 DCHECK_EQ(plugins.size(), 1u); | 275 DCHECK_EQ(plugins.size(), 1u); |
| 275 reader_webplugininfo_ = plugins[0]; | 276 reader_webplugininfo_ = plugins[0]; |
| 276 | 277 |
| 277 reader_vulnerable_ = reader_group->IsVulnerable(reader_webplugininfo_); | 278 reader_vulnerable_ = reader_group->IsVulnerable(reader_webplugininfo_); |
| 278 if (!reader_vulnerable_) { | 279 if (!reader_vulnerable_) { |
| 279 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString( | 280 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString( |
| 280 reader_webplugininfo_.version)); | 281 reader_webplugininfo_.version)); |
| 281 reader_vulnerable_ = | 282 reader_vulnerable_ = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 } | 318 } |
| 318 | 319 |
| 319 string16 PDFUnsupportedFeatureInfoBarDelegate::GetMessageText() const { | 320 string16 PDFUnsupportedFeatureInfoBarDelegate::GetMessageText() const { |
| 320 return l10n_util::GetStringUTF16(reader_installed_ ? | 321 return l10n_util::GetStringUTF16(reader_installed_ ? |
| 321 IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED : | 322 IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED : |
| 322 IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED); | 323 IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED); |
| 323 } | 324 } |
| 324 | 325 |
| 325 bool PDFUnsupportedFeatureInfoBarDelegate::OnYes() { | 326 bool PDFUnsupportedFeatureInfoBarDelegate::OnYes() { |
| 326 if (!reader_installed_) { | 327 if (!reader_installed_) { |
| 327 UserMetrics::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK")); | 328 content::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK")); |
| 328 OpenReaderUpdateURL(tab_contents_->tab_contents()); | 329 OpenReaderUpdateURL(tab_contents_->tab_contents()); |
| 329 return true; | 330 return true; |
| 330 } | 331 } |
| 331 | 332 |
| 332 UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); | 333 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); |
| 333 | 334 |
| 334 if (reader_vulnerable_) { | 335 if (reader_vulnerable_) { |
| 335 PDFUnsupportedFeatureInterstitial* interstitial = | 336 PDFUnsupportedFeatureInterstitial* interstitial = |
| 336 new PDFUnsupportedFeatureInterstitial(tab_contents_, | 337 new PDFUnsupportedFeatureInterstitial(tab_contents_, |
| 337 reader_webplugininfo_); | 338 reader_webplugininfo_); |
| 338 interstitial->Show(); | 339 interstitial->Show(); |
| 339 return true; | 340 return true; |
| 340 } | 341 } |
| 341 | 342 |
| 342 if (tab_contents_->profile()->GetPrefs()->GetBoolean( | 343 if (tab_contents_->profile()->GetPrefs()->GetBoolean( |
| 343 prefs::kPluginsShowSetReaderDefaultInfobar)) { | 344 prefs::kPluginsShowSetReaderDefaultInfobar)) { |
| 344 InfoBarDelegate* bar = new PDFEnableAdobeReaderInfoBarDelegate( | 345 InfoBarDelegate* bar = new PDFEnableAdobeReaderInfoBarDelegate( |
| 345 tab_contents_->infobar_tab_helper(), tab_contents_->profile()); | 346 tab_contents_->infobar_tab_helper(), tab_contents_->profile()); |
| 346 OpenUsingReader(tab_contents_, reader_webplugininfo_, this, bar); | 347 OpenUsingReader(tab_contents_, reader_webplugininfo_, this, bar); |
| 347 return false; | 348 return false; |
| 348 } | 349 } |
| 349 | 350 |
| 350 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL); | 351 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL); |
| 351 return true; | 352 return true; |
| 352 } | 353 } |
| 353 | 354 |
| 354 void PDFUnsupportedFeatureInfoBarDelegate::OnNo() { | 355 void PDFUnsupportedFeatureInfoBarDelegate::OnNo() { |
| 355 UserMetrics::RecordAction(reader_installed_ ? | 356 content::RecordAction(reader_installed_ ? |
| 356 UserMetricsAction("PDF_UseReaderInfoBarCancel") : | 357 UserMetricsAction("PDF_UseReaderInfoBarCancel") : |
| 357 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); | 358 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); |
| 358 } | 359 } |
| 359 | 360 |
| 360 void GotPluginGroupsCallback(int process_id, | 361 void GotPluginGroupsCallback(int process_id, |
| 361 int routing_id, | 362 int routing_id, |
| 362 const std::vector<PluginGroup>& groups) { | 363 const std::vector<PluginGroup>& groups) { |
| 363 TabContents* tab_contents = | 364 TabContents* tab_contents = |
| 364 tab_util::GetTabContentsByID(process_id, routing_id); | 365 tab_util::GetTabContentsByID(process_id, routing_id); |
| 365 if (!tab_contents) | 366 if (!tab_contents) |
| 366 return; | 367 return; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 // Only works for Windows for now. For Mac, we'll have to launch the file | 399 // Only works for Windows for now. For Mac, we'll have to launch the file |
| 399 // externally since Adobe Reader doesn't work inside Chrome. | 400 // externally since Adobe Reader doesn't work inside Chrome. |
| 400 return; | 401 return; |
| 401 #endif | 402 #endif |
| 402 | 403 |
| 403 PluginService::GetInstance()->GetPluginGroups( | 404 PluginService::GetInstance()->GetPluginGroups( |
| 404 base::Bind(&GotPluginGroupsCallback, | 405 base::Bind(&GotPluginGroupsCallback, |
| 405 tab->render_view_host()->process()->GetID(), | 406 tab->render_view_host()->process()->GetID(), |
| 406 tab->render_view_host()->routing_id())); | 407 tab->render_view_host()->routing_id())); |
| 407 } | 408 } |
| OLD | NEW |