diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-28 14:55:53 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-28 14:55:53 +0000 |
commit | 4e0616edf0c949858b67859b6f27a0c573425988 (patch) | |
tree | 5ca36e9ca74c06a96d0c37fd0957091b9bf10408 /chrome | |
parent | 0298a21bc8ad80bd7b1cb09ce6d5711e5f698348 (diff) | |
download | chromium_src-4e0616edf0c949858b67859b6f27a0c573425988.zip chromium_src-4e0616edf0c949858b67859b6f27a0c573425988.tar.gz chromium_src-4e0616edf0c949858b67859b6f27a0c573425988.tar.bz2 |
Add ppapi plugins to about:plugins
Querying the plugin path and actual mime type is moved from creation of the
WebPluginDelegate to creation of the WebPlugin. This cleaned up some code.
R=jam
BUG=45289
TEST=none
Review URL: http://codereview.chromium.org/2262002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48484 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/plugin_service.cc | 21 | ||||
-rw-r--r-- | chrome/browser/plugin_service.h | 2 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_renderer.gypi | 2 | ||||
-rw-r--r-- | chrome/common/pepper_plugin_registry.cc (renamed from chrome/renderer/pepper_plugin_registry.cc) | 50 | ||||
-rw-r--r-- | chrome/common/pepper_plugin_registry.h | 38 | ||||
-rw-r--r-- | chrome/renderer/pepper_devices_unittest.cc | 3 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_registry.h | 28 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 67 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 5 | ||||
-rw-r--r-- | chrome/renderer/renderer_main.cc | 2 |
11 files changed, 128 insertions, 92 deletions
diff --git a/chrome/browser/plugin_service.cc b/chrome/browser/plugin_service.cc index 5a77ee2..37e3d2d 100644 --- a/chrome/browser/plugin_service.cc +++ b/chrome/browser/plugin_service.cc @@ -28,6 +28,7 @@ #include "chrome/common/logging_chrome.h" #include "chrome/common/notification_type.h" #include "chrome/common/notification_service.h" +#include "chrome/common/pepper_plugin_registry.h" #include "chrome/common/plugin_messages.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" @@ -148,6 +149,8 @@ PluginService::PluginService() : main_message_loop_(MessageLoop::current()), resource_dispatcher_host_(NULL), ui_locale_(ASCIIToWide(g_browser_process->GetApplicationLocale())) { + RegisterPepperPlugins(); + // Have the NPAPI plugin list search for Chrome plugins as well. ChromePluginLib::RegisterPluginsWithNPAPI(); // Load the one specified on the command line as well. @@ -415,3 +418,21 @@ bool PluginService::PluginAllowedForURL(const FilePath& plugin_path, return (url.scheme() == required_url.scheme() && url.host() == required_url.host()); } + +void PluginService::RegisterPepperPlugins() { + std::vector<PepperPluginInfo> plugins; + PepperPluginRegistry::GetList(&plugins); + for (size_t i = 0; i < plugins.size(); ++i) { + NPAPI::PluginVersionInfo info; + info.path = plugins[i].path; + info.product_name = plugins[i].path.BaseName().ToWStringHack(); + info.mime_types = ASCIIToWide(JoinString(plugins[i].mime_types, '|')); + + // These NPAPI entry points will never be called. TODO(darin): Come up + // with a cleaner way to register pepper plugins with the NPAPI PluginList, + // or perhaps refactor the PluginList to be less specific to NPAPI. + memset(&info.entry_points, 0, sizeof(info.entry_points)); + + NPAPI::PluginList::Singleton()->RegisterInternalPlugin(info); + } +} diff --git a/chrome/browser/plugin_service.h b/chrome/browser/plugin_service.h index 3ed6f31..b20e5ae 100644 --- a/chrome/browser/plugin_service.h +++ b/chrome/browser/plugin_service.h @@ -117,6 +117,8 @@ class PluginService // the given URL. bool PluginAllowedForURL(const FilePath& plugin_path, const GURL& url); + void RegisterPepperPlugins(); + // mapping between plugin path and PluginProcessHost typedef base::hash_map<FilePath, PluginProcessHost*> PluginMap; PluginMap plugin_hosts_; diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index a5e579c..064775a 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -220,6 +220,8 @@ 'common/page_transition_types.cc', 'common/page_transition_types.h', 'common/page_zoom.h', + 'common/pepper_plugin_registry.cc', + 'common/pepper_plugin_registry.h', 'common/plugin_carbon_interpose_constants_mac.h', 'common/plugin_carbon_interpose_constants_mac.cc', 'common/plugin_messages.h', diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index d308da9..ef80621 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -111,8 +111,6 @@ 'renderer/pepper_devices.h', 'renderer/pepper_plugin_delegate_impl.cc', 'renderer/pepper_plugin_delegate_impl.h', - 'renderer/pepper_plugin_registry.cc', - 'renderer/pepper_plugin_registry.h', 'renderer/pepper_scrollbar_widget.cc', 'renderer/pepper_scrollbar_widget.h', 'renderer/pepper_widget.cc', diff --git a/chrome/renderer/pepper_plugin_registry.cc b/chrome/common/pepper_plugin_registry.cc index e183d0f..0a23eca 100644 --- a/chrome/renderer/pepper_plugin_registry.cc +++ b/chrome/common/pepper_plugin_registry.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/renderer/pepper_plugin_registry.h" +#include "chrome/common/pepper_plugin_registry.h" #include "base/command_line.h" #include "base/string_util.h" @@ -14,15 +14,8 @@ PepperPluginRegistry* PepperPluginRegistry::GetInstance() { return ®istry; } -pepper::PluginModule* PepperPluginRegistry::GetModule( - const std::string& mime_type) const { - ModuleMap::const_iterator it = modules_.find(mime_type); - if (it == modules_.end()) - return NULL; - return it->second; -} - -PepperPluginRegistry::PepperPluginRegistry() { +// static +void PepperPluginRegistry::GetList(std::vector<PepperPluginInfo>* plugins) { const std::wstring& value = CommandLine::ForCurrentProcess()->GetSwitchValue( switches::kRegisterPepperPlugins); if (value.empty()) @@ -42,20 +35,33 @@ PepperPluginRegistry::PepperPluginRegistry() { continue; } - const FilePath& file_path = FilePath::FromWStringHack(parts[0]); - ModuleHandle module = pepper::PluginModule::CreateModule(file_path); + PepperPluginInfo plugin; + plugin.path = FilePath::FromWStringHack(parts[0]); + for (size_t j = 1; j < parts.size(); ++j) + plugin.mime_types.push_back(WideToASCII(parts[j])); + + plugins->push_back(plugin); + } +} + +pepper::PluginModule* PepperPluginRegistry::GetModule( + const FilePath& path) const { + ModuleMap::const_iterator it = modules_.find(path); + if (it == modules_.end()) + return NULL; + return it->second; +} + +PepperPluginRegistry::PepperPluginRegistry() { + std::vector<PepperPluginInfo> plugins; + GetList(&plugins); + for (size_t i = 0; i < plugins.size(); ++i) { + const FilePath& path = plugins[i].path; + ModuleHandle module = pepper::PluginModule::CreateModule(path); if (!module) { - DLOG(ERROR) << "Failed to load pepper module: " << file_path.value(); + DLOG(ERROR) << "Failed to load pepper module: " << path.value(); continue; } - - for (size_t j = 1; j < parts.size(); ++j) { - const std::string& mime_type = WideToASCII(parts[j]); - if (modules_.find(mime_type) != modules_.end()) { - DLOG(ERROR) << "Type is already registered"; - continue; - } - modules_[mime_type] = module; - } + modules_[path] = module; } } diff --git a/chrome/common/pepper_plugin_registry.h b/chrome/common/pepper_plugin_registry.h new file mode 100644 index 0000000..940a1ba --- /dev/null +++ b/chrome/common/pepper_plugin_registry.h @@ -0,0 +1,38 @@ +// Copyright (c) 2010 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. + +#ifndef CHROME_COMMON_PEPPER_PLUGIN_REGISTRY_H_ +#define CHROME_COMMON_PEPPER_PLUGIN_REGISTRY_H_ + +#include <string> +#include <map> + +#include "webkit/glue/plugins/pepper_plugin_module.h" + +struct PepperPluginInfo { + FilePath path; + std::vector<std::string> mime_types; +}; + +// This class holds references to all of the known pepper plugin modules. +class PepperPluginRegistry { + public: + static PepperPluginRegistry* GetInstance(); + + // Returns the list of known pepper plugins. This method is static so that + // it can be used by the browser process, which has no need to load the + // pepper plugin modules. + static void GetList(std::vector<PepperPluginInfo>* plugins); + + pepper::PluginModule* GetModule(const FilePath& path) const; + + private: + PepperPluginRegistry(); + + typedef scoped_refptr<pepper::PluginModule> ModuleHandle; + typedef std::map<FilePath, ModuleHandle> ModuleMap; + ModuleMap modules_; +}; + +#endif // CHROME_COMMON_PEPPER_PLUGIN_REGISTRY_H_ diff --git a/chrome/renderer/pepper_devices_unittest.cc b/chrome/renderer/pepper_devices_unittest.cc index 02a93cb..c3903b3 100644 --- a/chrome/renderer/pepper_devices_unittest.cc +++ b/chrome/renderer/pepper_devices_unittest.cc @@ -168,7 +168,8 @@ void PepperDeviceTest::SetUp() { // sufficiently for the test). WebKit::WebPluginParams params; plugin_.reset(new webkit_glue::WebPluginImpl( - NULL, params, base::WeakPtr<webkit_glue::WebPluginPageDelegate>())); + NULL, params, FilePath(), std::string(), + base::WeakPtr<webkit_glue::WebPluginPageDelegate>())); // Create a pepper plugin for the RenderView. pepper_plugin_ = WebPluginDelegatePepper::Create( diff --git a/chrome/renderer/pepper_plugin_registry.h b/chrome/renderer/pepper_plugin_registry.h deleted file mode 100644 index b601609..0000000 --- a/chrome/renderer/pepper_plugin_registry.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2010 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. - -#ifndef CHROME_RENDERER_PEPPER_PLUGIN_REGISTRY_H_ -#define CHROME_RENDERER_PEPPER_PLUGIN_REGISTRY_H_ - -#include <string> -#include <map> - -#include "webkit/glue/plugins/pepper_plugin_module.h" - -// This class holds references to all of the known pepper plugin modules. -class PepperPluginRegistry { - public: - static PepperPluginRegistry* GetInstance(); - - pepper::PluginModule* GetModule(const std::string& mime_type) const; - - private: - PepperPluginRegistry(); - - typedef scoped_refptr<pepper::PluginModule> ModuleHandle; - typedef std::map<std::string, ModuleHandle> ModuleMap; - ModuleMap modules_; -}; - -#endif // CHROME_RENDERER_PEPPER_PLUGIN_REGISTRY_H_ diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 174a119..df1e665 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -32,6 +32,7 @@ #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/page_zoom.h" +#include "chrome/common/pepper_plugin_registry.h" #include "chrome/common/render_messages.h" #include "chrome/common/renderer_preferences.h" #include "chrome/common/thumbnail_score.h" @@ -51,7 +52,6 @@ #include "chrome/renderer/media/ipc_video_renderer.h" #include "chrome/renderer/navigation_state.h" #include "chrome/renderer/notification_provider.h" -#include "chrome/renderer/pepper_plugin_registry.h" #include "chrome/renderer/plugin_channel_host.h" #include "chrome/renderer/print_web_view_helper.h" #include "chrome/renderer/render_process.h" @@ -2101,13 +2101,26 @@ void RenderView::runModal() { WebPlugin* RenderView::createPlugin( WebFrame* frame, const WebPluginParams& params) { + FilePath path; + std::string actual_mime_type; + render_thread_->Send(new ViewHostMsg_GetPluginPath( + params.url, frame->top()->url(), params.mimeType.utf8(), &path, + &actual_mime_type)); + if (path.value().empty()) + return NULL; + + if (actual_mime_type.empty()) + actual_mime_type = params.mimeType.utf8(); + scoped_refptr<pepper::PluginModule> pepper_module = - PepperPluginRegistry::GetInstance()->GetModule(params.mimeType.utf8()); + PepperPluginRegistry::GetInstance()->GetModule(path); if (pepper_module) { - return new pepper::WebPluginImpl(pepper_module, frame, params, + return new pepper::WebPluginImpl(pepper_module, params, pepper_delegate_.AsWeakPtr()); } - return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr()); + + return new webkit_glue::WebPluginImpl(frame, params, path, actual_mime_type, + AsWeakPtr()); } WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) { @@ -3106,37 +3119,16 @@ void RenderView::ReportNoFindInPageResults(int request_id) { // webkit_glue::WebPluginPageDelegate ----------------------------------------- webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate( - const GURL& url, - const std::string& mime_type, - std::string* actual_mime_type) { + const FilePath& file_path, + const std::string& mime_type) { if (!PluginChannelHost::IsListening()) return NULL; - GURL policy_url; - WebFrame* main_frame = webview()->mainFrame(); - if (main_frame) - policy_url = main_frame->url(); - - FilePath path; - render_thread_->Send(new ViewHostMsg_GetPluginPath( - url, policy_url, mime_type, &path, actual_mime_type)); - if (path.value().empty()) - return NULL; - - FilePath internal_pdf_path; - PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path); - - const std::string* mime_type_to_use; - if (!actual_mime_type->empty()) - mime_type_to_use = actual_mime_type; - else - mime_type_to_use = &mime_type; - bool use_pepper_host = false; bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); // Check for trusted Pepper plugins. const char kPepperPrefix[] = "pepper-"; - if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) { + if (StartsWithASCII(mime_type, kPepperPrefix, true)) { if (CommandLine::ForCurrentProcess()-> HasSwitch(switches::kInternalPepper)) { in_process_plugin = true; @@ -3145,10 +3137,15 @@ webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate( // In process Pepper plugins must be explicitly enabled. return NULL; } - } else if (path == internal_pdf_path) { - in_process_plugin = true; - use_pepper_host = true; + } else { + FilePath internal_pdf_path; + PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path); + if (file_path == internal_pdf_path) { + in_process_plugin = true; + use_pepper_host = true; + } } + // Check for Native Client modules. if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) { if (mime_type == "application/x-nacl-srpc") { @@ -3156,17 +3153,17 @@ webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate( use_pepper_host = true; } } + if (in_process_plugin) { if (use_pepper_host) { WebPluginDelegatePepper* pepper_plugin = - WebPluginDelegatePepper::Create(path, *mime_type_to_use, - AsWeakPtr()); + WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr()); current_pepper_plugins_.insert(pepper_plugin); return pepper_plugin; } else { #if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac. return WebPluginDelegateImpl::Create( - path, *mime_type_to_use, gfx::NativeViewFromId(host_window_)); + file_path, mime_type, gfx::NativeViewFromId(host_window_)); #else NOTIMPLEMENTED(); return NULL; @@ -3174,7 +3171,7 @@ webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate( } } - return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr()); + return new WebPluginDelegateProxy(mime_type, AsWeakPtr()); } void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) { diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 283f203..89e46a9 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -411,9 +411,8 @@ class RenderView : public RenderWidget, // webkit_glue::WebPluginPageDelegate virtual webkit_glue::WebPluginDelegate* CreatePluginDelegate( - const GURL& url, - const std::string& mime_type, - std::string* actual_mime_type); + const FilePath& file_path, + const std::string& mime_type); virtual void CreatedPluginWindow(gfx::PluginWindowHandle handle); virtual void WillDestroyPluginWindow(gfx::PluginWindowHandle handle); virtual void DidMovePlugin(const webkit_glue::WebPluginGeometry& move); diff --git a/chrome/renderer/renderer_main.cc b/chrome/renderer/renderer_main.cc index b1f70ba..1f77d3e 100644 --- a/chrome/renderer/renderer_main.cc +++ b/chrome/renderer/renderer_main.cc @@ -27,7 +27,7 @@ #include "chrome/common/logging_chrome.h" #include "chrome/common/main_function_params.h" #include "chrome/common/net/net_resource_provider.h" -#include "chrome/renderer/pepper_plugin_registry.h" +#include "chrome/common/pepper_plugin_registry.h" #include "chrome/renderer/renderer_main_platform_delegate.h" #include "chrome/renderer/render_process_impl.h" #include "chrome/renderer/render_thread.h" |