WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 NetscapePlugin_h
       
    27 #define NetscapePlugin_h
       
    28 
       
    29 #include "NetscapePluginModule.h"
       
    30 #include "Plugin.h"
       
    31 #include <WebCore/IntRect.h>
       
    32 #include <WebCore/StringHash.h>
       
    33 
       
    34 namespace WebCore {
       
    35     class HTTPHeaderMap;
       
    36 }
       
    37 
       
    38 namespace WebKit {
       
    39 
       
    40 class NetscapePluginStream;
       
    41     
       
    42 class NetscapePlugin : public Plugin {
       
    43 public:
       
    44     static PassRefPtr<NetscapePlugin> create(PassRefPtr<NetscapePluginModule> pluginModule)
       
    45     {
       
    46         return adoptRef(new NetscapePlugin(pluginModule));
       
    47     }
       
    48     virtual ~NetscapePlugin();
       
    49 
       
    50     static PassRefPtr<NetscapePlugin> fromNPP(NPP);
       
    51 
       
    52 #if PLATFORM(MAC)
       
    53     NPError setDrawingModel(NPDrawingModel);
       
    54     NPError setEventModel(NPEventModel);
       
    55 #endif
       
    56 
       
    57     void invalidate(const NPRect*);
       
    58     const char* userAgent();
       
    59     void loadURL(const WebCore::String& method, const WebCore::String& urlString, const WebCore::String& target, const WebCore::HTTPHeaderMap& headerFields,
       
    60                  const Vector<char>& httpBody, bool sendNotification, void* notificationData);
       
    61     NPError destroyStream(NPStream*, NPReason);
       
    62 
       
    63     // These return retained objects.
       
    64     NPObject* windowScriptNPObject();
       
    65     NPObject* pluginElementNPObject();
       
    66 
       
    67     void cancelStreamLoad(NetscapePluginStream*);
       
    68     void removePluginStream(NetscapePluginStream*);
       
    69 
       
    70     // Member functions for calling into the plug-in.
       
    71     NPError NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData*);
       
    72     NPError NPP_Destroy(NPSavedData**);
       
    73     NPError NPP_SetWindow(NPWindow*);
       
    74     NPError NPP_NewStream(NPMIMEType, NPStream*, NPBool seekable, uint16_t* stype);
       
    75     NPError NPP_DestroyStream(NPStream*, NPReason);
       
    76     void NPP_StreamAsFile(NPStream*, const char* filename);
       
    77 
       
    78     int32_t NPP_WriteReady(NPStream*);
       
    79     int32_t NPP_Write(NPStream*, int32_t offset, int32_t len, void* buffer);
       
    80     void NPP_URLNotify(const char* url, NPReason, void* notifyData);
       
    81     NPError NPP_GetValue(NPPVariable, void *value);
       
    82 
       
    83 private:
       
    84     NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule);
       
    85 
       
    86     void callSetWindow();
       
    87     bool shouldLoadSrcURL();
       
    88     NetscapePluginStream* streamFromID(uint64_t streamID);
       
    89     void stopAllStreams();
       
    90     bool allowPopups() const;
       
    91 
       
    92     bool platformPostInitialize();
       
    93     void platformPaint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect);
       
    94 
       
    95     // Plugin
       
    96     virtual bool initialize(PluginController*, const Parameters&);
       
    97     virtual void destroy();
       
    98     virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect);
       
    99     virtual void geometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect);
       
   100     virtual void frameDidFinishLoading(uint64_t requestID);
       
   101     virtual void frameDidFail(uint64_t requestID, bool wasCancelled);
       
   102     virtual void didEvaluateJavaScript(uint64_t requestID, const WebCore::String& requestURLString, const WebCore::String& result);
       
   103     virtual void streamDidReceiveResponse(uint64_t streamID, const WebCore::KURL& responseURL, uint32_t streamLength, 
       
   104                                           uint32_t lastModifiedTime, const WebCore::String& mimeType, const WebCore::String& headers);
       
   105     virtual void streamDidReceiveData(uint64_t streamID, const char* bytes, int length);
       
   106     virtual void streamDidFinishLoading(uint64_t streamID);
       
   107     virtual void streamDidFail(uint64_t streamID, bool wasCancelled);
       
   108 
       
   109     virtual PluginController* controller();
       
   110 
       
   111     PluginController* m_pluginController;
       
   112     uint64_t m_nextRequestID;
       
   113 
       
   114     typedef HashMap<uint64_t, std::pair<WebCore::String, void*> > PendingURLNotifyMap;
       
   115     PendingURLNotifyMap m_pendingURLNotifications;
       
   116 
       
   117     typedef HashMap<uint64_t, RefPtr<NetscapePluginStream> > StreamsMap;
       
   118     StreamsMap m_streams;
       
   119 
       
   120     RefPtr<NetscapePluginModule> m_pluginModule;
       
   121     NPP_t m_npp;
       
   122     NPWindow m_npWindow;
       
   123 
       
   124     WebCore::IntRect m_frameRect;
       
   125     WebCore::IntRect m_clipRect;
       
   126 
       
   127     CString m_userAgent;
       
   128 
       
   129     bool m_isStarted;
       
   130     bool m_inNPPNew;
       
   131 
       
   132 #if PLATFORM(MAC)
       
   133     NPDrawingModel m_drawingModel;
       
   134     NPEventModel m_eventModel;
       
   135 #endif
       
   136 };
       
   137 
       
   138 // Move these functions to NetscapePluginWin.cpp
       
   139 #if !PLATFORM(MAC)
       
   140 inline bool NetscapePlugin::platformPostInitialize()
       
   141 {
       
   142     return true;
       
   143 }
       
   144 
       
   145 inline void NetscapePlugin::platformPaint(WebCore::GraphicsContext*, const WebCore::IntRect&)
       
   146 {
       
   147 }
       
   148 #endif
       
   149 
       
   150 } // namespace WebKit
       
   151 
       
   152 #endif // NetscapePlugin_h