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