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