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

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

Issue 10411098: Reland 138502 - Move version metadata from PluginGroup into PluginInstaller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 8 years, 7 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/resources/plugins_win.json ('k') | chrome/browser/ui/webui/plugins_ui.cc » ('j') | 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"
(...skipping 17 matching lines...) Expand all
28 #include "content/public/browser/user_metrics.h" 28 #include "content/public/browser/user_metrics.h"
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 #include "grit/browser_resources.h" 30 #include "grit/browser_resources.h"
31 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
32 #include "grit/theme_resources_standard.h" 32 #include "grit/theme_resources_standard.h"
33 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/base/resource/resource_bundle.h" 34 #include "ui/base/resource/resource_bundle.h"
35 #include "ui/gfx/image/image.h" 35 #include "ui/gfx/image/image.h"
36 #include "webkit/plugins/npapi/plugin_group.h" 36 #include "webkit/plugins/npapi/plugin_group.h"
37 37
38 #if defined(ENABLE_PLUGIN_INSTALLATION)
39 #include "chrome/browser/plugin_finder.h"
40 #include "chrome/browser/plugin_installer.h"
41 #else
42 // Forward-declare PluginFinder. It's never actually used, but we pass a NULL
43 // pointer instead.
44 class PluginFinder;
45 #endif
46
38 using content::InterstitialPage; 47 using content::InterstitialPage;
39 using content::OpenURLParams; 48 using content::OpenURLParams;
40 using content::PluginService; 49 using content::PluginService;
41 using content::Referrer; 50 using content::Referrer;
42 using content::UserMetricsAction; 51 using content::UserMetricsAction;
43 using content::WebContents; 52 using content::WebContents;
44 using webkit::npapi::PluginGroup; 53 using webkit::npapi::PluginGroup;
45 using webkit::WebPluginInfo; 54 using webkit::WebPluginInfo;
46 55
47 namespace { 56 namespace {
48 57
49 // Only launch Adobe Reader X or later.
50 static const uint16 kMinReaderVersionToUse = 10;
51
52 static const char kReaderUpdateUrl[] = 58 static const char kReaderUpdateUrl[] =
53 "http://www.adobe.com/go/getreader_chrome"; 59 "http://www.adobe.com/go/getreader_chrome";
54 60
55 // The info bar delegate used to ask the user if they want to use Adobe Reader 61 // The info bar delegate used to ask the user if they want to use Adobe Reader
56 // by default. We want the infobar to have [No][Yes], so we swap the text on 62 // by default. We want the infobar to have [No][Yes], so we swap the text on
57 // the buttons, and the meaning of the delegate callbacks. 63 // the buttons, and the meaning of the delegate callbacks.
58 class PDFEnableAdobeReaderInfoBarDelegate : public ConfirmInfoBarDelegate { 64 class PDFEnableAdobeReaderInfoBarDelegate : public ConfirmInfoBarDelegate {
59 public: 65 public:
60 explicit PDFEnableAdobeReaderInfoBarDelegate( 66 explicit PDFEnableAdobeReaderInfoBarDelegate(
61 InfoBarTabHelper* infobar_helper, 67 InfoBarTabHelper* infobar_helper,
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 InterstitialPage* interstitial_page_; // Owns us. 249 InterstitialPage* interstitial_page_; // Owns us.
244 250
245 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); 251 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial);
246 }; 252 };
247 253
248 // The info bar delegate used to inform the user that we don't support a feature 254 // The info bar delegate used to inform the user that we don't support a feature
249 // in the PDF. See the comment about how we swap buttons for 255 // in the PDF. See the comment about how we swap buttons for
250 // PDFEnableAdobeReaderInfoBarDelegate. 256 // PDFEnableAdobeReaderInfoBarDelegate.
251 class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate { 257 class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate {
252 public: 258 public:
253 // |reader_group| is NULL if Adobe Reader isn't installed. 259 // |reader| is NULL if Adobe Reader isn't installed.
254 PDFUnsupportedFeatureInfoBarDelegate(TabContentsWrapper* tab_contents, 260 PDFUnsupportedFeatureInfoBarDelegate(TabContentsWrapper* tab_contents,
255 const PluginGroup* reader_group); 261 const webkit::WebPluginInfo* reader,
262 PluginFinder* plugin_finder);
256 virtual ~PDFUnsupportedFeatureInfoBarDelegate(); 263 virtual ~PDFUnsupportedFeatureInfoBarDelegate();
257 264
258 // ConfirmInfoBarDelegate 265 // ConfirmInfoBarDelegate
259 virtual void InfoBarDismissed() OVERRIDE; 266 virtual void InfoBarDismissed() OVERRIDE;
260 virtual gfx::Image* GetIcon() const OVERRIDE; 267 virtual gfx::Image* GetIcon() const OVERRIDE;
261 virtual Type GetInfoBarType() const OVERRIDE; 268 virtual Type GetInfoBarType() const OVERRIDE;
262 virtual bool Accept() OVERRIDE; 269 virtual bool Accept() OVERRIDE;
263 virtual bool Cancel() OVERRIDE; 270 virtual bool Cancel() OVERRIDE;
264 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 271 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
265 virtual string16 GetMessageText() const OVERRIDE; 272 virtual string16 GetMessageText() const OVERRIDE;
266 273
267 private: 274 private:
268 bool OnYes(); 275 bool OnYes();
269 void OnNo(); 276 void OnNo();
270 277
271 TabContentsWrapper* tab_contents_; 278 TabContentsWrapper* tab_contents_;
272 bool reader_installed_; 279 bool reader_installed_;
273 bool reader_vulnerable_; 280 bool reader_vulnerable_;
274 WebPluginInfo reader_webplugininfo_; 281 WebPluginInfo reader_webplugininfo_;
275 282
276 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureInfoBarDelegate); 283 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureInfoBarDelegate);
277 }; 284 };
278 285
279 PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate( 286 PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate(
280 TabContentsWrapper* tab_contents, 287 TabContentsWrapper* tab_contents,
281 const PluginGroup* reader_group) 288 const webkit::WebPluginInfo* reader,
289 PluginFinder* plugin_finder)
282 : ConfirmInfoBarDelegate(tab_contents->infobar_tab_helper()), 290 : ConfirmInfoBarDelegate(tab_contents->infobar_tab_helper()),
283 tab_contents_(tab_contents), 291 tab_contents_(tab_contents),
284 reader_installed_(!!reader_group), 292 reader_installed_(!!reader),
285 reader_vulnerable_(false) { 293 reader_vulnerable_(false) {
286 if (!reader_installed_) { 294 if (!reader_installed_) {
287 content::RecordAction( 295 content::RecordAction(
288 UserMetricsAction("PDF_InstallReaderInfoBarShown")); 296 UserMetricsAction("PDF_InstallReaderInfoBarShown"));
289 return; 297 return;
290 } 298 }
291 299
292 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); 300 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown"));
293 const std::vector<WebPluginInfo>& plugins = 301 reader_webplugininfo_ = *reader;
294 reader_group->web_plugin_infos();
295 DCHECK_EQ(plugins.size(), 1u);
296 reader_webplugininfo_ = plugins[0];
297 302
298 reader_vulnerable_ = reader_group->IsVulnerable(reader_webplugininfo_); 303 #if defined(ENABLE_PLUGIN_INSTALLATION)
299 if (!reader_vulnerable_) { 304 PluginInstaller* installer =
300 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString( 305 plugin_finder->FindPluginWithIdentifier("adobe-reader");
301 reader_webplugininfo_.version)); 306
302 reader_vulnerable_ = 307 reader_vulnerable_ =
303 version.get() && (version->components()[0] < kMinReaderVersionToUse); 308 installer->GetSecurityStatus(*reader) !=
304 } 309 PluginInstaller::SECURITY_STATUS_UP_TO_DATE;
310 #else
311 NOTREACHED();
312 #endif
305 } 313 }
306 314
307 PDFUnsupportedFeatureInfoBarDelegate::~PDFUnsupportedFeatureInfoBarDelegate() { 315 PDFUnsupportedFeatureInfoBarDelegate::~PDFUnsupportedFeatureInfoBarDelegate() {
308 } 316 }
309 317
310 void PDFUnsupportedFeatureInfoBarDelegate::InfoBarDismissed() { 318 void PDFUnsupportedFeatureInfoBarDelegate::InfoBarDismissed() {
311 OnNo(); 319 OnNo();
312 } 320 }
313 321
314 gfx::Image* PDFUnsupportedFeatureInfoBarDelegate::GetIcon() const { 322 gfx::Image* PDFUnsupportedFeatureInfoBarDelegate::GetIcon() const {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 378 }
371 379
372 void PDFUnsupportedFeatureInfoBarDelegate::OnNo() { 380 void PDFUnsupportedFeatureInfoBarDelegate::OnNo() {
373 content::RecordAction(reader_installed_ ? 381 content::RecordAction(reader_installed_ ?
374 UserMetricsAction("PDF_UseReaderInfoBarCancel") : 382 UserMetricsAction("PDF_UseReaderInfoBarCancel") :
375 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); 383 UserMetricsAction("PDF_InstallReaderInfoBarCancel"));
376 } 384 }
377 385
378 void GotPluginGroupsCallback(int process_id, 386 void GotPluginGroupsCallback(int process_id,
379 int routing_id, 387 int routing_id,
388 PluginFinder* plugin_finder,
380 const std::vector<PluginGroup>& groups) { 389 const std::vector<PluginGroup>& groups) {
381 WebContents* web_contents = 390 WebContents* web_contents =
382 tab_util::GetWebContentsByID(process_id, routing_id); 391 tab_util::GetWebContentsByID(process_id, routing_id);
383 if (!web_contents) 392 if (!web_contents)
384 return; 393 return;
385 394
386 TabContentsWrapper* tab = 395 TabContentsWrapper* tab =
387 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); 396 TabContentsWrapper::GetCurrentWrapperForContents(web_contents);
388 if (!tab) 397 if (!tab)
389 return; 398 return;
390 399
391 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); 400 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName));
392
393 // If the Reader plugin is disabled by policy, don't prompt them. 401 // If the Reader plugin is disabled by policy, don't prompt them.
394 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); 402 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile());
395 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == 403 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) ==
396 PluginPrefs::POLICY_DISABLED) { 404 PluginPrefs::POLICY_DISABLED) {
397 return; 405 return;
398 } 406 }
399 407
400 const PluginGroup* reader_group = NULL; 408 const webkit::WebPluginInfo* reader = NULL;
401 for (size_t i = 0; i < groups.size(); ++i) { 409 for (size_t i = 0; i < groups.size(); ++i) {
402 if (groups[i].GetGroupName() == reader_group_name) { 410 if (groups[i].GetGroupName() == reader_group_name) {
403 reader_group = &groups[i]; 411 const std::vector<WebPluginInfo>& plugins =
412 groups[i].web_plugin_infos();
413 DCHECK_EQ(plugins.size(), 1u);
414 reader = &plugins[0];
404 break; 415 break;
405 } 416 }
406 } 417 }
407 418
408 tab->infobar_tab_helper()->AddInfoBar( 419 tab->infobar_tab_helper()->AddInfoBar(
409 new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group)); 420 new PDFUnsupportedFeatureInfoBarDelegate(tab, reader, plugin_finder));
421 }
422
423 void GotPluginFinderCallback(int process_id,
424 int routing_id,
425 PluginFinder* plugin_finder) {
426 PluginService::GetInstance()->GetPluginGroups(
427 base::Bind(&GotPluginGroupsCallback, process_id, routing_id,
428 base::Unretained(plugin_finder)));
410 } 429 }
411 430
412 } // namespace 431 } // namespace
413 432
414 void PDFHasUnsupportedFeature(TabContentsWrapper* tab) { 433 void PDFHasUnsupportedFeature(TabContentsWrapper* tab) {
415 #if !defined(OS_WIN) 434 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION)
416 // Only works for Windows for now. For Mac, we'll have to launch the file 435 // Only works for Windows for now. For Mac, we'll have to launch the file
417 // externally since Adobe Reader doesn't work inside Chrome. 436 // externally since Adobe Reader doesn't work inside Chrome.
418 return; 437 PluginFinder::Get(base::Bind(&GotPluginFinderCallback,
438 tab->web_contents()->GetRenderProcessHost()->GetID(),
439 tab->web_contents()->GetRenderViewHost()->GetRoutingID()));
419 #endif 440 #endif
420
421 PluginService::GetInstance()->GetPluginGroups(
422 base::Bind(&GotPluginGroupsCallback,
423 tab->web_contents()->GetRenderProcessHost()->GetID(),
424 tab->web_contents()->GetRenderViewHost()->GetRoutingID()));
425 } 441 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/plugins_win.json ('k') | chrome/browser/ui/webui/plugins_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698