| 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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/lifetime/application_lifetime.h" | 10 #include "chrome/browser/lifetime/application_lifetime.h" |
| 11 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 11 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| 12 #include "chrome/browser/plugins/plugin_metadata.h" | 12 #include "chrome/browser/plugins/plugin_metadata.h" |
| 13 #include "chrome/browser/plugins/plugin_prefs.h" | 13 #include "chrome/browser/plugins/plugin_prefs.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/renderer_preferences_util.h" | 15 #include "chrome/browser/renderer_preferences_util.h" |
| 16 #include "chrome/browser/tab_contents/tab_util.h" | 16 #include "chrome/browser/tab_contents/tab_util.h" |
| 17 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" | |
| 18 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" | |
| 19 #include "chrome/common/chrome_content_client.h" | 17 #include "chrome/common/chrome_content_client.h" |
| 18 #include "components/pdf/browser/open_pdf_in_reader_prompt_delegate.h" |
| 19 #include "components/pdf/browser/pdf_tab_helper.h" |
| 20 #include "content/public/browser/interstitial_page.h" | 20 #include "content/public/browser/interstitial_page.h" |
| 21 #include "content/public/browser/interstitial_page_delegate.h" | 21 #include "content/public/browser/interstitial_page_delegate.h" |
| 22 #include "content/public/browser/navigation_details.h" | 22 #include "content/public/browser/navigation_details.h" |
| 23 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
| 24 #include "content/public/browser/page_navigator.h" | 24 #include "content/public/browser/page_navigator.h" |
| 25 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
| 26 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
| 27 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
| 28 #include "content/public/browser/user_metrics.h" | 28 #include "content/public/browser/user_metrics.h" |
| 29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 46 using content::WebPluginInfo; | 46 using content::WebPluginInfo; |
| 47 | 47 |
| 48 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 const char kAdobeReaderUpdateUrl[] = "http://www.adobe.com/go/getreader_chrome"; | 51 const char kAdobeReaderUpdateUrl[] = "http://www.adobe.com/go/getreader_chrome"; |
| 52 | 52 |
| 53 // 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 |
| 54 // by default. | 54 // by default. |
| 55 class PDFEnableAdobeReaderPromptDelegate | 55 class PDFEnableAdobeReaderPromptDelegate |
| 56 : public OpenPDFInReaderPromptDelegate { | 56 : public pdf::OpenPDFInReaderPromptDelegate { |
| 57 public: | 57 public: |
| 58 explicit PDFEnableAdobeReaderPromptDelegate(Profile* profile); | 58 explicit PDFEnableAdobeReaderPromptDelegate(Profile* profile); |
| 59 virtual ~PDFEnableAdobeReaderPromptDelegate(); | 59 virtual ~PDFEnableAdobeReaderPromptDelegate(); |
| 60 | 60 |
| 61 // OpenPDFInReaderPromptDelegate | 61 // pdf::OpenPDFInReaderPromptDelegate |
| 62 virtual base::string16 GetMessageText() const OVERRIDE; | 62 virtual base::string16 GetMessageText() const OVERRIDE; |
| 63 virtual base::string16 GetAcceptButtonText() const OVERRIDE; | 63 virtual base::string16 GetAcceptButtonText() const OVERRIDE; |
| 64 virtual base::string16 GetCancelButtonText() const OVERRIDE; | 64 virtual base::string16 GetCancelButtonText() const OVERRIDE; |
| 65 virtual bool ShouldExpire( | 65 virtual bool ShouldExpire( |
| 66 const content::LoadCommittedDetails& details) const OVERRIDE; | 66 const content::LoadCommittedDetails& details) const OVERRIDE; |
| 67 virtual void Accept() OVERRIDE; | 67 virtual void Accept() OVERRIDE; |
| 68 virtual void Cancel() OVERRIDE; | 68 virtual void Cancel() OVERRIDE; |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 void OnYes(); | 71 void OnYes(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 void OpenReaderUpdateURL(WebContents* web_contents) { | 123 void OpenReaderUpdateURL(WebContents* web_contents) { |
| 124 OpenURLParams params( | 124 OpenURLParams params( |
| 125 GURL(kAdobeReaderUpdateUrl), Referrer(), NEW_FOREGROUND_TAB, | 125 GURL(kAdobeReaderUpdateUrl), Referrer(), NEW_FOREGROUND_TAB, |
| 126 content::PAGE_TRANSITION_LINK, false); | 126 content::PAGE_TRANSITION_LINK, false); |
| 127 web_contents->OpenURL(params); | 127 web_contents->OpenURL(params); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Opens the PDF using Adobe Reader. | 130 // Opens the PDF using Adobe Reader. |
| 131 void OpenUsingReader(WebContents* web_contents, | 131 void OpenUsingReader(WebContents* web_contents, |
| 132 const WebPluginInfo& reader_plugin, | 132 const WebPluginInfo& reader_plugin, |
| 133 OpenPDFInReaderPromptDelegate* delegate) { | 133 pdf::OpenPDFInReaderPromptDelegate* delegate) { |
| 134 ChromePluginServiceFilter::GetInstance()->OverridePluginForFrame( | 134 ChromePluginServiceFilter::GetInstance()->OverridePluginForFrame( |
| 135 web_contents->GetRenderProcessHost()->GetID(), | 135 web_contents->GetRenderProcessHost()->GetID(), |
| 136 web_contents->GetMainFrame()->GetRoutingID(), | 136 web_contents->GetMainFrame()->GetRoutingID(), |
| 137 web_contents->GetURL(), | 137 web_contents->GetURL(), |
| 138 reader_plugin); | 138 reader_plugin); |
| 139 web_contents->ReloadFocusedFrame(false); | 139 web_contents->ReloadFocusedFrame(false); |
| 140 | 140 |
| 141 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); | 141 pdf::PDFTabHelper* pdf_tab_helper = |
| 142 pdf::PDFTabHelper::FromWebContents(web_contents); |
| 142 if (delegate) | 143 if (delegate) |
| 143 pdf_tab_helper->ShowOpenInReaderPrompt(make_scoped_ptr(delegate)); | 144 pdf_tab_helper->ShowOpenInReaderPrompt(make_scoped_ptr(delegate)); |
| 144 } | 145 } |
| 145 | 146 |
| 146 // An interstitial to be used when the user chooses to open a PDF using Adobe | 147 // An interstitial to be used when the user chooses to open a PDF using Adobe |
| 147 // Reader, but it is out of date. | 148 // Reader, but it is out of date. |
| 148 class PDFUnsupportedFeatureInterstitial | 149 class PDFUnsupportedFeatureInterstitial |
| 149 : public content::InterstitialPageDelegate { | 150 : public content::InterstitialPageDelegate { |
| 150 public: | 151 public: |
| 151 PDFUnsupportedFeatureInterstitial( | 152 PDFUnsupportedFeatureInterstitial( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 WebContents* web_contents_; | 225 WebContents* web_contents_; |
| 225 WebPluginInfo reader_webplugininfo_; | 226 WebPluginInfo reader_webplugininfo_; |
| 226 InterstitialPage* interstitial_page_; // Owns us. | 227 InterstitialPage* interstitial_page_; // Owns us. |
| 227 | 228 |
| 228 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); | 229 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); |
| 229 }; | 230 }; |
| 230 | 231 |
| 231 // The delegate for the bubble used to inform the user that we don't support a | 232 // The delegate for the bubble used to inform the user that we don't support a |
| 232 // feature in the PDF. | 233 // feature in the PDF. |
| 233 class PDFUnsupportedFeaturePromptDelegate | 234 class PDFUnsupportedFeaturePromptDelegate |
| 234 : public OpenPDFInReaderPromptDelegate { | 235 : public pdf::OpenPDFInReaderPromptDelegate { |
| 235 public: | 236 public: |
| 236 PDFUnsupportedFeaturePromptDelegate( | 237 PDFUnsupportedFeaturePromptDelegate( |
| 237 WebContents* web_contents, | 238 WebContents* web_contents, |
| 238 const AdobeReaderPluginInfo& reader_info); | 239 const AdobeReaderPluginInfo& reader_info); |
| 239 virtual ~PDFUnsupportedFeaturePromptDelegate(); | 240 virtual ~PDFUnsupportedFeaturePromptDelegate(); |
| 240 | 241 |
| 241 // OpenPDFInReaderPromptDelegate: | 242 // pdf::OpenPDFInReaderPromptDelegate: |
| 242 virtual base::string16 GetMessageText() const OVERRIDE; | 243 virtual base::string16 GetMessageText() const OVERRIDE; |
| 243 virtual base::string16 GetAcceptButtonText() const OVERRIDE; | 244 virtual base::string16 GetAcceptButtonText() const OVERRIDE; |
| 244 virtual base::string16 GetCancelButtonText() const OVERRIDE; | 245 virtual base::string16 GetCancelButtonText() const OVERRIDE; |
| 245 virtual bool ShouldExpire( | 246 virtual bool ShouldExpire( |
| 246 const content::LoadCommittedDetails& details) const OVERRIDE; | 247 const content::LoadCommittedDetails& details) const OVERRIDE; |
| 247 virtual void Accept() OVERRIDE; | 248 virtual void Accept() OVERRIDE; |
| 248 virtual void Cancel() OVERRIDE; | 249 virtual void Cancel() OVERRIDE; |
| 249 | 250 |
| 250 private: | 251 private: |
| 251 WebContents* web_contents_; | 252 WebContents* web_contents_; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); | 307 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); |
| 307 | 308 |
| 308 if (!reader_info_.is_secure) { | 309 if (!reader_info_.is_secure) { |
| 309 new PDFUnsupportedFeatureInterstitial(web_contents_, | 310 new PDFUnsupportedFeatureInterstitial(web_contents_, |
| 310 reader_info_.plugin_info); | 311 reader_info_.plugin_info); |
| 311 return; | 312 return; |
| 312 } | 313 } |
| 313 | 314 |
| 314 Profile* profile = | 315 Profile* profile = |
| 315 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 316 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 316 OpenPDFInReaderPromptDelegate* delegate = | 317 pdf::OpenPDFInReaderPromptDelegate* delegate = |
| 317 new PDFEnableAdobeReaderPromptDelegate(profile); | 318 new PDFEnableAdobeReaderPromptDelegate(profile); |
| 318 | 319 |
| 319 OpenUsingReader(web_contents_, reader_info_.plugin_info, delegate); | 320 OpenUsingReader(web_contents_, reader_info_.plugin_info, delegate); |
| 320 } | 321 } |
| 321 | 322 |
| 322 void PDFUnsupportedFeaturePromptDelegate::Cancel() { | 323 void PDFUnsupportedFeaturePromptDelegate::Cancel() { |
| 323 content::RecordAction(reader_info_.is_installed ? | 324 content::RecordAction(reader_info_.is_installed ? |
| 324 UserMetricsAction("PDF_UseReaderInfoBarCancel") : | 325 UserMetricsAction("PDF_UseReaderInfoBarCancel") : |
| 325 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); | 326 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); |
| 326 } | 327 } |
| 327 | 328 |
| 328 void MaybeShowOpenPDFInReaderPrompt(WebContents* web_contents, | 329 void MaybeShowOpenPDFInReaderPrompt(WebContents* web_contents, |
| 329 const AdobeReaderPluginInfo& reader_info) { | 330 const AdobeReaderPluginInfo& reader_info) { |
| 330 // If the Reader plugin is disabled by policy, don't prompt them. | 331 // If the Reader plugin is disabled by policy, don't prompt them. |
| 331 if (!reader_info.is_installed || !reader_info.is_enabled) | 332 if (!reader_info.is_installed || !reader_info.is_enabled) |
| 332 return; | 333 return; |
| 333 | 334 |
| 334 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt( | 335 scoped_ptr<pdf::OpenPDFInReaderPromptDelegate> prompt( |
| 335 new PDFUnsupportedFeaturePromptDelegate(web_contents, reader_info)); | 336 new PDFUnsupportedFeaturePromptDelegate(web_contents, reader_info)); |
| 336 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); | 337 pdf::PDFTabHelper* pdf_tab_helper = |
| 338 pdf::PDFTabHelper::FromWebContents(web_contents); |
| 337 pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass()); | 339 pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass()); |
| 338 } | 340 } |
| 339 | 341 |
| 340 void GotPluginsCallback(int process_id, | 342 void GotPluginsCallback(int process_id, |
| 341 int routing_id, | 343 int routing_id, |
| 342 const AdobeReaderPluginInfo& reader_info) { | 344 const AdobeReaderPluginInfo& reader_info) { |
| 343 WebContents* web_contents = | 345 WebContents* web_contents = |
| 344 tab_util::GetWebContentsByID(process_id, routing_id); | 346 tab_util::GetWebContentsByID(process_id, routing_id); |
| 345 if (web_contents) | 347 if (web_contents) |
| 346 MaybeShowOpenPDFInReaderPrompt(web_contents, reader_info); | 348 MaybeShowOpenPDFInReaderPrompt(web_contents, reader_info); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 360 MaybeShowOpenPDFInReaderPrompt(web_contents, reader_info); | 362 MaybeShowOpenPDFInReaderPrompt(web_contents, reader_info); |
| 361 return; | 363 return; |
| 362 } | 364 } |
| 363 GetAdobeReaderPluginInfoAsync( | 365 GetAdobeReaderPluginInfoAsync( |
| 364 profile, | 366 profile, |
| 365 base::Bind(&GotPluginsCallback, | 367 base::Bind(&GotPluginsCallback, |
| 366 web_contents->GetRenderProcessHost()->GetID(), | 368 web_contents->GetRenderProcessHost()->GetID(), |
| 367 web_contents->GetRenderViewHost()->GetRoutingID())); | 369 web_contents->GetRenderViewHost()->GetRoutingID())); |
| 368 #endif // defined(OS_WIN) | 370 #endif // defined(OS_WIN) |
| 369 } | 371 } |
| OLD | NEW |