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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "base/version.h" | 11 #include "base/version.h" |
12 #include "chrome/browser/chrome_plugin_service_filter.h" | 12 #include "chrome/browser/chrome_plugin_service_filter.h" |
13 #include "chrome/browser/lifetime/application_lifetime.h" | 13 #include "chrome/browser/lifetime/application_lifetime.h" |
14 #include "chrome/browser/plugins/plugin_finder.h" | 14 #include "chrome/browser/plugins/plugin_finder.h" |
15 #include "chrome/browser/plugins/plugin_metadata.h" | 15 #include "chrome/browser/plugins/plugin_metadata.h" |
16 #include "chrome/browser/plugins/plugin_prefs.h" | 16 #include "chrome/browser/plugins/plugin_prefs.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/renderer_preferences_util.h" | 19 #include "chrome/browser/renderer_preferences_util.h" |
20 #include "chrome/browser/tab_contents/tab_util.h" | 20 #include "chrome/browser/tab_contents/tab_util.h" |
21 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" | 21 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" |
22 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" | 22 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" |
23 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
24 #include "chrome/common/chrome_content_client.h" | 23 #include "chrome/common/chrome_content_client.h" |
25 #include "chrome/common/jstemplate_builder.h" | 24 #include "chrome/common/jstemplate_builder.h" |
26 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
27 #include "content/public/browser/interstitial_page.h" | 26 #include "content/public/browser/interstitial_page.h" |
28 #include "content/public/browser/interstitial_page_delegate.h" | 27 #include "content/public/browser/interstitial_page_delegate.h" |
29 #include "content/public/browser/navigation_details.h" | 28 #include "content/public/browser/navigation_details.h" |
30 #include "content/public/browser/navigation_entry.h" | 29 #include "content/public/browser/navigation_entry.h" |
31 #include "content/public/browser/plugin_service.h" | 30 #include "content/public/browser/plugin_service.h" |
32 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
33 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 121 |
123 string16 PDFEnableAdobeReaderPromptDelegate::GetCancelButtonText() const { | 122 string16 PDFEnableAdobeReaderPromptDelegate::GetCancelButtonText() const { |
124 return l10n_util::GetStringUTF16(IDS_DONE); | 123 return l10n_util::GetStringUTF16(IDS_DONE); |
125 } | 124 } |
126 | 125 |
127 string16 PDFEnableAdobeReaderPromptDelegate::GetMessageText() const { | 126 string16 PDFEnableAdobeReaderPromptDelegate::GetMessageText() const { |
128 return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); | 127 return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); |
129 } | 128 } |
130 | 129 |
131 // Launch the url to get the latest Adbobe Reader installer. | 130 // Launch the url to get the latest Adbobe Reader installer. |
132 void OpenReaderUpdateURL(WebContents* tab) { | 131 void OpenReaderUpdateURL(WebContents* web_contents) { |
133 OpenURLParams params( | 132 OpenURLParams params( |
134 GURL(kAdobeReaderUpdateUrl), Referrer(), NEW_FOREGROUND_TAB, | 133 GURL(kAdobeReaderUpdateUrl), Referrer(), NEW_FOREGROUND_TAB, |
135 content::PAGE_TRANSITION_LINK, false); | 134 content::PAGE_TRANSITION_LINK, false); |
136 tab->OpenURL(params); | 135 web_contents->OpenURL(params); |
137 } | 136 } |
138 | 137 |
139 // Opens the PDF using Adobe Reader. | 138 // Opens the PDF using Adobe Reader. |
140 void OpenUsingReader(WebContents* web_contents, | 139 void OpenUsingReader(WebContents* web_contents, |
141 const WebPluginInfo& reader_plugin, | 140 const WebPluginInfo& reader_plugin, |
142 OpenPDFInReaderPromptDelegate* delegate) { | 141 OpenPDFInReaderPromptDelegate* delegate) { |
143 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( | 142 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( |
144 web_contents->GetRenderProcessHost()->GetID(), | 143 web_contents->GetRenderProcessHost()->GetID(), |
145 web_contents->GetRenderViewHost()->GetRoutingID(), | 144 web_contents->GetRenderViewHost()->GetRoutingID(), |
146 web_contents->GetURL(), | 145 web_contents->GetURL(), |
147 reader_plugin); | 146 reader_plugin); |
148 web_contents->GetRenderViewHost()->ReloadFrame(); | 147 web_contents->GetRenderViewHost()->ReloadFrame(); |
149 | 148 |
150 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); | 149 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); |
151 if (delegate) | 150 if (delegate) |
152 pdf_tab_helper->ShowOpenInReaderPrompt(make_scoped_ptr(delegate)); | 151 pdf_tab_helper->ShowOpenInReaderPrompt(make_scoped_ptr(delegate)); |
153 } | 152 } |
154 | 153 |
155 // An interstitial to be used when the user chooses to open a PDF using Adobe | 154 // An interstitial to be used when the user chooses to open a PDF using Adobe |
156 // Reader, but it is out of date. | 155 // Reader, but it is out of date. |
157 class PDFUnsupportedFeatureInterstitial | 156 class PDFUnsupportedFeatureInterstitial |
158 : public content::InterstitialPageDelegate { | 157 : public content::InterstitialPageDelegate { |
159 public: | 158 public: |
160 PDFUnsupportedFeatureInterstitial( | 159 PDFUnsupportedFeatureInterstitial( |
161 TabContents* tab, | 160 WebContents* web_contents, |
162 const WebPluginInfo& reader_webplugininfo) | 161 const WebPluginInfo& reader_webplugininfo) |
163 : tab_contents_(tab), | 162 : web_contents_(web_contents), |
164 reader_webplugininfo_(reader_webplugininfo) { | 163 reader_webplugininfo_(reader_webplugininfo) { |
165 content::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); | 164 content::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); |
166 interstitial_page_ = InterstitialPage::Create( | 165 interstitial_page_ = InterstitialPage::Create( |
167 tab->web_contents(), false, tab->web_contents()->GetURL(), this); | 166 web_contents, false, web_contents->GetURL(), this); |
168 interstitial_page_->Show(); | 167 interstitial_page_->Show(); |
169 } | 168 } |
170 | 169 |
171 protected: | 170 protected: |
172 // InterstitialPageDelegate implementation. | 171 // InterstitialPageDelegate implementation. |
173 virtual std::string GetHTMLContents() OVERRIDE { | 172 virtual std::string GetHTMLContents() OVERRIDE { |
174 DictionaryValue strings; | 173 DictionaryValue strings; |
175 strings.SetString( | 174 strings.SetString( |
176 "title", | 175 "title", |
177 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_TITLE)); | 176 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_TITLE)); |
(...skipping 24 matching lines...) Expand all Loading... |
202 if (command == "0") { | 201 if (command == "0") { |
203 content::RecordAction( | 202 content::RecordAction( |
204 UserMetricsAction("PDF_ReaderInterstitialCancel")); | 203 UserMetricsAction("PDF_ReaderInterstitialCancel")); |
205 interstitial_page_->DontProceed(); | 204 interstitial_page_->DontProceed(); |
206 return; | 205 return; |
207 } | 206 } |
208 | 207 |
209 if (command == "1") { | 208 if (command == "1") { |
210 content::RecordAction( | 209 content::RecordAction( |
211 UserMetricsAction("PDF_ReaderInterstitialUpdate")); | 210 UserMetricsAction("PDF_ReaderInterstitialUpdate")); |
212 OpenReaderUpdateURL(tab_contents_->web_contents()); | 211 OpenReaderUpdateURL(web_contents_); |
213 } else if (command == "2") { | 212 } else if (command == "2") { |
214 content::RecordAction( | 213 content::RecordAction( |
215 UserMetricsAction("PDF_ReaderInterstitialIgnore")); | 214 UserMetricsAction("PDF_ReaderInterstitialIgnore")); |
216 // Pretend that the plug-in is up-to-date so that we don't block it. | 215 // Pretend that the plug-in is up-to-date so that we don't block it. |
217 reader_webplugininfo_.version = ASCIIToUTF16("11.0.0.0"); | 216 reader_webplugininfo_.version = ASCIIToUTF16("11.0.0.0"); |
218 OpenUsingReader(tab_contents_->web_contents(), reader_webplugininfo_, | 217 OpenUsingReader(web_contents_, reader_webplugininfo_, NULL); |
219 NULL); | |
220 } else { | 218 } else { |
221 NOTREACHED(); | 219 NOTREACHED(); |
222 } | 220 } |
223 interstitial_page_->Proceed(); | 221 interstitial_page_->Proceed(); |
224 } | 222 } |
225 | 223 |
226 virtual void OverrideRendererPrefs( | 224 virtual void OverrideRendererPrefs( |
227 content::RendererPreferences* prefs) OVERRIDE { | 225 content::RendererPreferences* prefs) OVERRIDE { |
228 renderer_preferences_util::UpdateFromSystemSettings( | 226 Profile* profile = |
229 prefs, tab_contents_->profile()); | 227 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 228 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); |
230 } | 229 } |
231 | 230 |
232 private: | 231 private: |
233 TabContents* tab_contents_; | 232 WebContents* web_contents_; |
234 WebPluginInfo reader_webplugininfo_; | 233 WebPluginInfo reader_webplugininfo_; |
235 InterstitialPage* interstitial_page_; // Owns us. | 234 InterstitialPage* interstitial_page_; // Owns us. |
236 | 235 |
237 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); | 236 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); |
238 }; | 237 }; |
239 | 238 |
240 // The delegate for the bubble used to inform the user that we don't support a | 239 // The delegate for the bubble used to inform the user that we don't support a |
241 // feature in the PDF. | 240 // feature in the PDF. |
242 class PDFUnsupportedFeaturePromptDelegate | 241 class PDFUnsupportedFeaturePromptDelegate |
243 : public OpenPDFInReaderPromptDelegate { | 242 : public OpenPDFInReaderPromptDelegate { |
244 public: | 243 public: |
245 // |reader| is NULL if Adobe Reader isn't installed. | 244 // |reader| is NULL if Adobe Reader isn't installed. |
246 PDFUnsupportedFeaturePromptDelegate(TabContents* tab_contents, | 245 PDFUnsupportedFeaturePromptDelegate(WebContents* web_contents, |
247 const webkit::WebPluginInfo* reader, | 246 const webkit::WebPluginInfo* reader, |
248 PluginFinder* plugin_finder); | 247 PluginFinder* plugin_finder); |
249 virtual ~PDFUnsupportedFeaturePromptDelegate(); | 248 virtual ~PDFUnsupportedFeaturePromptDelegate(); |
250 | 249 |
251 // OpenPDFInReaderPromptDelegate: | 250 // OpenPDFInReaderPromptDelegate: |
252 virtual string16 GetMessageText() const OVERRIDE; | 251 virtual string16 GetMessageText() const OVERRIDE; |
253 virtual string16 GetAcceptButtonText() const OVERRIDE; | 252 virtual string16 GetAcceptButtonText() const OVERRIDE; |
254 virtual string16 GetCancelButtonText() const OVERRIDE; | 253 virtual string16 GetCancelButtonText() const OVERRIDE; |
255 virtual bool ShouldExpire( | 254 virtual bool ShouldExpire( |
256 const content::LoadCommittedDetails& details) const OVERRIDE; | 255 const content::LoadCommittedDetails& details) const OVERRIDE; |
257 virtual void Accept() OVERRIDE; | 256 virtual void Accept() OVERRIDE; |
258 virtual void Cancel() OVERRIDE; | 257 virtual void Cancel() OVERRIDE; |
259 | 258 |
260 private: | 259 private: |
261 TabContents* tab_contents_; | 260 WebContents* web_contents_; |
262 bool reader_installed_; | 261 bool reader_installed_; |
263 bool reader_vulnerable_; | 262 bool reader_vulnerable_; |
264 WebPluginInfo reader_webplugininfo_; | 263 WebPluginInfo reader_webplugininfo_; |
265 | 264 |
266 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeaturePromptDelegate); | 265 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeaturePromptDelegate); |
267 }; | 266 }; |
268 | 267 |
269 PDFUnsupportedFeaturePromptDelegate::PDFUnsupportedFeaturePromptDelegate( | 268 PDFUnsupportedFeaturePromptDelegate::PDFUnsupportedFeaturePromptDelegate( |
270 TabContents* tab_contents, | 269 WebContents* web_contents, |
271 const webkit::WebPluginInfo* reader, | 270 const webkit::WebPluginInfo* reader, |
272 PluginFinder* plugin_finder) | 271 PluginFinder* plugin_finder) |
273 : tab_contents_(tab_contents), | 272 : web_contents_(web_contents), |
274 reader_installed_(!!reader), | 273 reader_installed_(!!reader), |
275 reader_vulnerable_(false) { | 274 reader_vulnerable_(false) { |
276 if (!reader_installed_) { | 275 if (!reader_installed_) { |
277 content::RecordAction( | 276 content::RecordAction( |
278 UserMetricsAction("PDF_InstallReaderInfoBarShown")); | 277 UserMetricsAction("PDF_InstallReaderInfoBarShown")); |
279 return; | 278 return; |
280 } | 279 } |
281 | 280 |
282 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); | 281 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); |
283 reader_webplugininfo_ = *reader; | 282 reader_webplugininfo_ = *reader; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 void PDFUnsupportedFeaturePromptDelegate::Accept() { | 323 void PDFUnsupportedFeaturePromptDelegate::Accept() { |
325 #if defined(OS_WIN) | 324 #if defined(OS_WIN) |
326 if (base::win::IsMetroProcess()) { | 325 if (base::win::IsMetroProcess()) { |
327 browser::AttemptRestartWithModeSwitch(); | 326 browser::AttemptRestartWithModeSwitch(); |
328 return; | 327 return; |
329 } | 328 } |
330 #endif | 329 #endif |
331 | 330 |
332 if (!reader_installed_) { | 331 if (!reader_installed_) { |
333 content::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK")); | 332 content::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK")); |
334 OpenReaderUpdateURL(tab_contents_->web_contents()); | 333 OpenReaderUpdateURL(web_contents_); |
335 return; | 334 return; |
336 } | 335 } |
337 | 336 |
338 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); | 337 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); |
339 | 338 |
340 if (reader_vulnerable_) { | 339 if (reader_vulnerable_) { |
341 new PDFUnsupportedFeatureInterstitial(tab_contents_, reader_webplugininfo_); | 340 new PDFUnsupportedFeatureInterstitial(web_contents_, reader_webplugininfo_); |
342 return; | 341 return; |
343 } | 342 } |
344 | 343 |
| 344 Profile* profile = |
| 345 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
345 OpenPDFInReaderPromptDelegate* delegate = | 346 OpenPDFInReaderPromptDelegate* delegate = |
346 new PDFEnableAdobeReaderPromptDelegate(tab_contents_->profile()); | 347 new PDFEnableAdobeReaderPromptDelegate(profile); |
347 | 348 |
348 OpenUsingReader(tab_contents_->web_contents(), reader_webplugininfo_, | 349 OpenUsingReader(web_contents_, reader_webplugininfo_, delegate); |
349 delegate); | |
350 } | 350 } |
351 | 351 |
352 void PDFUnsupportedFeaturePromptDelegate::Cancel() { | 352 void PDFUnsupportedFeaturePromptDelegate::Cancel() { |
353 content::RecordAction(reader_installed_ ? | 353 content::RecordAction(reader_installed_ ? |
354 UserMetricsAction("PDF_UseReaderInfoBarCancel") : | 354 UserMetricsAction("PDF_UseReaderInfoBarCancel") : |
355 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); | 355 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); |
356 } | 356 } |
357 | 357 |
358 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) | 358 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) |
359 void GotPluginsCallback(int process_id, | 359 void GotPluginsCallback(int process_id, |
360 int routing_id, | 360 int routing_id, |
361 const std::vector<webkit::WebPluginInfo>& plugins) { | 361 const std::vector<webkit::WebPluginInfo>& plugins) { |
362 WebContents* web_contents = | 362 WebContents* web_contents = |
363 tab_util::GetWebContentsByID(process_id, routing_id); | 363 tab_util::GetWebContentsByID(process_id, routing_id); |
364 if (!web_contents) | 364 if (!web_contents) |
365 return; | 365 return; |
366 | 366 |
367 TabContents* tab = TabContents::FromWebContents(web_contents); | |
368 if (!tab) | |
369 return; | |
370 | |
371 const webkit::WebPluginInfo* reader = NULL; | 367 const webkit::WebPluginInfo* reader = NULL; |
372 PluginFinder* plugin_finder = PluginFinder::GetInstance(); | 368 PluginFinder* plugin_finder = PluginFinder::GetInstance(); |
373 for (size_t i = 0; i < plugins.size(); ++i) { | 369 for (size_t i = 0; i < plugins.size(); ++i) { |
374 scoped_ptr<PluginMetadata> plugin_metadata( | 370 scoped_ptr<PluginMetadata> plugin_metadata( |
375 plugin_finder->GetPluginMetadata(plugins[i])); | 371 plugin_finder->GetPluginMetadata(plugins[i])); |
376 if (plugin_metadata->identifier() != kAdobeReaderIdentifier) | 372 if (plugin_metadata->identifier() != kAdobeReaderIdentifier) |
377 continue; | 373 continue; |
378 | 374 |
379 DCHECK(!reader); | 375 DCHECK(!reader); |
380 reader = &plugins[i]; | 376 reader = &plugins[i]; |
381 // 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. |
382 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); | 378 Profile* profile = |
| 379 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 380 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
383 if (plugin_prefs->PolicyStatusForPlugin(plugin_metadata->name()) == | 381 if (plugin_prefs->PolicyStatusForPlugin(plugin_metadata->name()) == |
384 PluginPrefs::POLICY_DISABLED) { | 382 PluginPrefs::POLICY_DISABLED) { |
385 return; | 383 return; |
386 } | 384 } |
387 break; | 385 break; |
388 } | 386 } |
389 | 387 |
390 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt( | 388 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt( |
391 new PDFUnsupportedFeaturePromptDelegate(tab, reader, plugin_finder)); | 389 new PDFUnsupportedFeaturePromptDelegate( |
| 390 web_contents, reader, plugin_finder)); |
392 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); | 391 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); |
393 pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass()); | 392 pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass()); |
394 } | 393 } |
395 #endif // defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) | 394 #endif // defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) |
396 | 395 |
397 } // namespace | 396 } // namespace |
398 | 397 |
399 void PDFHasUnsupportedFeature(content::WebContents* web_contents) { | 398 void PDFHasUnsupportedFeature(content::WebContents* web_contents) { |
400 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) | 399 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) |
401 // Only works for Windows for now. For Mac, we'll have to launch the file | 400 // Only works for Windows for now. For Mac, we'll have to launch the file |
402 // externally since Adobe Reader doesn't work inside Chrome. | 401 // externally since Adobe Reader doesn't work inside Chrome. |
403 PluginService::GetInstance()->GetPlugins(base::Bind(&GotPluginsCallback, | 402 PluginService::GetInstance()->GetPlugins(base::Bind(&GotPluginsCallback, |
404 web_contents->GetRenderProcessHost()->GetID(), | 403 web_contents->GetRenderProcessHost()->GetID(), |
405 web_contents->GetRenderViewHost()->GetRoutingID())); | 404 web_contents->GetRenderViewHost()->GetRoutingID())); |
406 #endif | 405 #endif |
407 } | 406 } |
OLD | NEW |