Home | History | Annotate | Download | only in Plugins
      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 struct NPObject;
     32 typedef struct _NPVariant NPVariant;
     33 
     34 namespace WebCore {
     35     class HTTPHeaderMap;
     36     class IntRect;
     37     class KURL;
     38 }
     39 
     40 namespace WebKit {
     41 
     42 class PluginController {
     43 public:
     44     // Tells the controller that the plug-in wants the given rect to be repainted. The rect is in the plug-in's coordinate system.
     45     virtual void invalidate(const WebCore::IntRect&) = 0;
     46 
     47     // Returns the user agent string.
     48     virtual String userAgent() = 0;
     49 
     50     // Loads the given URL and associates it with the request ID.
     51     //
     52     // If a target is specified, then the URL will be loaded in the window or frame that the target refers to.
     53     // Once the URL finishes loading, Plugin::frameDidFinishLoading will be called with the given requestID. If the URL
     54     // fails to load, Plugin::frameDidFailToLoad will be called.
     55     //
     56     // If the URL is a JavaScript URL, the JavaScript code will be evaluated and the result sent back using Plugin::didEvaluateJavaScript.
     57     virtual void loadURL(uint64_t requestID, const String& method, const String& urlString, const String& target,
     58                          const WebCore::HTTPHeaderMap& headerFields, const Vector<uint8_t>& httpBody, bool allowPopups) = 0;
     59 
     60     /// Cancels the load of a stream that was requested by loadURL.
     61     virtual void cancelStreamLoad(uint64_t streamID) = 0;
     62 
     63     // Cancels the load of the manual stream.
     64     virtual void cancelManualStreamLoad() = 0;
     65 
     66     // Get the NPObject that corresponds to the window JavaScript object. Returns a retained object.
     67     virtual NPObject* windowScriptNPObject() = 0;
     68 
     69     // Get the NPObject that corresponds to the plug-in's element. Returns a retained object.
     70     virtual NPObject* pluginElementNPObject() = 0;
     71 
     72     // Evaluates the given script string in the context of the given NPObject.
     73     virtual bool evaluate(NPObject*, const String& scriptString, NPVariant* result, bool allowPopups) = 0;
     74 
     75     // Set the statusbar text.
     76     virtual void setStatusbarText(const String&) = 0;
     77 
     78 #if USE(ACCELERATED_COMPOSITING)
     79     // Return whether accelerated compositing is enabled.
     80     virtual bool isAcceleratedCompositingEnabled() = 0;
     81 #endif
     82 
     83     // Tells the controller that the plug-in process has crashed.
     84     virtual void pluginProcessCrashed() = 0;
     85 
     86 #if PLATFORM(WIN)
     87     // The window to use as the parent of the plugin's window.
     88     virtual HWND nativeParentWindow() = 0;
     89 #endif
     90 
     91 #if PLATFORM(MAC)
     92     // Tells the controller that complex text input be enabled or disabled for the plug-in.
     93     virtual void setComplexTextInputEnabled(bool) = 0;
     94 
     95     // Returns the mach port of the compositing render server.
     96     virtual mach_port_t compositingRenderServerPort() = 0;
     97 #endif
     98 
     99     // Returns the proxies for the given URL or null on failure.
    100     virtual String proxiesForURL(const String&) = 0;
    101 
    102     // Returns the cookies for the given URL or null on failure.
    103     virtual String cookiesForURL(const String&) = 0;
    104 
    105     // Sets the cookies for the given URL.
    106     virtual void setCookiesForURL(const String& urlString, const String& cookieString) = 0;
    107 
    108     // Returns whether private browsing is enabled.
    109     virtual bool isPrivateBrowsingEnabled() = 0;
    110 
    111     // Increments a counter that prevents the plug-in from being destroyed.
    112     virtual void protectPluginFromDestruction() = 0;
    113 
    114     // Decrements a counter that, when it reaches 0, stops preventing the plug-in from being destroyed.
    115     virtual void unprotectPluginFromDestruction() = 0;
    116 
    117     // Helper class for delaying destruction of a plug-in.
    118     class PluginDestructionProtector {
    119     public:
    120         explicit PluginDestructionProtector(PluginController* pluginController)
    121             : m_pluginController(pluginController)
    122         {
    123             m_pluginController->protectPluginFromDestruction();
    124         }
    125 
    126         ~PluginDestructionProtector()
    127         {
    128             m_pluginController->unprotectPluginFromDestruction();
    129         }
    130 
    131     private:
    132         PluginController* m_pluginController;
    133     };
    134 
    135 protected:
    136     virtual ~PluginController() { }
    137 };
    138 
    139 } // namespace WebKit
    140 
    141 #endif // PluginController_h
    142