| 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 21 matching lines...) Expand all Loading... |
| 32 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
| 33 #include "content/public/browser/user_metrics.h" | 33 #include "content/public/browser/user_metrics.h" |
| 34 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 35 #include "grit/browser_resources.h" | 35 #include "grit/browser_resources.h" |
| 36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 37 #include "grit/theme_resources.h" | 37 #include "grit/theme_resources.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 39 #include "ui/base/layout.h" | 39 #include "ui/base/layout.h" |
| 40 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "ui/gfx/image/image.h" | 41 #include "ui/gfx/image/image.h" |
| 42 #include "webkit/plugins/npapi/plugin_group.h" | |
| 43 | 42 |
| 44 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
| 45 #include "base/win/metro.h" | 44 #include "base/win/metro.h" |
| 46 #endif | 45 #endif |
| 47 | 46 |
| 48 using content::InterstitialPage; | 47 using content::InterstitialPage; |
| 49 using content::OpenURLParams; | 48 using content::OpenURLParams; |
| 50 using content::PluginService; | 49 using content::PluginService; |
| 51 using content::Referrer; | 50 using content::Referrer; |
| 52 using content::UserMetricsAction; | 51 using content::UserMetricsAction; |
| 53 using content::WebContents; | 52 using content::WebContents; |
| 54 using webkit::npapi::PluginGroup; | |
| 55 using webkit::WebPluginInfo; | 53 using webkit::WebPluginInfo; |
| 56 | 54 |
| 57 namespace { | 55 namespace { |
| 58 | 56 |
| 59 static const char kReaderUpdateUrl[] = | 57 static const char kReaderUpdateUrl[] = |
| 60 "http://www.adobe.com/go/getreader_chrome"; | 58 "http://www.adobe.com/go/getreader_chrome"; |
| 61 | 59 |
| 62 // The info bar delegate used to ask the user if they want to use Adobe Reader | 60 // 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 | 61 // 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. | 62 // the buttons, and the meaning of the delegate callbacks. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 123 } |
| 126 | 124 |
| 127 string16 PDFEnableAdobeReaderInfoBarDelegate::GetMessageText() const { | 125 string16 PDFEnableAdobeReaderInfoBarDelegate::GetMessageText() const { |
| 128 return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); | 126 return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); |
| 129 } | 127 } |
| 130 | 128 |
| 131 void PDFEnableAdobeReaderInfoBarDelegate::OnYes() { | 129 void PDFEnableAdobeReaderInfoBarDelegate::OnYes() { |
| 132 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK")); | 130 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK")); |
| 133 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile_); | 131 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile_); |
| 134 plugin_prefs->EnablePluginGroup( | 132 plugin_prefs->EnablePluginGroup( |
| 135 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); | 133 true, ASCIIToUTF16(PluginMetadata::kAdobeReaderGroupName)); |
| 136 plugin_prefs->EnablePluginGroup( | 134 plugin_prefs->EnablePluginGroup( |
| 137 false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); | 135 false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); |
| 138 } | 136 } |
| 139 | 137 |
| 140 void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { | 138 void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { |
| 141 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel")); | 139 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel")); |
| 142 } | 140 } |
| 143 | 141 |
| 144 // Launch the url to get the latest Adbobe Reader installer. | 142 // Launch the url to get the latest Adbobe Reader installer. |
| 145 void OpenReaderUpdateURL(WebContents* tab) { | 143 void OpenReaderUpdateURL(WebContents* tab) { |
| 146 OpenURLParams params( | 144 OpenURLParams params( |
| 147 GURL(kReaderUpdateUrl), Referrer(), NEW_FOREGROUND_TAB, | 145 GURL(kReaderUpdateUrl), Referrer(), NEW_FOREGROUND_TAB, |
| 148 content::PAGE_TRANSITION_LINK, false); | 146 content::PAGE_TRANSITION_LINK, false); |
| 149 tab->OpenURL(params); | 147 tab->OpenURL(params); |
| 150 } | 148 } |
| 151 | 149 |
| 152 // Opens the PDF using Adobe Reader. | 150 // Opens the PDF using Adobe Reader. |
| 153 void OpenUsingReader(TabContents* tab, | 151 void OpenUsingReader(TabContents* tab, |
| 154 const WebPluginInfo& reader_plugin, | 152 const WebPluginInfo& reader_plugin, |
| 155 InfoBarDelegate* delegate) { | 153 InfoBarDelegate* delegate) { |
| 156 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( | 154 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( |
| 157 tab->web_contents()->GetRenderProcessHost()->GetID(), | 155 tab->web_contents()->GetRenderProcessHost()->GetID(), |
| 158 tab->web_contents()->GetRenderViewHost()->GetRoutingID(), | 156 tab->web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 159 tab->web_contents()->GetURL(), | 157 tab->web_contents()->GetURL(), |
| 160 ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | 158 ASCIIToUTF16(PluginMetadata::kAdobeReaderGroupName)); |
| 161 tab->web_contents()->GetRenderViewHost()->ReloadFrame(); | 159 tab->web_contents()->GetRenderViewHost()->ReloadFrame(); |
| 162 | 160 |
| 163 if (delegate) | 161 if (delegate) |
| 164 tab->infobar_tab_helper()->AddInfoBar(delegate); | 162 tab->infobar_tab_helper()->AddInfoBar(delegate); |
| 165 } | 163 } |
| 166 | 164 |
| 167 // An interstitial to be used when the user chooses to open a PDF using Adobe | 165 // An interstitial to be used when the user chooses to open a PDF using Adobe |
| 168 // Reader, but it is out of date. | 166 // Reader, but it is out of date. |
| 169 class PDFUnsupportedFeatureInterstitial | 167 class PDFUnsupportedFeatureInterstitial |
| 170 : public content::InterstitialPageDelegate { | 168 : public content::InterstitialPageDelegate { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 const std::vector<webkit::WebPluginInfo>& plugins) { | 365 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 368 WebContents* web_contents = | 366 WebContents* web_contents = |
| 369 tab_util::GetWebContentsByID(process_id, routing_id); | 367 tab_util::GetWebContentsByID(process_id, routing_id); |
| 370 if (!web_contents) | 368 if (!web_contents) |
| 371 return; | 369 return; |
| 372 | 370 |
| 373 TabContents* tab = TabContents::FromWebContents(web_contents); | 371 TabContents* tab = TabContents::FromWebContents(web_contents); |
| 374 if (!tab) | 372 if (!tab) |
| 375 return; | 373 return; |
| 376 | 374 |
| 377 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | 375 string16 reader_group_name( |
| 376 ASCIIToUTF16(PluginMetadata::kAdobeReaderGroupName)); |
| 378 // If the Reader plugin is disabled by policy, don't prompt them. | 377 // If the Reader plugin is disabled by policy, don't prompt them. |
| 379 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); | 378 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); |
| 380 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == | 379 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == |
| 381 PluginPrefs::POLICY_DISABLED) { | 380 PluginPrefs::POLICY_DISABLED) { |
| 382 return; | 381 return; |
| 383 } | 382 } |
| 384 | 383 |
| 385 const webkit::WebPluginInfo* reader = NULL; | 384 const webkit::WebPluginInfo* reader = NULL; |
| 386 PluginFinder* plugin_finder = PluginFinder::GetInstance(); | 385 PluginFinder* plugin_finder = PluginFinder::GetInstance(); |
| 387 for (size_t i = 0; i < plugins.size(); ++i) { | 386 for (size_t i = 0; i < plugins.size(); ++i) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 403 | 402 |
| 404 void PDFHasUnsupportedFeature(content::WebContents* web_contents) { | 403 void PDFHasUnsupportedFeature(content::WebContents* web_contents) { |
| 405 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) | 404 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) |
| 406 // Only works for Windows for now. For Mac, we'll have to launch the file | 405 // 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. | 406 // externally since Adobe Reader doesn't work inside Chrome. |
| 408 PluginFinder::Get(base::Bind(&GotPluginsCallback, | 407 PluginFinder::Get(base::Bind(&GotPluginsCallback, |
| 409 web_contents->GetRenderProcessHost()->GetID(), | 408 web_contents->GetRenderProcessHost()->GetID(), |
| 410 web_contents->GetRenderViewHost()->GetRoutingID())); | 409 web_contents->GetRenderViewHost()->GetRoutingID())); |
| 411 #endif | 410 #endif |
| 412 } | 411 } |
| OLD | NEW |