webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
PluginView.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Collabora Ltd. All rights reserved.
4  * Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef PluginView_h
29 #define PluginView_h
30 
31 #include "FrameLoadRequest.h"
32 #include "IntRect.h"
33 #include "MediaCanStartListener.h"
34 #include "PluginViewBase.h"
35 #include "ResourceRequest.h"
36 #include "Timer.h"
37 #include <wtf/HashMap.h>
38 #include <wtf/HashSet.h>
39 #include <wtf/RefPtr.h>
40 #include <wtf/Vector.h>
41 #include <wtf/text/CString.h>
42 
43 #if ENABLE(NETSCAPE_PLUGIN_API)
44 #include "PluginStream.h"
45 #include "npruntime_internal.h"
46 #endif
47 
48 typedef PlatformWidget PlatformPluginWidget;
49 
50 namespace JSC {
51  namespace Bindings {
52  class Instance;
53  }
54 }
55 
56 namespace WebCore {
57  class Frame;
58  class FrameView;
59  class Image;
60  class HTMLPlugInElement;
61  class KeyboardEvent;
62  class MouseEvent;
63  class URL;
64 #if ENABLE(NETSCAPE_PLUGIN_API)
65  class PluginMessageThrottlerWin;
66 #endif
67  class PluginPackage;
68  class PluginRequest;
69  class PluginStream;
70  class ResourceError;
71  class ResourceResponse;
72  class WheelEvent;
73 
74  enum PluginStatus {
78  };
79 
80  class PluginRequest {
82  public:
83  PluginRequest(const FrameLoadRequest& frameLoadRequest, bool sendNotification, void* notifyData, bool shouldAllowPopups)
84  : m_frameLoadRequest(frameLoadRequest)
85  , m_notifyData(notifyData)
86  , m_sendNotification(sendNotification)
87  , m_shouldAllowPopups(shouldAllowPopups) { }
88  public:
89  const FrameLoadRequest& frameLoadRequest() const { return m_frameLoadRequest; }
90  void* notifyData() const { return m_notifyData; }
91  bool sendNotification() const { return m_sendNotification; }
92  bool shouldAllowPopups() const { return m_shouldAllowPopups; }
93  private:
94  FrameLoadRequest m_frameLoadRequest;
95  void* m_notifyData;
96  bool m_sendNotification;
97  bool m_shouldAllowPopups;
98  };
99 
101  public:
102  virtual ~PluginManualLoader() {}
103  virtual void didReceiveResponse(const ResourceResponse&) = 0;
104  virtual void didReceiveData(const char*, int) = 0;
105  virtual void didFinishLoading() = 0;
106  virtual void didFail(const ResourceError&) = 0;
107  };
108 
109  class PluginView : public PluginViewBase
110 #if ENABLE(NETSCAPE_PLUGIN_API)
111  , private PluginStreamClient
112 #endif
113  , public PluginManualLoader
114  , private MediaCanStartListener {
115  public:
116  static Ref<PluginView> create(Frame* parentFrame, const IntSize&, HTMLPlugInElement*, const URL&, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually);
117  virtual ~PluginView();
118 
119  PluginPackage* plugin() const { return m_plugin.get(); }
120 #if ENABLE(NETSCAPE_PLUGIN_API)
121  NPP instance() const { return m_instance; }
122 #endif
123 
124  void setNPWindowRect(const IntRect&);
125  static PluginView* currentPluginView();
126 
127 #if ENABLE(NETSCAPE_PLUGIN_API)
128  NPObject* npObject();
129 #endif
130  RefPtr<JSC::Bindings::Instance> bindingInstance() override;
131 
132  PluginStatus status() const { return m_status; }
133 
134 #if ENABLE(NETSCAPE_PLUGIN_API)
135  // NPN functions
136  NPError getURLNotify(const char* url, const char* target, void* notifyData);
137  NPError getURL(const char* url, const char* target);
138  NPError postURLNotify(const char* url, const char* target, uint32_t len, const char* but, NPBool file, void* notifyData);
139  NPError postURL(const char* url, const char* target, uint32_t len, const char* but, NPBool file);
140  NPError newStream(NPMIMEType type, const char* target, NPStream** stream);
141  int32_t write(NPStream* stream, int32_t len, void* buffer);
142  NPError destroyStream(NPStream* stream, NPReason reason);
143 #endif
144  const char* userAgent();
145 #if ENABLE(NETSCAPE_PLUGIN_API)
146  static const char* userAgentStatic();
147 #endif
148  void status(const char* message);
149 
150 #if ENABLE(NETSCAPE_PLUGIN_API)
151  NPError getValue(NPNVariable variable, void* value);
152  static NPError getValueStatic(NPNVariable variable, void* value);
153  NPError setValue(NPPVariable variable, void* value);
154  NPError getValueForURL(NPNURLVariable variable, const char* url, char** value, uint32_t* len);
155  NPError setValueForURL(NPNURLVariable variable, const char* url, const char* value, uint32_t len);
156  NPError getAuthenticationInfo(const char* protocol, const char* host, int32_t port, const char* scheme, const char* realm, char** username, uint32_t* ulen, char** password, uint32_t* plen);
157  void invalidateRect(NPRect*);
158  void invalidateRegion(NPRegion);
159 #endif
160  void forceRedraw();
161  void pushPopupsEnabledState(bool state);
162  void popPopupsEnabledState();
163 
164  void invalidateRect(const IntRect&) override;
165 
166  bool arePopupsAllowed() const;
167 
168  void setJavaScriptPaused(bool) override;
169 
170  void privateBrowsingStateChanged(bool) override;
171 
172  void disconnectStream(PluginStream*);
173 #if ENABLE(NETSCAPE_PLUGIN_API)
174  void streamDidFinishLoading(PluginStream* stream) override { disconnectStream(stream); }
175 #endif
176 
177  // Widget functions
178  void setFrameRect(const IntRect&) override;
179  void frameRectsChanged() override;
180  void setFocus(bool) override;
181  void show() override;
182  void hide() override;
183  void paint(GraphicsContext&, const IntRect&) override;
184  void clipRectChanged() override;
185 
186  // This method is used by plugins on all platforms to obtain a clip rect that includes clips set by WebCore,
187  // e.g., in overflow:auto sections. The clip rects coordinates are in the containing window's coordinate space.
188  // This clip includes any clips that the widget itself sets up for its children.
189  IntRect windowClipRect() const;
190 
191  void handleEvent(Event*) override;
192  void setParent(ScrollView*) override;
193  void setParentVisible(bool) override;
194 
195  bool isPluginView() const override { return true; }
196 
197  Frame* parentFrame() const { return m_parentFrame.get(); }
198 
199  void focusPluginElement();
200 
201  const String& pluginsPage() const { return m_pluginsPage; }
202  const String& mimeType() const { return m_mimeType; }
203  const URL& url() const { return m_url; }
204 
205 #if ENABLE(NETSCAPE_PLUGIN_API)
206  static LRESULT CALLBACK PluginViewWndProc(HWND, UINT, WPARAM, LPARAM);
207  LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
208  WNDPROC pluginWndProc() const { return m_pluginWndProc; }
209 #endif
210 
211  // Used for manual loading
212  void didReceiveResponse(const ResourceResponse&) override;
213  void didReceiveData(const char*, int) override;
214  void didFinishLoading() override;
215  void didFail(const ResourceError&) override;
216 
217  static bool isCallingPlugin();
218 
219  bool start();
220 
221 #if ENABLE(NETSCAPE_PLUGIN_API)
222  static void keepAlive(NPP);
223 #endif
224  void keepAlive();
225 
226 #if PLATFORM(X11)
227  static Display* getPluginDisplay(Frame*);
228  static Window getRootWindow(Frame* parentFrame);
229 #endif
230 
231  private:
232  PluginView(Frame* parentFrame, const IntSize&, PluginPackage*, HTMLPlugInElement*, const URL&, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually);
233 
234  void setParameters(const Vector<String>& paramNames, const Vector<String>& paramValues);
235  bool startOrAddToUnstartedList();
236  void init();
237  bool platformStart();
238  void stop();
239  void platformDestroy();
240  static void setCurrentPluginView(PluginView*);
241 #if ENABLE(NETSCAPE_PLUGIN_API)
242  NPError load(const FrameLoadRequest&, bool sendNotification, void* notifyData);
243  NPError handlePost(const char* url, const char* target, uint32_t len, const char* buf, bool file, void* notifyData, bool sendNotification, bool allowHeaders);
244  NPError handlePostReadFile(Vector<char>& buffer, uint32_t len, const char* buf);
245 #endif
246  static void freeStringArray(char** stringArray, int length);
247  void setCallingPlugin(bool) const;
248 
249  void invalidateWindowlessPluginRect(const IntRect&);
250 
251  void mediaCanStart(Document&) override;
252 
253 #if ENABLE(NETSCAPE_PLUGIN_API)
254  void paintWindowedPluginIntoContext(GraphicsContext&, const IntRect&);
255  static HDC WINAPI hookedBeginPaint(HWND, PAINTSTRUCT*);
256  static BOOL WINAPI hookedEndPaint(HWND, const PAINTSTRUCT*);
257 #endif
258 
259 #if ENABLE(NETSCAPE_PLUGIN_API)
260  static bool platformGetValueStatic(NPNVariable variable, void* value, NPError* result);
261  bool platformGetValue(NPNVariable variable, void* value, NPError* result);
262 #endif
263 
264  RefPtr<Frame> m_parentFrame;
265  RefPtr<PluginPackage> m_plugin;
266  HTMLPlugInElement* m_element;
267  bool m_isStarted;
268  URL m_url;
269  PluginStatus m_status;
270  Vector<IntRect> m_invalidRects;
271 
272  void performRequest(PluginRequest*);
273  void scheduleRequest(std::unique_ptr<PluginRequest>);
274  void requestTimerFired();
275  void invalidateTimerFired();
276  Timer m_requestTimer;
277  Timer m_invalidateTimer;
278 
279  void popPopupsStateTimerFired();
280  Timer m_popPopupsStateTimer;
281 
282  void lifeSupportTimerFired();
283  Timer m_lifeSupportTimer;
284 
285 #if ENABLE(NETSCAPE_PLUGIN_API)
286  bool dispatchNPEvent(NPEvent&);
287 #endif
288 
289  void updatePluginWidget();
290  void paintMissingPluginIcon(GraphicsContext&, const IntRect&);
291 
292  void handleKeyboardEvent(KeyboardEvent*);
293  void handleMouseEvent(MouseEvent*);
294 
295  void paintIntoTransformedContext(HDC);
296  RefPtr<Image> snapshot();
297 
298  float deviceScaleFactor() const;
299 
300  int m_mode;
301  int m_paramCount;
302  char** m_paramNames;
303  char** m_paramValues;
304  String m_pluginsPage;
305 
306  String m_mimeType;
307  WTF::CString m_userAgent;
308 
309 #if ENABLE(NETSCAPE_PLUGIN_API)
310  NPP m_instance;
311  NPP_t m_instanceStruct;
312  NPWindow m_npWindow;
313 #endif
314 
315  NPObject* m_elementNPObject;
316 
317  Vector<bool, 4> m_popupStateStack;
318 
319  HashSet<RefPtr<PluginStream> > m_streams;
321 
322  bool m_isWindowed;
323  bool m_isTransparent;
324  bool m_haveInitialized;
325  bool m_isWaitingToStart;
326 
327 #if ENABLE(NETSCAPE_PLUGIN_API)
328  std::unique_ptr<PluginMessageThrottlerWin> m_messageThrottler;
329  WNDPROC m_pluginWndProc;
330  unsigned m_lastMessage;
331  bool m_isCallingPluginWndProc;
332  HDC m_wmPrintHDC;
333  bool m_haveUpdatedPluginWidget;
334 #endif
335 
336 public:
337  void setPlatformPluginWidget(PlatformPluginWidget widget) { setPlatformWidget(widget); }
338  PlatformPluginWidget platformPluginWidget() const { return platformWidget(); }
339 
340 private:
341  IntRect m_clipRect; // The clip rect to apply to a windowed plug-in
342  IntRect m_windowRect; // Our window rect.
343 
344  bool m_loadManually;
345  RefPtr<PluginStream> m_manualStream;
346 
347  bool m_isJavaScriptPaused;
348 
349  bool m_haveCalledSetWindow;
350 
351  static PluginView* s_currentPluginView;
352  };
353 
355 {
356  ASSERT(!widget || widget->isPluginView());
357  return static_cast<PluginView*>(widget);
358 }
359 
360 inline const PluginView* toPluginView(const Widget* widget)
361 {
362  ASSERT(!widget || widget->isPluginView());
363  return static_cast<const PluginView*>(widget);
364 }
365 
366 // This will catch anyone doing an unnecessary cast.
367 void toPluginView(const PluginView*);
368 
369 } // namespace WebCore
370 
371 #endif
void write(TextStream &, const RenderObject &, int indent=0, RenderAsTextBehavior=RenderAsTextBehaviorNormal)
Definition: RenderTreeAsText.cpp:529
Definition: FrameLoadRequest.h:36
bool sendNotification() const
Definition: PluginView.h:91
BOOL
Definition: PlatformScreenIOS.mm:46
USVString protocol
Definition: RTCPeerConnection.idl:48
Definition: npapi.h:176
virtual bool isPluginView() const
Definition: Widget.h:136
Definition: MouseEvent.h:34
Definition: Timer.h:131
EGLStreamKHR stream
Definition: eglext.h:340
bool shouldAllowPopups() const
Definition: PluginView.h:92
unsigned char NPBool
Definition: npapi.h:158
EGLOutputPortEXT port
Definition: eglext.h:698
Definition: Document.h:277
signed int int32_t
Definition: ptypes.h:101
PluginPackage * plugin() const
Definition: PluginView.h:119
unsigned int uint32_t
Definition: ptypes.h:105
Definition: npapi.h:462
NPNVariable
Definition: npapi.h:390
Definition: PluginViewBase.h:46
void * notifyData() const
Definition: PluginView.h:90
Definition: AirOpcode.h:4
EGLContext EGLenum target
Definition: eglext.h:192
int16_t NPReason
Definition: npapi.h:160
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: gl2ext.h:134
int16_t NPError
Definition: npapi.h:159
NPNURLVariable
Definition: npapi.h:440
const FrameLoadRequest & frameLoadRequest() const
Definition: PluginView.h:89
std::unique_ptr< Layout > create(RenderBlockFlow &)
Definition: SimpleLineLayout.cpp:861
Definition: WheelEvent.idl:24
Definition: npapi.h:184
Definition: IntRect.h:70
PluginStatus status() const
Definition: PluginView.h:132
const String & pluginsPage() const
Definition: PluginView.h:201
Definition: PluginPackage.h:46
struct HWND__ * HWND
Definition: DumpRenderTreeWin.h:38
Definition: GraphicsContext.h:245
Definition: status.py:1
PluginRequest(const FrameLoadRequest &frameLoadRequest, bool sendNotification, void *notifyData, bool shouldAllowPopups)
Definition: PluginView.h:83
Definition: WTFString.h:78
GLuint start
Definition: gl2ext.h:323
Definition: PluginStream.h:57
String getURL(IDataObject *dataObject, DragData::FilenameConversionPolicy filenamePolicy, String *title)
Definition: ClipboardUtilitiesWin.cpp:455
VoEFile * file
Definition: voe_cmd_test.cc:59
char * NPMIMEType
Definition: npapi.h:161
bool isPluginView() const override
Definition: PluginView.h:195
PlatformPluginWidget platformPluginWidget() const
Definition: PluginView.h:338
Definition: PluginView.h:80
Definition: PluginView.h:100
void * NPEvent
Definition: npapi.h:525
OPENSSL_EXPORT const ASN1_OBJECT int const unsigned char int len
Definition: x509.h:1053
Definition: PluginView.h:77
const AtomicString & password()
Definition: InputTypeNames.cpp:106
void setPlatformPluginWidget(PlatformPluginWidget widget)
Definition: PluginView.h:337
Definition: ScrollView.h:63
Definition: MediaCanStartListener.h:32
const String & mimeType() const
Definition: PluginView.h:202
EGLAttrib * value
Definition: eglext.h:120
XID Window
Definition: platform_glx.h:181
Definition: PluginView.h:109
PlatformWidget PlatformPluginWidget
Definition: PluginView.h:48
#define WTF_MAKE_NONCOPYABLE(ClassName)
Definition: Noncopyable.h:24
WINAPI
Definition: RenderThemeWin.cpp:150
Definition: CString.h:56
const URL & url() const
Definition: PluginView.h:203
Definition: KeyboardEvent.idl:23
Definition: Forward.h:36
Definition: MouseEvent.idl:23
USVString reason
Definition: CloseEvent.idl:43
Definition: KeyboardEvent.h:37
EGLenum type
Definition: eglext.h:63
Definition: ResourceError.h:45
result
Definition: target-blank-opener-post-window.php:5
void init()
Definition: HTMLNames.cpp:1637
DOMString username
Definition: RTCIceServer.idl:31
url
Definition: setup.py:223
Definition: PluginStream.h:51
Definition: ProfilerEvent.h:37
Definition: npruntime.h:323
struct _XDisplay Display
Definition: shared_x_display.h:25
void toPluginView(const PluginView *)
Definition: PluginView.h:76
Definition: URL.h:52
Definition: HashSet.h:33
Definition: ResourceResponse.h:39
EGLContext EGLenum EGLClientBuffer buffer
Definition: eglext.h:192
void * NPRegion
Definition: npapi.h:539
#define ASSERT(assertion)
Definition: Assertions.h:283
plen
Definition: parse_delay_file.m:33
virtual ~PluginManualLoader()
Definition: PluginView.h:102
GLuint GLsizei const GLchar * message
Definition: gl2ext.h:137
This file is generated by create-http-header-name-table, do not edit.
Definition: CharsetData.cpp:6
Definition: Frame.h:113
CFAllocatorRef CFURLRef URL
Definition: AVFoundationCFSoftLinking.h:225
string state
Definition: buildtests.py:34
Definition: PluginView.h:75
Definition: HTMLPlugInElement.h:41
GLuint GLsizei GLsizei * length
Definition: gl2.h:435
Definition: IntSize.h:69
#define WTF_MAKE_FAST_ALLOCATED
Definition: FastMalloc.h:139
NPPVariable
Definition: npapi.h:335
Definition: Widget.h:93
Definition: npapi.h:217
PluginStatus
Definition: PluginView.h:74
Frame * parentFrame() const
Definition: PluginView.h:197