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/chrome_plugin_service_filter.h" | |
11 #include "chrome/browser/infobars/infobar_tab_helper.h" | 10 #include "chrome/browser/infobars/infobar_tab_helper.h" |
12 #include "chrome/browser/plugin_prefs.h" | 11 #include "chrome/browser/plugin_prefs.h" |
| 12 #include "chrome/browser/chrome_plugin_service_filter.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" | 15 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" |
16 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 16 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
18 #include "chrome/common/chrome_content_client.h" | 18 #include "chrome/common/chrome_content_client.h" |
19 #include "chrome/common/jstemplate_builder.h" | 19 #include "chrome/common/jstemplate_builder.h" |
20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
21 #include "content/browser/plugin_service.h" | 21 #include "content/browser/plugin_service.h" |
22 #include "content/browser/renderer_host/render_process_host.h" | 22 #include "content/browser/renderer_host/render_process_host.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 IDS_PDF_INFOBAR_NEVER_USE_READER_BUTTON : | 109 IDS_PDF_INFOBAR_NEVER_USE_READER_BUTTON : |
110 IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON); | 110 IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON); |
111 } | 111 } |
112 | 112 |
113 string16 PDFEnableAdobeReaderInfoBarDelegate::GetMessageText() const { | 113 string16 PDFEnableAdobeReaderInfoBarDelegate::GetMessageText() const { |
114 return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); | 114 return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); |
115 } | 115 } |
116 | 116 |
117 void PDFEnableAdobeReaderInfoBarDelegate::OnYes() { | 117 void PDFEnableAdobeReaderInfoBarDelegate::OnYes() { |
118 UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK")); | 118 UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK")); |
| 119 webkit::npapi::PluginList::Singleton()->EnableGroup(false, |
| 120 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); |
119 Profile* profile = | 121 Profile* profile = |
120 Profile::FromBrowserContext(tab_contents_->browser_context()); | 122 Profile::FromBrowserContext(tab_contents_->browser_context()); |
121 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); | 123 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
122 plugin_prefs->EnablePluginGroup( | 124 plugin_prefs->EnablePluginGroup( |
123 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); | 125 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); |
124 plugin_prefs->EnablePluginGroup( | 126 plugin_prefs->UpdatePreferences(0); |
125 false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); | |
126 } | 127 } |
127 | 128 |
128 void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { | 129 void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { |
129 UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel")); | 130 UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel")); |
130 } | 131 } |
131 | 132 |
132 // Launch the url to get the latest Adbobe Reader installer. | 133 // Launch the url to get the latest Adbobe Reader installer. |
133 void OpenReaderUpdateURL(TabContents* tab) { | 134 void OpenReaderUpdateURL(TabContents* tab) { |
134 tab->OpenURL(GURL(kReaderUpdateUrl), GURL(), CURRENT_TAB, | 135 tab->OpenURL(GURL(kReaderUpdateUrl), GURL(), CURRENT_TAB, |
135 PageTransition::LINK); | 136 PageTransition::LINK); |
136 } | 137 } |
137 | 138 |
138 // Opens the PDF using Adobe Reader. | 139 // Opens the PDF using Adobe Reader. |
139 void OpenUsingReader(TabContentsWrapper* tab, | 140 void OpenUsingReader(TabContentsWrapper* tab, |
140 const WebPluginInfo& reader_plugin, | 141 const WebPluginInfo& reader_plugin, |
141 InfoBarDelegate* old_delegate, | 142 InfoBarDelegate* old_delegate, |
142 InfoBarDelegate* new_delegate) { | 143 InfoBarDelegate* new_delegate) { |
143 WebPluginInfo plugin = reader_plugin; | 144 WebPluginInfo plugin = reader_plugin; |
144 // Give the plugin a new version so that the renderer doesn't show the blocked | 145 // The plugin is disabled, so enable it to get around the renderer check. |
| 146 // Also give it a new version so that the renderer doesn't show the blocked |
145 // plugin UI if it's vulnerable, since we already went through the | 147 // plugin UI if it's vulnerable, since we already went through the |
146 // interstitial. | 148 // interstitial. |
| 149 plugin.enabled = WebPluginInfo::USER_ENABLED; |
147 plugin.version = ASCIIToUTF16("11.0.0.0"); | 150 plugin.version = ASCIIToUTF16("11.0.0.0"); |
148 | 151 |
149 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( | 152 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( |
150 tab->render_view_host()->process()->id(), | 153 tab->render_view_host()->process()->id(), |
151 tab->render_view_host()->routing_id(), | 154 tab->render_view_host()->routing_id(), |
152 tab->tab_contents()->GetURL(), | 155 tab->tab_contents()->GetURL(), |
153 plugin); | 156 plugin); |
154 tab->render_view_host()->Send(new ViewMsg_ReloadFrame( | 157 tab->render_view_host()->Send(new ViewMsg_ReloadFrame( |
155 tab->render_view_host()->routing_id())); | 158 tab->render_view_host()->routing_id())); |
156 | 159 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 tab_contents_(tab_contents), | 277 tab_contents_(tab_contents), |
275 reader_installed_(!!reader_group), | 278 reader_installed_(!!reader_group), |
276 reader_vulnerable_(false) { | 279 reader_vulnerable_(false) { |
277 if (!reader_installed_) { | 280 if (!reader_installed_) { |
278 UserMetrics::RecordAction( | 281 UserMetrics::RecordAction( |
279 UserMetricsAction("PDF_InstallReaderInfoBarShown")); | 282 UserMetricsAction("PDF_InstallReaderInfoBarShown")); |
280 return; | 283 return; |
281 } | 284 } |
282 | 285 |
283 UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); | 286 UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); |
284 const std::vector<WebPluginInfo>& plugins = | 287 std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos(); |
285 reader_group->web_plugin_infos(); | |
286 DCHECK_EQ(plugins.size(), 1u); | 288 DCHECK_EQ(plugins.size(), 1u); |
287 reader_webplugininfo_ = plugins[0]; | 289 reader_webplugininfo_ = plugins[0]; |
288 | 290 |
289 reader_vulnerable_ = reader_group->IsVulnerable(reader_webplugininfo_); | 291 reader_vulnerable_ = reader_group->IsVulnerable(); |
290 if (!reader_vulnerable_) { | 292 if (!reader_vulnerable_) { |
291 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString( | 293 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString( |
292 reader_webplugininfo_.version)); | 294 reader_webplugininfo_.version)); |
293 reader_vulnerable_ = | 295 reader_vulnerable_ = |
294 version.get() && (version->components()[0] < kMinReaderVersionToUse); | 296 version.get() && (version->components()[0] < kMinReaderVersionToUse); |
295 } | 297 } |
296 } | 298 } |
297 | 299 |
298 PDFUnsupportedFeatureInfoBarDelegate::~PDFUnsupportedFeatureInfoBarDelegate() { | 300 PDFUnsupportedFeatureInfoBarDelegate::~PDFUnsupportedFeatureInfoBarDelegate() { |
299 } | 301 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 | 375 |
374 void PDFHasUnsupportedFeature(TabContentsWrapper* tab) { | 376 void PDFHasUnsupportedFeature(TabContentsWrapper* tab) { |
375 #if !defined(OS_WIN) | 377 #if !defined(OS_WIN) |
376 // Only works for Windows for now. For Mac, we'll have to launch the file | 378 // Only works for Windows for now. For Mac, we'll have to launch the file |
377 // externally since Adobe Reader doesn't work inside Chrome. | 379 // externally since Adobe Reader doesn't work inside Chrome. |
378 return; | 380 return; |
379 #endif | 381 #endif |
380 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | 382 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); |
381 | 383 |
382 // If the Reader plugin is disabled by policy, don't prompt them. | 384 // If the Reader plugin is disabled by policy, don't prompt them. |
383 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); | 385 if (PluginGroup::IsPluginNameDisabledByPolicy(reader_group_name)) |
384 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == | |
385 PluginPrefs::POLICY_DISABLED) { | |
386 return; | 386 return; |
387 } | |
388 | 387 |
389 PluginGroup* reader_group = NULL; | 388 PluginGroup* reader_group = NULL; |
390 std::vector<PluginGroup> plugin_groups; | 389 std::vector<PluginGroup> plugin_groups; |
391 PluginList::Singleton()->GetPluginGroups(false, &plugin_groups); | 390 PluginList::Singleton()->GetPluginGroups(false, &plugin_groups); |
392 for (size_t i = 0; i < plugin_groups.size(); ++i) { | 391 for (size_t i = 0; i < plugin_groups.size(); ++i) { |
393 if (plugin_groups[i].GetGroupName() == reader_group_name) { | 392 if (plugin_groups[i].GetGroupName() == reader_group_name) { |
394 reader_group = &plugin_groups[i]; | 393 reader_group = &plugin_groups[i]; |
395 break; | 394 break; |
396 } | 395 } |
397 } | 396 } |
398 | 397 |
399 tab->infobar_tab_helper()->AddInfoBar( | 398 tab->infobar_tab_helper()->AddInfoBar( |
400 new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group)); | 399 new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group)); |
401 } | 400 } |
OLD | NEW |