OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 using content::OpenURLParams; | 49 using content::OpenURLParams; |
50 using content::PluginService; | 50 using content::PluginService; |
51 using content::Referrer; | 51 using content::Referrer; |
52 using content::UserMetricsAction; | 52 using content::UserMetricsAction; |
53 using content::WebContents; | 53 using content::WebContents; |
54 using webkit::npapi::PluginGroup; | 54 using webkit::npapi::PluginGroup; |
55 using webkit::WebPluginInfo; | 55 using webkit::WebPluginInfo; |
56 | 56 |
57 namespace { | 57 namespace { |
58 | 58 |
59 static const char kReaderUpdateUrl[] = | 59 static const char kAdobeReaderIdentifier[] = "adobe-reader"; |
| 60 static const char kAdobeReaderUpdateUrl[] = |
60 "http://www.adobe.com/go/getreader_chrome"; | 61 "http://www.adobe.com/go/getreader_chrome"; |
61 | 62 |
62 // The info bar delegate used to ask the user if they want to use Adobe Reader | 63 // The info bar delegate used to ask the user if they want to use Adobe Reader |
63 // by default. We want the infobar to have [No][Yes], so we swap the text on | 64 // by default. We want the infobar to have [No][Yes], so we swap the text on |
64 // the buttons, and the meaning of the delegate callbacks. | 65 // the buttons, and the meaning of the delegate callbacks. |
65 class PDFEnableAdobeReaderInfoBarDelegate : public ConfirmInfoBarDelegate { | 66 class PDFEnableAdobeReaderInfoBarDelegate : public ConfirmInfoBarDelegate { |
66 public: | 67 public: |
67 explicit PDFEnableAdobeReaderInfoBarDelegate( | 68 explicit PDFEnableAdobeReaderInfoBarDelegate( |
68 InfoBarTabHelper* infobar_helper, | 69 InfoBarTabHelper* infobar_helper, |
69 Profile* profile); | 70 Profile* profile); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); | 138 false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); |
138 } | 139 } |
139 | 140 |
140 void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { | 141 void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { |
141 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel")); | 142 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel")); |
142 } | 143 } |
143 | 144 |
144 // Launch the url to get the latest Adbobe Reader installer. | 145 // Launch the url to get the latest Adbobe Reader installer. |
145 void OpenReaderUpdateURL(WebContents* tab) { | 146 void OpenReaderUpdateURL(WebContents* tab) { |
146 OpenURLParams params( | 147 OpenURLParams params( |
147 GURL(kReaderUpdateUrl), Referrer(), NEW_FOREGROUND_TAB, | 148 GURL(kAdobeReaderUpdateUrl), Referrer(), NEW_FOREGROUND_TAB, |
148 content::PAGE_TRANSITION_LINK, false); | 149 content::PAGE_TRANSITION_LINK, false); |
149 tab->OpenURL(params); | 150 tab->OpenURL(params); |
150 } | 151 } |
151 | 152 |
152 // Opens the PDF using Adobe Reader. | 153 // Opens the PDF using Adobe Reader. |
153 void OpenUsingReader(TabContents* tab, | 154 void OpenUsingReader(TabContents* tab, |
154 const WebPluginInfo& reader_plugin, | 155 const WebPluginInfo& reader_plugin, |
155 InfoBarDelegate* delegate) { | 156 InfoBarDelegate* delegate) { |
156 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( | 157 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( |
157 tab->web_contents()->GetRenderProcessHost()->GetID(), | 158 tab->web_contents()->GetRenderProcessHost()->GetID(), |
158 tab->web_contents()->GetRenderViewHost()->GetRoutingID(), | 159 tab->web_contents()->GetRenderViewHost()->GetRoutingID(), |
159 tab->web_contents()->GetURL(), | 160 tab->web_contents()->GetURL(), |
160 ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | 161 reader_plugin); |
161 tab->web_contents()->GetRenderViewHost()->ReloadFrame(); | 162 tab->web_contents()->GetRenderViewHost()->ReloadFrame(); |
162 | 163 |
163 if (delegate) | 164 if (delegate) |
164 tab->infobar_tab_helper()->AddInfoBar(delegate); | 165 tab->infobar_tab_helper()->AddInfoBar(delegate); |
165 } | 166 } |
166 | 167 |
167 // An interstitial to be used when the user chooses to open a PDF using Adobe | 168 // An interstitial to be used when the user chooses to open a PDF using Adobe |
168 // Reader, but it is out of date. | 169 // Reader, but it is out of date. |
169 class PDFUnsupportedFeatureInterstitial | 170 class PDFUnsupportedFeatureInterstitial |
170 : public content::InterstitialPageDelegate { | 171 : public content::InterstitialPageDelegate { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return; | 220 return; |
220 } | 221 } |
221 | 222 |
222 if (command == "1") { | 223 if (command == "1") { |
223 content::RecordAction( | 224 content::RecordAction( |
224 UserMetricsAction("PDF_ReaderInterstitialUpdate")); | 225 UserMetricsAction("PDF_ReaderInterstitialUpdate")); |
225 OpenReaderUpdateURL(tab_contents_->web_contents()); | 226 OpenReaderUpdateURL(tab_contents_->web_contents()); |
226 } else if (command == "2") { | 227 } else if (command == "2") { |
227 content::RecordAction( | 228 content::RecordAction( |
228 UserMetricsAction("PDF_ReaderInterstitialIgnore")); | 229 UserMetricsAction("PDF_ReaderInterstitialIgnore")); |
| 230 // Pretend that the plug-in is up-to-date so that we don't block it. |
| 231 reader_webplugininfo_.version = ASCIIToUTF16("11.0.0.0"); |
229 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL); | 232 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL); |
230 } else { | 233 } else { |
231 NOTREACHED(); | 234 NOTREACHED(); |
232 } | 235 } |
233 interstitial_page_->Proceed(); | 236 interstitial_page_->Proceed(); |
234 } | 237 } |
235 | 238 |
236 virtual void OverrideRendererPrefs( | 239 virtual void OverrideRendererPrefs( |
237 content::RendererPreferences* prefs) OVERRIDE { | 240 content::RendererPreferences* prefs) OVERRIDE { |
238 renderer_preferences_util::UpdateFromSystemSettings( | 241 renderer_preferences_util::UpdateFromSystemSettings( |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 const std::vector<webkit::WebPluginInfo>& plugins) { | 370 const std::vector<webkit::WebPluginInfo>& plugins) { |
368 WebContents* web_contents = | 371 WebContents* web_contents = |
369 tab_util::GetWebContentsByID(process_id, routing_id); | 372 tab_util::GetWebContentsByID(process_id, routing_id); |
370 if (!web_contents) | 373 if (!web_contents) |
371 return; | 374 return; |
372 | 375 |
373 TabContents* tab = TabContents::FromWebContents(web_contents); | 376 TabContents* tab = TabContents::FromWebContents(web_contents); |
374 if (!tab) | 377 if (!tab) |
375 return; | 378 return; |
376 | 379 |
377 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | |
378 // If the Reader plugin is disabled by policy, don't prompt them. | |
379 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); | |
380 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == | |
381 PluginPrefs::POLICY_DISABLED) { | |
382 return; | |
383 } | |
384 | |
385 const webkit::WebPluginInfo* reader = NULL; | 380 const webkit::WebPluginInfo* reader = NULL; |
386 PluginFinder* plugin_finder = PluginFinder::GetInstance(); | 381 PluginFinder* plugin_finder = PluginFinder::GetInstance(); |
387 for (size_t i = 0; i < plugins.size(); ++i) { | 382 for (size_t i = 0; i < plugins.size(); ++i) { |
388 PluginMetadata* plugin_metadata = | 383 PluginMetadata* plugin_metadata = |
389 plugin_finder->GetPluginMetadata(plugins[i]); | 384 plugin_finder->GetPluginMetadata(plugins[i]); |
390 if (reader_group_name == plugin_metadata->name()) { | 385 if (plugin_metadata->identifier() != kAdobeReaderIdentifier) |
391 DCHECK(!reader); | 386 continue; |
392 reader = &plugins[i]; | 387 |
| 388 DCHECK(!reader); |
| 389 reader = &plugins[i]; |
| 390 // If the Reader plugin is disabled by policy, don't prompt them. |
| 391 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); |
| 392 if (plugin_prefs->PolicyStatusForPlugin(plugin_metadata->name()) == |
| 393 PluginPrefs::POLICY_DISABLED) { |
| 394 return; |
393 } | 395 } |
| 396 break; |
394 } | 397 } |
395 | 398 |
396 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt( | 399 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt( |
397 new PDFUnsupportedFeaturePromptDelegate(tab, reader, plugin_finder)); | 400 new PDFUnsupportedFeaturePromptDelegate(tab, reader, plugin_finder)); |
398 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); | 401 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); |
399 pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass()); | 402 pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass()); |
400 } | 403 } |
401 | 404 |
402 } // namespace | 405 } // namespace |
403 | 406 |
404 void PDFHasUnsupportedFeature(content::WebContents* web_contents) { | 407 void PDFHasUnsupportedFeature(content::WebContents* web_contents) { |
405 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) | 408 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) |
406 // Only works for Windows for now. For Mac, we'll have to launch the file | 409 // Only works for Windows for now. For Mac, we'll have to launch the file |
407 // externally since Adobe Reader doesn't work inside Chrome. | 410 // externally since Adobe Reader doesn't work inside Chrome. |
408 PluginService::GetInstance()->GetPlugins(base::Bind(&GotPluginsCallback, | 411 PluginService::GetInstance()->GetPlugins(base::Bind(&GotPluginsCallback, |
409 web_contents->GetRenderProcessHost()->GetID(), | 412 web_contents->GetRenderProcessHost()->GetID(), |
410 web_contents->GetRenderViewHost()->GetRoutingID())); | 413 web_contents->GetRenderViewHost()->GetRoutingID())); |
411 #endif | 414 #endif |
412 } | 415 } |
OLD | NEW |