| 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/bind.h" |
| 7 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 8 #include "base/values.h" | 9 #include "base/values.h" |
| 9 #include "base/version.h" | 10 #include "base/version.h" |
| 10 #include "chrome/browser/chrome_plugin_service_filter.h" | 11 #include "chrome/browser/chrome_plugin_service_filter.h" |
| 11 #include "chrome/browser/infobars/infobar_tab_helper.h" | 12 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 12 #include "chrome/browser/plugin_prefs.h" | 13 #include "chrome/browser/plugin_prefs.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" | 16 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" |
| 16 #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" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 18 #include "chrome/common/chrome_content_client.h" | 20 #include "chrome/common/chrome_content_client.h" |
| 19 #include "chrome/common/jstemplate_builder.h" | 21 #include "chrome/common/jstemplate_builder.h" |
| 20 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 21 #include "content/browser/plugin_service.h" | 23 #include "content/browser/plugin_service.h" |
| 22 #include "content/browser/renderer_host/render_process_host.h" | 24 #include "content/browser/renderer_host/render_process_host.h" |
| 23 #include "content/browser/renderer_host/render_view_host.h" | 25 #include "content/browser/renderer_host/render_view_host.h" |
| 24 #include "content/browser/user_metrics.h" | 26 #include "content/browser/user_metrics.h" |
| 25 #include "content/common/view_messages.h" | 27 #include "content/common/view_messages.h" |
| 26 #include "grit/browser_resources.h" | 28 #include "grit/browser_resources.h" |
| 27 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 28 #include "grit/theme_resources_standard.h" | 30 #include "grit/theme_resources_standard.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/gfx/image/image.h" | 33 #include "ui/gfx/image/image.h" |
| 32 #include "webkit/plugins/npapi/plugin_group.h" | 34 #include "webkit/plugins/npapi/plugin_group.h" |
| 33 #include "webkit/plugins/npapi/plugin_list.h" | |
| 34 #include "webkit/plugins/webplugininfo.h" | |
| 35 | 35 |
| 36 using webkit::npapi::PluginGroup; | 36 using webkit::npapi::PluginGroup; |
| 37 using webkit::npapi::PluginList; | |
| 38 using webkit::WebPluginInfo; | 37 using webkit::WebPluginInfo; |
| 39 | 38 |
| 40 namespace { | 39 namespace { |
| 41 | 40 |
| 42 // Only launch Adobe Reader X or later. | 41 // Only launch Adobe Reader X or later. |
| 43 static const uint16 kMinReaderVersionToUse = 10; | 42 static const uint16 kMinReaderVersionToUse = 10; |
| 44 | 43 |
| 45 static const char kReaderUpdateUrl[] = | 44 static const char kReaderUpdateUrl[] = |
| 46 "http://www.adobe.com/go/getreader_chrome"; | 45 "http://www.adobe.com/go/getreader_chrome"; |
| 47 | 46 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); | 228 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); |
| 230 }; | 229 }; |
| 231 | 230 |
| 232 // The info bar delegate used to inform the user that we don't support a feature | 231 // The info bar delegate used to inform the user that we don't support a feature |
| 233 // in the PDF. See the comment about how we swap buttons for | 232 // in the PDF. See the comment about how we swap buttons for |
| 234 // PDFEnableAdobeReaderInfoBarDelegate. | 233 // PDFEnableAdobeReaderInfoBarDelegate. |
| 235 class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate { | 234 class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 236 public: | 235 public: |
| 237 // |reader_group| is NULL if Adobe Reader isn't installed. | 236 // |reader_group| is NULL if Adobe Reader isn't installed. |
| 238 PDFUnsupportedFeatureInfoBarDelegate(TabContentsWrapper* tab_contents, | 237 PDFUnsupportedFeatureInfoBarDelegate(TabContentsWrapper* tab_contents, |
| 239 PluginGroup* reader_group); | 238 const PluginGroup* reader_group); |
| 240 virtual ~PDFUnsupportedFeatureInfoBarDelegate(); | 239 virtual ~PDFUnsupportedFeatureInfoBarDelegate(); |
| 241 | 240 |
| 242 // ConfirmInfoBarDelegate | 241 // ConfirmInfoBarDelegate |
| 243 virtual void InfoBarDismissed() OVERRIDE; | 242 virtual void InfoBarDismissed() OVERRIDE; |
| 244 virtual gfx::Image* GetIcon() const OVERRIDE; | 243 virtual gfx::Image* GetIcon() const OVERRIDE; |
| 245 virtual Type GetInfoBarType() const OVERRIDE; | 244 virtual Type GetInfoBarType() const OVERRIDE; |
| 246 virtual bool Accept() OVERRIDE; | 245 virtual bool Accept() OVERRIDE; |
| 247 virtual bool Cancel() OVERRIDE; | 246 virtual bool Cancel() OVERRIDE; |
| 248 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 247 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 249 virtual string16 GetMessageText() const OVERRIDE; | 248 virtual string16 GetMessageText() const OVERRIDE; |
| 250 | 249 |
| 251 private: | 250 private: |
| 252 bool OnYes(); | 251 bool OnYes(); |
| 253 void OnNo(); | 252 void OnNo(); |
| 254 | 253 |
| 255 TabContentsWrapper* tab_contents_; | 254 TabContentsWrapper* tab_contents_; |
| 256 bool reader_installed_; | 255 bool reader_installed_; |
| 257 bool reader_vulnerable_; | 256 bool reader_vulnerable_; |
| 258 WebPluginInfo reader_webplugininfo_; | 257 WebPluginInfo reader_webplugininfo_; |
| 259 | 258 |
| 260 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureInfoBarDelegate); | 259 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureInfoBarDelegate); |
| 261 }; | 260 }; |
| 262 | 261 |
| 263 PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate( | 262 PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate( |
| 264 TabContentsWrapper* tab_contents, | 263 TabContentsWrapper* tab_contents, |
| 265 PluginGroup* reader_group) | 264 const PluginGroup* reader_group) |
| 266 : ConfirmInfoBarDelegate(tab_contents->tab_contents()), | 265 : ConfirmInfoBarDelegate(tab_contents->tab_contents()), |
| 267 tab_contents_(tab_contents), | 266 tab_contents_(tab_contents), |
| 268 reader_installed_(!!reader_group), | 267 reader_installed_(!!reader_group), |
| 269 reader_vulnerable_(false) { | 268 reader_vulnerable_(false) { |
| 270 if (!reader_installed_) { | 269 if (!reader_installed_) { |
| 271 UserMetrics::RecordAction( | 270 UserMetrics::RecordAction( |
| 272 UserMetricsAction("PDF_InstallReaderInfoBarShown")); | 271 UserMetricsAction("PDF_InstallReaderInfoBarShown")); |
| 273 return; | 272 return; |
| 274 } | 273 } |
| 275 | 274 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL); | 354 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL); |
| 356 return true; | 355 return true; |
| 357 } | 356 } |
| 358 | 357 |
| 359 void PDFUnsupportedFeatureInfoBarDelegate::OnNo() { | 358 void PDFUnsupportedFeatureInfoBarDelegate::OnNo() { |
| 360 UserMetrics::RecordAction(reader_installed_ ? | 359 UserMetrics::RecordAction(reader_installed_ ? |
| 361 UserMetricsAction("PDF_UseReaderInfoBarCancel") : | 360 UserMetricsAction("PDF_UseReaderInfoBarCancel") : |
| 362 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); | 361 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); |
| 363 } | 362 } |
| 364 | 363 |
| 365 } // namespace | 364 void GotPluginGroupsCallback(int process_id, |
| 365 int routing_id, |
| 366 const std::vector<PluginGroup>& groups) { |
| 367 TabContents* tab_contents = |
| 368 tab_util::GetTabContentsByID(process_id, routing_id); |
| 369 if (!tab_contents) |
| 370 return; |
| 366 | 371 |
| 367 void PDFHasUnsupportedFeature(TabContentsWrapper* tab) { | 372 TabContentsWrapper* tab = |
| 368 #if !defined(OS_WIN) | 373 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); |
| 369 // Only works for Windows for now. For Mac, we'll have to launch the file | 374 if (!tab) |
| 370 // externally since Adobe Reader doesn't work inside Chrome. | 375 return; |
| 371 return; | 376 |
| 372 #endif | |
| 373 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | 377 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); |
| 374 | 378 |
| 375 // If the Reader plugin is disabled by policy, don't prompt them. | 379 // If the Reader plugin is disabled by policy, don't prompt them. |
| 376 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); | 380 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); |
| 377 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == | 381 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == |
| 378 PluginPrefs::POLICY_DISABLED) { | 382 PluginPrefs::POLICY_DISABLED) { |
| 379 return; | 383 return; |
| 380 } | 384 } |
| 381 | 385 |
| 382 PluginGroup* reader_group = NULL; | 386 const PluginGroup* reader_group = NULL; |
| 383 std::vector<PluginGroup> plugin_groups; | 387 for (size_t i = 0; i < groups.size(); ++i) { |
| 384 PluginList::Singleton()->GetPluginGroups(false, &plugin_groups); | 388 if (groups[i].GetGroupName() == reader_group_name) { |
| 385 for (size_t i = 0; i < plugin_groups.size(); ++i) { | 389 reader_group = &groups[i]; |
| 386 if (plugin_groups[i].GetGroupName() == reader_group_name) { | |
| 387 reader_group = &plugin_groups[i]; | |
| 388 break; | 390 break; |
| 389 } | 391 } |
| 390 } | 392 } |
| 391 | 393 |
| 392 tab->infobar_tab_helper()->AddInfoBar( | 394 tab->infobar_tab_helper()->AddInfoBar( |
| 393 new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group)); | 395 new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group)); |
| 394 } | 396 } |
| 397 |
| 398 } // namespace |
| 399 |
| 400 void PDFHasUnsupportedFeature(TabContentsWrapper* tab) { |
| 401 #if !defined(OS_WIN) |
| 402 // Only works for Windows for now. For Mac, we'll have to launch the file |
| 403 // externally since Adobe Reader doesn't work inside Chrome. |
| 404 return; |
| 405 #endif |
| 406 |
| 407 PluginService::GetInstance()->GetPluginGroups( |
| 408 base::Bind(&GotPluginGroupsCallback, |
| 409 tab->render_view_host()->process()->id(), |
| 410 tab->render_view_host()->routing_id())); |
| 411 } |
| OLD | NEW |