| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This class responds to requests from renderers for the list of plugins, and | 5 // This class responds to requests from renderers for the list of plugins, and |
| 6 // also a proxy object for plugin instances. | 6 // also a proxy object for plugin instances. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_PLUGIN_SERVICE_H_ | 8 #ifndef CHROME_BROWSER_PLUGIN_SERVICE_H_ |
| 9 #define CHROME_BROWSER_PLUGIN_SERVICE_H_ | 9 #define CHROME_BROWSER_PLUGIN_SERVICE_H_ |
| 10 #pragma once | 10 #pragma once |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/hash_tables.h" | 16 #include "base/hash_tables.h" |
| 17 #include "base/lock.h" |
| 17 #include "base/scoped_vector.h" | 18 #include "base/scoped_vector.h" |
| 18 #include "base/singleton.h" | 19 #include "base/singleton.h" |
| 19 #include "base/synchronization/waitable_event_watcher.h" | 20 #include "base/synchronization/waitable_event_watcher.h" |
| 20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 21 #include "chrome/browser/plugin_process_host.h" | 22 #include "chrome/browser/plugin_process_host.h" |
| 22 #include "chrome/common/notification_observer.h" | 23 #include "chrome/common/notification_observer.h" |
| 23 #include "chrome/common/notification_registrar.h" | 24 #include "chrome/common/notification_registrar.h" |
| 24 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 25 #include "ipc/ipc_channel_handle.h" | 26 #include "ipc/ipc_channel_handle.h" |
| 27 #include "webkit/plugins/npapi/webplugininfo.h" |
| 26 | 28 |
| 27 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
| 28 #include "base/scoped_ptr.h" | 30 #include "base/scoped_ptr.h" |
| 29 #include "base/win/registry.h" | 31 #include "base/win/registry.h" |
| 30 #endif | 32 #endif |
| 31 | 33 |
| 32 #if defined(OS_LINUX) | 34 #if defined(OS_LINUX) |
| 33 #include "chrome/browser/file_path_watcher/file_path_watcher.h" | 35 #include "chrome/browser/file_path_watcher/file_path_watcher.h" |
| 34 #endif | 36 #endif |
| 35 | 37 |
| 36 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
| 37 namespace chromeos { | 39 namespace chromeos { |
| 38 class PluginSelectionPolicy; | 40 class PluginSelectionPolicy; |
| 39 } | 41 } |
| 40 #endif | 42 #endif |
| 41 | 43 |
| 42 namespace IPC { | 44 namespace IPC { |
| 43 class Message; | 45 class Message; |
| 44 } | 46 } |
| 45 | 47 |
| 46 class MessageLoop; | 48 class MessageLoop; |
| 47 class Profile; | 49 class Profile; |
| 48 class PluginDirWatcherDelegate; | 50 class PluginDirWatcherDelegate; |
| 49 class ResourceDispatcherHost; | 51 class ResourceDispatcherHost; |
| 50 | 52 |
| 51 namespace net { | 53 namespace net { |
| 52 class URLRequestContext; | 54 class URLRequestContext; |
| 53 } // namespace net | 55 } // namespace net |
| 54 | 56 |
| 55 namespace webkit { | |
| 56 namespace npapi { | |
| 57 struct WebPluginInfo; | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 // This must be created on the main thread but it's only called on the IO/file | 57 // This must be created on the main thread but it's only called on the IO/file |
| 62 // thread. | 58 // thread. |
| 63 class PluginService | 59 class PluginService |
| 64 : public base::WaitableEventWatcher::Delegate, | 60 : public base::WaitableEventWatcher::Delegate, |
| 65 public NotificationObserver { | 61 public NotificationObserver { |
| 66 public: | 62 public: |
| 63 struct OverriddenPlugin { |
| 64 int render_process_id; |
| 65 int render_view_id; |
| 66 GURL url; |
| 67 webkit::npapi::WebPluginInfo plugin; |
| 68 }; |
| 69 |
| 67 // Initializes the global instance; should be called on startup from the main | 70 // Initializes the global instance; should be called on startup from the main |
| 68 // thread. | 71 // thread. |
| 69 static void InitGlobalInstance(Profile* profile); | 72 static void InitGlobalInstance(Profile* profile); |
| 70 | 73 |
| 71 // Returns the PluginService singleton. | 74 // Returns the PluginService singleton. |
| 72 static PluginService* GetInstance(); | 75 static PluginService* GetInstance(); |
| 73 | 76 |
| 74 // Load all the plugins that should be loaded for the lifetime of the browser | 77 // Load all the plugins that should be loaded for the lifetime of the browser |
| 75 // (ie, with the LoadOnStartup flag set). | 78 // (ie, with the LoadOnStartup flag set). |
| 76 void LoadChromePlugins(ResourceDispatcherHost* resource_dispatcher_host); | 79 void LoadChromePlugins(ResourceDispatcherHost* resource_dispatcher_host); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 90 | 93 |
| 91 // Returns the plugin process host corresponding to the plugin process that | 94 // Returns the plugin process host corresponding to the plugin process that |
| 92 // has been started by this service. This will start a process to host the | 95 // has been started by this service. This will start a process to host the |
| 93 // 'plugin_path' if needed. If the process fails to start, the return value | 96 // 'plugin_path' if needed. If the process fails to start, the return value |
| 94 // is NULL. Must be called on the IO thread. | 97 // is NULL. Must be called on the IO thread. |
| 95 PluginProcessHost* FindOrStartPluginProcess(const FilePath& plugin_path); | 98 PluginProcessHost* FindOrStartPluginProcess(const FilePath& plugin_path); |
| 96 | 99 |
| 97 // Opens a channel to a plugin process for the given mime type, starting | 100 // Opens a channel to a plugin process for the given mime type, starting |
| 98 // a new plugin process if necessary. This must be called on the IO thread | 101 // a new plugin process if necessary. This must be called on the IO thread |
| 99 // or else a deadlock can occur. | 102 // or else a deadlock can occur. |
| 100 void OpenChannelToPlugin(const GURL& url, | 103 void OpenChannelToPlugin(int render_process_id, |
| 104 int render_view_id, |
| 105 const GURL& url, |
| 101 const std::string& mime_type, | 106 const std::string& mime_type, |
| 102 PluginProcessHost::Client* client); | 107 PluginProcessHost::Client* client); |
| 103 | 108 |
| 104 // Gets the first allowed plugin in the list of plugins that matches | 109 // Gets the first allowed plugin in the list of plugins that matches |
| 105 // the given url and mime type. Must be called on the FILE thread. | 110 // the given url and mime type. Must be called on the FILE thread. |
| 106 bool GetFirstAllowedPluginInfo(const GURL& url, | 111 bool GetFirstAllowedPluginInfo(int render_process_id, |
| 112 int render_view_id, |
| 113 const GURL& url, |
| 107 const std::string& mime_type, | 114 const std::string& mime_type, |
| 108 webkit::npapi::WebPluginInfo* info, | 115 webkit::npapi::WebPluginInfo* info, |
| 109 std::string* actual_mime_type); | 116 std::string* actual_mime_type); |
| 110 | 117 |
| 111 // Returns true if the given plugin is allowed to be used by a page with | 118 // Returns true if the given plugin is allowed to be used by a page with |
| 112 // the given URL. | 119 // the given URL. |
| 113 bool PrivatePluginAllowedForURL(const FilePath& plugin_path, const GURL& url); | 120 bool PrivatePluginAllowedForURL(const FilePath& plugin_path, const GURL& url); |
| 114 | 121 |
| 122 // Safe to be called from any thread. |
| 123 void OverridePluginForTab(OverriddenPlugin plugin); |
| 124 |
| 115 // The UI thread's message loop | 125 // The UI thread's message loop |
| 116 MessageLoop* main_message_loop() { return main_message_loop_; } | 126 MessageLoop* main_message_loop() { return main_message_loop_; } |
| 117 | 127 |
| 118 ResourceDispatcherHost* resource_dispatcher_host() const { | 128 ResourceDispatcherHost* resource_dispatcher_host() const { |
| 119 return resource_dispatcher_host_; | 129 return resource_dispatcher_host_; |
| 120 } | 130 } |
| 121 | 131 |
| 122 static void EnableChromePlugins(bool enable); | 132 static void EnableChromePlugins(bool enable); |
| 123 | 133 |
| 124 private: | 134 private: |
| 125 friend struct DefaultSingletonTraits<PluginService>; | 135 friend struct DefaultSingletonTraits<PluginService>; |
| 126 | 136 |
| 127 // Creates the PluginService object, but doesn't actually build the plugin | 137 // Creates the PluginService object, but doesn't actually build the plugin |
| 128 // list yet. It's generated lazily. | 138 // list yet. It's generated lazily. |
| 129 PluginService(); | 139 PluginService(); |
| 130 ~PluginService(); | 140 ~PluginService(); |
| 131 | 141 |
| 132 // base::WaitableEventWatcher::Delegate implementation. | 142 // base::WaitableEventWatcher::Delegate implementation. |
| 133 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); | 143 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); |
| 134 | 144 |
| 135 // NotificationObserver implementation | 145 // NotificationObserver implementation |
| 136 virtual void Observe(NotificationType type, const NotificationSource& source, | 146 virtual void Observe(NotificationType type, const NotificationSource& source, |
| 137 const NotificationDetails& details); | 147 const NotificationDetails& details); |
| 138 | 148 |
| 139 void RegisterPepperPlugins(); | 149 void RegisterPepperPlugins(); |
| 140 | 150 |
| 141 // Helper so we can do the plugin lookup on the FILE thread. | 151 // Helper so we can do the plugin lookup on the FILE thread. |
| 142 void GetAllowedPluginForOpenChannelToPlugin( | 152 void GetAllowedPluginForOpenChannelToPlugin( |
| 153 int render_process_id, |
| 154 int render_view_id, |
| 143 const GURL& url, | 155 const GURL& url, |
| 144 const std::string& mime_type, | 156 const std::string& mime_type, |
| 145 PluginProcessHost::Client* client); | 157 PluginProcessHost::Client* client); |
| 146 | 158 |
| 147 // Helper so we can finish opening the channel after looking up the | 159 // Helper so we can finish opening the channel after looking up the |
| 148 // plugin. | 160 // plugin. |
| 149 void FinishOpenChannelToPlugin( | 161 void FinishOpenChannelToPlugin( |
| 150 const FilePath& plugin_path, | 162 const FilePath& plugin_path, |
| 151 PluginProcessHost::Client* client); | 163 PluginProcessHost::Client* client); |
| 152 | 164 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 #endif | 208 #endif |
| 197 | 209 |
| 198 #if defined(OS_LINUX) | 210 #if defined(OS_LINUX) |
| 199 ScopedVector<FilePathWatcher> file_watchers_; | 211 ScopedVector<FilePathWatcher> file_watchers_; |
| 200 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_; | 212 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_; |
| 201 #endif | 213 #endif |
| 202 | 214 |
| 203 // Set to true if chrome plugins are enabled. Defaults to true. | 215 // Set to true if chrome plugins are enabled. Defaults to true. |
| 204 static bool enable_chrome_plugins_; | 216 static bool enable_chrome_plugins_; |
| 205 | 217 |
| 218 std::vector<OverriddenPlugin> overridden_plugins_; |
| 219 base::Lock overridden_plugins_lock_; |
| 220 |
| 206 DISALLOW_COPY_AND_ASSIGN(PluginService); | 221 DISALLOW_COPY_AND_ASSIGN(PluginService); |
| 207 }; | 222 }; |
| 208 | 223 |
| 209 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); | 224 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); |
| 210 | 225 |
| 211 #endif // CHROME_BROWSER_PLUGIN_SERVICE_H_ | 226 #endif // CHROME_BROWSER_PLUGIN_SERVICE_H_ |
| OLD | NEW |