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

Side by Side Diff: chrome/browser/ui/pdf/adobe_reader_info_win.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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
6
7 #include <algorithm>
8 #include <vector>
9
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/win/registry.h"
13 #include "chrome/browser/plugins/plugin_finder.h"
14 #include "chrome/browser/plugins/plugin_metadata.h"
15 #include "chrome/browser/plugins/plugin_prefs.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/tab_contents/tab_util.h"
18 #include "chrome/installer/util/shell_util.h"
19 #include "content/public/browser/plugin_service.h"
20 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/web_contents.h"
23
24 namespace {
25
26 #if defined(ENABLE_PLUGIN_INSTALLATION)
27 const char kAdobeReaderIdentifier[] = "adobe-reader";
28 const char kPdfMimeType[] = "application/pdf";
29
30 bool IsPdfMimeType(const content::WebPluginMimeType& plugin_mime_type) {
31 return plugin_mime_type.mime_type == kPdfMimeType;
32 }
33
34 AdobeReaderPluginInfo GetReaderPlugin(
35 content::WebContents* web_contents,
36 const std::vector<content::WebPluginInfo>& plugins) {
37 AdobeReaderPluginInfo reader_info;
38 reader_info.is_installed = false;
39 reader_info.is_enabled = false;
40 reader_info.is_secure = false;
41
42 PluginFinder* plugin_finder = PluginFinder::GetInstance();
43 for (size_t i = 0; i < plugins.size(); ++i) {
44 const content::WebPluginInfo& plugin = plugins[i];
45 if (plugin.is_pepper_plugin())
46 continue;
47 if (std::find_if(plugin.mime_types.begin(), plugin.mime_types.end(),
48 IsPdfMimeType) == plugin.mime_types.end())
49 continue;
50 scoped_ptr<PluginMetadata> plugin_metadata(
51 plugin_finder->GetPluginMetadata(plugins[i]));
52 if (plugin_metadata->identifier() != kAdobeReaderIdentifier)
53 continue;
54
55 reader_info.is_installed = true;
56
57 if (web_contents) {
58 Profile* profile =
59 Profile::FromBrowserContext(web_contents->GetBrowserContext());
60 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile);
61 PluginPrefs::PolicyStatus plugin_status =
62 plugin_prefs->PolicyStatusForPlugin(plugin_metadata->name());
63 reader_info.is_enabled = plugin_status != PluginPrefs::POLICY_DISABLED;
64 }
65
66 PluginMetadata::SecurityStatus security_status =
67 plugin_metadata->GetSecurityStatus(plugins[i]);
68 reader_info.is_secure =
69 security_status == PluginMetadata::SECURITY_STATUS_UP_TO_DATE;
70
71 reader_info.plugin_info = plugins[i];
72 break;
73 }
asanka 2014/06/09 21:22:22 What about is_default_plugin_for_pdf ? My cursory
Lei Zhang 2014/06/12 05:04:26 We check |kAdobeReaderIdentifier| above. If it nev
jam 2014/06/12 18:19:01 It should only affect downloads.
74 return reader_info;
75 }
76
77 void OnGotPluginInfo(int process_id,
78 int routing_id,
79 const GetAdobeReaderPluginInfoCallback& callback,
80 const std::vector<content::WebPluginInfo>& plugins) {
81 content::WebContents* web_contents =
82 tab_util::GetWebContentsByID(process_id, routing_id);
83 callback.Run(GetReaderPlugin(web_contents, plugins));
84 }
85 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
jam 2014/06/09 19:49:09 nit: move the anonymous namespace inside the ifdef
Lei Zhang 2014/06/12 05:04:26 I removed the ENABLE_PLUGIN_INSTALLATION) #ifdefs
86
87 } // namespace
88
89 #if defined(ENABLE_PLUGIN_INSTALLATION)
90 void GetAdobeReaderPluginInfoAsync(
91 content::WebContents* web_contents,
92 const GetAdobeReaderPluginInfoCallback& callback) {
93 DCHECK(!callback.is_null());
94 content::PluginService::GetInstance()->GetPlugins(
95 base::Bind(&OnGotPluginInfo,
96 web_contents->GetRenderProcessHost()->GetID(),
97 web_contents->GetRenderViewHost()->GetRoutingID(),
98 callback));
99 }
100
101 bool GetAdobeReaderPluginInfo(content::WebContents* web_contents,
102 AdobeReaderPluginInfo* reader_info) {
103 DCHECK(reader_info);
104 std::vector<content::WebPluginInfo> plugins;
105 bool up_to_date = content::PluginService::GetInstance()->GetPluginInfoArray(
106 GURL(), kPdfMimeType, false, &plugins, NULL);
107 *reader_info = GetReaderPlugin(web_contents, plugins);
108 return up_to_date;
109 }
110 #endif
111
112 bool IsAdobeReaderDefaultPDFViewer() {
113 base::string16 key_path(L"AcroExch.Document");
114 key_path.append(ShellUtil::kRegShellOpen);
115 base::win::RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ);
116 base::string16 app_cmd;
117 static base::char16 kReaderKey[] = L"Reader\\AcroRd32.exe";
118 return (key.Valid() && (key.ReadValue(L"", &app_cmd) == ERROR_SUCCESS) &&
119 app_cmd.find(kReaderKey) != base::string16::npos);
asanka 2014/06/09 21:22:22 Shouldn't this also check HKCR\.pdf ? .pdf might b
Lei Zhang 2014/06/12 05:04:26 Sure. I improved the detection here.
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698