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/pdf_unsupported_feature.h" | 5 #include "chrome/browser/pdf_unsupported_feature.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "base/version.h" | 9 #include "base/version.h" |
10 #include "chrome/browser/metrics/user_metrics.h" | |
10 #include "chrome/browser/plugin_service.h" | 11 #include "chrome/browser/plugin_service.h" |
11 #include "chrome/browser/renderer_host/render_process_host.h" | 12 #include "chrome/browser/renderer_host/render_process_host.h" |
12 #include "chrome/browser/renderer_host/render_view_host.h" | 13 #include "chrome/browser/renderer_host/render_view_host.h" |
13 #include "chrome/browser/tab_contents/infobar_delegate.h" | 14 #include "chrome/browser/tab_contents/infobar_delegate.h" |
14 #include "chrome/browser/tab_contents/interstitial_page.h" | 15 #include "chrome/browser/tab_contents/interstitial_page.h" |
15 #include "chrome/browser/tab_contents/tab_contents.h" | 16 #include "chrome/browser/tab_contents/tab_contents.h" |
16 #include "chrome/common/jstemplate_builder.h" | 17 #include "chrome/common/jstemplate_builder.h" |
18 #include "chrome/common/pepper_plugin_registry.h" | |
17 #include "grit/browser_resources.h" | 19 #include "grit/browser_resources.h" |
18 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
21 #include "webkit/plugins/npapi/plugin_group.h" | 23 #include "webkit/plugins/npapi/plugin_group.h" |
22 #include "webkit/plugins/npapi/plugin_list.h" | 24 #include "webkit/plugins/npapi/plugin_list.h" |
23 #include "webkit/plugins/npapi/webplugininfo.h" | 25 #include "webkit/plugins/npapi/webplugininfo.h" |
24 | 26 |
25 using webkit::npapi::PluginGroup; | 27 using webkit::npapi::PluginGroup; |
26 using webkit::npapi::PluginList; | 28 using webkit::npapi::PluginList; |
27 using webkit::npapi::WebPluginInfo; | 29 using webkit::npapi::WebPluginInfo; |
28 | 30 |
29 // Only launch Adobe Reader X or later. | 31 // Only launch Adobe Reader X or later. |
30 static const uint16 kMinReaderVersionToUse = 10; | 32 static const uint16 kMinReaderVersionToUse = 10; |
31 | 33 |
32 namespace { | 34 namespace { |
33 | 35 |
36 // The info bar delegate used to ask the user if they want to use Adobe Reader | |
37 // by default. | |
38 class PDFEnableAdobeReaderConfirmInfoBarDelegate | |
39 : public ConfirmInfoBarDelegate { | |
40 public: | |
41 PDFEnableAdobeReaderConfirmInfoBarDelegate( | |
42 TabContents* tab_contents) | |
43 : ConfirmInfoBarDelegate(tab_contents) { | |
44 UserMetrics::RecordAction(UserMetricsAction( | |
45 "PDF_EnableReaderInfoBarShown")); | |
Chris Evans
2011/01/26 23:31:30
Will this style of linebreak match the regex in ex
jam
2011/01/26 23:45:57
ah, good point. i forgot to run the script to ver
| |
46 } | |
47 | |
48 // ConfirmInfoBarDelegate | |
49 virtual void InfoBarClosed() { | |
Chris Evans
2011/01/26 23:31:30
Do you want to UMA the act of closing this bar?
jam
2011/01/26 23:45:57
that's done in virtual bool Cancel() {
| |
50 delete this; | |
51 } | |
Chris Evans
2011/01/26 23:31:30
Style: newline here?
jam
2011/01/26 23:45:57
Done.
| |
52 virtual Type GetInfoBarType() { | |
Chris Evans
2011/01/26 23:31:30
I think you're missing a const -- wrong overload?
jam
2011/01/26 23:45:57
good catch, done
| |
53 return PAGE_ACTION_TYPE; | |
54 } | |
55 virtual bool Accept() { | |
56 UserMetrics::RecordAction(UserMetricsAction( | |
57 "PDF_EnableReaderInfoBarOK")); | |
58 webkit::npapi::PluginList::Singleton()->EnableGroup( | |
59 false, ASCIIToUTF16(PepperPluginRegistry::kPDFPluginName)); | |
60 webkit::npapi::PluginList::Singleton()->EnableGroup( | |
61 true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); | |
62 return true; | |
63 } | |
64 virtual bool Cancel() { | |
65 UserMetrics::RecordAction(UserMetricsAction( | |
66 "PDF_EnableReaderInfoBarCancel")); | |
67 return true; | |
68 } | |
69 virtual int GetButtons() const { | |
70 return BUTTON_OK | BUTTON_CANCEL; | |
71 } | |
72 virtual string16 GetButtonLabel(InfoBarButton button) const { | |
73 switch (button) { | |
74 case BUTTON_OK: | |
75 return l10n_util::GetStringUTF16( | |
76 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); | |
77 case BUTTON_CANCEL: | |
78 return l10n_util::GetStringUTF16( | |
79 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); | |
80 default: | |
81 // All buttons are labeled above. | |
82 NOTREACHED() << "Bad button id " << button; | |
83 return string16(); | |
84 } | |
85 } | |
86 virtual string16 GetMessageText() const { | |
87 return l10n_util::GetStringUTF16( | |
88 IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER); | |
Chris Evans
2011/01/26 23:31:30
This does not seem be to be defined in this CL?
We
jam
2011/01/26 23:45:57
it was checked in earlier.
| |
89 } | |
90 | |
91 private: | |
92 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderConfirmInfoBarDelegate); | |
93 }; | |
94 | |
34 // Launch the url to get the latest Adbobe Reader installer. | 95 // Launch the url to get the latest Adbobe Reader installer. |
35 void OpenReaderUpdateURL(TabContents* tab) { | 96 void OpenReaderUpdateURL(TabContents* tab) { |
36 tab->OpenURL(GURL(PluginGroup::kAdobeReaderUpdateURL), GURL(), CURRENT_TAB, | 97 tab->OpenURL(GURL(PluginGroup::kAdobeReaderUpdateURL), GURL(), CURRENT_TAB, |
37 PageTransition::LINK); | 98 PageTransition::LINK); |
38 } | 99 } |
39 | 100 |
40 // Opens the PDF using Adobe Reader. | 101 // Opens the PDF using Adobe Reader. |
41 void OpenUsingReader(TabContents* tab, const WebPluginInfo& reader_plugin) { | 102 void OpenUsingReader(TabContents* tab, |
103 const WebPluginInfo& reader_plugin, | |
104 InfoBarDelegate* old_delegate) { | |
42 PluginService::OverriddenPlugin plugin; | 105 PluginService::OverriddenPlugin plugin; |
43 plugin.render_process_id = tab->GetRenderProcessHost()->id(); | 106 plugin.render_process_id = tab->GetRenderProcessHost()->id(); |
44 plugin.render_view_id = tab->render_view_host()->routing_id(); | 107 plugin.render_view_id = tab->render_view_host()->routing_id(); |
45 plugin.url = tab->GetURL(); | 108 plugin.url = tab->GetURL(); |
46 plugin.plugin = reader_plugin; | 109 plugin.plugin = reader_plugin; |
110 // The plugin is disabled, so enable it to get around the renderer check. | |
111 // Also give it a new version so that the renderer doesn't show the blocked | |
112 // plugin UI if it's vulnerable, since we already went through the | |
113 // interstitial. | |
114 plugin.plugin.enabled = WebPluginInfo::USER_ENABLED; | |
115 plugin.plugin.version = ASCIIToUTF16("11.0.0.0"); | |
47 | 116 |
48 PluginService::GetInstance()->OverridePluginForTab(plugin); | 117 PluginService::GetInstance()->OverridePluginForTab(plugin); |
49 tab->render_view_host()->ReloadFrame(); | 118 tab->render_view_host()->ReloadFrame(); |
119 | |
120 if (old_delegate) { | |
121 tab->ReplaceInfoBar( | |
122 old_delegate, new PDFEnableAdobeReaderConfirmInfoBarDelegate(tab)); | |
Chris Evans
2011/01/26 23:31:30
Do the common construction of that object once, ou
jam
2011/01/26 23:45:57
Done.
| |
123 } else { | |
124 tab->AddInfoBar(new PDFEnableAdobeReaderConfirmInfoBarDelegate(tab)); | |
125 } | |
50 } | 126 } |
51 | 127 |
52 // An interstitial to be used when the user chooses to open a PDF using Adobe | 128 // An interstitial to be used when the user chooses to open a PDF using Adobe |
53 // Reader, but it is out of date. | 129 // Reader, but it is out of date. |
54 class PDFUnsupportedFeatureInterstitial : public InterstitialPage { | 130 class PDFUnsupportedFeatureInterstitial : public InterstitialPage { |
55 public: | 131 public: |
56 PDFUnsupportedFeatureInterstitial( | 132 PDFUnsupportedFeatureInterstitial( |
57 TabContents* tab, | 133 TabContents* tab, |
58 const WebPluginInfo& reader_webplugininfo) | 134 const WebPluginInfo& reader_webplugininfo) |
59 : InterstitialPage(tab, false, tab->GetURL()), | 135 : InterstitialPage(tab, false, tab->GetURL()), |
60 reader_webplugininfo_(reader_webplugininfo) { | 136 reader_webplugininfo_(reader_webplugininfo) { |
137 UserMetrics::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); | |
61 } | 138 } |
62 | 139 |
63 protected: | 140 protected: |
64 // InterstitialPage implementation. | 141 // InterstitialPage implementation. |
65 virtual std::string GetHTMLContents() { | 142 virtual std::string GetHTMLContents() { |
66 DictionaryValue strings; | 143 DictionaryValue strings; |
67 strings.SetString( | 144 strings.SetString( |
68 "title", | 145 "title", |
69 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_TITLE)); | 146 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_TITLE)); |
70 strings.SetString( | 147 strings.SetString( |
(...skipping 14 matching lines...) Expand all Loading... | |
85 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_CANCEL)); | 162 l10n_util::GetStringUTF16(IDS_READER_OUT_OF_DATE_BLOCKING_PAGE_CANCEL)); |
86 | 163 |
87 base::StringPiece html(ResourceBundle::GetSharedInstance(). | 164 base::StringPiece html(ResourceBundle::GetSharedInstance(). |
88 GetRawDataResource(IDR_READER_OUT_OF_DATE_HTML)); | 165 GetRawDataResource(IDR_READER_OUT_OF_DATE_HTML)); |
89 | 166 |
90 return jstemplate_builder::GetI18nTemplateHtml(html, &strings); | 167 return jstemplate_builder::GetI18nTemplateHtml(html, &strings); |
91 } | 168 } |
92 | 169 |
93 virtual void CommandReceived(const std::string& command) { | 170 virtual void CommandReceived(const std::string& command) { |
94 if (command == "0") { | 171 if (command == "0") { |
172 UserMetrics::RecordAction(UserMetricsAction( | |
173 "PDF_ReaderInterstitialCancel")); | |
95 DontProceed(); | 174 DontProceed(); |
96 return; | 175 return; |
97 } | 176 } |
98 | 177 |
99 if (command == "1") { | 178 if (command == "1") { |
179 UserMetrics::RecordAction(UserMetricsAction( | |
180 "PDF_ReaderInterstitialUpdate")); | |
100 OpenReaderUpdateURL(tab()); | 181 OpenReaderUpdateURL(tab()); |
101 } else if (command == "2") { | 182 } else if (command == "2") { |
102 OpenUsingReader(tab(), reader_webplugininfo_); | 183 UserMetrics::RecordAction(UserMetricsAction( |
184 "PDF_ReaderInterstitialIgnore")); | |
185 OpenUsingReader(tab(), reader_webplugininfo_, NULL); | |
103 } else { | 186 } else { |
104 NOTREACHED(); | 187 NOTREACHED(); |
105 } | 188 } |
106 Proceed(); | 189 Proceed(); |
107 } | 190 } |
108 | 191 |
109 private: | 192 private: |
110 WebPluginInfo reader_webplugininfo_; | 193 WebPluginInfo reader_webplugininfo_; |
111 | 194 |
112 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); | 195 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); |
113 }; | 196 }; |
114 | 197 |
115 // The info bar delegate used to inform the user that we don't support a feature | 198 // The info bar delegate used to inform the user that we don't support a feature |
116 // in the PDF. | 199 // in the PDF. |
117 class PDFUnsupportedFeatureConfirmInfoBarDelegate | 200 class PDFUnsupportedFeatureConfirmInfoBarDelegate |
118 : public ConfirmInfoBarDelegate { | 201 : public ConfirmInfoBarDelegate { |
119 public: | 202 public: |
120 PDFUnsupportedFeatureConfirmInfoBarDelegate( | 203 PDFUnsupportedFeatureConfirmInfoBarDelegate( |
121 TabContents* tab_contents, | 204 TabContents* tab_contents, |
122 PluginGroup* reader_group) // NULL if Adobe Reader isn't installed. | 205 PluginGroup* reader_group) // NULL if Adobe Reader isn't installed. |
123 : ConfirmInfoBarDelegate(tab_contents), | 206 : ConfirmInfoBarDelegate(tab_contents), |
124 tab_contents_(tab_contents), | 207 tab_contents_(tab_contents), |
125 reader_installed_(!!reader_group), | 208 reader_installed_(!!reader_group), |
126 reader_vulnerable_(false) { | 209 reader_vulnerable_(false) { |
127 if (reader_installed_) { | 210 if (reader_installed_) { |
211 UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); | |
128 std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos(); | 212 std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos(); |
129 DCHECK_EQ(plugins.size(), 1u); | 213 DCHECK_EQ(plugins.size(), 1u); |
130 reader_webplugininfo_ = plugins[0]; | 214 reader_webplugininfo_ = plugins[0]; |
131 | 215 |
132 reader_vulnerable_ = reader_group->IsVulnerable(); | 216 reader_vulnerable_ = reader_group->IsVulnerable(); |
133 if (!reader_vulnerable_) { | 217 if (!reader_vulnerable_) { |
134 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString( | 218 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString( |
135 reader_webplugininfo_.version)); | 219 reader_webplugininfo_.version)); |
136 if (version.get()) { | 220 if (version.get()) { |
137 if (version->components()[0] < kMinReaderVersionToUse) | 221 if (version->components()[0] < kMinReaderVersionToUse) |
138 reader_vulnerable_ = true; | 222 reader_vulnerable_ = true; |
139 } | 223 } |
140 } | 224 } |
225 } else { | |
226 UserMetrics::RecordAction(UserMetricsAction( | |
227 "PDF_InstallReaderInfoBarShown")); | |
141 } | 228 } |
142 } | 229 } |
143 | 230 |
144 // ConfirmInfoBarDelegate | 231 // ConfirmInfoBarDelegate |
145 virtual void InfoBarClosed() { | 232 virtual void InfoBarClosed() { |
146 delete this; | 233 delete this; |
147 } | 234 } |
148 virtual Type GetInfoBarType() { | 235 virtual Type GetInfoBarType() { |
149 return PAGE_ACTION_TYPE; | 236 return PAGE_ACTION_TYPE; |
150 } | 237 } |
151 virtual bool Accept() { | 238 virtual bool Accept() { |
152 LaunchReader(); | 239 if (!reader_installed_) { |
240 UserMetrics::RecordAction(UserMetricsAction( | |
241 "PDF_InstallReaderInfoBarOK")); | |
242 OpenReaderUpdateURL(tab_contents_); | |
243 return true; | |
244 } | |
245 | |
246 UserMetrics::RecordAction(UserMetricsAction( | |
247 "PDF_UseReaderInfoBarOK")); | |
248 | |
249 if (reader_vulnerable_) { | |
250 PDFUnsupportedFeatureInterstitial* interstitial = new | |
251 PDFUnsupportedFeatureInterstitial( | |
252 tab_contents_, reader_webplugininfo_); | |
253 interstitial->Show(); | |
254 return true; | |
255 } | |
256 | |
257 OpenUsingReader(tab_contents_, reader_webplugininfo_, this); | |
258 return false; | |
259 } | |
260 virtual bool Cancel() { | |
261 if (reader_installed_) { | |
262 UserMetrics::RecordAction(UserMetricsAction( | |
263 "PDF_UseReaderInfoBarCancel")); | |
264 } else { | |
265 UserMetrics::RecordAction(UserMetricsAction( | |
266 "PDF_InstallReaderInfoBarCancel")); | |
267 } | |
153 return true; | 268 return true; |
154 } | 269 } |
155 virtual int GetButtons() const { | 270 virtual int GetButtons() const { |
156 return BUTTON_OK | BUTTON_CANCEL; | 271 return BUTTON_OK | BUTTON_CANCEL; |
157 } | 272 } |
158 virtual string16 GetButtonLabel(InfoBarButton button) const { | 273 virtual string16 GetButtonLabel(InfoBarButton button) const { |
159 switch (button) { | 274 switch (button) { |
160 case BUTTON_OK: | 275 case BUTTON_OK: |
161 return l10n_util::GetStringUTF16( | 276 return l10n_util::GetStringUTF16( |
162 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); | 277 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); |
163 case BUTTON_CANCEL: | 278 case BUTTON_CANCEL: |
164 return l10n_util::GetStringUTF16( | 279 return l10n_util::GetStringUTF16( |
165 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); | 280 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); |
166 default: | 281 default: |
167 // All buttons are labeled above. | 282 // All buttons are labeled above. |
168 NOTREACHED() << "Bad button id " << button; | 283 NOTREACHED() << "Bad button id " << button; |
169 return string16(); | 284 return string16(); |
170 } | 285 } |
171 } | 286 } |
172 virtual string16 GetMessageText() const { | 287 virtual string16 GetMessageText() const { |
173 return l10n_util::GetStringUTF16(reader_installed_ ? | 288 return l10n_util::GetStringUTF16(reader_installed_ ? |
174 IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED : | 289 IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED : |
175 IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED); | 290 IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED); |
176 } | 291 } |
177 | 292 |
178 private: | 293 private: |
179 void LaunchReader() { | |
180 if (!reader_installed_) { | |
181 OpenReaderUpdateURL(tab_contents_); | |
182 return; | |
183 } | |
184 | |
185 if (reader_vulnerable_) { | |
186 PDFUnsupportedFeatureInterstitial* interstitial = new | |
187 PDFUnsupportedFeatureInterstitial( | |
188 tab_contents_, reader_webplugininfo_); | |
189 interstitial->Show(); | |
190 return; | |
191 } | |
192 | |
193 OpenUsingReader(tab_contents_, reader_webplugininfo_); | |
194 } | |
195 | |
196 TabContents* tab_contents_; | 294 TabContents* tab_contents_; |
197 bool reader_installed_; | 295 bool reader_installed_; |
198 bool reader_vulnerable_; | 296 bool reader_vulnerable_; |
199 WebPluginInfo reader_webplugininfo_; | 297 WebPluginInfo reader_webplugininfo_; |
200 | 298 |
201 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureConfirmInfoBarDelegate); | 299 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureConfirmInfoBarDelegate); |
202 }; | 300 }; |
203 | 301 |
204 } // namespace | 302 } // namespace |
205 | 303 |
206 void PDFHasUnsupportedFeature(TabContents* tab) { | 304 void PDFHasUnsupportedFeature(TabContents* tab) { |
207 #if !defined(OS_WIN) | 305 #if !defined(OS_WIN) |
208 // Only works for Windows for now. For Mac, we'll have to launch the file | 306 // Only works for Windows for now. For Mac, we'll have to launch the file |
209 // externally since Adobe Reader doesn't work inside Chrome. | 307 // externally since Adobe Reader doesn't work inside Chrome. |
210 return; | 308 return; |
211 #endif | 309 #endif |
310 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | |
311 | |
312 // If the Reader plugin is disabled by policy, don't prompt them. | |
313 if (PluginGroup::IsPluginNameDisabledByPolicy(reader_group_name)) | |
314 return; | |
Chris Evans
2011/01/26 23:31:30
Is there a command line flag for disabling this? I
jam
2011/01/26 23:45:57
this code is doing exactly what you're asking for
| |
212 | 315 |
213 PluginGroup* reader_group = NULL; | 316 PluginGroup* reader_group = NULL; |
214 std::vector<PluginGroup> plugin_groups; | 317 std::vector<PluginGroup> plugin_groups; |
215 PluginList::Singleton()->GetPluginGroups( | 318 PluginList::Singleton()->GetPluginGroups( |
216 false, &plugin_groups); | 319 false, &plugin_groups); |
217 string16 reader_group_name(UTF8ToUTF16(PluginGroup::kAdobeReaderGroupName)); | |
218 for (size_t i = 0; i < plugin_groups.size(); ++i) { | 320 for (size_t i = 0; i < plugin_groups.size(); ++i) { |
219 if (plugin_groups[i].GetGroupName() == reader_group_name) { | 321 if (plugin_groups[i].GetGroupName() == reader_group_name) { |
220 reader_group = &plugin_groups[i]; | 322 reader_group = &plugin_groups[i]; |
221 break; | 323 break; |
222 } | 324 } |
223 } | 325 } |
224 | 326 |
225 // If the plugin is disabled by policy or by the user, don't prompt them. | |
226 if (reader_group && !reader_group->Enabled()) | |
227 return; | |
228 | |
229 tab->AddInfoBar(new PDFUnsupportedFeatureConfirmInfoBarDelegate( | 327 tab->AddInfoBar(new PDFUnsupportedFeatureConfirmInfoBarDelegate( |
230 tab, reader_group)); | 328 tab, reader_group)); |
231 } | 329 } |
OLD | NEW |