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/infobars/infobar_tab_helper.h" | 10 #include "chrome/browser/infobars/infobar_tab_helper.h" |
11 #include "chrome/browser/plugin_prefs.h" | 11 #include "chrome/browser/plugin_prefs.h" |
12 #include "chrome/browser/chrome_plugin_service_filter.h" | 12 #include "chrome/browser/chrome_plugin_service_filter.h" |
Joao da Silva
2011/09/13 09:30:48
Nit: this line is out of place, please fix
Bernhard Bauer
2011/09/13 12:13:01
Done.
| |
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)); | |
121 Profile* profile = | 119 Profile* profile = |
122 Profile::FromBrowserContext(tab_contents_->browser_context()); | 120 Profile::FromBrowserContext(tab_contents_->browser_context()); |
123 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); | 121 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
124 plugin_prefs->EnablePluginGroup( | 122 plugin_prefs->EnablePluginGroup( |
jam
2011/09/13 01:47:31
wouldn't these two calls assert since they're not
Bernhard Bauer
2011/09/13 12:13:01
Indeed! Thanks for catching that. I changed Plugin
jam
2011/09/13 15:58:13
cool. i was just going to comment that it would be
| |
125 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); | 123 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); |
126 plugin_prefs->UpdatePreferences(0); | 124 plugin_prefs->EnablePluginGroup( |
125 false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); | |
127 } | 126 } |
128 | 127 |
129 void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { | 128 void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { |
130 UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel")); | 129 UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel")); |
131 } | 130 } |
132 | 131 |
133 // Launch the url to get the latest Adbobe Reader installer. | 132 // Launch the url to get the latest Adbobe Reader installer. |
134 void OpenReaderUpdateURL(TabContents* tab) { | 133 void OpenReaderUpdateURL(TabContents* tab) { |
135 tab->OpenURL(GURL(kReaderUpdateUrl), GURL(), CURRENT_TAB, | 134 tab->OpenURL(GURL(kReaderUpdateUrl), GURL(), CURRENT_TAB, |
136 PageTransition::LINK); | 135 PageTransition::LINK); |
137 } | 136 } |
138 | 137 |
139 // Opens the PDF using Adobe Reader. | 138 // Opens the PDF using Adobe Reader. |
140 void OpenUsingReader(TabContentsWrapper* tab, | 139 void OpenUsingReader(TabContentsWrapper* tab, |
141 const WebPluginInfo& reader_plugin, | 140 const WebPluginInfo& reader_plugin, |
142 InfoBarDelegate* old_delegate, | 141 InfoBarDelegate* old_delegate, |
143 InfoBarDelegate* new_delegate) { | 142 InfoBarDelegate* new_delegate) { |
144 WebPluginInfo plugin = reader_plugin; | 143 WebPluginInfo plugin = reader_plugin; |
145 // The plugin is disabled, so enable it to get around the renderer check. | 144 // Give the plugin a new version so that the renderer doesn't show the blocked |
146 // Also give it a new version so that the renderer doesn't show the blocked | |
147 // plugin UI if it's vulnerable, since we already went through the | 145 // plugin UI if it's vulnerable, since we already went through the |
148 // interstitial. | 146 // interstitial. |
149 plugin.enabled = WebPluginInfo::USER_ENABLED; | |
150 plugin.version = ASCIIToUTF16("11.0.0.0"); | 147 plugin.version = ASCIIToUTF16("11.0.0.0"); |
151 | 148 |
152 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( | 149 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( |
153 tab->render_view_host()->process()->id(), | 150 tab->render_view_host()->process()->id(), |
154 tab->render_view_host()->routing_id(), | 151 tab->render_view_host()->routing_id(), |
155 tab->tab_contents()->GetURL(), | 152 tab->tab_contents()->GetURL(), |
156 plugin); | 153 plugin); |
157 tab->render_view_host()->Send(new ViewMsg_ReloadFrame( | 154 tab->render_view_host()->Send(new ViewMsg_ReloadFrame( |
158 tab->render_view_host()->routing_id())); | 155 tab->render_view_host()->routing_id())); |
159 | 156 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 tab_contents_(tab_contents), | 274 tab_contents_(tab_contents), |
278 reader_installed_(!!reader_group), | 275 reader_installed_(!!reader_group), |
279 reader_vulnerable_(false) { | 276 reader_vulnerable_(false) { |
280 if (!reader_installed_) { | 277 if (!reader_installed_) { |
281 UserMetrics::RecordAction( | 278 UserMetrics::RecordAction( |
282 UserMetricsAction("PDF_InstallReaderInfoBarShown")); | 279 UserMetricsAction("PDF_InstallReaderInfoBarShown")); |
283 return; | 280 return; |
284 } | 281 } |
285 | 282 |
286 UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); | 283 UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); |
287 std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos(); | 284 const std::vector<WebPluginInfo>& plugins = |
285 reader_group->web_plugin_infos(); | |
288 DCHECK_EQ(plugins.size(), 1u); | 286 DCHECK_EQ(plugins.size(), 1u); |
289 reader_webplugininfo_ = plugins[0]; | 287 reader_webplugininfo_ = plugins[0]; |
290 | 288 |
291 reader_vulnerable_ = reader_group->IsVulnerable(); | 289 reader_vulnerable_ = reader_group->IsVulnerable(reader_webplugininfo_); |
292 if (!reader_vulnerable_) { | 290 if (!reader_vulnerable_) { |
293 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString( | 291 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString( |
294 reader_webplugininfo_.version)); | 292 reader_webplugininfo_.version)); |
295 reader_vulnerable_ = | 293 reader_vulnerable_ = |
296 version.get() && (version->components()[0] < kMinReaderVersionToUse); | 294 version.get() && (version->components()[0] < kMinReaderVersionToUse); |
297 } | 295 } |
298 } | 296 } |
299 | 297 |
300 PDFUnsupportedFeatureInfoBarDelegate::~PDFUnsupportedFeatureInfoBarDelegate() { | 298 PDFUnsupportedFeatureInfoBarDelegate::~PDFUnsupportedFeatureInfoBarDelegate() { |
301 } | 299 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 | 373 |
376 void PDFHasUnsupportedFeature(TabContentsWrapper* tab) { | 374 void PDFHasUnsupportedFeature(TabContentsWrapper* tab) { |
377 #if !defined(OS_WIN) | 375 #if !defined(OS_WIN) |
378 // Only works for Windows for now. For Mac, we'll have to launch the file | 376 // Only works for Windows for now. For Mac, we'll have to launch the file |
379 // externally since Adobe Reader doesn't work inside Chrome. | 377 // externally since Adobe Reader doesn't work inside Chrome. |
380 return; | 378 return; |
381 #endif | 379 #endif |
382 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | 380 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); |
383 | 381 |
384 // If the Reader plugin is disabled by policy, don't prompt them. | 382 // If the Reader plugin is disabled by policy, don't prompt them. |
385 if (PluginGroup::IsPluginNameDisabledByPolicy(reader_group_name)) | 383 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); |
384 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == | |
385 PluginPrefs::POLICY_DISABLED) { | |
386 return; | 386 return; |
387 } | |
387 | 388 |
388 PluginGroup* reader_group = NULL; | 389 PluginGroup* reader_group = NULL; |
389 std::vector<PluginGroup> plugin_groups; | 390 std::vector<PluginGroup> plugin_groups; |
390 PluginList::Singleton()->GetPluginGroups(false, &plugin_groups); | 391 PluginList::Singleton()->GetPluginGroups(false, &plugin_groups); |
391 for (size_t i = 0; i < plugin_groups.size(); ++i) { | 392 for (size_t i = 0; i < plugin_groups.size(); ++i) { |
392 if (plugin_groups[i].GetGroupName() == reader_group_name) { | 393 if (plugin_groups[i].GetGroupName() == reader_group_name) { |
393 reader_group = &plugin_groups[i]; | 394 reader_group = &plugin_groups[i]; |
394 break; | 395 break; |
395 } | 396 } |
396 } | 397 } |
397 | 398 |
398 tab->infobar_tab_helper()->AddInfoBar( | 399 tab->infobar_tab_helper()->AddInfoBar( |
399 new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group)); | 400 new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group)); |
400 } | 401 } |
OLD | NEW |