Chromium Code Reviews| Index: chrome/browser/ui/pdf/adobe_reader_info_win.cc |
| diff --git a/chrome/browser/ui/pdf/adobe_reader_info_win.cc b/chrome/browser/ui/pdf/adobe_reader_info_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bc495063154e286cc363b455db47fc4d01a6b714 |
| --- /dev/null |
| +++ b/chrome/browser/ui/pdf/adobe_reader_info_win.cc |
| @@ -0,0 +1,120 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/pdf/adobe_reader_info_win.h" |
| + |
| +#include <algorithm> |
| +#include <vector> |
| + |
| +#include "base/bind.h" |
| +#include "base/callback.h" |
| +#include "base/win/registry.h" |
| +#include "chrome/browser/plugins/plugin_finder.h" |
| +#include "chrome/browser/plugins/plugin_metadata.h" |
| +#include "chrome/browser/plugins/plugin_prefs.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/tab_contents/tab_util.h" |
| +#include "chrome/installer/util/shell_util.h" |
| +#include "content/public/browser/plugin_service.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/web_contents.h" |
| + |
| +namespace { |
| + |
| +#if defined(ENABLE_PLUGIN_INSTALLATION) |
| +const char kAdobeReaderIdentifier[] = "adobe-reader"; |
| +const char kPdfMimeType[] = "application/pdf"; |
| + |
| +bool IsPdfMimeType(const content::WebPluginMimeType& plugin_mime_type) { |
| + return plugin_mime_type.mime_type == kPdfMimeType; |
| +} |
| + |
| +AdobeReaderPluginInfo GetReaderPlugin( |
| + content::WebContents* web_contents, |
| + const std::vector<content::WebPluginInfo>& plugins) { |
| + AdobeReaderPluginInfo reader_info; |
| + reader_info.is_installed = false; |
| + reader_info.is_enabled = false; |
| + reader_info.is_secure = false; |
| + |
| + PluginFinder* plugin_finder = PluginFinder::GetInstance(); |
| + for (size_t i = 0; i < plugins.size(); ++i) { |
| + const content::WebPluginInfo& plugin = plugins[i]; |
| + if (plugin.is_pepper_plugin()) |
| + continue; |
| + if (std::find_if(plugin.mime_types.begin(), plugin.mime_types.end(), |
| + IsPdfMimeType) == plugin.mime_types.end()) |
| + continue; |
| + scoped_ptr<PluginMetadata> plugin_metadata( |
| + plugin_finder->GetPluginMetadata(plugins[i])); |
| + if (plugin_metadata->identifier() != kAdobeReaderIdentifier) |
| + continue; |
| + |
| + reader_info.is_installed = true; |
| + |
| + if (web_contents) { |
| + Profile* profile = |
| + Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| + PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
| + PluginPrefs::PolicyStatus plugin_status = |
| + plugin_prefs->PolicyStatusForPlugin(plugin_metadata->name()); |
| + reader_info.is_enabled = plugin_status != PluginPrefs::POLICY_DISABLED; |
| + } |
| + |
| + PluginMetadata::SecurityStatus security_status = |
| + plugin_metadata->GetSecurityStatus(plugins[i]); |
| + reader_info.is_secure = |
| + security_status == PluginMetadata::SECURITY_STATUS_UP_TO_DATE; |
| + |
| + reader_info.plugin_info = plugins[i]; |
| + break; |
| + } |
|
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.
|
| + return reader_info; |
| +} |
| + |
| +void OnGotPluginInfo(int process_id, |
| + int routing_id, |
| + const GetAdobeReaderPluginInfoCallback& callback, |
| + const std::vector<content::WebPluginInfo>& plugins) { |
| + content::WebContents* web_contents = |
| + tab_util::GetWebContentsByID(process_id, routing_id); |
| + callback.Run(GetReaderPlugin(web_contents, plugins)); |
| +} |
| +#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
|
| + |
| +} // namespace |
| + |
| +#if defined(ENABLE_PLUGIN_INSTALLATION) |
| +void GetAdobeReaderPluginInfoAsync( |
| + content::WebContents* web_contents, |
| + const GetAdobeReaderPluginInfoCallback& callback) { |
| + DCHECK(!callback.is_null()); |
| + content::PluginService::GetInstance()->GetPlugins( |
| + base::Bind(&OnGotPluginInfo, |
| + web_contents->GetRenderProcessHost()->GetID(), |
| + web_contents->GetRenderViewHost()->GetRoutingID(), |
| + callback)); |
| +} |
| + |
| +bool GetAdobeReaderPluginInfo(content::WebContents* web_contents, |
| + AdobeReaderPluginInfo* reader_info) { |
| + DCHECK(reader_info); |
| + std::vector<content::WebPluginInfo> plugins; |
| + bool up_to_date = content::PluginService::GetInstance()->GetPluginInfoArray( |
| + GURL(), kPdfMimeType, false, &plugins, NULL); |
| + *reader_info = GetReaderPlugin(web_contents, plugins); |
| + return up_to_date; |
| +} |
| +#endif |
| + |
| +bool IsAdobeReaderDefaultPDFViewer() { |
| + base::string16 key_path(L"AcroExch.Document"); |
| + key_path.append(ShellUtil::kRegShellOpen); |
| + base::win::RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ); |
| + base::string16 app_cmd; |
| + static base::char16 kReaderKey[] = L"Reader\\AcroRd32.exe"; |
| + return (key.Valid() && (key.ReadValue(L"", &app_cmd) == ERROR_SUCCESS) && |
| + 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.
|
| +} |