Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: chrome/browser/ui/pdf/pdf_unsupported_feature.cc

Issue 324593004: Windows: Add an "Open in Adobe Reader" menu item for PDF files in the download shelf. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/prefs/pref_service.h"
10 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h"
12 #include "base/version.h"
13 #include "chrome/browser/lifetime/application_lifetime.h" 10 #include "chrome/browser/lifetime/application_lifetime.h"
14 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" 11 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
15 #include "chrome/browser/plugins/plugin_finder.h"
16 #include "chrome/browser/plugins/plugin_metadata.h" 12 #include "chrome/browser/plugins/plugin_metadata.h"
17 #include "chrome/browser/plugins/plugin_prefs.h" 13 #include "chrome/browser/plugins/plugin_prefs.h"
18 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/renderer_preferences_util.h" 15 #include "chrome/browser/renderer_preferences_util.h"
20 #include "chrome/browser/tab_contents/tab_util.h" 16 #include "chrome/browser/tab_contents/tab_util.h"
21 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" 17 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h"
22 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" 18 #include "chrome/browser/ui/pdf/pdf_tab_helper.h"
23 #include "chrome/common/chrome_content_client.h" 19 #include "chrome/common/chrome_content_client.h"
24 #include "chrome/common/pref_names.h"
25 #include "content/public/browser/interstitial_page.h" 20 #include "content/public/browser/interstitial_page.h"
26 #include "content/public/browser/interstitial_page_delegate.h" 21 #include "content/public/browser/interstitial_page_delegate.h"
27 #include "content/public/browser/navigation_details.h" 22 #include "content/public/browser/navigation_details.h"
28 #include "content/public/browser/navigation_entry.h" 23 #include "content/public/browser/navigation_entry.h"
29 #include "content/public/browser/plugin_service.h" 24 #include "content/public/browser/page_navigator.h"
30 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
31 #include "content/public/browser/render_process_host.h" 26 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/render_view_host.h" 27 #include "content/public/browser/render_view_host.h"
33 #include "content/public/browser/user_metrics.h" 28 #include "content/public/browser/user_metrics.h"
34 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/page_transition_types.h"
36 #include "grit/browser_resources.h" 30 #include "grit/browser_resources.h"
37 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
38 #include "grit/theme_resources.h"
39 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
40 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/base/webui/jstemplate_builder.h" 34 #include "ui/base/webui/jstemplate_builder.h"
42 #include "ui/gfx/image/image.h"
43 35
44 #if defined(OS_WIN) 36 #if defined(OS_WIN)
45 #include "base/win/metro.h" 37 #include "base/win/metro.h"
46 #endif 38 #endif
47 39
40 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION)
41 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
42 #endif
43
48 using base::UserMetricsAction; 44 using base::UserMetricsAction;
49 using content::InterstitialPage; 45 using content::InterstitialPage;
50 using content::OpenURLParams; 46 using content::OpenURLParams;
51 using content::PluginService;
52 using content::Referrer; 47 using content::Referrer;
53 using content::WebContents; 48 using content::WebContents;
54 using content::WebPluginInfo; 49 using content::WebPluginInfo;
55 50
56 namespace { 51 namespace {
57 52
58 const char kAdobeReaderUpdateUrl[] = "http://www.adobe.com/go/getreader_chrome"; 53 const char kAdobeReaderUpdateUrl[] = "http://www.adobe.com/go/getreader_chrome";
59 54
60 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION)
61 const char kAdobeReaderIdentifier[] = "adobe-reader";
62 #endif
63
64 // The prompt delegate used to ask the user if they want to use Adobe Reader 55 // The prompt delegate used to ask the user if they want to use Adobe Reader
65 // by default. 56 // by default.
66 class PDFEnableAdobeReaderPromptDelegate 57 class PDFEnableAdobeReaderPromptDelegate
67 : public OpenPDFInReaderPromptDelegate { 58 : public OpenPDFInReaderPromptDelegate {
68 public: 59 public:
69 explicit PDFEnableAdobeReaderPromptDelegate(Profile* profile); 60 explicit PDFEnableAdobeReaderPromptDelegate(Profile* profile);
70 virtual ~PDFEnableAdobeReaderPromptDelegate(); 61 virtual ~PDFEnableAdobeReaderPromptDelegate();
71 62
72 // OpenPDFInReaderPromptDelegate 63 // OpenPDFInReaderPromptDelegate
73 virtual base::string16 GetMessageText() const OVERRIDE; 64 virtual base::string16 GetMessageText() const OVERRIDE;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 InterstitialPage* interstitial_page_; // Owns us. 228 InterstitialPage* interstitial_page_; // Owns us.
238 229
239 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); 230 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial);
240 }; 231 };
241 232
242 // 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
243 // feature in the PDF. 234 // feature in the PDF.
244 class PDFUnsupportedFeaturePromptDelegate 235 class PDFUnsupportedFeaturePromptDelegate
245 : public OpenPDFInReaderPromptDelegate { 236 : public OpenPDFInReaderPromptDelegate {
246 public: 237 public:
247 // |reader| is NULL if Adobe Reader isn't installed. 238 PDFUnsupportedFeaturePromptDelegate(
248 PDFUnsupportedFeaturePromptDelegate(WebContents* web_contents, 239 WebContents* web_contents,
249 const content::WebPluginInfo* reader, 240 const AdobeReaderPluginInfo& reader_info);
250 PluginFinder* plugin_finder);
251 virtual ~PDFUnsupportedFeaturePromptDelegate(); 241 virtual ~PDFUnsupportedFeaturePromptDelegate();
252 242
253 // OpenPDFInReaderPromptDelegate: 243 // OpenPDFInReaderPromptDelegate:
254 virtual base::string16 GetMessageText() const OVERRIDE; 244 virtual base::string16 GetMessageText() const OVERRIDE;
255 virtual base::string16 GetAcceptButtonText() const OVERRIDE; 245 virtual base::string16 GetAcceptButtonText() const OVERRIDE;
256 virtual base::string16 GetCancelButtonText() const OVERRIDE; 246 virtual base::string16 GetCancelButtonText() const OVERRIDE;
257 virtual bool ShouldExpire( 247 virtual bool ShouldExpire(
258 const content::LoadCommittedDetails& details) const OVERRIDE; 248 const content::LoadCommittedDetails& details) const OVERRIDE;
259 virtual void Accept() OVERRIDE; 249 virtual void Accept() OVERRIDE;
260 virtual void Cancel() OVERRIDE; 250 virtual void Cancel() OVERRIDE;
261 251
262 private: 252 private:
263 WebContents* web_contents_; 253 WebContents* web_contents_;
264 bool reader_installed_; 254 const AdobeReaderPluginInfo reader_info_;
265 bool reader_vulnerable_;
266 WebPluginInfo reader_webplugininfo_;
267 255
268 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeaturePromptDelegate); 256 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeaturePromptDelegate);
269 }; 257 };
270 258
271 PDFUnsupportedFeaturePromptDelegate::PDFUnsupportedFeaturePromptDelegate( 259 PDFUnsupportedFeaturePromptDelegate::PDFUnsupportedFeaturePromptDelegate(
272 WebContents* web_contents, 260 WebContents* web_contents,
273 const content::WebPluginInfo* reader, 261 const AdobeReaderPluginInfo& reader_info)
274 PluginFinder* plugin_finder)
275 : web_contents_(web_contents), 262 : web_contents_(web_contents),
276 reader_installed_(!!reader), 263 reader_info_(reader_info) {
277 reader_vulnerable_(false) { 264 content::RecordAction(reader_info_.is_installed ?
278 if (!reader_installed_) { 265 UserMetricsAction("PDF_UseReaderInfoBarShown") :
279 content::RecordAction( 266 UserMetricsAction("PDF_InstallReaderInfoBarShown"));
280 UserMetricsAction("PDF_InstallReaderInfoBarShown"));
281 return;
282 }
283
284 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown"));
285 reader_webplugininfo_ = *reader;
286
287 #if defined(ENABLE_PLUGIN_INSTALLATION)
288 scoped_ptr<PluginMetadata> plugin_metadata(
289 plugin_finder->GetPluginMetadata(reader_webplugininfo_));
290
291 reader_vulnerable_ = plugin_metadata->GetSecurityStatus(*reader) !=
292 PluginMetadata::SECURITY_STATUS_UP_TO_DATE;
293 #else
294 NOTREACHED();
295 #endif
296 } 267 }
297 268
298 PDFUnsupportedFeaturePromptDelegate::~PDFUnsupportedFeaturePromptDelegate() { 269 PDFUnsupportedFeaturePromptDelegate::~PDFUnsupportedFeaturePromptDelegate() {
299 } 270 }
300 271
301 base::string16 PDFUnsupportedFeaturePromptDelegate::GetMessageText() const { 272 base::string16 PDFUnsupportedFeaturePromptDelegate::GetMessageText() const {
302 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_MESSAGE); 273 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_MESSAGE);
303 } 274 }
304 275
305 base::string16 PDFUnsupportedFeaturePromptDelegate::GetAcceptButtonText() 276 base::string16 PDFUnsupportedFeaturePromptDelegate::GetAcceptButtonText()
306 const { 277 const {
307 #if defined(OS_WIN) 278 #if defined(OS_WIN)
308 if (base::win::IsMetroProcess()) 279 if (base::win::IsMetroProcess())
309 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_METRO_MODE_LINK); 280 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_METRO_MODE_LINK);
310 #endif 281 #endif
311 282
312 if (reader_installed_) 283 return l10n_util::GetStringUTF16(
313 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_OPEN_IN_READER_LINK); 284 reader_info_.is_installed ? IDS_PDF_BUBBLE_OPEN_IN_READER_LINK
314 285 : IDS_PDF_BUBBLE_INSTALL_READER_LINK);
315 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_INSTALL_READER_LINK);
316 } 286 }
317 287
318 base::string16 PDFUnsupportedFeaturePromptDelegate::GetCancelButtonText() 288 base::string16 PDFUnsupportedFeaturePromptDelegate::GetCancelButtonText()
319 const { 289 const {
320 return l10n_util::GetStringUTF16(IDS_DONE); 290 return l10n_util::GetStringUTF16(IDS_DONE);
321 } 291 }
322 292
323 bool PDFUnsupportedFeaturePromptDelegate::ShouldExpire( 293 bool PDFUnsupportedFeaturePromptDelegate::ShouldExpire(
324 const content::LoadCommittedDetails& details) const { 294 const content::LoadCommittedDetails& details) const {
325 return !details.is_in_page; 295 return !details.is_in_page;
326 } 296 }
327 297
328 void PDFUnsupportedFeaturePromptDelegate::Accept() { 298 void PDFUnsupportedFeaturePromptDelegate::Accept() {
329 #if defined(OS_WIN) 299 #if defined(OS_WIN)
330 if (base::win::IsMetroProcess()) { 300 if (base::win::IsMetroProcess()) {
331 chrome::AttemptRestartWithModeSwitch(); 301 chrome::AttemptRestartWithModeSwitch();
332 return; 302 return;
333 } 303 }
334 #endif 304 #endif
335 305
336 if (!reader_installed_) { 306 if (!reader_info_.is_installed) {
337 content::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK")); 307 content::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK"));
338 OpenReaderUpdateURL(web_contents_); 308 OpenReaderUpdateURL(web_contents_);
339 return; 309 return;
340 } 310 }
341 311
342 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); 312 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK"));
343 313
344 if (reader_vulnerable_) { 314 if (!reader_info_.is_secure) {
345 new PDFUnsupportedFeatureInterstitial(web_contents_, reader_webplugininfo_); 315 new PDFUnsupportedFeatureInterstitial(web_contents_,
316 reader_info_.plugin_info);
346 return; 317 return;
347 } 318 }
348 319
349 Profile* profile = 320 Profile* profile =
350 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 321 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
351 OpenPDFInReaderPromptDelegate* delegate = 322 OpenPDFInReaderPromptDelegate* delegate =
352 new PDFEnableAdobeReaderPromptDelegate(profile); 323 new PDFEnableAdobeReaderPromptDelegate(profile);
353 324
354 OpenUsingReader(web_contents_, reader_webplugininfo_, delegate); 325 OpenUsingReader(web_contents_, reader_info_.plugin_info, delegate);
355 } 326 }
356 327
357 void PDFUnsupportedFeaturePromptDelegate::Cancel() { 328 void PDFUnsupportedFeaturePromptDelegate::Cancel() {
358 content::RecordAction(reader_installed_ ? 329 content::RecordAction(reader_info_.is_installed ?
359 UserMetricsAction("PDF_UseReaderInfoBarCancel") : 330 UserMetricsAction("PDF_UseReaderInfoBarCancel") :
360 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); 331 UserMetricsAction("PDF_InstallReaderInfoBarCancel"));
361 } 332 }
362 333
363 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) 334 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION)
364 void GotPluginsCallback(int process_id, 335 void MaybeShowOpenPDFInReaderPrompt(WebContents* web_contents,
365 int routing_id, 336 const AdobeReaderPluginInfo& reader_info) {
366 const std::vector<content::WebPluginInfo>& plugins) { 337 // If the Reader plugin is disabled by policy, don't prompt them.
367 WebContents* web_contents = 338 if (!reader_info.is_installed || !reader_info.is_enabled)
368 tab_util::GetWebContentsByID(process_id, routing_id);
369 if (!web_contents)
370 return; 339 return;
371 340
372 const content::WebPluginInfo* reader = NULL;
373 PluginFinder* plugin_finder = PluginFinder::GetInstance();
374 for (size_t i = 0; i < plugins.size(); ++i) {
375 scoped_ptr<PluginMetadata> plugin_metadata(
376 plugin_finder->GetPluginMetadata(plugins[i]));
377 if (plugin_metadata->identifier() != kAdobeReaderIdentifier)
378 continue;
379
380 DCHECK(!reader);
381 reader = &plugins[i];
382 // If the Reader plugin is disabled by policy, don't prompt them.
383 Profile* profile =
384 Profile::FromBrowserContext(web_contents->GetBrowserContext());
385 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile);
386 if (plugin_prefs->PolicyStatusForPlugin(plugin_metadata->name()) ==
387 PluginPrefs::POLICY_DISABLED) {
388 return;
389 }
390 break;
391 }
392
393 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt( 341 scoped_ptr<OpenPDFInReaderPromptDelegate> prompt(
394 new PDFUnsupportedFeaturePromptDelegate( 342 new PDFUnsupportedFeaturePromptDelegate(web_contents, reader_info));
395 web_contents, reader, plugin_finder));
396 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents); 343 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents);
397 pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass()); 344 pdf_tab_helper->ShowOpenInReaderPrompt(prompt.Pass());
398 } 345 }
346
347 void GotPluginsCallback(int process_id,
348 int routing_id,
349 const AdobeReaderPluginInfo& reader_info) {
350 WebContents* web_contents =
351 tab_util::GetWebContentsByID(process_id, routing_id);
352 if (web_contents)
353 MaybeShowOpenPDFInReaderPrompt(web_contents, reader_info);
354 }
355
399 #endif // defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) 356 #endif // defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION)
400 357
401 } // namespace 358 } // namespace
402 359
403 void PDFHasUnsupportedFeature(content::WebContents* web_contents) { 360 void PDFHasUnsupportedFeature(WebContents* web_contents) {
404 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) 361 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION)
405 // Only works for Windows for now. For Mac, we'll have to launch the file 362 // Only works for Windows for now. For Mac, we'll have to launch the file
406 // externally since Adobe Reader doesn't work inside Chrome. 363 // externally since Adobe Reader doesn't work inside Chrome.
407 PluginService::GetInstance()->GetPlugins(base::Bind(&GotPluginsCallback, 364 AdobeReaderPluginInfo reader_info;
408 web_contents->GetRenderProcessHost()->GetID(), 365 if (GetAdobeReaderPluginInfo(web_contents, &reader_info)) {
409 web_contents->GetRenderViewHost()->GetRoutingID())); 366 MaybeShowOpenPDFInReaderPrompt(web_contents, reader_info);
367 return;
368 }
369 GetAdobeReaderPluginInfoAsync(
370 web_contents,
371 base::Bind(&GotPluginsCallback,
372 web_contents->GetRenderProcessHost()->GetID(),
373 web_contents->GetRenderViewHost()->GetRoutingID()));
410 #endif 374 #endif
411 } 375 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698