| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/singleton.h" | 17 #include "base/singleton.h" |
| 18 #include "base/waitable_event_watcher.h" | 18 #include "base/waitable_event_watcher.h" |
| 19 #include "chrome/common/notification_observer.h" | 19 #include "chrome/common/notification_observer.h" |
| 20 #include "chrome/common/notification_registrar.h" | 20 #include "chrome/common/notification_registrar.h" |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 | 22 |
| 23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 24 #include "base/registry.h" | 24 #include "base/registry.h" |
| 25 #include "base/scoped_ptr.h" | 25 #include "base/scoped_ptr.h" |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 #if defined(OS_CHROMEOS) |
| 29 namespace chromeos { |
| 30 class PluginSelectionPolicy; |
| 31 } |
| 32 #endif |
| 33 |
| 28 namespace IPC { | 34 namespace IPC { |
| 29 class Message; | 35 class Message; |
| 30 } | 36 } |
| 31 | 37 |
| 32 class MessageLoop; | 38 class MessageLoop; |
| 33 class PluginProcessHost; | 39 class PluginProcessHost; |
| 34 class Profile; | 40 class Profile; |
| 35 class URLRequestContext; | |
| 36 class ResourceDispatcherHost; | 41 class ResourceDispatcherHost; |
| 37 class ResourceMessageFilter; | 42 class ResourceMessageFilter; |
| 43 class URLRequestContext; |
| 44 struct WebPluginInfo; |
| 38 | 45 |
| 39 // This must be created on the main thread but it's only called on the IO/file | 46 // This must be created on the main thread but it's only called on the IO/file |
| 40 // thread. | 47 // thread. |
| 41 class PluginService | 48 class PluginService |
| 42 : public base::WaitableEventWatcher::Delegate, | 49 : public base::WaitableEventWatcher::Delegate, |
| 43 public NotificationObserver { | 50 public NotificationObserver { |
| 44 public: | 51 public: |
| 45 // Initializes the global instance; should be called on startup from the main | 52 // Initializes the global instance; should be called on startup from the main |
| 46 // thread. | 53 // thread. |
| 47 static void InitGlobalInstance(Profile* profile); | 54 static void InitGlobalInstance(Profile* profile); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 71 // 'plugin_path' if needed. If the process fails to start, the return value | 78 // 'plugin_path' if needed. If the process fails to start, the return value |
| 72 // is NULL. Must be called on the IO thread. | 79 // is NULL. Must be called on the IO thread. |
| 73 PluginProcessHost* FindOrStartPluginProcess(const FilePath& plugin_path); | 80 PluginProcessHost* FindOrStartPluginProcess(const FilePath& plugin_path); |
| 74 | 81 |
| 75 // Opens a channel to a plugin process for the given mime type, starting | 82 // Opens a channel to a plugin process for the given mime type, starting |
| 76 // a new plugin process if necessary. This must be called on the IO thread | 83 // a new plugin process if necessary. This must be called on the IO thread |
| 77 // or else a deadlock can occur. | 84 // or else a deadlock can occur. |
| 78 void OpenChannelToPlugin(ResourceMessageFilter* renderer_msg_filter, | 85 void OpenChannelToPlugin(ResourceMessageFilter* renderer_msg_filter, |
| 79 const GURL& url, | 86 const GURL& url, |
| 80 const std::string& mime_type, | 87 const std::string& mime_type, |
| 81 const std::string& locale, | |
| 82 IPC::Message* reply_msg); | 88 IPC::Message* reply_msg); |
| 83 | 89 |
| 90 // Gets the first allowed plugin in the list of plugins that matches |
| 91 // the given url and mime type. Must be called on the FILE thread. |
| 92 bool GetFirstAllowedPluginInfo(const GURL& url, |
| 93 const std::string& mime_type, |
| 94 WebPluginInfo* info, |
| 95 std::string* actual_mime_type); |
| 96 |
| 84 // Returns true if the given plugin is allowed to be used by a page with | 97 // Returns true if the given plugin is allowed to be used by a page with |
| 85 // the given URL. | 98 // the given URL. |
| 86 bool PrivatePluginAllowedForURL(const FilePath& plugin_path, const GURL& url); | 99 bool PrivatePluginAllowedForURL(const FilePath& plugin_path, const GURL& url); |
| 87 | 100 |
| 88 // The UI thread's message loop | 101 // The UI thread's message loop |
| 89 MessageLoop* main_message_loop() { return main_message_loop_; } | 102 MessageLoop* main_message_loop() { return main_message_loop_; } |
| 90 | 103 |
| 91 ResourceDispatcherHost* resource_dispatcher_host() const { | 104 ResourceDispatcherHost* resource_dispatcher_host() const { |
| 92 return resource_dispatcher_host_; | 105 return resource_dispatcher_host_; |
| 93 } | 106 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 104 | 117 |
| 105 // base::WaitableEventWatcher::Delegate implementation. | 118 // base::WaitableEventWatcher::Delegate implementation. |
| 106 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); | 119 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); |
| 107 | 120 |
| 108 // NotificationObserver implementation | 121 // NotificationObserver implementation |
| 109 virtual void Observe(NotificationType type, const NotificationSource& source, | 122 virtual void Observe(NotificationType type, const NotificationSource& source, |
| 110 const NotificationDetails& details); | 123 const NotificationDetails& details); |
| 111 | 124 |
| 112 void RegisterPepperPlugins(); | 125 void RegisterPepperPlugins(); |
| 113 | 126 |
| 127 // Helper so we can do the plugin lookup on the FILE thread. |
| 128 void GetAllowedPluginForOpenChannelToPlugin( |
| 129 ResourceMessageFilter* renderer_msg_filter, |
| 130 const GURL& url, |
| 131 const std::string& mime_type, |
| 132 IPC::Message* reply_msg); |
| 133 |
| 134 // Helper so we can finish opening the channel after looking up the |
| 135 // plugin. |
| 136 void FinishOpenChannelToPlugin( |
| 137 ResourceMessageFilter* renderer_msg_filter, |
| 138 const std::string& mime_type, |
| 139 const FilePath& plugin_path, |
| 140 IPC::Message* reply_msg); |
| 141 |
| 114 // mapping between plugin path and PluginProcessHost | 142 // mapping between plugin path and PluginProcessHost |
| 115 typedef base::hash_map<FilePath, PluginProcessHost*> PluginMap; | 143 typedef base::hash_map<FilePath, PluginProcessHost*> PluginMap; |
| 116 PluginMap plugin_hosts_; | 144 PluginMap plugin_hosts_; |
| 117 | 145 |
| 118 // The main thread's message loop. | 146 // The main thread's message loop. |
| 119 MessageLoop* main_message_loop_; | 147 MessageLoop* main_message_loop_; |
| 120 | 148 |
| 121 // The IO thread's resource dispatcher host. | 149 // The IO thread's resource dispatcher host. |
| 122 ResourceDispatcherHost* resource_dispatcher_host_; | 150 ResourceDispatcherHost* resource_dispatcher_host_; |
| 123 | 151 |
| 124 // The data directory that Chrome plugins should use to store persistent data. | 152 // The data directory that Chrome plugins should use to store persistent data. |
| 125 FilePath chrome_plugin_data_dir_; | 153 FilePath chrome_plugin_data_dir_; |
| 126 | 154 |
| 127 // The browser's UI locale. | 155 // The browser's UI locale. |
| 128 const std::string ui_locale_; | 156 const std::string ui_locale_; |
| 129 | 157 |
| 130 // Map of plugin paths to the origin they are restricted to. Used for | 158 // Map of plugin paths to the origin they are restricted to. Used for |
| 131 // extension-only plugins. | 159 // extension-only plugins. |
| 132 typedef base::hash_map<FilePath, GURL> PrivatePluginMap; | 160 typedef base::hash_map<FilePath, GURL> PrivatePluginMap; |
| 133 PrivatePluginMap private_plugins_; | 161 PrivatePluginMap private_plugins_; |
| 134 | 162 |
| 135 NotificationRegistrar registrar_; | 163 NotificationRegistrar registrar_; |
| 136 | 164 |
| 165 #if defined(OS_CHROMEOS) |
| 166 scoped_refptr<chromeos::PluginSelectionPolicy> plugin_selection_policy_; |
| 167 #endif |
| 168 |
| 137 #if defined(OS_WIN) | 169 #if defined(OS_WIN) |
| 138 // Registry keys for getting notifications when new plugins are installed. | 170 // Registry keys for getting notifications when new plugins are installed. |
| 139 RegKey hkcu_key_; | 171 RegKey hkcu_key_; |
| 140 RegKey hklm_key_; | 172 RegKey hklm_key_; |
| 141 scoped_ptr<base::WaitableEvent> hkcu_event_; | 173 scoped_ptr<base::WaitableEvent> hkcu_event_; |
| 142 scoped_ptr<base::WaitableEvent> hklm_event_; | 174 scoped_ptr<base::WaitableEvent> hklm_event_; |
| 143 base::WaitableEventWatcher hkcu_watcher_; | 175 base::WaitableEventWatcher hkcu_watcher_; |
| 144 base::WaitableEventWatcher hklm_watcher_; | 176 base::WaitableEventWatcher hklm_watcher_; |
| 145 #endif | 177 #endif |
| 146 | 178 |
| 147 // Set to true if chrome plugins are enabled. Defaults to true. | 179 // Set to true if chrome plugins are enabled. Defaults to true. |
| 148 static bool enable_chrome_plugins_; | 180 static bool enable_chrome_plugins_; |
| 149 | 181 |
| 150 DISALLOW_COPY_AND_ASSIGN(PluginService); | 182 DISALLOW_COPY_AND_ASSIGN(PluginService); |
| 151 }; | 183 }; |
| 152 | 184 |
| 185 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); |
| 186 |
| 153 #endif // CHROME_BROWSER_PLUGIN_SERVICE_H_ | 187 #endif // CHROME_BROWSER_PLUGIN_SERVICE_H_ |
| OLD | NEW |