| 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" |
| 11 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 11 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
| 12 #include "chrome/browser/chrome_plugin_service_filter.h" | 12 #include "chrome/browser/chrome_plugin_service_filter.h" |
| 13 #include "chrome/browser/infobars/infobar_tab_helper.h" | 13 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 14 #include "chrome/browser/lifetime/application_lifetime.h" | 14 #include "chrome/browser/lifetime/application_lifetime.h" |
| 15 #include "chrome/browser/plugins/plugin_finder.h" | 15 #include "chrome/browser/plugins/plugin_finder.h" |
| 16 #include "chrome/browser/plugins/plugin_installer.h" | 16 #include "chrome/browser/plugins/plugin_metadata.h" |
| 17 #include "chrome/browser/plugins/plugin_prefs.h" | 17 #include "chrome/browser/plugins/plugin_prefs.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/renderer_preferences_util.h" | 20 #include "chrome/browser/renderer_preferences_util.h" |
| 21 #include "chrome/browser/tab_contents/tab_util.h" | 21 #include "chrome/browser/tab_contents/tab_util.h" |
| 22 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" | 22 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" |
| 23 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" | 23 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 25 #include "chrome/common/chrome_content_client.h" | 25 #include "chrome/common/chrome_content_client.h" |
| 26 #include "chrome/common/jstemplate_builder.h" | 26 #include "chrome/common/jstemplate_builder.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 if (!reader_installed_) { | 284 if (!reader_installed_) { |
| 285 content::RecordAction( | 285 content::RecordAction( |
| 286 UserMetricsAction("PDF_InstallReaderInfoBarShown")); | 286 UserMetricsAction("PDF_InstallReaderInfoBarShown")); |
| 287 return; | 287 return; |
| 288 } | 288 } |
| 289 | 289 |
| 290 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); | 290 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); |
| 291 reader_webplugininfo_ = *reader; | 291 reader_webplugininfo_ = *reader; |
| 292 | 292 |
| 293 #if defined(ENABLE_PLUGIN_INSTALLATION) | 293 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 294 PluginInstaller* installer = | 294 PluginMetadata* plugin_metadata = |
| 295 plugin_finder->FindPluginWithIdentifier("adobe-reader"); | 295 plugin_finder->GetPluginMetadata(reader_webplugininfo_); |
| 296 | 296 |
| 297 reader_vulnerable_ = | 297 reader_vulnerable_ = plugin_metadata->GetSecurityStatus(*reader) != |
| 298 installer->GetSecurityStatus(*reader) != | 298 PluginMetadata::SECURITY_STATUS_UP_TO_DATE; |
| 299 PluginInstaller::SECURITY_STATUS_UP_TO_DATE; | |
| 300 #else | 299 #else |
| 301 NOTREACHED(); | 300 NOTREACHED(); |
| 302 #endif | 301 #endif |
| 303 } | 302 } |
| 304 | 303 |
| 305 PDFUnsupportedFeaturePromptDelegate::~PDFUnsupportedFeaturePromptDelegate() { | 304 PDFUnsupportedFeaturePromptDelegate::~PDFUnsupportedFeaturePromptDelegate() { |
| 306 } | 305 } |
| 307 | 306 |
| 308 string16 PDFUnsupportedFeaturePromptDelegate::GetMessageText() const { | 307 string16 PDFUnsupportedFeaturePromptDelegate::GetMessageText() const { |
| 309 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_MESSAGE); | 308 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_MESSAGE); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 357 } |
| 359 | 358 |
| 360 void PDFUnsupportedFeaturePromptDelegate::Cancel() { | 359 void PDFUnsupportedFeaturePromptDelegate::Cancel() { |
| 361 content::RecordAction(reader_installed_ ? | 360 content::RecordAction(reader_installed_ ? |
| 362 UserMetricsAction("PDF_UseReaderInfoBarCancel") : | 361 UserMetricsAction("PDF_UseReaderInfoBarCancel") : |
| 363 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); | 362 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); |
| 364 } | 363 } |
| 365 | 364 |
| 366 void GotPluginsCallback(int process_id, | 365 void GotPluginsCallback(int process_id, |
| 367 int routing_id, | 366 int routing_id, |
| 368 PluginFinder* plugin_finder, | |
| 369 const std::vector<webkit::WebPluginInfo>& plugins) { | 367 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 370 WebContents* web_contents = | 368 WebContents* web_contents = |
| 371 tab_util::GetWebContentsByID(process_id, routing_id); | 369 tab_util::GetWebContentsByID(process_id, routing_id); |
| 372 if (!web_contents) | 370 if (!web_contents) |
| 373 return; | 371 return; |
| 374 | 372 |
| 375 TabContents* tab = TabContents::FromWebContents(web_contents); | 373 TabContents* tab = TabContents::FromWebContents(web_contents); |
| 376 if (!tab) | 374 if (!tab) |
| 377 return; | 375 return; |
| 378 | 376 |
| 379 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | 377 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); |
| 380 // If the Reader plugin is disabled by policy, don't prompt them. | 378 // If the Reader plugin is disabled by policy, don't prompt them. |
| 381 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); | 379 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); |
| 382 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == | 380 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == |
| 383 PluginPrefs::POLICY_DISABLED) { | 381 PluginPrefs::POLICY_DISABLED) { |
| 384 return; | 382 return; |
| 385 } | 383 } |
| 386 | 384 |
| 387 const webkit::WebPluginInfo* reader = NULL; | 385 const webkit::WebPluginInfo* reader = NULL; |
| 386 PluginFinder* plugin_finder = PluginFinder::GetInstance(); |
| 388 for (size_t i = 0; i < plugins.size(); ++i) { | 387 for (size_t i = 0; i < plugins.size(); ++i) { |
| 389 PluginInstaller* installer = plugin_finder->GetPluginInstaller(plugins[i]); | 388 PluginMetadata* plugin_metadata = |
| 390 if (reader_group_name == installer->name()) { | 389 plugin_finder->GetPluginMetadata(plugins[i]); |
| 390 if (reader_group_name == plugin_metadata->name()) { |
| 391 DCHECK(!reader); | 391 DCHECK(!reader); |
| 392 reader = &plugins[i]; | 392 reader = &plugins[i]; |
| 393 } | 393 } |
| 394 } | 394 } |
| 395 | 395 |
| 396 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt( | 396 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt( |
| 397 new PDFUnsupportedFeaturePromptDelegate(tab, reader, plugin_finder)); | 397 new PDFUnsupportedFeaturePromptDelegate(tab, reader, plugin_finder)); |
| 398 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); | 398 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); |
| 399 pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass()); | 399 pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass()); |
| 400 } | 400 } |
| 401 | 401 |
| 402 void GotPluginFinderCallback(int process_id, | |
| 403 int routing_id, | |
| 404 PluginFinder* plugin_finder) { | |
| 405 PluginService::GetInstance()->GetPlugins( | |
| 406 base::Bind(&GotPluginsCallback, process_id, routing_id, | |
| 407 base::Unretained(plugin_finder))); | |
| 408 } | |
| 409 | |
| 410 } // namespace | 402 } // namespace |
| 411 | 403 |
| 412 void PDFHasUnsupportedFeature(content::WebContents* web_contents) { | 404 void PDFHasUnsupportedFeature(content::WebContents* web_contents) { |
| 413 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) | 405 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) |
| 414 // Only works for Windows for now. For Mac, we'll have to launch the file | 406 // Only works for Windows for now. For Mac, we'll have to launch the file |
| 415 // externally since Adobe Reader doesn't work inside Chrome. | 407 // externally since Adobe Reader doesn't work inside Chrome. |
| 416 PluginFinder::Get(base::Bind(&GotPluginFinderCallback, | 408 PluginService::GetInstance()->GetPlugins(base::Bind(&GotPluginsCallback, |
| 417 web_contents->GetRenderProcessHost()->GetID(), | 409 web_contents->GetRenderProcessHost()->GetID(), |
| 418 web_contents->GetRenderViewHost()->GetRoutingID())); | 410 web_contents->GetRenderViewHost()->GetRoutingID())); |
| 419 #endif | 411 #endif |
| 420 } | 412 } |
| OLD | NEW |