| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_COMMON_CHROME_PLUGIN_LIB_H_ | |
| 6 #define CHROME_COMMON_CHROME_PLUGIN_LIB_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/file_path.h" | |
| 11 #include "base/ref_counted.h" | |
| 12 #include "chrome/common/chrome_plugin_api.h" | |
| 13 | |
| 14 class MessageLoop; | |
| 15 | |
| 16 // A ChromePluginLib is a single Chrome Plugin Library. | |
| 17 // This class is used in the browser process (IO thread), and the plugin process | |
| 18 // (plugin thread). It should not be accessed on other threads, because it | |
| 19 // issues a NOTIFY_CHROME_PLUGIN_UNLOADED notification. | |
| 20 class ChromePluginLib : public base::RefCounted<ChromePluginLib> { | |
| 21 public: | |
| 22 static bool IsInitialized(); | |
| 23 static ChromePluginLib* Create(const FilePath& filename, | |
| 24 const CPBrowserFuncs* bfuncs); | |
| 25 static ChromePluginLib* Find(const FilePath& filename); | |
| 26 static void Destroy(const FilePath& filename); | |
| 27 static bool IsPluginThread(); | |
| 28 static MessageLoop* GetPluginThreadLoop(); | |
| 29 | |
| 30 static ChromePluginLib* FromCPID(CPID id) { | |
| 31 return reinterpret_cast<ChromePluginLib*>(id); | |
| 32 } | |
| 33 | |
| 34 // Adds Chrome plugins to the NPAPI plugin list. | |
| 35 static void RegisterPluginsWithNPAPI(); | |
| 36 | |
| 37 // Loads all the plugins that are marked as "LoadOnStartup" in the | |
| 38 // registry. This should only be called in the browser process. | |
| 39 static void LoadChromePlugins(const CPBrowserFuncs* bfuncs); | |
| 40 | |
| 41 // Unloads all the loaded plugins and cleans up the plugin map. | |
| 42 static void UnloadAllPlugins(); | |
| 43 | |
| 44 // Returns true if the plugin is currently loaded. | |
| 45 bool is_loaded() const { return initialized_; } | |
| 46 | |
| 47 // Get the Plugin's function pointer table. | |
| 48 const CPPluginFuncs& functions() const; | |
| 49 | |
| 50 CPID cpid() { return reinterpret_cast<CPID>(this); } | |
| 51 | |
| 52 const FilePath& filename() { return filename_; } | |
| 53 | |
| 54 // Plugin API functions | |
| 55 | |
| 56 // Method to call a test function in the plugin, used for unit tests. | |
| 57 int CP_Test(void* param); | |
| 58 | |
| 59 #if defined(OS_WIN) | |
| 60 // The registry path to search for Chrome Plugins/ | |
| 61 static const TCHAR kRegistryChromePlugins[]; | |
| 62 #endif // defined(OS_WIN) | |
| 63 | |
| 64 private: | |
| 65 friend class base::RefCounted<ChromePluginLib>; | |
| 66 | |
| 67 explicit ChromePluginLib(const FilePath& filename); | |
| 68 ~ChromePluginLib(); | |
| 69 | |
| 70 // Method to initialize a Plugin. | |
| 71 // Initialize can be safely called multiple times. | |
| 72 bool CP_Initialize(const CPBrowserFuncs* bfuncs); | |
| 73 | |
| 74 // Method to shutdown a Plugin. | |
| 75 void CP_Shutdown(); | |
| 76 | |
| 77 // Attempts to load the plugin. | |
| 78 // Returns true if it is a legitimate plugin, false otherwise | |
| 79 bool Load(); | |
| 80 | |
| 81 // Unloads the plugin. | |
| 82 void Unload(); | |
| 83 | |
| 84 FilePath filename_; // the path to the plugin | |
| 85 #if defined(OS_WIN) | |
| 86 // TODO(port): Remove ifdefs when we have portable replacement for HMODULE. | |
| 87 HMODULE module_; // the opened plugin handle | |
| 88 #endif // defined(OS_WIN) | |
| 89 bool initialized_; // is the plugin initialized | |
| 90 | |
| 91 // Exported symbols from the plugin, looked up by name. | |
| 92 CP_VersionNegotiateFunc CP_VersionNegotiate_; | |
| 93 CP_InitializeFunc CP_Initialize_; | |
| 94 | |
| 95 // Additional function pointers provided by the plugin. | |
| 96 CPPluginFuncs plugin_funcs_; | |
| 97 | |
| 98 // Used for unit tests. | |
| 99 typedef int (STDCALL *CP_TestFunc)(void*); | |
| 100 CP_TestFunc CP_Test_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(ChromePluginLib); | |
| 103 }; | |
| 104 | |
| 105 #endif // CHROME_COMMON_CHROME_PLUGIN_LIB_H_ | |
| OLD | NEW |