1/* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef PluginController_h 27#define PluginController_h 28 29#include <wtf/Forward.h> 30 31#if PLATFORM(COCOA) 32#include "PluginComplexTextInputState.h" 33#endif 34 35struct NPObject; 36typedef struct _NPVariant NPVariant; 37typedef void* NPIdentifier; 38 39namespace WebCore { 40 class HTTPHeaderMap; 41 class IntRect; 42 class URL; 43 class ProtectionSpace; 44} 45 46namespace WebKit { 47 48class PluginController { 49public: 50 // Returns false if the plugin has explicitly been hidden. Returns true otherwise (even if the plugin is currently obscured from view on screen.) 51 virtual bool isPluginVisible() = 0; 52 53 // Tells the controller that the plug-in wants the given rect to be repainted. The rect is in the plug-in's coordinate system. 54 virtual void invalidate(const WebCore::IntRect&) = 0; 55 56 // Returns the user agent string. 57 virtual String userAgent() = 0; 58 59 // Loads the given URL and associates it with the request ID. 60 // 61 // If a target is specified, then the URL will be loaded in the window or frame that the target refers to. 62 // Once the URL finishes loading, Plugin::frameDidFinishLoading will be called with the given requestID. If the URL 63 // fails to load, Plugin::frameDidFailToLoad will be called. 64 // 65 // If the URL is a JavaScript URL, the JavaScript code will be evaluated and the result sent back using Plugin::didEvaluateJavaScript. 66 virtual void loadURL(uint64_t requestID, const String& method, const String& urlString, const String& target, 67 const WebCore::HTTPHeaderMap& headerFields, const Vector<uint8_t>& httpBody, bool allowPopups) = 0; 68 69 /// Cancels the load of a stream that was requested by loadURL. 70 virtual void cancelStreamLoad(uint64_t streamID) = 0; 71 72 // Cancels the load of the manual stream. 73 virtual void cancelManualStreamLoad() = 0; 74 75#if ENABLE(NETSCAPE_PLUGIN_API) 76 // Get the NPObject that corresponds to the window JavaScript object. Returns a retained object. 77 virtual NPObject* windowScriptNPObject() = 0; 78 79 // Get the NPObject that corresponds to the plug-in's element. Returns a retained object. 80 virtual NPObject* pluginElementNPObject() = 0; 81 82 // Evaluates the given script string in the context of the given NPObject. 83 virtual bool evaluate(NPObject*, const String& scriptString, NPVariant* result, bool allowPopups) = 0; 84#endif 85 86 // Set the statusbar text. 87 virtual void setStatusbarText(const String&) = 0; 88 89 // Return whether accelerated compositing is enabled. 90 virtual bool isAcceleratedCompositingEnabled() = 0; 91 92 // Tells the controller that the plug-in process has crashed. 93 virtual void pluginProcessCrashed() = 0; 94 95 // Tells the controller that we're about to dispatch an event to the plug-in. 96 virtual void willSendEventToPlugin() = 0; 97 98#if PLATFORM(COCOA) 99 // Tells the controller that the plug-in focus or window focus did change. 100 virtual void pluginFocusOrWindowFocusChanged(bool) = 0; 101 102 // Tells the controller that complex text input be enabled or disabled for the plug-in. 103 virtual void setComplexTextInputState(PluginComplexTextInputState) = 0; 104 105 // Returns the mach port of the compositing render server. 106 virtual mach_port_t compositingRenderServerPort() = 0; 107 108 // Open the preference pane for this plug-in (as stated in the plug-in's Info.plist). 109 virtual void openPluginPreferencePane() = 0; 110#endif 111 112 // Returns the contents scale factor. 113 virtual float contentsScaleFactor() = 0; 114 115 // Returns the proxies for the given URL or null on failure. 116 virtual String proxiesForURL(const String&) = 0; 117 118 // Returns the cookies for the given URL or null on failure. 119 virtual String cookiesForURL(const String&) = 0; 120 121 // Sets the cookies for the given URL. 122 virtual void setCookiesForURL(const String& urlString, const String& cookieString) = 0; 123 124 // Get authentication credentials for the given protection space. 125 virtual bool getAuthenticationInfo(const WebCore::ProtectionSpace&, String& username, String& password) = 0; 126 127 // Returns whether private browsing is enabled. 128 virtual bool isPrivateBrowsingEnabled() = 0; 129 130 // Returns whether or not asynchronous plugin initialization is enabled. 131 virtual bool asynchronousPluginInitializationEnabled() const { return false; } 132 133 // Returns whether or not asynchronous plugin initialization should be attempted for all plugins. 134 virtual bool asynchronousPluginInitializationEnabledForAllPlugins() const { return false; } 135 136 // Returns the articifical plugin delay to use for testing of asynchronous plugin initialization. 137 virtual bool artificialPluginInitializationDelayEnabled() const { return false; } 138 139 // Increments a counter that prevents the plug-in from being destroyed. 140 virtual void protectPluginFromDestruction() = 0; 141 142 // Decrements a counter that, when it reaches 0, stops preventing the plug-in from being destroyed. 143 virtual void unprotectPluginFromDestruction() = 0; 144 145#if PLUGIN_ARCHITECTURE(X11) 146 // Create a plugin container for windowed plugins 147 virtual uint64_t createPluginContainer() = 0; 148 virtual void windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID) = 0; 149 virtual void windowedPluginVisibilityDidChange(bool isVisible, uint64_t windowID) = 0; 150#endif 151 152 // Called when the a plug-in instance is successfully initialized, either synchronously or asynchronously. 153 virtual void didInitializePlugin() = 0; 154 155 // Called when the a plug-in instance fails to initialized, either synchronously or asynchronously. 156 virtual void didFailToInitializePlugin() = 0; 157 158 // Helper class for delaying destruction of a plug-in. 159 class PluginDestructionProtector { 160 public: 161 explicit PluginDestructionProtector(PluginController* pluginController) 162 : m_pluginController(pluginController) 163 { 164 m_pluginController->protectPluginFromDestruction(); 165 } 166 167 ~PluginDestructionProtector() 168 { 169 m_pluginController->unprotectPluginFromDestruction(); 170 } 171 172 private: 173 PluginController* m_pluginController; 174 }; 175 176protected: 177 virtual ~PluginController() { } 178}; 179 180} // namespace WebKit 181 182#endif // PluginController_h 183