| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 10 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
| 15 #include "base/lock.h" | 15 #include "base/lock.h" |
| 16 #include "base/ref_counted.h" | 16 #include "base/ref_counted.h" |
| 17 #include "base/singleton.h" |
| 17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 18 #include "webkit/glue/webplugin.h" | 19 #include "webkit/glue/webplugin.h" |
| 19 | 20 |
| 20 namespace IPC { | 21 namespace IPC { |
| 21 class Message; | 22 class Message; |
| 22 } | 23 } |
| 23 | 24 |
| 24 class MessageLoop; | 25 class MessageLoop; |
| 25 class PluginProcessHost; | 26 class PluginProcessHost; |
| 26 class URLRequestContext; | 27 class URLRequestContext; |
| 27 class ResourceDispatcherHost; | 28 class ResourceDispatcherHost; |
| 28 class ResourceMessageFilter; | 29 class ResourceMessageFilter; |
| 29 | 30 |
| 30 // This can be called on the main thread and IO thread. However it must | 31 // This can be called on the main thread and IO thread. However it must |
| 31 // be created on the main thread. | 32 // be created on the main thread. |
| 32 class PluginService { | 33 class PluginService { |
| 33 public: | 34 public: |
| 34 // Returns the PluginService singleton. | 35 // Returns the PluginService singleton. |
| 35 static PluginService* GetInstance(); | 36 static PluginService* GetInstance(); |
| 36 | 37 |
| 37 // Creates the PluginService object, but doesn't actually build the plugin | |
| 38 // list yet. It's generated lazily. | |
| 39 // Note: don't call these directly - use GetInstance() above. They are public | |
| 40 // so Singleton can access them. | |
| 41 PluginService(); | |
| 42 ~PluginService(); | |
| 43 | |
| 44 // Gets the list of available plugins. | 38 // Gets the list of available plugins. |
| 45 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); | 39 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); |
| 46 | 40 |
| 47 // Load all the plugins that should be loaded for the lifetime of the browser | 41 // Load all the plugins that should be loaded for the lifetime of the browser |
| 48 // (ie, with the LoadOnStartup flag set). | 42 // (ie, with the LoadOnStartup flag set). |
| 49 void LoadChromePlugins(ResourceDispatcherHost* resource_dispatcher_host); | 43 void LoadChromePlugins(ResourceDispatcherHost* resource_dispatcher_host); |
| 50 | 44 |
| 51 // Sets/gets the data directory that Chrome plugins should use to store | 45 // Sets/gets the data directory that Chrome plugins should use to store |
| 52 // persistent data. | 46 // persistent data. |
| 53 void SetChromePluginDataDir(const FilePath& data_dir); | 47 void SetChromePluginDataDir(const FilePath& data_dir); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 71 // Opens a channel to a plugin process for the given mime type, starting | 65 // Opens a channel to a plugin process for the given mime type, starting |
| 72 // a new plugin process if necessary. This must be called on the IO thread | 66 // a new plugin process if necessary. This must be called on the IO thread |
| 73 // or else a deadlock can occur. | 67 // or else a deadlock can occur. |
| 74 void OpenChannelToPlugin(ResourceMessageFilter* renderer_msg_filter, | 68 void OpenChannelToPlugin(ResourceMessageFilter* renderer_msg_filter, |
| 75 const GURL& url, | 69 const GURL& url, |
| 76 const std::string& mime_type, | 70 const std::string& mime_type, |
| 77 const std::string& clsid, | 71 const std::string& clsid, |
| 78 const std::wstring& locale, | 72 const std::wstring& locale, |
| 79 IPC::Message* reply_msg); | 73 IPC::Message* reply_msg); |
| 80 | 74 |
| 81 // A PluginProcessHost object calls this before its process is shut down. | |
| 82 void OnPluginProcessIsShuttingDown(PluginProcessHost* host); | |
| 83 | |
| 84 // A PluginProcessHost object calls this after its process has exited. This | |
| 85 // call deletes the host instance. | |
| 86 void OnPluginProcessExited(PluginProcessHost* host); | |
| 87 | |
| 88 bool HavePluginFor(const std::string& mime_type, bool allow_wildcard); | 75 bool HavePluginFor(const std::string& mime_type, bool allow_wildcard); |
| 89 | 76 |
| 90 FilePath GetPluginPath(const GURL& url, | 77 FilePath GetPluginPath(const GURL& url, |
| 91 const std::string& mime_type, | 78 const std::string& mime_type, |
| 92 const std::string& clsid, | 79 const std::string& clsid, |
| 93 std::string* actual_mime_type); | 80 std::string* actual_mime_type); |
| 94 | 81 |
| 95 // Get plugin info by matching full path. | 82 // Get plugin info by matching full path. |
| 96 bool GetPluginInfoByPath(const FilePath& plugin_path, | 83 bool GetPluginInfoByPath(const FilePath& plugin_path, |
| 97 WebPluginInfo* info); | 84 WebPluginInfo* info); |
| 98 | 85 |
| 99 // Returns true if the plugin's mime-type supports a given mime-type. | 86 // Returns true if the plugin's mime-type supports a given mime-type. |
| 100 // Checks for absolute matching and wildcards. mime-types should be in | 87 // Checks for absolute matching and wildcards. mime-types should be in |
| 101 // lower case. | 88 // lower case. |
| 102 bool SupportsMimeType(const std::wstring& plugin_mime_type, | 89 bool SupportsMimeType(const std::wstring& plugin_mime_type, |
| 103 const std::wstring& mime_type); | 90 const std::wstring& mime_type); |
| 104 | 91 |
| 105 // The UI thread's message loop | 92 // The UI thread's message loop |
| 106 MessageLoop* main_message_loop() { return main_message_loop_; } | 93 MessageLoop* main_message_loop() { return main_message_loop_; } |
| 107 | 94 |
| 108 ResourceDispatcherHost* resource_dispatcher_host() const { | 95 ResourceDispatcherHost* resource_dispatcher_host() const { |
| 109 return resource_dispatcher_host_; | 96 return resource_dispatcher_host_; |
| 110 } | 97 } |
| 111 | 98 |
| 112 // Initiates shutdown on all running PluginProcessHost instances. | 99 // Initiates shutdown on all running PluginProcessHost instances. |
| 113 // Can be invoked on the main thread. | 100 // Can be invoked on the main thread. |
| 114 void Shutdown(); | 101 void Shutdown(); |
| 115 | 102 |
| 116 private: | 103 private: |
| 117 friend class PluginProcessHostIterator; | 104 friend DefaultSingletonTraits<PluginService>; |
| 118 | 105 |
| 119 // Removes a host from the plugin_hosts collection | 106 // Creates the PluginService object, but doesn't actually build the plugin |
| 120 void RemoveHost(PluginProcessHost* host); | 107 // list yet. It's generated lazily. |
| 108 PluginService(); |
| 109 ~PluginService(); |
| 121 | 110 |
| 122 // Shutdown handler which executes in the context of the IO thread. | 111 // Shutdown handler which executes in the context of the IO thread. |
| 123 void OnShutdown(); | 112 void OnShutdown(); |
| 124 | 113 |
| 125 // mapping between plugin path and PluginProcessHost | 114 // mapping between plugin path and PluginProcessHost |
| 126 typedef base::hash_map<FilePath, PluginProcessHost*> PluginMap; | 115 typedef base::hash_map<FilePath, PluginProcessHost*> PluginMap; |
| 127 PluginMap plugin_hosts_; | 116 PluginMap plugin_hosts_; |
| 128 | 117 |
| 129 // The main thread's message loop. | 118 // The main thread's message loop. |
| 130 MessageLoop* main_message_loop_; | 119 MessageLoop* main_message_loop_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 158 | 147 |
| 159 DISALLOW_COPY_AND_ASSIGN(ShutdownHandler); | 148 DISALLOW_COPY_AND_ASSIGN(ShutdownHandler); |
| 160 }; | 149 }; |
| 161 | 150 |
| 162 friend class ShutdownHandler; | 151 friend class ShutdownHandler; |
| 163 scoped_refptr<ShutdownHandler> plugin_shutdown_handler_; | 152 scoped_refptr<ShutdownHandler> plugin_shutdown_handler_; |
| 164 | 153 |
| 165 DISALLOW_COPY_AND_ASSIGN(PluginService); | 154 DISALLOW_COPY_AND_ASSIGN(PluginService); |
| 166 }; | 155 }; |
| 167 | 156 |
| 168 // The PluginProcessHostIterator allows to iterate through all the | |
| 169 // PluginProcessHosts. Note that this should be done from the IO thread and that | |
| 170 // the iterator should not be kept around as it may be invalidated on | |
| 171 // subsequent event processing in the event loop. | |
| 172 class PluginProcessHostIterator { | |
| 173 public: | |
| 174 PluginProcessHostIterator(); | |
| 175 PluginProcessHostIterator(const PluginProcessHostIterator& instance); | |
| 176 | |
| 177 PluginProcessHostIterator& operator=( | |
| 178 const PluginProcessHostIterator& instance) { | |
| 179 iterator_ = instance.iterator_; | |
| 180 return *this; | |
| 181 } | |
| 182 | |
| 183 const PluginProcessHost* operator->() const { | |
| 184 return iterator_->second; | |
| 185 } | |
| 186 | |
| 187 const PluginProcessHost* operator*() const { | |
| 188 return iterator_->second; | |
| 189 } | |
| 190 | |
| 191 const PluginProcessHost* operator++() { // ++preincrement | |
| 192 ++iterator_; | |
| 193 if (iterator_ == end_) | |
| 194 return NULL; | |
| 195 else | |
| 196 return iterator_->second; | |
| 197 } | |
| 198 | |
| 199 const PluginProcessHost* operator++(int) { // postincrement++ | |
| 200 const PluginProcessHost* r; | |
| 201 if (iterator_ == end_) | |
| 202 r = NULL; | |
| 203 else | |
| 204 r = iterator_->second; | |
| 205 iterator_++; | |
| 206 return r; | |
| 207 } | |
| 208 | |
| 209 bool Done() { | |
| 210 return (iterator_ == end_); | |
| 211 } | |
| 212 | |
| 213 private: | |
| 214 PluginService::PluginMap::const_iterator iterator_; | |
| 215 PluginService::PluginMap::const_iterator end_; | |
| 216 }; | |
| 217 | |
| 218 #endif // CHROME_BROWSER_PLUGIN_SERVICE_H_ | 157 #endif // CHROME_BROWSER_PLUGIN_SERVICE_H_ |
| OLD | NEW |