• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PluginView_h
27 #define PluginView_h
28 
29 #include "NPRuntimeObjectMap.h"
30 #include "Plugin.h"
31 #include "PluginController.h"
32 #include "RunLoop.h"
33 #include "WebFrame.h"
34 
35 #include <WebCore/MediaCanStartListener.h>
36 #include <WebCore/ResourceError.h>
37 #include <WebCore/ResourceResponse.h>
38 #include <WebCore/PluginViewBase.h>
39 #include <wtf/Deque.h>
40 
41 // FIXME: Eventually this should move to WebCore.
42 
43 namespace WebCore {
44     class Frame;
45     class HTMLPlugInElement;
46 }
47 
48 namespace WebKit {
49 
50 class PluginView : public WebCore::PluginViewBase, WebCore::MediaCanStartListener, PluginController, WebFrame::LoadListener {
51 public:
52     static PassRefPtr<PluginView> create(PassRefPtr<WebCore::HTMLPlugInElement>, PassRefPtr<Plugin>, const Plugin::Parameters&);
53 
54     WebCore::Frame* frame();
55 
isBeingDestroyed()56     bool isBeingDestroyed() const { return m_isBeingDestroyed; }
57 
58     void manualLoadDidReceiveResponse(const WebCore::ResourceResponse&);
59     void manualLoadDidReceiveData(const char* bytes, int length);
60     void manualLoadDidFinishLoading();
61     void manualLoadDidFail(const WebCore::ResourceError&);
62 
63 #if PLATFORM(MAC)
64     void setWindowIsVisible(bool);
65     void setWindowIsFocused(bool);
66     void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
67     bool sendComplexTextInput(uint64_t pluginComplexTextInputIdentifier, const String& textInput);
68 #endif
69 
70 private:
71     PluginView(PassRefPtr<WebCore::HTMLPlugInElement>, PassRefPtr<Plugin>, const Plugin::Parameters& parameters);
72     virtual ~PluginView();
73 
74     void initializePlugin();
75     void destroyPlugin();
76 
77     void viewGeometryDidChange();
78     WebCore::IntRect clipRectInWindowCoordinates() const;
79     void focusPluginElement();
80 
81     void pendingURLRequestsTimerFired();
82     class URLRequest;
83     void performURLRequest(URLRequest*);
84 
85     // Perform a URL request where the frame target is not null.
86     void performFrameLoadURLRequest(URLRequest*);
87 
88     // Perform a URL request where the URL protocol is "javascript:".
89     void performJavaScriptURLRequest(URLRequest*);
90 
91     class Stream;
92     void addStream(Stream*);
93     void removeStream(Stream*);
94     void cancelAllStreams();
95 
96     void redeliverManualStream();
97 
98     // WebCore::PluginViewBase
99 #if PLATFORM(MAC)
100     virtual PlatformLayer* platformLayer() const;
101 #endif
102     virtual JSC::JSObject* scriptObject(JSC::JSGlobalObject*);
103     virtual void privateBrowsingStateChanged(bool);
104 
105     // WebCore::Widget
106     virtual void setFrameRect(const WebCore::IntRect&);
107     virtual void setBoundsSize(const WebCore::IntSize&);
108     virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect&);
109     virtual void invalidateRect(const WebCore::IntRect&);
110     virtual void setFocus(bool);
111     virtual void frameRectsChanged();
112     virtual void setParent(WebCore::ScrollView*);
113     virtual void handleEvent(WebCore::Event*);
114     virtual void notifyWidget(WebCore::WidgetNotification);
115 
116     // WebCore::MediaCanStartListener
117     virtual void mediaCanStart();
118 
119     // PluginController
120     virtual void invalidate(const WebCore::IntRect&);
121     virtual String userAgent();
122     virtual void loadURL(uint64_t requestID, const String& method, const String& urlString, const String& target,
123                          const WebCore::HTTPHeaderMap& headerFields, const Vector<uint8_t>& httpBody, bool allowPopups);
124     virtual void cancelStreamLoad(uint64_t streamID);
125     virtual void cancelManualStreamLoad();
126     virtual NPObject* windowScriptNPObject();
127     virtual NPObject* pluginElementNPObject();
128     virtual bool evaluate(NPObject*, const String&scriptString, NPVariant* result, bool allowPopups);
129     virtual void setStatusbarText(const String&);
130     virtual bool isAcceleratedCompositingEnabled();
131     virtual void pluginProcessCrashed();
132 #if PLATFORM(WIN)
133     virtual HWND nativeParentWindow();
134 #endif
135 #if PLATFORM(MAC)
136     virtual void setComplexTextInputEnabled(bool);
137     virtual mach_port_t compositingRenderServerPort();
138 #endif
139     virtual String proxiesForURL(const String&);
140     virtual String cookiesForURL(const String&);
141     virtual void setCookiesForURL(const String& urlString, const String& cookieString);
142     virtual bool isPrivateBrowsingEnabled();
143     virtual void protectPluginFromDestruction();
144     virtual void unprotectPluginFromDestruction();
145 
146     // WebFrame::LoadListener
147     virtual void didFinishLoad(WebFrame*);
148     virtual void didFailLoad(WebFrame*, bool wasCancelled);
149 
150     RefPtr<WebCore::HTMLPlugInElement> m_pluginElement;
151     RefPtr<Plugin> m_plugin;
152     WebPage* m_webPage;
153     Plugin::Parameters m_parameters;
154 
155     bool m_isInitialized;
156     bool m_isWaitingUntilMediaCanStart;
157     bool m_isBeingDestroyed;
158 
159     // Pending URLRequests that the plug-in has made.
160     Deque<RefPtr<URLRequest> > m_pendingURLRequests;
161     RunLoop::Timer<PluginView> m_pendingURLRequestsTimer;
162 
163     // Pending frame loads that the plug-in has made.
164     typedef HashMap<RefPtr<WebFrame>, RefPtr<URLRequest> > FrameLoadMap;
165     FrameLoadMap m_pendingFrameLoads;
166 
167     // Streams that the plug-in has requested to load.
168     HashMap<uint64_t, RefPtr<Stream> > m_streams;
169 
170     // A map of all related NPObjects for this plug-in view.
171     NPRuntimeObjectMap m_npRuntimeObjectMap;
172 
173     // The manual stream state. This is used so we can deliver a manual stream to a plug-in
174     // when it is initialized.
175     enum ManualStreamState {
176         StreamStateInitial,
177         StreamStateHasReceivedResponse,
178         StreamStateFinished,
179         StreamStateFailed
180     };
181     ManualStreamState m_manualStreamState;
182 
183     WebCore::ResourceResponse m_manualStreamResponse;
184     WebCore::ResourceError m_manualStreamError;
185     RefPtr<WebCore::SharedBuffer> m_manualStreamData;
186 
187     RefPtr<ShareableBitmap> m_snapshot;
188     WebCore::IntSize m_boundsSize;
189 };
190 
191 } // namespace WebKit
192 
193 #endif // PluginView_h
194