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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/prefs/pref_service.h" | |
10 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
11 #include "base/values.h" | |
12 #include "base/version.h" | |
13 #include "chrome/browser/lifetime/application_lifetime.h" | 10 #include "chrome/browser/lifetime/application_lifetime.h" |
14 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 11 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
15 #include "chrome/browser/plugins/plugin_finder.h" | |
16 #include "chrome/browser/plugins/plugin_metadata.h" | 12 #include "chrome/browser/plugins/plugin_metadata.h" |
17 #include "chrome/browser/plugins/plugin_prefs.h" | 13 #include "chrome/browser/plugins/plugin_prefs.h" |
18 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/renderer_preferences_util.h" | 15 #include "chrome/browser/renderer_preferences_util.h" |
20 #include "chrome/browser/tab_contents/tab_util.h" | 16 #include "chrome/browser/tab_contents/tab_util.h" |
21 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" | 17 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" |
22 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" | 18 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" |
23 #include "chrome/common/chrome_content_client.h" | 19 #include "chrome/common/chrome_content_client.h" |
24 #include "chrome/common/pref_names.h" | |
25 #include "content/public/browser/interstitial_page.h" | 20 #include "content/public/browser/interstitial_page.h" |
26 #include "content/public/browser/interstitial_page_delegate.h" | 21 #include "content/public/browser/interstitial_page_delegate.h" |
27 #include "content/public/browser/navigation_details.h" | 22 #include "content/public/browser/navigation_details.h" |
28 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
29 #include "content/public/browser/plugin_service.h" | 24 #include "content/public/browser/page_navigator.h" |
30 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
31 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
32 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
33 #include "content/public/browser/user_metrics.h" | 28 #include "content/public/browser/user_metrics.h" |
34 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
35 #include "content/public/common/page_transition_types.h" | |
36 #include "grit/browser_resources.h" | 30 #include "grit/browser_resources.h" |
37 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
38 #include "grit/theme_resources.h" | |
39 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
40 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
41 #include "ui/base/webui/jstemplate_builder.h" | 34 #include "ui/base/webui/jstemplate_builder.h" |
42 #include "ui/gfx/image/image.h" | |
43 | 35 |
44 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
45 #include "base/win/metro.h" | 37 #include "base/win/metro.h" |
| 38 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" |
46 #endif | 39 #endif |
47 | 40 |
48 using base::UserMetricsAction; | 41 using base::UserMetricsAction; |
49 using content::InterstitialPage; | 42 using content::InterstitialPage; |
50 using content::OpenURLParams; | 43 using content::OpenURLParams; |
51 using content::PluginService; | |
52 using content::Referrer; | 44 using content::Referrer; |
53 using content::WebContents; | 45 using content::WebContents; |
54 using content::WebPluginInfo; | 46 using content::WebPluginInfo; |
55 | 47 |
| 48 #if defined(OS_WIN) |
56 namespace { | 49 namespace { |
57 | 50 |
58 const char kAdobeReaderUpdateUrl[] = "http://www.adobe.com/go/getreader_chrome"; | 51 const char kAdobeReaderUpdateUrl[] = "http://www.adobe.com/go/getreader_chrome"; |
59 | 52 |
60 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) | |
61 const char kAdobeReaderIdentifier[] = "adobe-reader"; | |
62 #endif | |
63 | |
64 // The prompt delegate used to ask the user if they want to use Adobe Reader | 53 // The prompt delegate used to ask the user if they want to use Adobe Reader |
65 // by default. | 54 // by default. |
66 class PDFEnableAdobeReaderPromptDelegate | 55 class PDFEnableAdobeReaderPromptDelegate |
67 : public OpenPDFInReaderPromptDelegate { | 56 : public OpenPDFInReaderPromptDelegate { |
68 public: | 57 public: |
69 explicit PDFEnableAdobeReaderPromptDelegate(Profile* profile); | 58 explicit PDFEnableAdobeReaderPromptDelegate(Profile* profile); |
70 virtual ~PDFEnableAdobeReaderPromptDelegate(); | 59 virtual ~PDFEnableAdobeReaderPromptDelegate(); |
71 | 60 |
72 // OpenPDFInReaderPromptDelegate | 61 // OpenPDFInReaderPromptDelegate |
73 virtual base::string16 GetMessageText() const OVERRIDE; | 62 virtual base::string16 GetMessageText() const OVERRIDE; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 InterstitialPage* interstitial_page_; // Owns us. | 226 InterstitialPage* interstitial_page_; // Owns us. |
238 | 227 |
239 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); | 228 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); |
240 }; | 229 }; |
241 | 230 |
242 // The delegate for the bubble used to inform the user that we don't support a | 231 // The delegate for the bubble used to inform the user that we don't support a |
243 // feature in the PDF. | 232 // feature in the PDF. |
244 class PDFUnsupportedFeaturePromptDelegate | 233 class PDFUnsupportedFeaturePromptDelegate |
245 : public OpenPDFInReaderPromptDelegate { | 234 : public OpenPDFInReaderPromptDelegate { |
246 public: | 235 public: |
247 // |reader| is NULL if Adobe Reader isn't installed. | 236 PDFUnsupportedFeaturePromptDelegate( |
248 PDFUnsupportedFeaturePromptDelegate(WebContents* web_contents, | 237 WebContents* web_contents, |
249 const content::WebPluginInfo* reader, | 238 const AdobeReaderPluginInfo& reader_info); |
250 PluginFinder* plugin_finder); | |
251 virtual ~PDFUnsupportedFeaturePromptDelegate(); | 239 virtual ~PDFUnsupportedFeaturePromptDelegate(); |
252 | 240 |
253 // OpenPDFInReaderPromptDelegate: | 241 // OpenPDFInReaderPromptDelegate: |
254 virtual base::string16 GetMessageText() const OVERRIDE; | 242 virtual base::string16 GetMessageText() const OVERRIDE; |
255 virtual base::string16 GetAcceptButtonText() const OVERRIDE; | 243 virtual base::string16 GetAcceptButtonText() const OVERRIDE; |
256 virtual base::string16 GetCancelButtonText() const OVERRIDE; | 244 virtual base::string16 GetCancelButtonText() const OVERRIDE; |
257 virtual bool ShouldExpire( | 245 virtual bool ShouldExpire( |
258 const content::LoadCommittedDetails& details) const OVERRIDE; | 246 const content::LoadCommittedDetails& details) const OVERRIDE; |
259 virtual void Accept() OVERRIDE; | 247 virtual void Accept() OVERRIDE; |
260 virtual void Cancel() OVERRIDE; | 248 virtual void Cancel() OVERRIDE; |
261 | 249 |
262 private: | 250 private: |
263 WebContents* web_contents_; | 251 WebContents* web_contents_; |
264 bool reader_installed_; | 252 const AdobeReaderPluginInfo reader_info_; |
265 bool reader_vulnerable_; | |
266 WebPluginInfo reader_webplugininfo_; | |
267 | 253 |
268 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeaturePromptDelegate); | 254 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeaturePromptDelegate); |
269 }; | 255 }; |
270 | 256 |
271 PDFUnsupportedFeaturePromptDelegate::PDFUnsupportedFeaturePromptDelegate( | 257 PDFUnsupportedFeaturePromptDelegate::PDFUnsupportedFeaturePromptDelegate( |
272 WebContents* web_contents, | 258 WebContents* web_contents, |
273 const content::WebPluginInfo* reader, | 259 const AdobeReaderPluginInfo& reader_info) |
274 PluginFinder* plugin_finder) | |
275 : web_contents_(web_contents), | 260 : web_contents_(web_contents), |
276 reader_installed_(!!reader), | 261 reader_info_(reader_info) { |
277 reader_vulnerable_(false) { | 262 content::RecordAction(reader_info_.is_installed ? |
278 if (!reader_installed_) { | 263 UserMetricsAction("PDF_UseReaderInfoBarShown") : |
279 content::RecordAction( | 264 UserMetricsAction("PDF_InstallReaderInfoBarShown")); |
280 UserMetricsAction("PDF_InstallReaderInfoBarShown")); | |
281 return; | |
282 } | |
283 | |
284 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); | |
285 reader_webplugininfo_ = *reader; | |
286 | |
287 #if defined(ENABLE_PLUGIN_INSTALLATION) | |
288 scoped_ptr<PluginMetadata> plugin_metadata( | |
289 plugin_finder->GetPluginMetadata(reader_webplugininfo_)); | |
290 | |
291 reader_vulnerable_ = plugin_metadata->GetSecurityStatus(*reader) != | |
292 PluginMetadata::SECURITY_STATUS_UP_TO_DATE; | |
293 #else | |
294 NOTREACHED(); | |
295 #endif | |
296 } | 265 } |
297 | 266 |
298 PDFUnsupportedFeaturePromptDelegate::~PDFUnsupportedFeaturePromptDelegate() { | 267 PDFUnsupportedFeaturePromptDelegate::~PDFUnsupportedFeaturePromptDelegate() { |
299 } | 268 } |
300 | 269 |
301 base::string16 PDFUnsupportedFeaturePromptDelegate::GetMessageText() const { | 270 base::string16 PDFUnsupportedFeaturePromptDelegate::GetMessageText() const { |
302 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_MESSAGE); | 271 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_MESSAGE); |
303 } | 272 } |
304 | 273 |
305 base::string16 PDFUnsupportedFeaturePromptDelegate::GetAcceptButtonText() | 274 base::string16 PDFUnsupportedFeaturePromptDelegate::GetAcceptButtonText() |
306 const { | 275 const { |
307 #if defined(OS_WIN) | |
308 if (base::win::IsMetroProcess()) | 276 if (base::win::IsMetroProcess()) |
309 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_METRO_MODE_LINK); | 277 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_METRO_MODE_LINK); |
310 #endif | |
311 | 278 |
312 if (reader_installed_) | 279 return l10n_util::GetStringUTF16( |
313 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_OPEN_IN_READER_LINK); | 280 reader_info_.is_installed ? IDS_PDF_BUBBLE_OPEN_IN_READER_LINK |
314 | 281 : IDS_PDF_BUBBLE_INSTALL_READER_LINK); |
315 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_INSTALL_READER_LINK); | |
316 } | 282 } |
317 | 283 |
318 base::string16 PDFUnsupportedFeaturePromptDelegate::GetCancelButtonText() | 284 base::string16 PDFUnsupportedFeaturePromptDelegate::GetCancelButtonText() |
319 const { | 285 const { |
320 return l10n_util::GetStringUTF16(IDS_DONE); | 286 return l10n_util::GetStringUTF16(IDS_DONE); |
321 } | 287 } |
322 | 288 |
323 bool PDFUnsupportedFeaturePromptDelegate::ShouldExpire( | 289 bool PDFUnsupportedFeaturePromptDelegate::ShouldExpire( |
324 const content::LoadCommittedDetails& details) const { | 290 const content::LoadCommittedDetails& details) const { |
325 return !details.is_in_page; | 291 return !details.is_in_page; |
326 } | 292 } |
327 | 293 |
328 void PDFUnsupportedFeaturePromptDelegate::Accept() { | 294 void PDFUnsupportedFeaturePromptDelegate::Accept() { |
329 #if defined(OS_WIN) | |
330 if (base::win::IsMetroProcess()) { | 295 if (base::win::IsMetroProcess()) { |
331 chrome::AttemptRestartWithModeSwitch(); | 296 chrome::AttemptRestartWithModeSwitch(); |
332 return; | 297 return; |
333 } | 298 } |
334 #endif | |
335 | 299 |
336 if (!reader_installed_) { | 300 if (!reader_info_.is_installed) { |
337 content::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK")); | 301 content::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK")); |
338 OpenReaderUpdateURL(web_contents_); | 302 OpenReaderUpdateURL(web_contents_); |
339 return; | 303 return; |
340 } | 304 } |
341 | 305 |
342 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); | 306 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); |
343 | 307 |
344 if (reader_vulnerable_) { | 308 if (!reader_info_.is_secure) { |
345 new PDFUnsupportedFeatureInterstitial(web_contents_, reader_webplugininfo_); | 309 new PDFUnsupportedFeatureInterstitial(web_contents_, |
| 310 reader_info_.plugin_info); |
346 return; | 311 return; |
347 } | 312 } |
348 | 313 |
349 Profile* profile = | 314 Profile* profile = |
350 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 315 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
351 OpenPDFInReaderPromptDelegate* delegate = | 316 OpenPDFInReaderPromptDelegate* delegate = |
352 new PDFEnableAdobeReaderPromptDelegate(profile); | 317 new PDFEnableAdobeReaderPromptDelegate(profile); |
353 | 318 |
354 OpenUsingReader(web_contents_, reader_webplugininfo_, delegate); | 319 OpenUsingReader(web_contents_, reader_info_.plugin_info, delegate); |
355 } | 320 } |
356 | 321 |
357 void PDFUnsupportedFeaturePromptDelegate::Cancel() { | 322 void PDFUnsupportedFeaturePromptDelegate::Cancel() { |
358 content::RecordAction(reader_installed_ ? | 323 content::RecordAction(reader_info_.is_installed ? |
359 UserMetricsAction("PDF_UseReaderInfoBarCancel") : | 324 UserMetricsAction("PDF_UseReaderInfoBarCancel") : |
360 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); | 325 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); |
361 } | 326 } |
362 | 327 |
363 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) | 328 void MaybeShowOpenPDFInReaderPrompt(WebContents* web_contents, |
364 void GotPluginsCallback(int process_id, | 329 const AdobeReaderPluginInfo& reader_info) { |
365 int routing_id, | 330 // If the Reader plugin is disabled by policy, don't prompt them. |
366 const std::vector<content::WebPluginInfo>& plugins) { | 331 if (!reader_info.is_installed || !reader_info.is_enabled) |
367 WebContents* web_contents = | |
368 tab_util::GetWebContentsByID(process_id, routing_id); | |
369 if (!web_contents) | |
370 return; | 332 return; |
371 | 333 |
372 const content::WebPluginInfo* reader = NULL; | |
373 PluginFinder* plugin_finder = PluginFinder::GetInstance(); | |
374 for (size_t i = 0; i < plugins.size(); ++i) { | |
375 scoped_ptr<PluginMetadata> plugin_metadata( | |
376 plugin_finder->GetPluginMetadata(plugins[i])); | |
377 if (plugin_metadata->identifier() != kAdobeReaderIdentifier) | |
378 continue; | |
379 | |
380 DCHECK(!reader); | |
381 reader = &plugins[i]; | |
382 // If the Reader plugin is disabled by policy, don't prompt them. | |
383 Profile* profile = | |
384 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
385 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); | |
386 if (plugin_prefs->PolicyStatusForPlugin(plugin_metadata->name()) == | |
387 PluginPrefs::POLICY_DISABLED) { | |
388 return; | |
389 } | |
390 break; | |
391 } | |
392 | |
393 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt( | 334 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt( |
394 new PDFUnsupportedFeaturePromptDelegate( | 335 new PDFUnsupportedFeaturePromptDelegate(web_contents, reader_info)); |
395 web_contents, reader, plugin_finder)); | |
396 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); | 336 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); |
397 pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass()); | 337 pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass()); |
398 } | 338 } |
399 #endif // defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) | 339 |
| 340 void GotPluginsCallback(int process_id, |
| 341 int routing_id, |
| 342 const AdobeReaderPluginInfo& reader_info) { |
| 343 WebContents* web_contents = |
| 344 tab_util::GetWebContentsByID(process_id, routing_id); |
| 345 if (web_contents) |
| 346 MaybeShowOpenPDFInReaderPrompt(web_contents, reader_info); |
| 347 } |
400 | 348 |
401 } // namespace | 349 } // namespace |
| 350 #endif // defined(OS_WIN) |
402 | 351 |
403 void PDFHasUnsupportedFeature(content::WebContents* web_contents) { | 352 void PDFHasUnsupportedFeature(WebContents* web_contents) { |
404 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) | 353 #if defined(OS_WIN) |
405 // Only works for Windows for now. For Mac, we'll have to launch the file | 354 // Only works for Windows for now. For Mac, we'll have to launch the file |
406 // externally since Adobe Reader doesn't work inside Chrome. | 355 // externally since Adobe Reader doesn't work inside Chrome. |
407 PluginService::GetInstance()->GetPlugins(base::Bind(&GotPluginsCallback, | 356 Profile* profile = |
408 web_contents->GetRenderProcessHost()->GetID(), | 357 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
409 web_contents->GetRenderViewHost()->GetRoutingID())); | 358 AdobeReaderPluginInfo reader_info; |
410 #endif | 359 if (GetAdobeReaderPluginInfo(profile, &reader_info)) { |
| 360 MaybeShowOpenPDFInReaderPrompt(web_contents, reader_info); |
| 361 return; |
| 362 } |
| 363 GetAdobeReaderPluginInfoAsync( |
| 364 profile, |
| 365 base::Bind(&GotPluginsCallback, |
| 366 web_contents->GetRenderProcessHost()->GetID(), |
| 367 web_contents->GetRenderViewHost()->GetRoutingID())); |
| 368 #endif // defined(OS_WIN) |
411 } | 369 } |
OLD | NEW |