| 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" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 const char kAdobeReaderUpdateUrl[] = "http://www.adobe.com/go/getreader_chrome"; | 52 const char kAdobeReaderUpdateUrl[] = "http://www.adobe.com/go/getreader_chrome"; |
| 53 | 53 |
| 54 // The prompt delegate used to ask the user if they want to use Adobe Reader | 54 // The prompt delegate used to ask the user if they want to use Adobe Reader |
| 55 // by default. | 55 // by default. |
| 56 class PDFEnableAdobeReaderPromptClient | 56 class PDFEnableAdobeReaderPromptClient |
| 57 : public pdf::OpenPDFInReaderPromptClient { | 57 : public pdf::OpenPDFInReaderPromptClient { |
| 58 public: | 58 public: |
| 59 explicit PDFEnableAdobeReaderPromptClient(Profile* profile); | 59 explicit PDFEnableAdobeReaderPromptClient(Profile* profile); |
| 60 virtual ~PDFEnableAdobeReaderPromptClient(); | 60 ~PDFEnableAdobeReaderPromptClient() override; |
| 61 | 61 |
| 62 // pdf::OpenPDFInReaderPromptClient | 62 // pdf::OpenPDFInReaderPromptClient |
| 63 virtual base::string16 GetMessageText() const override; | 63 base::string16 GetMessageText() const override; |
| 64 virtual base::string16 GetAcceptButtonText() const override; | 64 base::string16 GetAcceptButtonText() const override; |
| 65 virtual base::string16 GetCancelButtonText() const override; | 65 base::string16 GetCancelButtonText() const override; |
| 66 virtual bool ShouldExpire( | 66 bool ShouldExpire( |
| 67 const content::LoadCommittedDetails& details) const override; | 67 const content::LoadCommittedDetails& details) const override; |
| 68 virtual void Accept() override; | 68 void Accept() override; |
| 69 virtual void Cancel() override; | 69 void Cancel() override; |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 void OnYes(); | 72 void OnYes(); |
| 73 void OnNo(); | 73 void OnNo(); |
| 74 | 74 |
| 75 Profile* profile_; | 75 Profile* profile_; |
| 76 | 76 |
| 77 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderPromptClient); | 77 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderPromptClient); |
| 78 }; | 78 }; |
| 79 | 79 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 : web_contents_(web_contents), | 156 : web_contents_(web_contents), |
| 157 reader_webplugininfo_(reader_webplugininfo) { | 157 reader_webplugininfo_(reader_webplugininfo) { |
| 158 content::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); | 158 content::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); |
| 159 interstitial_page_ = InterstitialPage::Create( | 159 interstitial_page_ = InterstitialPage::Create( |
| 160 web_contents, false, web_contents->GetURL(), this); | 160 web_contents, false, web_contents->GetURL(), this); |
| 161 interstitial_page_->Show(); | 161 interstitial_page_->Show(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 protected: | 164 protected: |
| 165 // InterstitialPageDelegate implementation. | 165 // InterstitialPageDelegate implementation. |
| 166 virtual std::string GetHTMLContents() override { | 166 std::string GetHTMLContents() override { |
| 167 base::DictionaryValue strings; | 167 base::DictionaryValue strings; |
| 168 strings.SetString( | 168 strings.SetString( |
| 169 "title", | 169 "title", |
| 170 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_TITLE)); | 170 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_TITLE)); |
| 171 strings.SetString( | 171 strings.SetString( |
| 172 "headLine", | 172 "headLine", |
| 173 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_BODY)); | 173 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_BODY)); |
| 174 strings.SetString( | 174 strings.SetString( |
| 175 "update", | 175 "update", |
| 176 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_UPDATE)); | 176 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_UPDATE)); |
| 177 strings.SetString( | 177 strings.SetString( |
| 178 "open_with_reader", | 178 "open_with_reader", |
| 179 l10n_util::GetStringUTF16( | 179 l10n_util::GetStringUTF16( |
| 180 IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_PROCEED)); | 180 IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_PROCEED)); |
| 181 strings.SetString( | 181 strings.SetString( |
| 182 "ok", | 182 "ok", |
| 183 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_OK)); | 183 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_OK)); |
| 184 strings.SetString( | 184 strings.SetString( |
| 185 "cancel", | 185 "cancel", |
| 186 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_CANCEL)); | 186 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_CANCEL)); |
| 187 | 187 |
| 188 base::StringPiece html(ResourceBundle::GetSharedInstance(). | 188 base::StringPiece html(ResourceBundle::GetSharedInstance(). |
| 189 GetRawDataResource(IDR_READER_OUT_OF_DATE_HTML)); | 189 GetRawDataResource(IDR_READER_OUT_OF_DATE_HTML)); |
| 190 | 190 |
| 191 return webui::GetI18nTemplateHtml(html, &strings); | 191 return webui::GetI18nTemplateHtml(html, &strings); |
| 192 } | 192 } |
| 193 | 193 |
| 194 virtual void CommandReceived(const std::string& command) override { | 194 void CommandReceived(const std::string& command) override { |
| 195 if (command == "0") { | 195 if (command == "0") { |
| 196 content::RecordAction( | 196 content::RecordAction( |
| 197 UserMetricsAction("PDF_ReaderInterstitialCancel")); | 197 UserMetricsAction("PDF_ReaderInterstitialCancel")); |
| 198 interstitial_page_->DontProceed(); | 198 interstitial_page_->DontProceed(); |
| 199 return; | 199 return; |
| 200 } | 200 } |
| 201 | 201 |
| 202 if (command == "1") { | 202 if (command == "1") { |
| 203 content::RecordAction( | 203 content::RecordAction( |
| 204 UserMetricsAction("PDF_ReaderInterstitialUpdate")); | 204 UserMetricsAction("PDF_ReaderInterstitialUpdate")); |
| 205 OpenReaderUpdateURL(web_contents_); | 205 OpenReaderUpdateURL(web_contents_); |
| 206 } else if (command == "2") { | 206 } else if (command == "2") { |
| 207 content::RecordAction( | 207 content::RecordAction( |
| 208 UserMetricsAction("PDF_ReaderInterstitialIgnore")); | 208 UserMetricsAction("PDF_ReaderInterstitialIgnore")); |
| 209 // Pretend that the plugin is up-to-date so that we don't block it. | 209 // Pretend that the plugin is up-to-date so that we don't block it. |
| 210 reader_webplugininfo_.version = base::ASCIIToUTF16("11.0.0.0"); | 210 reader_webplugininfo_.version = base::ASCIIToUTF16("11.0.0.0"); |
| 211 OpenUsingReader(web_contents_, reader_webplugininfo_, NULL); | 211 OpenUsingReader(web_contents_, reader_webplugininfo_, NULL); |
| 212 } else { | 212 } else { |
| 213 NOTREACHED(); | 213 NOTREACHED(); |
| 214 } | 214 } |
| 215 interstitial_page_->Proceed(); | 215 interstitial_page_->Proceed(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 virtual void OverrideRendererPrefs( | 218 void OverrideRendererPrefs(content::RendererPreferences* prefs) override { |
| 219 content::RendererPreferences* prefs) override { | |
| 220 Profile* profile = | 219 Profile* profile = |
| 221 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 220 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 222 renderer_preferences_util::UpdateFromSystemSettings( | 221 renderer_preferences_util::UpdateFromSystemSettings( |
| 223 prefs, profile, web_contents_); | 222 prefs, profile, web_contents_); |
| 224 } | 223 } |
| 225 | 224 |
| 226 private: | 225 private: |
| 227 WebContents* web_contents_; | 226 WebContents* web_contents_; |
| 228 WebPluginInfo reader_webplugininfo_; | 227 WebPluginInfo reader_webplugininfo_; |
| 229 InterstitialPage* interstitial_page_; // Owns us. | 228 InterstitialPage* interstitial_page_; // Owns us. |
| 230 | 229 |
| 231 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); | 230 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); |
| 232 }; | 231 }; |
| 233 | 232 |
| 234 // The delegate for the bubble used to inform the user that we don't support a | 233 // The delegate for the bubble used to inform the user that we don't support a |
| 235 // feature in the PDF. | 234 // feature in the PDF. |
| 236 class PDFUnsupportedFeaturePromptClient | 235 class PDFUnsupportedFeaturePromptClient |
| 237 : public pdf::OpenPDFInReaderPromptClient { | 236 : public pdf::OpenPDFInReaderPromptClient { |
| 238 public: | 237 public: |
| 239 PDFUnsupportedFeaturePromptClient(WebContents* web_contents, | 238 PDFUnsupportedFeaturePromptClient(WebContents* web_contents, |
| 240 const AdobeReaderPluginInfo& reader_info); | 239 const AdobeReaderPluginInfo& reader_info); |
| 241 virtual ~PDFUnsupportedFeaturePromptClient(); | 240 ~PDFUnsupportedFeaturePromptClient() override; |
| 242 | 241 |
| 243 // pdf::OpenPDFInReaderPromptClient: | 242 // pdf::OpenPDFInReaderPromptClient: |
| 244 virtual base::string16 GetMessageText() const override; | 243 base::string16 GetMessageText() const override; |
| 245 virtual base::string16 GetAcceptButtonText() const override; | 244 base::string16 GetAcceptButtonText() const override; |
| 246 virtual base::string16 GetCancelButtonText() const override; | 245 base::string16 GetCancelButtonText() const override; |
| 247 virtual bool ShouldExpire( | 246 bool ShouldExpire( |
| 248 const content::LoadCommittedDetails& details) const override; | 247 const content::LoadCommittedDetails& details) const override; |
| 249 virtual void Accept() override; | 248 void Accept() override; |
| 250 virtual void Cancel() override; | 249 void Cancel() override; |
| 251 | 250 |
| 252 private: | 251 private: |
| 253 WebContents* web_contents_; | 252 WebContents* web_contents_; |
| 254 const AdobeReaderPluginInfo reader_info_; | 253 const AdobeReaderPluginInfo reader_info_; |
| 255 | 254 |
| 256 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeaturePromptClient); | 255 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeaturePromptClient); |
| 257 }; | 256 }; |
| 258 | 257 |
| 259 PDFUnsupportedFeaturePromptClient::PDFUnsupportedFeaturePromptClient( | 258 PDFUnsupportedFeaturePromptClient::PDFUnsupportedFeaturePromptClient( |
| 260 WebContents* web_contents, | 259 WebContents* web_contents, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 MaybeShowOpenPDFInReaderPrompt(web_contents, reader_info); | 359 MaybeShowOpenPDFInReaderPrompt(web_contents, reader_info); |
| 361 return; | 360 return; |
| 362 } | 361 } |
| 363 GetAdobeReaderPluginInfoAsync( | 362 GetAdobeReaderPluginInfoAsync( |
| 364 profile, | 363 profile, |
| 365 base::Bind(&GotPluginsCallback, | 364 base::Bind(&GotPluginsCallback, |
| 366 web_contents->GetRenderProcessHost()->GetID(), | 365 web_contents->GetRenderProcessHost()->GetID(), |
| 367 web_contents->GetRenderViewHost()->GetRoutingID())); | 366 web_contents->GetRenderViewHost()->GetRoutingID())); |
| 368 #endif // defined(OS_WIN) | 367 #endif // defined(OS_WIN) |
| 369 } | 368 } |
| OLD | NEW |