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