src/3rdparty/webkit/WebCore/plugins/PluginView.h
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /*
       
     2  * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
       
     3  * Copyright (C) 2008 Collabora Ltd. All rights reserved.
       
     4  *
       
     5  * Redistribution and use in source and binary forms, with or without
       
     6  * modification, are permitted provided that the following conditions
       
     7  * are met:
       
     8  * 1. Redistributions of source code must retain the above copyright
       
     9  *    notice, this list of conditions and the following disclaimer.
       
    10  * 2. Redistributions in binary form must reproduce the above copyright
       
    11  *    notice, this list of conditions and the following disclaimer in the
       
    12  *    documentation and/or other materials provided with the distribution.
       
    13  *
       
    14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
       
    15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       
    16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       
    17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
       
    18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
       
    19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       
    20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
       
    21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
       
    22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
       
    25  */
       
    26 
       
    27 #ifndef PluginView_H
       
    28 #define PluginView_H
       
    29 
       
    30 #include "CString.h"
       
    31 #include "FrameLoadRequest.h"
       
    32 #include "HaltablePlugin.h"
       
    33 #include "IntRect.h"
       
    34 #include "KURL.h"
       
    35 #include "PlatformString.h"
       
    36 #include "PluginStream.h"
       
    37 #include "ResourceRequest.h"
       
    38 #include "Timer.h"
       
    39 #include "Widget.h"
       
    40 #include "npruntime_internal.h"
       
    41 #include <wtf/HashMap.h>
       
    42 #include <wtf/HashSet.h>
       
    43 #include <wtf/OwnPtr.h>
       
    44 #include <wtf/PassRefPtr.h>
       
    45 #include <wtf/RefPtr.h>
       
    46 #include <wtf/Vector.h>
       
    47 
       
    48 #if PLATFORM(WIN_OS) && PLATFORM(QT)
       
    49 typedef struct HWND__* HWND;
       
    50 typedef HWND PlatformPluginWidget;
       
    51 #else
       
    52 typedef PlatformWidget PlatformPluginWidget;
       
    53 #endif
       
    54 
       
    55 namespace JSC {
       
    56     namespace Bindings {
       
    57         class Instance;
       
    58     }
       
    59 }
       
    60 
       
    61 namespace WebCore {
       
    62     class Element;
       
    63     class Frame;
       
    64     class KeyboardEvent;
       
    65     class MouseEvent;
       
    66     class KURL;
       
    67 #if PLATFORM(WIN_OS) && !PLATFORM(WX) && ENABLE(NETSCAPE_PLUGIN_API)
       
    68     class PluginMessageThrottlerWin;
       
    69 #endif
       
    70     class PluginPackage;
       
    71     class PluginRequest;
       
    72     class PluginStream;
       
    73     class ResourceError;
       
    74     class ResourceResponse;
       
    75 
       
    76     enum PluginStatus {
       
    77         PluginStatusCanNotFindPlugin,
       
    78         PluginStatusCanNotLoadPlugin,
       
    79         PluginStatusLoadedSuccessfully
       
    80     };
       
    81 
       
    82     class PluginRequest {
       
    83     public:
       
    84         PluginRequest(const FrameLoadRequest& frameLoadRequest, bool sendNotification, void* notifyData, bool shouldAllowPopups)
       
    85             : m_frameLoadRequest(frameLoadRequest)
       
    86             , m_notifyData(notifyData)
       
    87             , m_sendNotification(sendNotification)
       
    88             , m_shouldAllowPopups(shouldAllowPopups) { }
       
    89     public:
       
    90         const FrameLoadRequest& frameLoadRequest() const { return m_frameLoadRequest; }
       
    91         void* notifyData() const { return m_notifyData; }
       
    92         bool sendNotification() const { return m_sendNotification; }
       
    93         bool shouldAllowPopups() const { return m_shouldAllowPopups; }
       
    94     private:
       
    95         FrameLoadRequest m_frameLoadRequest;
       
    96         void* m_notifyData;
       
    97         bool m_sendNotification;
       
    98         bool m_shouldAllowPopups;
       
    99     };
       
   100 
       
   101     class PluginManualLoader {
       
   102     public:
       
   103         virtual ~PluginManualLoader() {}
       
   104         virtual void didReceiveResponse(const ResourceResponse&) = 0;
       
   105         virtual void didReceiveData(const char*, int) = 0;
       
   106         virtual void didFinishLoading() = 0;
       
   107         virtual void didFail(const ResourceError&) = 0;
       
   108     };
       
   109 
       
   110     class PluginView : public Widget, private PluginStreamClient, public PluginManualLoader, private HaltablePlugin {
       
   111     public:
       
   112         static PassRefPtr<PluginView> create(Frame* parentFrame, const IntSize&, Element*, const KURL&, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually);
       
   113         virtual ~PluginView();
       
   114 
       
   115         PluginPackage* plugin() const { return m_plugin.get(); }
       
   116         NPP instance() const { return m_instance; }
       
   117 
       
   118         void setNPWindowRect(const IntRect&);
       
   119         static PluginView* currentPluginView();
       
   120 
       
   121         PassRefPtr<JSC::Bindings::Instance> bindingInstance();
       
   122 
       
   123         PluginStatus status() const { return m_status; }
       
   124 
       
   125         // NPN functions
       
   126         NPError getURLNotify(const char* url, const char* target, void* notifyData);
       
   127         NPError getURL(const char* url, const char* target);
       
   128         NPError postURLNotify(const char* url, const char* target, uint32 len, const char* but, NPBool file, void* notifyData);
       
   129         NPError postURL(const char* url, const char* target, uint32 len, const char* but, NPBool file);
       
   130         NPError newStream(NPMIMEType type, const char* target, NPStream** stream);
       
   131         int32 write(NPStream* stream, int32 len, void* buffer);
       
   132         NPError destroyStream(NPStream* stream, NPReason reason);
       
   133         const char* userAgent();
       
   134 #if ENABLE(NETSCAPE_PLUGIN_API)
       
   135         static const char* userAgentStatic();
       
   136 #endif
       
   137         void status(const char* message);
       
   138         NPError getValue(NPNVariable variable, void* value);
       
   139 #if ENABLE(NETSCAPE_PLUGIN_API)
       
   140         static NPError getValueStatic(NPNVariable variable, void* value);
       
   141 #endif
       
   142         NPError setValue(NPPVariable variable, void* value);
       
   143         void invalidateRect(NPRect*);
       
   144         void invalidateRegion(NPRegion);
       
   145         void forceRedraw();
       
   146         void pushPopupsEnabledState(bool state);
       
   147         void popPopupsEnabledState();
       
   148 
       
   149         virtual void invalidateRect(const IntRect&);
       
   150 
       
   151         bool arePopupsAllowed() const;
       
   152 
       
   153         void setJavaScriptPaused(bool);
       
   154 
       
   155         void disconnectStream(PluginStream*);
       
   156         void streamDidFinishLoading(PluginStream* stream) { disconnectStream(stream); }
       
   157 
       
   158         // Widget functions
       
   159         virtual void setFrameRect(const IntRect&);
       
   160         virtual void frameRectsChanged();
       
   161         virtual void setFocus();
       
   162         virtual void show();
       
   163         virtual void hide();
       
   164         virtual void paint(GraphicsContext*, const IntRect&);
       
   165 
       
   166         // This method is used by plugins on all platforms to obtain a clip rect that includes clips set by WebCore,
       
   167         // e.g., in overflow:auto sections.  The clip rects coordinates are in the containing window's coordinate space.
       
   168         // This clip includes any clips that the widget itself sets up for its children.
       
   169         IntRect windowClipRect() const;
       
   170 
       
   171         virtual void handleEvent(Event*);
       
   172         virtual void setParent(ScrollView*);
       
   173         virtual void setParentVisible(bool);
       
   174 
       
   175         virtual bool isPluginView() const { return true; }
       
   176 
       
   177         Frame* parentFrame() const { return m_parentFrame; }
       
   178 
       
   179         void focusPluginElement();
       
   180 
       
   181         const String& pluginsPage() const { return m_pluginsPage; }
       
   182         const String& mimeType() const { return m_mimeType; }
       
   183         const KURL& url() const { return m_url; }
       
   184 
       
   185 #if PLATFORM(WIN_OS) && !PLATFORM(WX) && ENABLE(NETSCAPE_PLUGIN_API)
       
   186         static LRESULT CALLBACK PluginViewWndProc(HWND, UINT, WPARAM, LPARAM);
       
   187         LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
       
   188         WNDPROC pluginWndProc() const { return m_pluginWndProc; }
       
   189 #endif
       
   190 
       
   191         // Used for manual loading
       
   192         void didReceiveResponse(const ResourceResponse&);
       
   193         void didReceiveData(const char*, int);
       
   194         void didFinishLoading();
       
   195         void didFail(const ResourceError&);
       
   196 
       
   197         // HaltablePlugin
       
   198         virtual void halt();
       
   199         virtual void restart();
       
   200         virtual Node* node() const;
       
   201 
       
   202         bool isHalted() const { return m_isHalted; }
       
   203         bool hasBeenHalted() const { return m_hasBeenHalted; }
       
   204 
       
   205         static bool isCallingPlugin();
       
   206 
       
   207         bool start();
       
   208 
       
   209     private:
       
   210         PluginView(Frame* parentFrame, const IntSize&, PluginPackage*, Element*, const KURL&, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually);
       
   211 
       
   212         void setParameters(const Vector<String>& paramNames, const Vector<String>& paramValues);
       
   213         bool startOrAddToUnstartedList();
       
   214         void removeFromUnstartedListIfNecessary();
       
   215         void init();
       
   216         bool platformStart();
       
   217         void stop();
       
   218         void platformDestroy();
       
   219         static void setCurrentPluginView(PluginView*);
       
   220         NPError load(const FrameLoadRequest&, bool sendNotification, void* notifyData);
       
   221         NPError handlePost(const char* url, const char* target, uint32 len, const char* buf, bool file, void* notifyData, bool sendNotification, bool allowHeaders);
       
   222         NPError handlePostReadFile(Vector<char>& buffer, uint32 len, const char* buf);
       
   223         static void freeStringArray(char** stringArray, int length);
       
   224         void setCallingPlugin(bool) const;
       
   225 
       
   226         void invalidateWindowlessPluginRect(const IntRect&);
       
   227 
       
   228 #if PLATFORM(WIN_OS) && !PLATFORM(WX) && ENABLE(NETSCAPE_PLUGIN_API)
       
   229         void paintWindowedPluginIntoContext(GraphicsContext*, const IntRect&) const;
       
   230         static HDC WINAPI hookedBeginPaint(HWND, PAINTSTRUCT*);
       
   231         static BOOL WINAPI hookedEndPaint(HWND, const PAINTSTRUCT*);
       
   232 #endif
       
   233 
       
   234         Frame* m_parentFrame;
       
   235         RefPtr<PluginPackage> m_plugin;
       
   236         Element* m_element;
       
   237         bool m_isStarted;
       
   238         KURL m_url;
       
   239         KURL m_baseURL;
       
   240         PluginStatus m_status;
       
   241         Vector<IntRect> m_invalidRects;
       
   242 
       
   243         void performRequest(PluginRequest*);
       
   244         void scheduleRequest(PluginRequest*);
       
   245         void requestTimerFired(Timer<PluginView>*);
       
   246         void invalidateTimerFired(Timer<PluginView>*);
       
   247         Timer<PluginView> m_requestTimer;
       
   248         Timer<PluginView> m_invalidateTimer;
       
   249 
       
   250         void popPopupsStateTimerFired(Timer<PluginView>*);
       
   251         Timer<PluginView> m_popPopupsStateTimer;
       
   252 
       
   253 #ifndef NP_NO_CARBON
       
   254         bool dispatchNPEvent(NPEvent&);
       
   255 #endif
       
   256         void updatePluginWidget();
       
   257         void paintMissingPluginIcon(GraphicsContext*, const IntRect&);
       
   258 
       
   259         void handleKeyboardEvent(KeyboardEvent*);
       
   260         void handleMouseEvent(MouseEvent*);
       
   261 #if defined(Q_WS_X11) && ENABLE(NETSCAPE_PLUGIN_API)
       
   262         void handleFocusInEvent();
       
   263         void handleFocusOutEvent();
       
   264 #endif
       
   265 
       
   266         int m_mode;
       
   267         int m_paramCount;
       
   268         char** m_paramNames;
       
   269         char** m_paramValues;
       
   270         String m_pluginsPage;
       
   271 
       
   272         String m_mimeType;
       
   273         CString m_userAgent;
       
   274 
       
   275         NPP m_instance;
       
   276         NPP_t m_instanceStruct;
       
   277         NPWindow m_npWindow;
       
   278 
       
   279         Vector<bool, 4> m_popupStateStack;
       
   280 
       
   281         HashSet<RefPtr<PluginStream> > m_streams;
       
   282         Vector<PluginRequest*> m_requests;
       
   283 
       
   284         bool m_isWindowed;
       
   285         bool m_isTransparent;
       
   286         bool m_haveInitialized;
       
   287         bool m_isWaitingToStart;
       
   288 
       
   289 #if defined(XP_UNIX) || defined(Q_WS_X11)
       
   290         bool m_needsXEmbed;
       
   291 #endif
       
   292 
       
   293 #if PLATFORM(WIN_OS) && !PLATFORM(WX) && ENABLE(NETSCAPE_PLUGIN_API)
       
   294         OwnPtr<PluginMessageThrottlerWin> m_messageThrottler;
       
   295         WNDPROC m_pluginWndProc;
       
   296         unsigned m_lastMessage;
       
   297         bool m_isCallingPluginWndProc;
       
   298         HDC m_wmPrintHDC;
       
   299         bool m_haveUpdatedPluginWidget;
       
   300 #endif
       
   301 
       
   302 #if (PLATFORM(QT) && PLATFORM(WIN_OS)) || defined(XP_MACOSX)
       
   303         // On Mac OSX and Qt/Windows the plugin does not have its own native widget,
       
   304         // but is using the containing window as its reference for positioning/painting.
       
   305         PlatformPluginWidget m_window;
       
   306 public:
       
   307         PlatformPluginWidget platformPluginWidget() const { return m_window; }
       
   308         void setPlatformPluginWidget(PlatformPluginWidget widget) { m_window = widget; }
       
   309 #else
       
   310 public:
       
   311         void setPlatformPluginWidget(PlatformPluginWidget widget) { setPlatformWidget(widget); }
       
   312         PlatformPluginWidget platformPluginWidget() const { return platformWidget(); }
       
   313 #endif
       
   314 
       
   315 private:
       
   316 
       
   317 #if defined(XP_UNIX) || defined(Q_WS_X11) || PLATFORM(SYMBIAN)
       
   318         void setNPWindowIfNeeded();
       
   319 #elif defined(XP_MACOSX)
       
   320         NP_CGContext m_npCgContext;
       
   321         OwnPtr<Timer<PluginView> > m_nullEventTimer;
       
   322         NPDrawingModel m_drawingModel;
       
   323         NPEventModel m_eventModel;
       
   324 
       
   325         void setNPWindowIfNeeded();
       
   326         void nullEventTimerFired(Timer<PluginView>*);
       
   327         Point globalMousePosForPlugin() const;
       
   328 #endif
       
   329 
       
   330 #if defined(Q_WS_X11) && ENABLE(NETSCAPE_PLUGIN_API)
       
   331         bool m_hasPendingGeometryChange;
       
   332         Pixmap m_drawable;
       
   333         Visual* m_visual;
       
   334         Colormap m_colormap;
       
   335         Display* m_pluginDisplay;
       
   336 
       
   337         void initXEvent(XEvent* event);
       
   338 #endif
       
   339 
       
   340         IntRect m_clipRect; // The clip rect to apply to a windowed plug-in
       
   341         IntRect m_windowRect; // Our window rect.
       
   342 
       
   343         bool m_loadManually;
       
   344         RefPtr<PluginStream> m_manualStream;
       
   345 
       
   346         bool m_isJavaScriptPaused;
       
   347 
       
   348         bool m_isHalted;
       
   349         bool m_hasBeenHalted;
       
   350 
       
   351         static PluginView* s_currentPluginView;
       
   352     };
       
   353 
       
   354 } // namespace WebCore
       
   355 
       
   356 #endif