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 10388253: Revert 138502 - Move version metadata from PluginGroup into PluginInstaller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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"
11 #include "chrome/browser/chrome_plugin_service_filter.h" 11 #include "chrome/browser/chrome_plugin_service_filter.h"
12 #include "chrome/browser/infobars/infobar_tab_helper.h" 12 #include "chrome/browser/infobars/infobar_tab_helper.h"
13 #include "chrome/browser/plugin_finder.h"
14 #include "chrome/browser/plugin_installer.h"
15 #include "chrome/browser/plugin_prefs.h" 13 #include "chrome/browser/plugin_prefs.h"
16 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/renderer_preferences_util.h" 16 #include "chrome/browser/renderer_preferences_util.h"
19 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
20 #include "chrome/browser/tab_contents/tab_util.h" 18 #include "chrome/browser/tab_contents/tab_util.h"
21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
22 #include "chrome/common/chrome_content_client.h" 20 #include "chrome/common/chrome_content_client.h"
23 #include "chrome/common/jstemplate_builder.h" 21 #include "chrome/common/jstemplate_builder.h"
24 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
(...skipping 16 matching lines...) Expand all
41 using content::OpenURLParams; 39 using content::OpenURLParams;
42 using content::PluginService; 40 using content::PluginService;
43 using content::Referrer; 41 using content::Referrer;
44 using content::UserMetricsAction; 42 using content::UserMetricsAction;
45 using content::WebContents; 43 using content::WebContents;
46 using webkit::npapi::PluginGroup; 44 using webkit::npapi::PluginGroup;
47 using webkit::WebPluginInfo; 45 using webkit::WebPluginInfo;
48 46
49 namespace { 47 namespace {
50 48
49 // Only launch Adobe Reader X or later.
50 static const uint16 kMinReaderVersionToUse = 10;
51
51 static const char kReaderUpdateUrl[] = 52 static const char kReaderUpdateUrl[] =
52 "http://www.adobe.com/go/getreader_chrome"; 53 "http://www.adobe.com/go/getreader_chrome";
53 54
54 // The info bar delegate used to ask the user if they want to use Adobe Reader 55 // The info bar delegate used to ask the user if they want to use Adobe Reader
55 // by default. We want the infobar to have [No][Yes], so we swap the text on 56 // by default. We want the infobar to have [No][Yes], so we swap the text on
56 // the buttons, and the meaning of the delegate callbacks. 57 // the buttons, and the meaning of the delegate callbacks.
57 class PDFEnableAdobeReaderInfoBarDelegate : public ConfirmInfoBarDelegate { 58 class PDFEnableAdobeReaderInfoBarDelegate : public ConfirmInfoBarDelegate {
58 public: 59 public:
59 explicit PDFEnableAdobeReaderInfoBarDelegate( 60 explicit PDFEnableAdobeReaderInfoBarDelegate(
60 InfoBarTabHelper* infobar_helper, 61 InfoBarTabHelper* infobar_helper,
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 InterstitialPage* interstitial_page_; // Owns us. 243 InterstitialPage* interstitial_page_; // Owns us.
243 244
244 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); 245 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial);
245 }; 246 };
246 247
247 // The info bar delegate used to inform the user that we don't support a feature 248 // The info bar delegate used to inform the user that we don't support a feature
248 // in the PDF. See the comment about how we swap buttons for 249 // in the PDF. See the comment about how we swap buttons for
249 // PDFEnableAdobeReaderInfoBarDelegate. 250 // PDFEnableAdobeReaderInfoBarDelegate.
250 class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate { 251 class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate {
251 public: 252 public:
252 // |reader| is NULL if Adobe Reader isn't installed. 253 // |reader_group| is NULL if Adobe Reader isn't installed.
253 PDFUnsupportedFeatureInfoBarDelegate(TabContentsWrapper* tab_contents, 254 PDFUnsupportedFeatureInfoBarDelegate(TabContentsWrapper* tab_contents,
254 const webkit::WebPluginInfo* reader, 255 const PluginGroup* reader_group);
255 PluginFinder* plugin_finder);
256 virtual ~PDFUnsupportedFeatureInfoBarDelegate(); 256 virtual ~PDFUnsupportedFeatureInfoBarDelegate();
257 257
258 // ConfirmInfoBarDelegate 258 // ConfirmInfoBarDelegate
259 virtual void InfoBarDismissed() OVERRIDE; 259 virtual void InfoBarDismissed() OVERRIDE;
260 virtual gfx::Image* GetIcon() const OVERRIDE; 260 virtual gfx::Image* GetIcon() const OVERRIDE;
261 virtual Type GetInfoBarType() const OVERRIDE; 261 virtual Type GetInfoBarType() const OVERRIDE;
262 virtual bool Accept() OVERRIDE; 262 virtual bool Accept() OVERRIDE;
263 virtual bool Cancel() OVERRIDE; 263 virtual bool Cancel() OVERRIDE;
264 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 264 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
265 virtual string16 GetMessageText() const OVERRIDE; 265 virtual string16 GetMessageText() const OVERRIDE;
266 266
267 private: 267 private:
268 bool OnYes(); 268 bool OnYes();
269 void OnNo(); 269 void OnNo();
270 270
271 TabContentsWrapper* tab_contents_; 271 TabContentsWrapper* tab_contents_;
272 bool reader_installed_; 272 bool reader_installed_;
273 bool reader_vulnerable_; 273 bool reader_vulnerable_;
274 WebPluginInfo reader_webplugininfo_; 274 WebPluginInfo reader_webplugininfo_;
275 275
276 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureInfoBarDelegate); 276 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureInfoBarDelegate);
277 }; 277 };
278 278
279 PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate( 279 PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate(
280 TabContentsWrapper* tab_contents, 280 TabContentsWrapper* tab_contents,
281 const webkit::WebPluginInfo* reader, 281 const PluginGroup* reader_group)
282 PluginFinder* plugin_finder)
283 : ConfirmInfoBarDelegate(tab_contents->infobar_tab_helper()), 282 : ConfirmInfoBarDelegate(tab_contents->infobar_tab_helper()),
284 tab_contents_(tab_contents), 283 tab_contents_(tab_contents),
285 reader_installed_(!!reader), 284 reader_installed_(!!reader_group),
286 reader_vulnerable_(false) { 285 reader_vulnerable_(false) {
287 if (!reader_installed_) { 286 if (!reader_installed_) {
288 content::RecordAction( 287 content::RecordAction(
289 UserMetricsAction("PDF_InstallReaderInfoBarShown")); 288 UserMetricsAction("PDF_InstallReaderInfoBarShown"));
290 return; 289 return;
291 } 290 }
292 291
293 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown")); 292 content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown"));
294 reader_webplugininfo_ = *reader; 293 const std::vector<WebPluginInfo>& plugins =
294 reader_group->web_plugin_infos();
295 DCHECK_EQ(plugins.size(), 1u);
296 reader_webplugininfo_ = plugins[0];
295 297
296 PluginInstaller* installer = 298 reader_vulnerable_ = reader_group->IsVulnerable(reader_webplugininfo_);
297 plugin_finder->FindPluginWithIdentifier("adobe-reader"); 299 if (!reader_vulnerable_) {
298 300 scoped_ptr<Version> version(PluginGroup::CreateVersionFromString(
299 reader_vulnerable_ = 301 reader_webplugininfo_.version));
300 installer->GetSecurityStatus(*reader) != 302 reader_vulnerable_ =
301 PluginInstaller::SECURITY_STATUS_UP_TO_DATE; 303 version.get() && (version->components()[0] < kMinReaderVersionToUse);
304 }
302 } 305 }
303 306
304 PDFUnsupportedFeatureInfoBarDelegate::~PDFUnsupportedFeatureInfoBarDelegate() { 307 PDFUnsupportedFeatureInfoBarDelegate::~PDFUnsupportedFeatureInfoBarDelegate() {
305 } 308 }
306 309
307 void PDFUnsupportedFeatureInfoBarDelegate::InfoBarDismissed() { 310 void PDFUnsupportedFeatureInfoBarDelegate::InfoBarDismissed() {
308 OnNo(); 311 OnNo();
309 } 312 }
310 313
311 gfx::Image* PDFUnsupportedFeatureInfoBarDelegate::GetIcon() const { 314 gfx::Image* PDFUnsupportedFeatureInfoBarDelegate::GetIcon() const {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 370 }
368 371
369 void PDFUnsupportedFeatureInfoBarDelegate::OnNo() { 372 void PDFUnsupportedFeatureInfoBarDelegate::OnNo() {
370 content::RecordAction(reader_installed_ ? 373 content::RecordAction(reader_installed_ ?
371 UserMetricsAction("PDF_UseReaderInfoBarCancel") : 374 UserMetricsAction("PDF_UseReaderInfoBarCancel") :
372 UserMetricsAction("PDF_InstallReaderInfoBarCancel")); 375 UserMetricsAction("PDF_InstallReaderInfoBarCancel"));
373 } 376 }
374 377
375 void GotPluginGroupsCallback(int process_id, 378 void GotPluginGroupsCallback(int process_id,
376 int routing_id, 379 int routing_id,
377 PluginFinder* plugin_finder,
378 const std::vector<PluginGroup>& groups) { 380 const std::vector<PluginGroup>& groups) {
379 WebContents* web_contents = 381 WebContents* web_contents =
380 tab_util::GetWebContentsByID(process_id, routing_id); 382 tab_util::GetWebContentsByID(process_id, routing_id);
381 if (!web_contents) 383 if (!web_contents)
382 return; 384 return;
383 385
384 TabContentsWrapper* tab = 386 TabContentsWrapper* tab =
385 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); 387 TabContentsWrapper::GetCurrentWrapperForContents(web_contents);
386 if (!tab) 388 if (!tab)
387 return; 389 return;
388 390
389 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); 391 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName));
392
390 // If the Reader plugin is disabled by policy, don't prompt them. 393 // If the Reader plugin is disabled by policy, don't prompt them.
391 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); 394 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile());
392 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == 395 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) ==
393 PluginPrefs::POLICY_DISABLED) { 396 PluginPrefs::POLICY_DISABLED) {
394 return; 397 return;
395 } 398 }
396 399
397 const webkit::WebPluginInfo* reader = NULL; 400 const PluginGroup* reader_group = NULL;
398 for (size_t i = 0; i < groups.size(); ++i) { 401 for (size_t i = 0; i < groups.size(); ++i) {
399 if (groups[i].GetGroupName() == reader_group_name) { 402 if (groups[i].GetGroupName() == reader_group_name) {
400 const std::vector<WebPluginInfo>& plugins = 403 reader_group = &groups[i];
401 groups[i].web_plugin_infos();
402 DCHECK_EQ(plugins.size(), 1u);
403 reader = &plugins[0];
404 break; 404 break;
405 } 405 }
406 } 406 }
407 407
408 tab->infobar_tab_helper()->AddInfoBar( 408 tab->infobar_tab_helper()->AddInfoBar(
409 new PDFUnsupportedFeatureInfoBarDelegate(tab, reader, plugin_finder)); 409 new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group));
410 }
411
412 void GotPluginFinderCallback(int process_id,
413 int routing_id,
414 PluginFinder* plugin_finder) {
415 PluginService::GetInstance()->GetPluginGroups(
416 base::Bind(&GotPluginGroupsCallback, process_id, routing_id,
417 base::Unretained(plugin_finder)));
418 } 410 }
419 411
420 } // namespace 412 } // namespace
421 413
422 void PDFHasUnsupportedFeature(TabContentsWrapper* tab) { 414 void PDFHasUnsupportedFeature(TabContentsWrapper* tab) {
423 #if !defined(OS_WIN) 415 #if !defined(OS_WIN)
424 // 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
425 // externally since Adobe Reader doesn't work inside Chrome. 417 // externally since Adobe Reader doesn't work inside Chrome.
426 return; 418 return;
427 #endif 419 #endif
428 420
429 PluginFinder::Get(base::Bind(&GotPluginFinderCallback, 421 PluginService::GetInstance()->GetPluginGroups(
430 tab->web_contents()->GetRenderProcessHost()->GetID(), 422 base::Bind(&GotPluginGroupsCallback,
431 tab->web_contents()->GetRenderViewHost()->GetRoutingID())); 423 tab->web_contents()->GetRenderProcessHost()->GetID(),
424 tab->web_contents()->GetRenderViewHost()->GetRoutingID()));
432 } 425 }
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