[Release] Webkit-EFL Ver. 2.0_beta_118996_0.6.24
[framework/web/webkit-efl.git] / Source / WebCore / plugins / PluginView.h
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 COMPUTER, 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 COMPUTER, 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/OwnPtr.h>
40 #include <wtf/PassRefPtr.h>
41 #include <wtf/RefPtr.h>
42 #include <wtf/Vector.h>
43 #include <wtf/text/CString.h>
44 #if ENABLE(TOUCH_EVENTS) && PLATFORM(EFL) && ENABLE(TIZEN_NPAPI)
45 #include "Touch.h"
46 #include "TouchEvent.h"
47 #include "TouchList.h"
48 #endif
49 #if ENABLE(NETSCAPE_PLUGIN_API)
50 #include "PluginStream.h"
51 #include "npruntime_internal.h"
52 #endif
53
54 #if OS(WINDOWS) && (PLATFORM(QT) || PLATFORM(WX))
55 typedef struct HWND__* HWND;
56 typedef HWND PlatformPluginWidget;
57 #elif ENABLE(TIZEN_SUPPORT_PLUGINS)
58 class X11EmbedContainer;
59 typedef X11EmbedContainer* PlatformPluginWidget;
60 #else
61 typedef PlatformWidget PlatformPluginWidget;
62 #if defined(XP_MACOSX) && PLATFORM(QT)
63 #include <QPixmap>
64 #endif
65 #endif
66 #if PLATFORM(QT)
67 #if USE(TEXTURE_MAPPER)
68 #include "TextureMapperPlatformLayer.h"
69 #endif
70
71 #include <QImage>
72 QT_BEGIN_NAMESPACE
73 class QPainter;
74 QT_END_NAMESPACE
75 #endif
76 #if PLATFORM(QT) && USE(ACCELERATED_COMPOSITING) && ENABLE(NETSCAPE_PLUGIN_API) && defined(XP_UNIX)
77 #ifndef WTF_USE_ACCELERATED_COMPOSITING_PLUGIN_LAYER
78 #define WTF_USE_ACCELERATED_COMPOSITING_PLUGIN_LAYER 1
79 #endif
80 #endif
81 #if PLATFORM(GTK)
82 typedef struct _GtkSocket GtkSocket;
83 #endif
84
85 #if USE(JSC)
86 //mariusz.g@samsung.com
87 #if ENABLE(TIZEN_EVAS_OBJECT_PLUGIN) && PLATFORM(EFL)
88 #include <Evas.h>
89 #endif
90
91 namespace JSC {
92     namespace Bindings {
93         class Instance;
94     }
95 }
96 #endif
97
98 #if ENABLE(TIZEN_EVAS_OBJECT_PLUGIN) && PLATFORM(EFL)
99 typedef struct _PluginStorage PluginStorage;
100 struct _PluginStorage {
101     Evas_Object *pluginCanvas;
102     Evas_Object *pluginClipper;
103     Evas_Object *parentWindow;
104     Evas_Object *webview;
105 };
106 #endif
107
108 namespace WebCore {
109     class Frame;
110     class Image;
111     class HTMLPlugInElement;
112     class KeyboardEvent;
113     class MouseEvent;
114     class KURL;
115 #if OS(WINDOWS) && ENABLE(NETSCAPE_PLUGIN_API)
116     class PluginMessageThrottlerWin;
117 #endif
118     class PluginPackage;
119     class PluginRequest;
120     class PluginStream;
121     class ResourceError;
122     class ResourceResponse;
123
124     enum PluginStatus {
125         PluginStatusCanNotFindPlugin,
126         PluginStatusCanNotLoadPlugin,
127         PluginStatusLoadedSuccessfully
128     };
129
130     class PluginRequest {
131         WTF_MAKE_NONCOPYABLE(PluginRequest); WTF_MAKE_FAST_ALLOCATED;
132     public:
133         PluginRequest(const FrameLoadRequest& frameLoadRequest, bool sendNotification, void* notifyData, bool shouldAllowPopups)
134             : m_frameLoadRequest(frameLoadRequest)
135             , m_notifyData(notifyData)
136             , m_sendNotification(sendNotification)
137             , m_shouldAllowPopups(shouldAllowPopups) { }
138     public:
139         const FrameLoadRequest& frameLoadRequest() const { return m_frameLoadRequest; }
140         void* notifyData() const { return m_notifyData; }
141         bool sendNotification() const { return m_sendNotification; }
142         bool shouldAllowPopups() const { return m_shouldAllowPopups; }
143     private:
144         FrameLoadRequest m_frameLoadRequest;
145         void* m_notifyData;
146         bool m_sendNotification;
147         bool m_shouldAllowPopups;
148     };
149
150     class PluginManualLoader {
151     public:
152         virtual ~PluginManualLoader() {}
153         virtual void didReceiveResponse(const ResourceResponse&) = 0;
154         virtual void didReceiveData(const char*, int) = 0;
155         virtual void didFinishLoading() = 0;
156         virtual void didFail(const ResourceError&) = 0;
157     };
158
159     class PluginView : public PluginViewBase
160 #if ENABLE(NETSCAPE_PLUGIN_API)
161                      , private PluginStreamClient
162 #endif
163                      , public PluginManualLoader
164                      , private MediaCanStartListener {
165     public:
166         static PassRefPtr<PluginView> create(Frame* parentFrame, const IntSize&, HTMLPlugInElement*, const KURL&, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually);
167         virtual ~PluginView();
168
169         PluginPackage* plugin() const { return m_plugin.get(); }
170 #if ENABLE(NETSCAPE_PLUGIN_API)
171         NPP instance() const { return m_instance; }
172 #endif
173
174         void setNPWindowRect(const IntRect&);
175         static PluginView* currentPluginView();
176
177 #if ENABLE(NETSCAPE_PLUGIN_API)
178         NPObject* npObject();
179 #endif
180 #if USE(JSC)
181         PassRefPtr<JSC::Bindings::Instance> bindingInstance();
182 #endif
183
184         PluginStatus status() const { return m_status; }
185
186 #if ENABLE(NETSCAPE_PLUGIN_API)
187         // NPN functions
188         NPError getURLNotify(const char* url, const char* target, void* notifyData);
189         NPError getURL(const char* url, const char* target);
190         NPError postURLNotify(const char* url, const char* target, uint32_t len, const char* but, NPBool file, void* notifyData);
191         NPError postURL(const char* url, const char* target, uint32_t len, const char* but, NPBool file);
192         NPError newStream(NPMIMEType type, const char* target, NPStream** stream);
193         int32_t write(NPStream* stream, int32_t len, void* buffer);
194         NPError destroyStream(NPStream* stream, NPReason reason);
195 #endif
196         const char* userAgent();
197 #if ENABLE(NETSCAPE_PLUGIN_API)
198         static const char* userAgentStatic();
199 #endif
200         void status(const char* message);
201         
202 #if ENABLE(NETSCAPE_PLUGIN_API)
203         NPError getValue(NPNVariable variable, void* value);
204         static NPError getValueStatic(NPNVariable variable, void* value);
205         NPError setValue(NPPVariable variable, void* value);
206         NPError getValueForURL(NPNURLVariable variable, const char* url, char** value, uint32_t* len);
207         NPError setValueForURL(NPNURLVariable variable, const char* url, const char* value, uint32_t len);
208         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);
209         void invalidateRect(NPRect*);
210         void invalidateRegion(NPRegion);
211 #endif
212         void forceRedraw();
213         void pushPopupsEnabledState(bool state);
214         void popPopupsEnabledState();
215
216         virtual void invalidateRect(const IntRect&);
217
218         bool arePopupsAllowed() const;
219
220         void setJavaScriptPaused(bool);
221
222         void privateBrowsingStateChanged(bool);
223
224         void disconnectStream(PluginStream*);
225         void streamDidFinishLoading(PluginStream* stream) { disconnectStream(stream); }
226
227         // Widget functions
228         virtual void setFrameRect(const IntRect&);
229         virtual void frameRectsChanged();
230         virtual void setFocus(bool);
231         virtual void show();
232         virtual void hide();
233         virtual void paint(GraphicsContext*, const IntRect&);
234
235         // This method is used by plugins on all platforms to obtain a clip rect that includes clips set by WebCore,
236         // e.g., in overflow:auto sections.  The clip rects coordinates are in the containing window's coordinate space.
237         // This clip includes any clips that the widget itself sets up for its children.
238         IntRect windowClipRect() const;
239
240         virtual void handleEvent(Event*);
241         virtual void setParent(ScrollView*);
242         virtual void setParentVisible(bool);
243
244         virtual bool isPluginView() const { return true; }
245
246         Frame* parentFrame() const { return m_parentFrame.get(); }
247
248         void focusPluginElement();
249
250         const String& pluginsPage() const { return m_pluginsPage; }
251         const String& mimeType() const { return m_mimeType; }
252         const KURL& url() const { return m_url; }
253
254 #if OS(WINDOWS) && ENABLE(NETSCAPE_PLUGIN_API)
255         static LRESULT CALLBACK PluginViewWndProc(HWND, UINT, WPARAM, LPARAM);
256         LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
257         WNDPROC pluginWndProc() const { return m_pluginWndProc; }
258 #endif
259
260         // Used for manual loading
261         void didReceiveResponse(const ResourceResponse&);
262         void didReceiveData(const char*, int);
263         void didFinishLoading();
264         void didFail(const ResourceError&);
265
266         static bool isCallingPlugin();
267
268         bool start();
269
270 #if ENABLE(NETSCAPE_PLUGIN_API)
271         static void keepAlive(NPP);
272 #endif
273         void keepAlive();
274
275 #if USE(ACCELERATED_COMPOSITING)
276 #if USE(ACCELERATED_COMPOSITING_PLUGIN_LAYER)
277         virtual PlatformLayer* platformLayer() const;
278         bool shouldUseAcceleratedCompositing() const;
279 #else
280         virtual PlatformLayer* platformLayer() const { return 0; }
281 #endif
282 #endif
283
284 #if PLATFORM(QT) && ENABLE(NETSCAPE_PLUGIN_API) && defined(XP_UNIX)
285         // PluginViewQt (X11) needs a few workarounds when running under DRT
286         static void setIsRunningUnderDRT(bool flag) { s_isRunningUnderDRT = flag; }
287 #endif
288
289 #if PLATFORM(EFL)
290 #if ENABLE(NETSCAPE_PLUGIN_API)
291         bool dispatchWheelEvent(NPEvent*);
292 #if ENABLE(TIZEN_NPAPI)
293         bool dispatchTNPEvent(TNPEvent*);
294 #endif
295 #endif
296         bool isPluginStarted() const { return m_isStarted; }
297 #if ENABLE(NETSCAPE_PLUGIN_API) && ENABLE(TIZEN_SUPPORT_PLUGINS) && ENABLE(TIZEN_DONT_PAN_OVER_SOME_PLUGINS)
298         static bool isPluginHandlingEvents() { return s_isHandlingEvents; }
299         static void setPluginHandlingEvents(bool isHandling);
300         static PluginView* currentPluginHandlingEvents() { return s_currentPluginHandlingEvents; }
301 #endif // ENABLE(NETSCAPE_PLUGIN_API) && ENABLE(TIZEN_SUPPORT_PLUGINS) && ENABLE(TIZEN_DONT_PAN_OVER_SOME_PLUGINS)
302 #if ENABLE(TIZEN_EVAS_OBJECT_PLUGIN)
303         Evas_Object* getPluginCanvas() { return m_pluginEvasObject; }
304         Evas_Object* getPluginClipper() { return m_pluginEvasObjectClipper; }
305 #endif
306 #endif // PLATFORM(EFL)
307
308     private:
309         PluginView(Frame* parentFrame, const IntSize&, PluginPackage*, HTMLPlugInElement*, const KURL&, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually);
310
311         void setParameters(const Vector<String>& paramNames, const Vector<String>& paramValues);
312         bool startOrAddToUnstartedList();
313         void init();
314         bool platformStart();
315         void stop();
316         void platformDestroy();
317         static void setCurrentPluginView(PluginView*);
318 #if ENABLE(NETSCAPE_PLUGIN_API)
319         NPError load(const FrameLoadRequest&, bool sendNotification, void* notifyData);
320         NPError handlePost(const char* url, const char* target, uint32_t len, const char* buf, bool file, void* notifyData, bool sendNotification, bool allowHeaders);
321         NPError handlePostReadFile(Vector<char>& buffer, uint32_t len, const char* buf);
322 #endif
323         static void freeStringArray(char** stringArray, int length);
324         void setCallingPlugin(bool) const;
325
326         void invalidateWindowlessPluginRect(const IntRect&);
327
328         virtual void mediaCanStart();
329
330 #if OS(WINDOWS) && ENABLE(NETSCAPE_PLUGIN_API)
331         void paintWindowedPluginIntoContext(GraphicsContext*, const IntRect&);
332         static HDC WINAPI hookedBeginPaint(HWND, PAINTSTRUCT*);
333         static BOOL WINAPI hookedEndPaint(HWND, const PAINTSTRUCT*);
334 #endif
335
336 #if ENABLE(NETSCAPE_PLUGIN_API)
337         static bool platformGetValueStatic(NPNVariable variable, void* value, NPError* result);
338         bool platformGetValue(NPNVariable variable, void* value, NPError* result);
339 #endif
340
341         RefPtr<Frame> m_parentFrame;
342         RefPtr<PluginPackage> m_plugin;
343         HTMLPlugInElement* m_element;
344         bool m_isStarted;
345         KURL m_url;
346         PluginStatus m_status;
347         Vector<IntRect> m_invalidRects;
348
349         void performRequest(PluginRequest*);
350         void scheduleRequest(PluginRequest*);
351         void requestTimerFired(Timer<PluginView>*);
352         void invalidateTimerFired(Timer<PluginView>*);
353         Timer<PluginView> m_requestTimer;
354         Timer<PluginView> m_invalidateTimer;
355
356         void popPopupsStateTimerFired(Timer<PluginView>*);
357         Timer<PluginView> m_popPopupsStateTimer;
358
359         void lifeSupportTimerFired(Timer<PluginView>*);
360         Timer<PluginView> m_lifeSupportTimer;
361
362 #ifndef NP_NO_CARBON
363 #if ENABLE(NETSCAPE_PLUGIN_API)
364         bool dispatchNPEvent(NPEvent&);
365 #endif // ENABLE(NETSCAPE_PLUGIN_API)
366 #endif
367         void updatePluginWidget();
368         void paintMissingPluginIcon(GraphicsContext*, const IntRect&);
369
370         void handleKeyboardEvent(KeyboardEvent*);
371         void handleMouseEvent(MouseEvent*);
372 #if ENABLE(TOUCH_EVENTS) && PLATFORM(EFL) && ENABLE(TIZEN_NPAPI)
373         void handleTouchEvent(TouchEvent*);
374 #endif
375 #if defined(XP_UNIX) && ENABLE(NETSCAPE_PLUGIN_API)
376         void handleFocusInEvent();
377         void handleFocusOutEvent();
378 #endif
379
380 #if OS(WINDOWS)
381         void paintIntoTransformedContext(HDC);
382         PassRefPtr<Image> snapshot();
383 #endif
384
385         int m_mode;
386         int m_paramCount;
387         char** m_paramNames;
388         char** m_paramValues;
389         String m_pluginsPage;
390
391         String m_mimeType;
392         WTF::CString m_userAgent;
393
394 #if ENABLE(NETSCAPE_PLUGIN_API)
395         NPP m_instance;
396         NPP_t m_instanceStruct;
397         NPWindow m_npWindow;
398 #endif
399
400         Vector<bool, 4> m_popupStateStack;
401
402         HashSet<RefPtr<PluginStream> > m_streams;
403         Vector<PluginRequest*> m_requests;
404
405         bool m_isWindowed;
406         bool m_isTransparent;
407         bool m_haveInitialized;
408         bool m_isWaitingToStart;
409
410 #if defined(XP_UNIX)
411         bool m_needsXEmbed;
412 #endif
413
414 #if OS(WINDOWS) && ENABLE(NETSCAPE_PLUGIN_API)
415         OwnPtr<PluginMessageThrottlerWin> m_messageThrottler;
416         WNDPROC m_pluginWndProc;
417         unsigned m_lastMessage;
418         bool m_isCallingPluginWndProc;
419         HDC m_wmPrintHDC;
420         bool m_haveUpdatedPluginWidget;
421 #endif
422
423 #if ((PLATFORM(QT) || PLATFORM(WX)) && OS(WINDOWS)) || defined(XP_MACOSX) || PLATFORM(EFL)
424         // On Mac OSX and Qt/Windows the plugin does not have its own native widget,
425         // but is using the containing window as its reference for positioning/painting.
426         PlatformPluginWidget m_window;
427 public:
428         PlatformPluginWidget platformPluginWidget() const { return m_window; }
429         void setPlatformPluginWidget(PlatformPluginWidget widget) { m_window = widget; }
430 #else
431 public:
432         void setPlatformPluginWidget(PlatformPluginWidget widget) { setPlatformWidget(widget); }
433         PlatformPluginWidget platformPluginWidget() const { return platformWidget(); }
434 #endif
435
436 private:
437
438 #if defined(XP_UNIX) || PLATFORM(GTK)
439         void setNPWindowIfNeeded();
440 #elif defined(XP_MACOSX)
441         NP_CGContext m_npCgContext;
442         OwnPtr<Timer<PluginView> > m_nullEventTimer;
443         NPDrawingModel m_drawingModel;
444         NPEventModel m_eventModel;
445         CGContextRef m_contextRef;
446         WindowRef m_fakeWindow;
447 #if PLATFORM(QT)
448         QPixmap m_pixmap;
449 #endif
450
451         Point m_lastMousePos;
452         void setNPWindowIfNeeded();
453         void nullEventTimerFired(Timer<PluginView>*);
454         Point globalMousePosForPlugin() const;
455         Point mousePosForPlugin(MouseEvent* event = 0) const;
456 #endif
457
458 #if defined(XP_UNIX) && ENABLE(NETSCAPE_PLUGIN_API)
459         bool m_hasPendingGeometryChange;
460         Pixmap m_drawable;
461         Visual* m_visual;
462         Colormap m_colormap;
463         Display* m_pluginDisplay;
464
465         void initXEvent(XEvent* event);
466 #endif
467
468 #if PLATFORM(QT)
469 #if defined(XP_UNIX) && ENABLE(NETSCAPE_PLUGIN_API)
470         static bool s_isRunningUnderDRT;
471         static void setXKeyEventSpecificFields(XEvent*, KeyboardEvent*);
472         void paintUsingXPixmap(QPainter* painter, const QRect &exposedRect);
473         QWebPageClient* platformPageClient() const;
474 #endif
475 #if USE(ACCELERATED_COMPOSITING_PLUGIN_LAYER)
476         OwnPtr<PlatformLayer> m_platformLayer;
477         friend class PluginGraphicsLayerQt;
478 #endif // USE(ACCELERATED_COMPOSITING_PLUGIN_LAYER)
479 #endif // PLATFORM(QT)
480
481 #if PLATFORM(GTK)
482         static gboolean plugRemovedCallback(GtkSocket*, PluginView*);
483         static void plugAddedCallback(GtkSocket*, PluginView*);
484         void updateWidgetAllocationAndClip();
485         bool m_plugAdded;
486         IntRect m_delayedAllocation;
487 #endif
488
489         IntRect m_clipRect; // The clip rect to apply to a windowed plug-in
490         IntRect m_windowRect; // Our window rect.
491
492         bool m_loadManually;
493         RefPtr<PluginStream> m_manualStream;
494
495         bool m_isJavaScriptPaused;
496
497         bool m_haveCalledSetWindow;
498
499         static PluginView* s_currentPluginView;
500
501 //mariusz.g@samsung.com
502 #if PLATFORM(EFL)
503 #if ENABLE(TIZEN_EVAS_OBJECT_PLUGIN)
504         Evas_Object *m_pluginEvasObject;
505         Evas_Object *m_pluginEvasObjectClipper;
506         Evas_Object *m_pluginParentWindow;
507         Evas_Object *m_pluginWebview;
508         bool m_lastEventWasHandled;
509 #endif
510
511 #if ENABLE(TIZEN_SUPPORT_PLUGINS) && ENABLE(TIZEN_DONT_PAN_OVER_SOME_PLUGINS)
512         static bool s_isHandlingEvents;
513         static PluginView* s_currentPluginHandlingEvents;
514 #endif
515 #endif
516     };
517
518 } // namespace WebCore
519
520 #endif