PluginProxy.h revision 81bc750723a18f21cd17d1b173cd2a4dda9cea6e
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 PluginProxy_h
27#define PluginProxy_h
28
29#if ENABLE(PLUGIN_PROCESS)
30
31#include "Connection.h"
32#include "Plugin.h"
33
34#if PLATFORM(MAC)
35#include <wtf/RetainPtr.h>
36OBJC_CLASS CALayer;
37#endif
38
39namespace WebCore {
40    class HTTPHeaderMap;
41}
42
43namespace WebKit {
44
45class ShareableBitmap;
46class NPVariantData;
47class PluginProcessConnection;
48
49class PluginProxy : public Plugin {
50public:
51    static PassRefPtr<PluginProxy> create(const String& pluginPath);
52    ~PluginProxy();
53
54    uint64_t pluginInstanceID() const { return m_pluginInstanceID; }
55    void pluginProcessCrashed();
56
57    void didReceivePluginProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments);
58    CoreIPC::SyncReplyMode didReceiveSyncPluginProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
59
60private:
61    explicit PluginProxy(const String& pluginPath);
62
63    // Plugin
64    virtual bool initialize(PluginController*, const Parameters&);
65    virtual void destroy();
66    virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect);
67    virtual PassRefPtr<ShareableBitmap> snapshot();
68#if PLATFORM(MAC)
69    virtual PlatformLayer* pluginLayer();
70#endif
71    virtual void geometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect);
72    virtual void frameDidFinishLoading(uint64_t requestID);
73    virtual void frameDidFail(uint64_t requestID, bool wasCancelled);
74    virtual void didEvaluateJavaScript(uint64_t requestID, const WTF::String& requestURLString, const WTF::String& result);
75    virtual void streamDidReceiveResponse(uint64_t streamID, const WebCore::KURL& responseURL, uint32_t streamLength, uint32_t lastModifiedTime, const WTF::String& mimeType, const WTF::String& headers);
76    virtual void streamDidReceiveData(uint64_t streamID, const char* bytes, int length);
77    virtual void streamDidFinishLoading(uint64_t streamID);
78    virtual void streamDidFail(uint64_t streamID, bool wasCancelled);
79    virtual void manualStreamDidReceiveResponse(const WebCore::KURL& responseURL, uint32_t streamLength, uint32_t lastModifiedTime, const WTF::String& mimeType, const WTF::String& headers);
80    virtual void manualStreamDidReceiveData(const char* bytes, int length);
81    virtual void manualStreamDidFinishLoading();
82    virtual void manualStreamDidFail(bool wasCancelled);
83
84    virtual bool handleMouseEvent(const WebMouseEvent&);
85    virtual bool handleWheelEvent(const WebWheelEvent&);
86    virtual bool handleMouseEnterEvent(const WebMouseEvent&);
87    virtual bool handleMouseLeaveEvent(const WebMouseEvent&);
88    virtual bool handleKeyboardEvent(const WebKeyboardEvent&);
89    virtual void setFocus(bool);
90    virtual NPObject* pluginScriptableNPObject();
91#if PLATFORM(MAC)
92    virtual void windowFocusChanged(bool);
93    virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
94    virtual void windowVisibilityChanged(bool);
95    virtual uint64_t pluginComplexTextInputIdentifier() const;
96    virtual void sendComplexTextInput(const String& textInput);
97#endif
98
99    virtual void privateBrowsingStateChanged(bool);
100
101    virtual PluginController* controller();
102
103    bool needsBackingStore() const;
104
105    // Message handlers.
106    void loadURL(uint64_t requestID, const String& method, const String& urlString, const String& target, const WebCore::HTTPHeaderMap& headerFields, const Vector<uint8_t>& httpBody, bool allowPopups);
107    void update(const WebCore::IntRect& paintedRect);
108    void proxiesForURL(const String& urlString, String& proxyString);
109    void cookiesForURL(const String& urlString, String& cookieString);
110    void setCookiesForURL(const String& urlString, const String& cookieString);
111    void getWindowScriptNPObject(uint64_t& windowScriptNPObjectID);
112    void getPluginElementNPObject(uint64_t& pluginElementNPObjectID);
113    void evaluate(const NPVariantData& npObjectAsVariantData, const String& scriptString, bool allowPopups, bool& returnValue, NPVariantData& resultData);
114    void cancelStreamLoad(uint64_t streamID);
115    void cancelManualStreamLoad();
116    void setStatusbarText(const String& statusbarText);
117#if PLATFORM(MAC)
118    void setComplexTextInputEnabled(bool);
119#endif
120
121    String m_pluginPath;
122
123    RefPtr<PluginProcessConnection> m_connection;
124    uint64_t m_pluginInstanceID;
125
126    PluginController* m_pluginController;
127
128    // The plug-in rect in window coordinates.
129    WebCore::IntRect m_frameRect;
130
131    // This is the backing store that we paint when we're told to paint.
132    RefPtr<ShareableBitmap> m_backingStore;
133
134    // This is the shared memory backing store that the plug-in paints into. When the plug-in tells us
135    // that it's painted something in it, we'll blit from it to our own backing store.
136    RefPtr<ShareableBitmap> m_pluginBackingStore;
137
138    // Whether all of the plug-in backing store contains valid data.
139    bool m_pluginBackingStoreContainsValidData;
140
141    bool m_isStarted;
142
143    // Whether we're called invalidate in response to an update call, and are now waiting for a paint call.
144    bool m_waitingForPaintInResponseToUpdate;
145
146    // The client ID for the CA layer in the plug-in process. Will be 0 if the plug-in is not a CA plug-in.
147    uint32_t m_remoteLayerClientID;
148
149#if PLATFORM(MAC)
150    RetainPtr<CALayer> m_pluginLayer;
151#endif
152};
153
154} // namespace WebKit
155
156#endif // ENABLE(PLUGIN_PROCESS)
157
158#endif // PluginProxy_h
159