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

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

Issue 10905304: Reland 156033 - Add an icon and bubble to the location bar to open PDFs in Reader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: , Created 8 years, 2 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
« no previous file with comments | « chrome/browser/ui/pdf/pdf_tab_helper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/api/infobars/confirm_infobar_delegate.h"
12 #include "chrome/browser/chrome_plugin_service_filter.h" 11 #include "chrome/browser/chrome_plugin_service_filter.h"
13 #include "chrome/browser/infobars/infobar_tab_helper.h"
14 #include "chrome/browser/lifetime/application_lifetime.h" 12 #include "chrome/browser/lifetime/application_lifetime.h"
15 #include "chrome/browser/plugin_finder.h" 13 #include "chrome/browser/plugin_finder.h"
16 #include "chrome/browser/plugin_installer.h" 14 #include "chrome/browser/plugin_installer.h"
17 #include "chrome/browser/plugin_prefs.h" 15 #include "chrome/browser/plugin_prefs.h"
18 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/renderer_preferences_util.h" 18 #include "chrome/browser/renderer_preferences_util.h"
21 #include "chrome/browser/tab_contents/tab_util.h" 19 #include "chrome/browser/tab_contents/tab_util.h"
22 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" 20 #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h"
23 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" 21 #include "chrome/browser/ui/pdf/pdf_tab_helper.h"
24 #include "chrome/browser/ui/tab_contents/tab_contents.h" 22 #include "chrome/browser/ui/tab_contents/tab_contents.h"
25 #include "chrome/common/chrome_content_client.h" 23 #include "chrome/common/chrome_content_client.h"
26 #include "chrome/common/jstemplate_builder.h" 24 #include "chrome/common/jstemplate_builder.h"
27 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
28 #include "content/public/browser/interstitial_page.h" 26 #include "content/public/browser/interstitial_page.h"
29 #include "content/public/browser/interstitial_page_delegate.h" 27 #include "content/public/browser/interstitial_page_delegate.h"
28 #include "content/public/browser/navigation_details.h"
29 #include "content/public/browser/navigation_entry.h"
30 #include "content/public/browser/plugin_service.h" 30 #include "content/public/browser/plugin_service.h"
31 #include "content/public/browser/render_process_host.h" 31 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/render_view_host.h" 32 #include "content/public/browser/render_view_host.h"
33 #include "content/public/browser/user_metrics.h" 33 #include "content/public/browser/user_metrics.h"
34 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/page_transition_types.h"
35 #include "grit/browser_resources.h" 36 #include "grit/browser_resources.h"
36 #include "grit/generated_resources.h" 37 #include "grit/generated_resources.h"
37 #include "grit/theme_resources.h" 38 #include "grit/theme_resources.h"
38 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/layout.h" 40 #include "ui/base/layout.h"
40 #include "ui/base/resource/resource_bundle.h" 41 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/gfx/image/image.h" 42 #include "ui/gfx/image/image.h"
42 #include "webkit/plugins/npapi/plugin_group.h" 43 #include "webkit/plugins/npapi/plugin_group.h"
43 44
44 #if defined(OS_WIN) 45 #if defined(OS_WIN)
45 #include "base/win/metro.h" 46 #include "base/win/metro.h"
46 #endif 47 #endif
47 48
48 using content::InterstitialPage; 49 using content::InterstitialPage;
49 using content::OpenURLParams; 50 using content::OpenURLParams;
50 using content::PluginService; 51 using content::PluginService;
51 using content::Referrer; 52 using content::Referrer;
52 using content::UserMetricsAction; 53 using content::UserMetricsAction;
53 using content::WebContents; 54 using content::WebContents;
54 using webkit::npapi::PluginGroup; 55 using webkit::npapi::PluginGroup;
55 using webkit::WebPluginInfo; 56 using webkit::WebPluginInfo;
56 57
57 namespace { 58 namespace {
58 59
59 static const char kAdobeReaderIdentifier[] = "adobe-reader"; 60 static const char kAdobeReaderIdentifier[] = "adobe-reader";
60 static const char kAdobeReaderUpdateUrl[] = 61 static const char kAdobeReaderUpdateUrl[] =
61 "http://www.adobe.com/go/getreader_chrome"; 62 "http://www.adobe.com/go/getreader_chrome";
62 63
63 // The info bar delegate used to ask the user if they want to use Adobe Reader 64 // The prompt delegate used to ask the user if they want to use Adobe Reader
64 // by default. We want the infobar to have [No][Yes], so we swap the text on 65 // by default.
65 // the buttons, and the meaning of the delegate callbacks. 66 class PDFEnableAdobeReaderPromptDelegate
66 class PDFEnableAdobeReaderInfoBarDelegate : public ConfirmInfoBarDelegate { 67 : public OpenPDFInReaderPromptDelegate {
67 public: 68 public:
68 explicit PDFEnableAdobeReaderInfoBarDelegate( 69 explicit PDFEnableAdobeReaderPromptDelegate(Profile* profile);
69 InfoBarTabHelper* infobar_helper, 70 virtual ~PDFEnableAdobeReaderPromptDelegate();
70 Profile* profile);
71 virtual ~PDFEnableAdobeReaderInfoBarDelegate();
72 71
73 // ConfirmInfoBarDelegate 72 // OpenPDFInReaderPromptDelegate
74 virtual void InfoBarDismissed() OVERRIDE;
75 virtual Type GetInfoBarType() const OVERRIDE;
76 virtual bool Accept() OVERRIDE;
77 virtual bool Cancel() OVERRIDE;
78 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
79 virtual string16 GetMessageText() const OVERRIDE; 73 virtual string16 GetMessageText() const OVERRIDE;
74 virtual string16 GetAcceptButtonText() const OVERRIDE;
75 virtual string16 GetCancelButtonText() const OVERRIDE;
76 virtual bool ShouldExpire(
77 const content::LoadCommittedDetails& details) const OVERRIDE;
78 virtual void Accept() OVERRIDE;
79 virtual void Cancel() OVERRIDE;
80 80
81 private: 81 private:
82 void OnYes(); 82 void OnYes();
83 void OnNo(); 83 void OnNo();
84 84
85 Profile* profile_; 85 Profile* profile_;
86 86
87 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderInfoBarDelegate); 87 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderPromptDelegate);
88 }; 88 };
89 89
90 PDFEnableAdobeReaderInfoBarDelegate::PDFEnableAdobeReaderInfoBarDelegate( 90 PDFEnableAdobeReaderPromptDelegate::PDFEnableAdobeReaderPromptDelegate(
91 InfoBarTabHelper* infobar_helper, Profile* profile) 91 Profile* profile)
92 : ConfirmInfoBarDelegate(infobar_helper), 92 : profile_(profile) {
93 profile_(profile) {
94 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarShown")); 93 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarShown"));
95 } 94 }
96 95
97 PDFEnableAdobeReaderInfoBarDelegate::~PDFEnableAdobeReaderInfoBarDelegate() { 96 PDFEnableAdobeReaderPromptDelegate::~PDFEnableAdobeReaderPromptDelegate() {
98 } 97 }
99 98
100 void PDFEnableAdobeReaderInfoBarDelegate::InfoBarDismissed() { 99 bool PDFEnableAdobeReaderPromptDelegate::ShouldExpire(
101 OnNo(); 100 const content::LoadCommittedDetails& details) const {
101 content::PageTransition transition =
102 content::PageTransitionStripQualifier(details.entry->GetTransitionType());
103 // We don't want to expire on a reload, because that is how we open the PDF in
104 // Reader.
105 return !details.is_in_page && transition != content::PAGE_TRANSITION_RELOAD;
102 } 106 }
103 107
104 InfoBarDelegate::Type 108 void PDFEnableAdobeReaderPromptDelegate::Accept() {
105 PDFEnableAdobeReaderInfoBarDelegate::GetInfoBarType() const {
106 return PAGE_ACTION_TYPE;
107 }
108
109 bool PDFEnableAdobeReaderInfoBarDelegate::Accept() {
110 profile_->GetPrefs()->SetBoolean(
111 prefs::kPluginsShowSetReaderDefaultInfobar, false);
112 OnNo();
113 return true;
114 }
115
116 bool PDFEnableAdobeReaderInfoBarDelegate::Cancel() {
117 OnYes();
118 return true;
119 }
120
121 string16 PDFEnableAdobeReaderInfoBarDelegate::GetButtonLabel(
122 InfoBarButton button) const {
123 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
124 IDS_PDF_INFOBAR_NEVER_USE_READER_BUTTON :
125 IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON);
126 }
127
128 string16 PDFEnableAdobeReaderInfoBarDelegate::GetMessageText() const {
129 return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER);
130 }
131
132 void PDFEnableAdobeReaderInfoBarDelegate::OnYes() {
133 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK")); 109 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK"));
134 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile_); 110 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile_);
135 plugin_prefs->EnablePluginGroup( 111 plugin_prefs->EnablePluginGroup(
136 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); 112 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName));
137 plugin_prefs->EnablePluginGroup( 113 plugin_prefs->EnablePluginGroup(
138 false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); 114 false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName));
139 } 115 }
140 116
141 void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { 117 void PDFEnableAdobeReaderPromptDelegate::Cancel() {
118 // profile_->GetPrefs()->SetBoolean(
119 // prefs::kPluginsShowSetReaderDefaultInfobar, false);
142 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel")); 120 content::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel"));
143 } 121 }
144 122
123 string16 PDFEnableAdobeReaderPromptDelegate::GetAcceptButtonText() const {
124 return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON);
125 }
126
127 string16 PDFEnableAdobeReaderPromptDelegate::GetCancelButtonText() const {
128 return l10n_util::GetStringUTF16(IDS_DONE);
129 }
130
131 string16 PDFEnableAdobeReaderPromptDelegate::GetMessageText() const {
132 return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER);
133 }
134
145 // Launch the url to get the latest Adbobe Reader installer. 135 // Launch the url to get the latest Adbobe Reader installer.
146 void OpenReaderUpdateURL(WebContents* tab) { 136 void OpenReaderUpdateURL(WebContents* tab) {
147 OpenURLParams params( 137 OpenURLParams params(
148 GURL(kAdobeReaderUpdateUrl), Referrer(), NEW_FOREGROUND_TAB, 138 GURL(kAdobeReaderUpdateUrl), Referrer(), NEW_FOREGROUND_TAB,
149 content::PAGE_TRANSITION_LINK, false); 139 content::PAGE_TRANSITION_LINK, false);
150 tab->OpenURL(params); 140 tab->OpenURL(params);
151 } 141 }
152 142
153 // Opens the PDF using Adobe Reader. 143 // Opens the PDF using Adobe Reader.
154 void OpenUsingReader(WebContents* web_contents, 144 void OpenUsingReader(WebContents* web_contents,
155 const WebPluginInfo& reader_plugin, 145 const WebPluginInfo& reader_plugin,
156 InfoBarDelegate* delegate) { 146 OpenPDFInReaderPromptDelegate* delegate) {
157 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( 147 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab(
158 web_contents->GetRenderProcessHost()->GetID(), 148 web_contents->GetRenderProcessHost()->GetID(),
159 web_contents->GetRenderViewHost()->GetRoutingID(), 149 web_contents->GetRenderViewHost()->GetRoutingID(),
160 web_contents->GetURL(), 150 web_contents->GetURL(),
161 reader_plugin); 151 reader_plugin);
162 web_contents->GetRenderViewHost()->ReloadFrame(); 152 web_contents->GetRenderViewHost()->ReloadFrame();
163 153
154 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents);
164 if (delegate) 155 if (delegate)
165 tab->infobar_tab_helper()->AddInfoBar(delegate); 156 pdf_tab_helper->ShowOpenInReaderPrompt(make_scoped_ptr(delegate));
166 } 157 }
167 158
168 // An interstitial to be used when the user chooses to open a PDF using Adobe 159 // An interstitial to be used when the user chooses to open a PDF using Adobe
169 // Reader, but it is out of date. 160 // Reader, but it is out of date.
170 class PDFUnsupportedFeatureInterstitial 161 class PDFUnsupportedFeatureInterstitial
171 : public content::InterstitialPageDelegate { 162 : public content::InterstitialPageDelegate {
172 public: 163 public:
173 PDFUnsupportedFeatureInterstitial( 164 PDFUnsupportedFeatureInterstitial(
174 TabContents* tab, 165 TabContents* tab,
175 const WebPluginInfo& reader_webplugininfo) 166 const WebPluginInfo& reader_webplugininfo)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // |reader| is NULL if Adobe Reader isn't installed. 250 // |reader| is NULL if Adobe Reader isn't installed.
260 PDFUnsupportedFeaturePromptDelegate(TabContents* tab_contents, 251 PDFUnsupportedFeaturePromptDelegate(TabContents* tab_contents,
261 const webkit::WebPluginInfo* reader, 252 const webkit::WebPluginInfo* reader,
262 PluginFinder* plugin_finder); 253 PluginFinder* plugin_finder);
263 virtual ~PDFUnsupportedFeaturePromptDelegate(); 254 virtual ~PDFUnsupportedFeaturePromptDelegate();
264 255
265 // OpenPDFInReaderPromptDelegate: 256 // OpenPDFInReaderPromptDelegate:
266 virtual string16 GetMessageText() const OVERRIDE; 257 virtual string16 GetMessageText() const OVERRIDE;
267 virtual string16 GetAcceptButtonText() const OVERRIDE; 258 virtual string16 GetAcceptButtonText() const OVERRIDE;
268 virtual string16 GetCancelButtonText() const OVERRIDE; 259 virtual string16 GetCancelButtonText() const OVERRIDE;
260 virtual bool ShouldExpire(
261 const content::LoadCommittedDetails& details) const OVERRIDE;
269 virtual void Accept() OVERRIDE; 262 virtual void Accept() OVERRIDE;
270 virtual void Cancel() OVERRIDE; 263 virtual void Cancel() OVERRIDE;
271 264
272 private: 265 private:
273 TabContents* tab_contents_; 266 TabContents* tab_contents_;
274 bool reader_installed_; 267 bool reader_installed_;
275 bool reader_vulnerable_; 268 bool reader_vulnerable_;
276 WebPluginInfo reader_webplugininfo_; 269 WebPluginInfo reader_webplugininfo_;
277 270
278 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeaturePromptDelegate); 271 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeaturePromptDelegate);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 if (reader_installed_) 315 if (reader_installed_)
323 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_OPEN_IN_READER_LINK); 316 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_OPEN_IN_READER_LINK);
324 317
325 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_INSTALL_READER_LINK); 318 return l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_INSTALL_READER_LINK);
326 } 319 }
327 320
328 string16 PDFUnsupportedFeaturePromptDelegate::GetCancelButtonText() const { 321 string16 PDFUnsupportedFeaturePromptDelegate::GetCancelButtonText() const {
329 return l10n_util::GetStringUTF16(IDS_DONE); 322 return l10n_util::GetStringUTF16(IDS_DONE);
330 } 323 }
331 324
325 bool PDFUnsupportedFeaturePromptDelegate::ShouldExpire(
326 const content::LoadCommittedDetails& details) const {
327 return !details.is_in_page;
328 }
329
332 void PDFUnsupportedFeaturePromptDelegate::Accept() { 330 void PDFUnsupportedFeaturePromptDelegate::Accept() {
333 #if defined(OS_WIN) 331 #if defined(OS_WIN)
334 if (base::win::IsMetroProcess()) { 332 if (base::win::IsMetroProcess()) {
335 browser::AttemptRestartWithModeSwitch(); 333 browser::AttemptRestartWithModeSwitch();
336 return; 334 return;
337 } 335 }
338 #endif 336 #endif
339 337
340 if (!reader_installed_) { 338 if (!reader_installed_) {
341 content::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK")); 339 content::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK"));
342 OpenReaderUpdateURL(tab_contents_->web_contents()); 340 OpenReaderUpdateURL(tab_contents_->web_contents());
343 return; 341 return;
344 } 342 }
345 343
346 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); 344 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK"));
347 345
348 if (reader_vulnerable_) { 346 if (reader_vulnerable_) {
349 new PDFUnsupportedFeatureInterstitial(tab_contents_, reader_webplugininfo_); 347 new PDFUnsupportedFeatureInterstitial(tab_contents_, reader_webplugininfo_);
350 return; 348 return;
351 } 349 }
352 350
351 OpenPDFInReaderPromptDelegate* delegate = NULL;
353 if (tab_contents_->profile()->GetPrefs()->GetBoolean( 352 if (tab_contents_->profile()->GetPrefs()->GetBoolean(
354 prefs::kPluginsShowSetReaderDefaultInfobar)) { 353 prefs::kPluginsShowSetReaderDefaultInfobar)) {
355 InfoBarDelegate* bar = new PDFEnableAdobeReaderInfoBarDelegate( 354 delegate =
356 tab_contents_->infobar_tab_helper(), tab_contents_->profile()); 355 new PDFEnableAdobeReaderPromptDelegate(tab_contents_->profile());
357 OpenUsingReader(tab_contents_, reader_webplugininfo_, bar);
358 return;
359 } 356 }
360 357
361 OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL); 358 OpenUsingReader(tab_contents_->web_contents(), reader_webplugininfo_,
359 delegate);
362 } 360 }
363 361
364 void PDFUnsupportedFeaturePromptDelegate::Cancel() { 362 void PDFUnsupportedFeaturePromptDelegate::Cancel() {
365 content::RecordAction(reader_installed_ ? 363 content::RecordAction(reader_installed_ ?
366 UserMetricsAction("PDF_UseReaderInfoBarCancel") : 364 UserMetricsAction("PDF_UseReaderInfoBarCancel") :
367 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); 365 UserMetricsAction("PDF_InstallReaderInfoBarCancel"));
368 } 366 }
369 367
370 void GotPluginsCallback(int process_id, 368 void GotPluginsCallback(int process_id,
371 int routing_id, 369 int routing_id,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 413
416 void PDFHasUnsupportedFeature(content::WebContents* web_contents) { 414 void PDFHasUnsupportedFeature(content::WebContents* web_contents) {
417 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) 415 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION)
418 // Only works for Windows for now. For Mac, we'll have to launch the file 416 // Only works for Windows for now. For Mac, we'll have to launch the file
419 // externally since Adobe Reader doesn't work inside Chrome. 417 // externally since Adobe Reader doesn't work inside Chrome.
420 PluginFinder::Get(base::Bind(&GotPluginFinderCallback, 418 PluginFinder::Get(base::Bind(&GotPluginFinderCallback,
421 web_contents->GetRenderProcessHost()->GetID(), 419 web_contents->GetRenderProcessHost()->GetID(),
422 web_contents->GetRenderViewHost()->GetRoutingID())); 420 web_contents->GetRenderViewHost()->GetRoutingID()));
423 #endif 421 #endif
424 } 422 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/pdf/pdf_tab_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698