| 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/plugin_finder.h" |
| 15 #include "chrome/browser/plugin_installer.h" |
| 14 #include "chrome/browser/plugin_prefs.h" | 16 #include "chrome/browser/plugin_prefs.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/renderer_preferences_util.h" | 19 #include "chrome/browser/renderer_preferences_util.h" |
| 18 #include "chrome/browser/tab_contents/tab_util.h" | 20 #include "chrome/browser/tab_contents/tab_util.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 20 #include "chrome/common/chrome_content_client.h" | 22 #include "chrome/common/chrome_content_client.h" |
| 21 #include "chrome/common/jstemplate_builder.h" | 23 #include "chrome/common/jstemplate_builder.h" |
| 22 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 23 #include "content/public/browser/interstitial_page.h" | 25 #include "content/public/browser/interstitial_page.h" |
| 24 #include "content/public/browser/interstitial_page_delegate.h" | 26 #include "content/public/browser/interstitial_page_delegate.h" |
| 25 #include "content/public/browser/plugin_service.h" | 27 #include "content/public/browser/plugin_service.h" |
| 26 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
| 27 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
| 28 #include "content/public/browser/user_metrics.h" | 30 #include "content/public/browser/user_metrics.h" |
| 29 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 30 #include "grit/browser_resources.h" | 32 #include "grit/browser_resources.h" |
| 31 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 32 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/base/layout.h" | 36 #include "ui/base/layout.h" |
| 35 #include "ui/base/resource/resource_bundle.h" | 37 #include "ui/base/resource/resource_bundle.h" |
| 36 #include "ui/gfx/image/image.h" | 38 #include "ui/gfx/image/image.h" |
| 37 #include "webkit/plugins/npapi/plugin_group.h" | 39 #include "webkit/plugins/npapi/plugin_group.h" |
| 38 | 40 |
| 39 #if defined(ENABLE_PLUGIN_INSTALLATION) | |
| 40 #include "chrome/browser/plugin_finder.h" | |
| 41 #include "chrome/browser/plugin_installer.h" | |
| 42 #else | |
| 43 // Forward-declare PluginFinder. It's never actually used, but we pass a NULL | |
| 44 // pointer instead. | |
| 45 class PluginFinder; | |
| 46 #endif | |
| 47 | |
| 48 using content::InterstitialPage; | 41 using content::InterstitialPage; |
| 49 using content::OpenURLParams; | 42 using content::OpenURLParams; |
| 50 using content::PluginService; | 43 using content::PluginService; |
| 51 using content::Referrer; | 44 using content::Referrer; |
| 52 using content::UserMetricsAction; | 45 using content::UserMetricsAction; |
| 53 using content::WebContents; | 46 using content::WebContents; |
| 54 using webkit::npapi::PluginGroup; | 47 using webkit::npapi::PluginGroup; |
| 55 using webkit::WebPluginInfo; | 48 using webkit::WebPluginInfo; |
| 56 | 49 |
| 57 namespace { | 50 namespace { |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL); | 371 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL); |
| 379 return true; | 372 return true; |
| 380 } | 373 } |
| 381 | 374 |
| 382 void PDFUnsupportedFeatureInfoBarDelegate::OnNo() { | 375 void PDFUnsupportedFeatureInfoBarDelegate::OnNo() { |
| 383 content::RecordAction(reader_installed_ ? | 376 content::RecordAction(reader_installed_ ? |
| 384 UserMetricsAction("PDF_UseReaderInfoBarCancel") : | 377 UserMetricsAction("PDF_UseReaderInfoBarCancel") : |
| 385 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); | 378 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); |
| 386 } | 379 } |
| 387 | 380 |
| 388 void GotPluginGroupsCallback(int process_id, | 381 void GotPluginsCallback(int process_id, |
| 389 int routing_id, | 382 int routing_id, |
| 390 PluginFinder* plugin_finder, | 383 PluginFinder* plugin_finder, |
| 391 const std::vector<PluginGroup>& groups) { | 384 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 392 WebContents* web_contents = | 385 WebContents* web_contents = |
| 393 tab_util::GetWebContentsByID(process_id, routing_id); | 386 tab_util::GetWebContentsByID(process_id, routing_id); |
| 394 if (!web_contents) | 387 if (!web_contents) |
| 395 return; | 388 return; |
| 396 | 389 |
| 397 TabContents* tab = TabContents::FromWebContents(web_contents); | 390 TabContents* tab = TabContents::FromWebContents(web_contents); |
| 398 if (!tab) | 391 if (!tab) |
| 399 return; | 392 return; |
| 400 | 393 |
| 401 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | 394 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); |
| 402 // If the Reader plugin is disabled by policy, don't prompt them. | 395 // If the Reader plugin is disabled by policy, don't prompt them. |
| 403 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); | 396 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); |
| 404 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == | 397 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == |
| 405 PluginPrefs::POLICY_DISABLED) { | 398 PluginPrefs::POLICY_DISABLED) { |
| 406 return; | 399 return; |
| 407 } | 400 } |
| 408 | 401 |
| 409 const webkit::WebPluginInfo* reader = NULL; | 402 const webkit::WebPluginInfo* reader = NULL; |
| 410 for (size_t i = 0; i < groups.size(); ++i) { | 403 for (size_t i = 0; i < plugins.size(); ++i) { |
| 411 if (groups[i].GetGroupName() == reader_group_name) { | 404 PluginInstaller* installer = plugin_finder->GetPluginInstaller(plugins[i]); |
| 412 const std::vector<WebPluginInfo>& plugins = | 405 if (reader_group_name == installer->name()) { |
| 413 groups[i].web_plugin_infos(); | 406 DCHECK(!reader); |
| 414 DCHECK_EQ(plugins.size(), 1u); | 407 reader = &plugins[i]; |
| 415 reader = &plugins[0]; | |
| 416 break; | |
| 417 } | 408 } |
| 418 } | 409 } |
| 419 | 410 |
| 420 tab->infobar_tab_helper()->AddInfoBar( | 411 tab->infobar_tab_helper()->AddInfoBar( |
| 421 new PDFUnsupportedFeatureInfoBarDelegate(tab, reader, plugin_finder)); | 412 new PDFUnsupportedFeatureInfoBarDelegate(tab, reader, plugin_finder)); |
| 422 } | 413 } |
| 423 | 414 |
| 424 void GotPluginFinderCallback(int process_id, | 415 void GotPluginFinderCallback(int process_id, |
| 425 int routing_id, | 416 int routing_id, |
| 426 PluginFinder* plugin_finder) { | 417 PluginFinder* plugin_finder) { |
| 427 PluginService::GetInstance()->GetPluginGroups( | 418 PluginService::GetInstance()->GetPlugins( |
| 428 base::Bind(&GotPluginGroupsCallback, process_id, routing_id, | 419 base::Bind(&GotPluginsCallback, process_id, routing_id, |
| 429 base::Unretained(plugin_finder))); | 420 base::Unretained(plugin_finder))); |
| 430 } | 421 } |
| 431 | 422 |
| 432 } // namespace | 423 } // namespace |
| 433 | 424 |
| 434 void PDFHasUnsupportedFeature(TabContents* tab) { | 425 void PDFHasUnsupportedFeature(TabContents* tab) { |
| 435 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) | 426 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) |
| 436 // Only works for Windows for now. For Mac, we'll have to launch the file | 427 // Only works for Windows for now. For Mac, we'll have to launch the file |
| 437 // externally since Adobe Reader doesn't work inside Chrome. | 428 // externally since Adobe Reader doesn't work inside Chrome. |
| 438 PluginFinder::Get(base::Bind(&GotPluginFinderCallback, | 429 PluginFinder::Get(base::Bind(&GotPluginFinderCallback, |
| 439 tab->web_contents()->GetRenderProcessHost()->GetID(), | 430 tab->web_contents()->GetRenderProcessHost()->GetID(), |
| 440 tab->web_contents()->GetRenderViewHost()->GetRoutingID())); | 431 tab->web_contents()->GetRenderViewHost()->GetRoutingID())); |
| 441 #endif | 432 #endif |
| 442 } | 433 } |
| OLD | NEW |