OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chrome_plugin_service_filter.h" | 11 #include "chrome/browser/chrome_plugin_service_filter.h" |
12 #include "chrome/browser/infobars/infobar_tab_helper.h" | 12 #include "chrome/browser/infobars/infobar_tab_helper.h" |
13 #include "chrome/browser/plugin_prefs.h" | 13 #include "chrome/browser/plugin_prefs.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" | 16 #include "chrome/browser/renderer_preferences_util.h" |
17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
18 #include "chrome/browser/tab_contents/tab_util.h" | 18 #include "chrome/browser/tab_contents/tab_util.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
20 #include "chrome/common/chrome_content_client.h" | 20 #include "chrome/common/chrome_content_client.h" |
21 #include "chrome/common/jstemplate_builder.h" | 21 #include "chrome/common/jstemplate_builder.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "content/browser/renderer_host/render_view_host.h" | 23 #include "content/browser/renderer_host/render_view_host.h" |
| 24 #include "content/browser/tab_contents/interstitial_page.h" |
| 25 #include "content/public/browser/interstitial_page_delegate.h" |
24 #include "content/public/browser/plugin_service.h" | 26 #include "content/public/browser/plugin_service.h" |
25 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
26 #include "content/public/browser/user_metrics.h" | 28 #include "content/public/browser/user_metrics.h" |
27 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
28 #include "grit/browser_resources.h" | 30 #include "grit/browser_resources.h" |
29 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
30 #include "grit/theme_resources_standard.h" | 32 #include "grit/theme_resources_standard.h" |
31 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
32 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
33 #include "ui/gfx/image/image.h" | 35 #include "ui/gfx/image/image.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 if (old_delegate) { | 157 if (old_delegate) { |
156 tab->infobar_tab_helper()->ReplaceInfoBar(old_delegate, new_delegate); | 158 tab->infobar_tab_helper()->ReplaceInfoBar(old_delegate, new_delegate); |
157 } else { | 159 } else { |
158 tab->infobar_tab_helper()->AddInfoBar(new_delegate); | 160 tab->infobar_tab_helper()->AddInfoBar(new_delegate); |
159 } | 161 } |
160 } | 162 } |
161 } | 163 } |
162 | 164 |
163 // 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 |
164 // Reader, but it is out of date. | 166 // Reader, but it is out of date. |
165 class PDFUnsupportedFeatureInterstitial : public ChromeInterstitialPage { | 167 class PDFUnsupportedFeatureInterstitial |
| 168 : public content::InterstitialPageDelegate { |
166 public: | 169 public: |
167 PDFUnsupportedFeatureInterstitial( | 170 PDFUnsupportedFeatureInterstitial( |
168 TabContentsWrapper* tab, | 171 TabContentsWrapper* tab, |
169 const WebPluginInfo& reader_webplugininfo) | 172 const WebPluginInfo& reader_webplugininfo) |
170 : ChromeInterstitialPage( | 173 : tab_contents_(tab), |
171 tab->web_contents(), false, tab->web_contents()->GetURL()), | |
172 tab_contents_(tab), | |
173 reader_webplugininfo_(reader_webplugininfo) { | 174 reader_webplugininfo_(reader_webplugininfo) { |
174 content::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); | 175 content::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); |
| 176 interstitial_page_ = InterstitialPage::Create( |
| 177 tab->web_contents(), false, tab->web_contents()->GetURL(), this); |
| 178 interstitial_page_->Show(); |
175 } | 179 } |
176 | 180 |
177 protected: | 181 protected: |
178 // ChromeInterstitialPage implementation. | 182 // InterstitialPageDelegate implementation. |
179 virtual std::string GetHTMLContents() { | 183 virtual std::string GetHTMLContents() OVERRIDE { |
180 DictionaryValue strings; | 184 DictionaryValue strings; |
181 strings.SetString( | 185 strings.SetString( |
182 "title", | 186 "title", |
183 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_TITLE)); | 187 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_TITLE)); |
184 strings.SetString( | 188 strings.SetString( |
185 "headLine", | 189 "headLine", |
186 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_BODY)); | 190 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_BODY)); |
187 strings.SetString( | 191 strings.SetString( |
188 "update", | 192 "update", |
189 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_UPDATE)); | 193 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_UPDATE)); |
190 strings.SetString( | 194 strings.SetString( |
191 "open_with_reader", | 195 "open_with_reader", |
192 l10n_util::GetStringUTF16( | 196 l10n_util::GetStringUTF16( |
193 IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_PROCEED)); | 197 IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_PROCEED)); |
194 strings.SetString( | 198 strings.SetString( |
195 "ok", | 199 "ok", |
196 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_OK)); | 200 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_OK)); |
197 strings.SetString( | 201 strings.SetString( |
198 "cancel", | 202 "cancel", |
199 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_CANCEL)); | 203 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_CANCEL)); |
200 | 204 |
201 base::StringPiece html(ResourceBundle::GetSharedInstance(). | 205 base::StringPiece html(ResourceBundle::GetSharedInstance(). |
202 GetRawDataResource(IDR_READER_OUT_OF_DATE_HTML)); | 206 GetRawDataResource(IDR_READER_OUT_OF_DATE_HTML)); |
203 | 207 |
204 return jstemplate_builder::GetI18nTemplateHtml(html, &strings); | 208 return jstemplate_builder::GetI18nTemplateHtml(html, &strings); |
205 } | 209 } |
206 | 210 |
207 virtual void CommandReceived(const std::string& command) { | 211 virtual void CommandReceived(const std::string& command) OVERRIDE { |
208 if (command == "0") { | 212 if (command == "0") { |
209 content::RecordAction( | 213 content::RecordAction( |
210 UserMetricsAction("PDF_ReaderInterstitialCancel")); | 214 UserMetricsAction("PDF_ReaderInterstitialCancel")); |
211 DontProceed(); | 215 interstitial_page_->DontProceed(); |
212 return; | 216 return; |
213 } | 217 } |
214 | 218 |
215 if (command == "1") { | 219 if (command == "1") { |
216 content::RecordAction( | 220 content::RecordAction( |
217 UserMetricsAction("PDF_ReaderInterstitialUpdate")); | 221 UserMetricsAction("PDF_ReaderInterstitialUpdate")); |
218 OpenReaderUpdateURL(tab()); | 222 OpenReaderUpdateURL(tab_contents_->web_contents()); |
219 } else if (command == "2") { | 223 } else if (command == "2") { |
220 content::RecordAction( | 224 content::RecordAction( |
221 UserMetricsAction("PDF_ReaderInterstitialIgnore")); | 225 UserMetricsAction("PDF_ReaderInterstitialIgnore")); |
222 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL); | 226 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL); |
223 } else { | 227 } else { |
224 NOTREACHED(); | 228 NOTREACHED(); |
225 } | 229 } |
226 Proceed(); | 230 interstitial_page_->Proceed(); |
| 231 } |
| 232 |
| 233 virtual void OverrideRendererPrefs( |
| 234 content::RendererPreferences* prefs) OVERRIDE { |
| 235 renderer_preferences_util::UpdateFromSystemSettings( |
| 236 prefs, tab_contents_->profile()); |
227 } | 237 } |
228 | 238 |
229 private: | 239 private: |
230 TabContentsWrapper* tab_contents_; | 240 TabContentsWrapper* tab_contents_; |
231 WebPluginInfo reader_webplugininfo_; | 241 WebPluginInfo reader_webplugininfo_; |
| 242 InterstitialPage* interstitial_page_; // Owns us. |
232 | 243 |
233 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); | 244 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); |
234 }; | 245 }; |
235 | 246 |
236 // The info bar delegate used to inform the user that we don't support a feature | 247 // The info bar delegate used to inform the user that we don't support a feature |
237 // in the PDF. See the comment about how we swap buttons for | 248 // in the PDF. See the comment about how we swap buttons for |
238 // PDFEnableAdobeReaderInfoBarDelegate. | 249 // PDFEnableAdobeReaderInfoBarDelegate. |
239 class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate { | 250 class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate { |
240 public: | 251 public: |
241 // |reader_group| is NULL if Adobe Reader isn't installed. | 252 // |reader_group| is NULL if Adobe Reader isn't installed. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 bool PDFUnsupportedFeatureInfoBarDelegate::OnYes() { | 345 bool PDFUnsupportedFeatureInfoBarDelegate::OnYes() { |
335 if (!reader_installed_) { | 346 if (!reader_installed_) { |
336 content::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK")); | 347 content::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK")); |
337 OpenReaderUpdateURL(tab_contents_->web_contents()); | 348 OpenReaderUpdateURL(tab_contents_->web_contents()); |
338 return true; | 349 return true; |
339 } | 350 } |
340 | 351 |
341 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); | 352 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); |
342 | 353 |
343 if (reader_vulnerable_) { | 354 if (reader_vulnerable_) { |
344 PDFUnsupportedFeatureInterstitial* interstitial = | 355 new PDFUnsupportedFeatureInterstitial(tab_contents_, reader_webplugininfo_); |
345 new PDFUnsupportedFeatureInterstitial(tab_contents_, | |
346 reader_webplugininfo_); | |
347 interstitial->Show(); | |
348 return true; | 356 return true; |
349 } | 357 } |
350 | 358 |
351 if (tab_contents_->profile()->GetPrefs()->GetBoolean( | 359 if (tab_contents_->profile()->GetPrefs()->GetBoolean( |
352 prefs::kPluginsShowSetReaderDefaultInfobar)) { | 360 prefs::kPluginsShowSetReaderDefaultInfobar)) { |
353 InfoBarDelegate* bar = new PDFEnableAdobeReaderInfoBarDelegate( | 361 InfoBarDelegate* bar = new PDFEnableAdobeReaderInfoBarDelegate( |
354 tab_contents_->infobar_tab_helper(), tab_contents_->profile()); | 362 tab_contents_->infobar_tab_helper(), tab_contents_->profile()); |
355 OpenUsingReader(tab_contents_, reader_webplugininfo_, this, bar); | 363 OpenUsingReader(tab_contents_, reader_webplugininfo_, this, bar); |
356 return false; | 364 return false; |
357 } | 365 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 // Only works for Windows for now. For Mac, we'll have to launch the file | 415 // Only works for Windows for now. For Mac, we'll have to launch the file |
408 // externally since Adobe Reader doesn't work inside Chrome. | 416 // externally since Adobe Reader doesn't work inside Chrome. |
409 return; | 417 return; |
410 #endif | 418 #endif |
411 | 419 |
412 PluginService::GetInstance()->GetPluginGroups( | 420 PluginService::GetInstance()->GetPluginGroups( |
413 base::Bind(&GotPluginGroupsCallback, | 421 base::Bind(&GotPluginGroupsCallback, |
414 tab->web_contents()->GetRenderProcessHost()->GetID(), | 422 tab->web_contents()->GetRenderProcessHost()->GetID(), |
415 tab->web_contents()->GetRenderViewHost()->routing_id())); | 423 tab->web_contents()->GetRenderViewHost()->routing_id())); |
416 } | 424 } |
OLD | NEW |