plugin_service.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CONTENT_PUBLIC_BROWSER_PLUGIN_SERVICE_H_ 6#define CONTENT_PUBLIC_BROWSER_PLUGIN_SERVICE_H_ 7 8#include <string> 9#include <vector> 10 11#include "base/callback.h" 12#include "base/string16.h" 13#include "content/common/content_export.h" 14 15class FilePath; 16class GURL; 17 18namespace webkit { 19struct WebPluginInfo; 20namespace npapi { 21class PluginList; 22} 23} 24 25namespace content { 26 27class BrowserContext; 28class PluginProcessHost; 29class PluginServiceFilter; 30class ResourceContext; 31struct PepperPluginInfo; 32 33// This must be created on the main thread but it's only called on the IO/file 34// thread. This is an asynchronous wrapper around the PluginList interface for 35// querying plugin information. This must be used instead of that to avoid 36// doing expensive disk operations on the IO/UI threads. 37class PluginService { 38 public: 39 typedef base::Callback<void(const std::vector<webkit::WebPluginInfo>&)> 40 GetPluginsCallback; 41 42 // Returns the PluginService singleton. 43 CONTENT_EXPORT static PluginService* GetInstance(); 44 45 // Tells all the renderer processes associated with the given browser context 46 // to throw away their cache of the plugin list, and optionally also reload 47 // all the pages with plugins. If |browser_context| is NULL, purges the cache 48 // in all renderers. 49 // NOTE: can only be called on the UI thread. 50 CONTENT_EXPORT static void PurgePluginListCache( 51 BrowserContext* browser_context, 52 bool reload_pages); 53 54 virtual ~PluginService() {} 55 56 // Must be called on the instance to finish initialization. 57 virtual void Init() = 0; 58 59 // Starts watching for changes in the list of installed plug-ins. 60 virtual void StartWatchingPlugins() = 0; 61 62 // Gets the plugin in the list of plugins that matches the given url and mime 63 // type. Returns true if the data is frome a stale plugin list, false if it 64 // is up to date. This can be called from any thread. 65 virtual bool GetPluginInfoArray( 66 const GURL& url, 67 const std::string& mime_type, 68 bool allow_wildcard, 69 std::vector<webkit::WebPluginInfo>* info, 70 std::vector<std::string>* actual_mime_types) = 0; 71 72 // Gets plugin info for an individual plugin and filters the plugins using 73 // the |context| and renderer IDs. This will report whether the data is stale 74 // via |is_stale| and returns whether or not the plugin can be found. 75 virtual bool GetPluginInfo(int render_process_id, 76 int render_view_id, 77 ResourceContext* context, 78 const GURL& url, 79 const GURL& page_url, 80 const std::string& mime_type, 81 bool allow_wildcard, 82 bool* is_stale, 83 webkit::WebPluginInfo* info, 84 std::string* actual_mime_type) = 0; 85 86 // Get plugin info by plugin path (including disabled plugins). Returns true 87 // if the plugin is found and WebPluginInfo has been filled in |info|. This 88 // will use cached data in the plugin list. 89 virtual bool GetPluginInfoByPath(const FilePath& plugin_path, 90 webkit::WebPluginInfo* info) = 0; 91 92 // Returns the display name for the plugin identified by the given path. If 93 // the path doesn't identify a plugin, or the plugin has no display name, 94 // this will attempt to generate a display name from the path. 95 virtual string16 GetPluginDisplayNameByPath(const FilePath& plugin_path) = 0; 96 97 // Asynchronously loads plugins if necessary and then calls back to the 98 // provided function on the calling MessageLoop on completion. 99 virtual void GetPlugins(const GetPluginsCallback& callback) = 0; 100 101 // Returns information about a pepper plugin if it exists, otherwise NULL. 102 // The caller does not own the pointer, and it's not guaranteed to live past 103 // the call stack. 104 virtual PepperPluginInfo* GetRegisteredPpapiPluginInfo( 105 const FilePath& plugin_path) = 0; 106 107 virtual void SetFilter(PluginServiceFilter* filter) = 0; 108 virtual PluginServiceFilter* GetFilter() = 0; 109 110 // If the plugin with the given path is running, cleanly shuts it down. 111 virtual void ForcePluginShutdown(const FilePath& plugin_path) = 0; 112 113 // Used to monitor plug-in stability. An unstable plug-in is one that has 114 // crashed more than a set number of times in a set time period. 115 virtual bool IsPluginUnstable(const FilePath& plugin_path) = 0; 116 117 // The following functions are wrappers around webkit::npapi::PluginList. 118 // These must be used instead of those in order to ensure that we have a 119 // single global list in the component build and so that we don't 120 // accidentally load plugins in the wrong process or thread. Refer to 121 // PluginList for further documentation of these functions. 122 virtual void RefreshPlugins() = 0; 123 virtual void AddExtraPluginPath(const FilePath& path) = 0; 124 virtual void AddExtraPluginDir(const FilePath& path) = 0; 125 virtual void RemoveExtraPluginPath(const FilePath& path) = 0; 126 virtual void UnregisterInternalPlugin(const FilePath& path) = 0; 127 virtual void RegisterInternalPlugin(const webkit::WebPluginInfo& info, 128 bool add_at_beginning) = 0; 129 virtual void GetInternalPlugins( 130 std::vector<webkit::WebPluginInfo>* plugins) = 0; 131 132 // TODO(dpranke): This should be private. 133 virtual webkit::npapi::PluginList* GetPluginList() = 0; 134 135 virtual void SetPluginListForTesting( 136 webkit::npapi::PluginList* plugin_list) = 0; 137 138#if defined(OS_MACOSX) 139 // Called when the application is made active so that modal plugin windows can 140 // be made forward too. 141 virtual void AppActivated() = 0; 142#endif 143}; 144 145} // namespace content 146 147#endif // CONTENT_PUBLIC_BROWSER_PLUGIN_SERVICE_H_ 148