PluginProxy.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. #ifndef PluginProxy_h
  26. #define PluginProxy_h
  27. #if ENABLE(PLUGIN_PROCESS)
  28. #include "Connection.h"
  29. #include "Plugin.h"
  30. #include "PluginProcess.h"
  31. #include <WebCore/AffineTransform.h>
  32. #include <WebCore/FindOptions.h>
  33. #include <WebCore/IntRect.h>
  34. #include <WebCore/SecurityOrigin.h>
  35. #if PLATFORM(MAC)
  36. #include <wtf/RetainPtr.h>
  37. OBJC_CLASS CALayer;
  38. #endif
  39. namespace WebCore {
  40. class HTTPHeaderMap;
  41. class ProtectionSpace;
  42. }
  43. namespace WebKit {
  44. class ShareableBitmap;
  45. class NPVariantData;
  46. class PluginProcessConnection;
  47. struct PluginCreationParameters;
  48. class PluginProxy : public Plugin {
  49. public:
  50. static PassRefPtr<PluginProxy> create(uint64_t pluginProcessToken, bool isRestartedProcess);
  51. ~PluginProxy();
  52. uint64_t pluginInstanceID() const { return m_pluginInstanceID; }
  53. void pluginProcessCrashed();
  54. void didReceivePluginProxyMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
  55. void didReceiveSyncPluginProxyMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&);
  56. bool isBeingAsynchronouslyInitialized() const { return m_waitingOnAsynchronousInitialization; }
  57. private:
  58. explicit PluginProxy(uint64_t pluginProcessToken, bool isRestartedProcess);
  59. // Plugin
  60. virtual bool initialize(const Parameters&);
  61. bool initializeSynchronously();
  62. virtual void destroy();
  63. virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect);
  64. virtual bool supportsSnapshotting() const;
  65. virtual PassRefPtr<ShareableBitmap> snapshot();
  66. #if PLATFORM(MAC)
  67. virtual PlatformLayer* pluginLayer();
  68. #endif
  69. virtual bool isTransparent();
  70. virtual bool wantsWheelEvents() OVERRIDE;
  71. virtual void geometryDidChange(const WebCore::IntSize& pluginSize, const WebCore::IntRect& clipRect, const WebCore::AffineTransform& pluginToRootViewTransform);
  72. virtual void visibilityDidChange();
  73. virtual void frameDidFinishLoading(uint64_t requestID);
  74. virtual void frameDidFail(uint64_t requestID, bool wasCancelled);
  75. virtual void didEvaluateJavaScript(uint64_t requestID, const String& result);
  76. virtual void streamDidReceiveResponse(uint64_t streamID, const WebCore::KURL& responseURL, uint32_t streamLength, uint32_t lastModifiedTime, const String& mimeType, const String& headers, const String& suggestedFileName);
  77. virtual void streamDidReceiveData(uint64_t streamID, const char* bytes, int length);
  78. virtual void streamDidFinishLoading(uint64_t streamID);
  79. virtual void streamDidFail(uint64_t streamID, bool wasCancelled);
  80. virtual void manualStreamDidReceiveResponse(const WebCore::KURL& responseURL, uint32_t streamLength, uint32_t lastModifiedTime, const WTF::String& mimeType, const WTF::String& headers, const String& suggestedFileName);
  81. virtual void manualStreamDidReceiveData(const char* bytes, int length);
  82. virtual void manualStreamDidFinishLoading();
  83. virtual void manualStreamDidFail(bool wasCancelled);
  84. virtual bool handleMouseEvent(const WebMouseEvent&);
  85. virtual bool handleWheelEvent(const WebWheelEvent&);
  86. virtual bool handleMouseEnterEvent(const WebMouseEvent&);
  87. virtual bool handleMouseLeaveEvent(const WebMouseEvent&);
  88. virtual bool handleContextMenuEvent(const WebMouseEvent&);
  89. virtual bool handleKeyboardEvent(const WebKeyboardEvent&);
  90. virtual void setFocus(bool);
  91. virtual bool handleEditingCommand(const String& commandName, const String& argument) OVERRIDE;
  92. virtual bool isEditingCommandEnabled(const String& commandName) OVERRIDE;
  93. virtual bool shouldAllowScripting() OVERRIDE { return true; }
  94. virtual bool shouldAllowNavigationFromDrags() OVERRIDE { return false; }
  95. virtual bool handlesPageScaleFactor();
  96. virtual NPObject* pluginScriptableNPObject();
  97. #if PLATFORM(MAC)
  98. virtual void windowFocusChanged(bool);
  99. virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
  100. virtual void windowVisibilityChanged(bool);
  101. virtual uint64_t pluginComplexTextInputIdentifier() const;
  102. virtual void sendComplexTextInput(const String& textInput);
  103. virtual void setLayerHostingMode(LayerHostingMode) OVERRIDE;
  104. #endif
  105. virtual void contentsScaleFactorChanged(float);
  106. virtual void storageBlockingStateChanged(bool);
  107. virtual void privateBrowsingStateChanged(bool);
  108. virtual bool getFormValue(String& formValue);
  109. virtual bool handleScroll(WebCore::ScrollDirection, WebCore::ScrollGranularity);
  110. virtual WebCore::Scrollbar* horizontalScrollbar();
  111. virtual WebCore::Scrollbar* verticalScrollbar();
  112. virtual unsigned countFindMatches(const String&, WebCore::FindOptions, unsigned) OVERRIDE { return 0; }
  113. virtual bool findString(const String&, WebCore::FindOptions, unsigned) OVERRIDE { return false; }
  114. virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint&) const OVERRIDE;
  115. virtual PassRefPtr<WebCore::SharedBuffer> liveResourceData() const OVERRIDE;
  116. virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&) OVERRIDE { return false; }
  117. virtual String getSelectionString() const OVERRIDE { return String(); }
  118. float contentsScaleFactor();
  119. bool needsBackingStore() const;
  120. bool updateBackingStore();
  121. uint64_t windowNPObjectID();
  122. WebCore::IntRect pluginBounds();
  123. void geometryDidChange();
  124. // Message handlers.
  125. void loadURL(uint64_t requestID, const String& method, const String& urlString, const String& target, const WebCore::HTTPHeaderMap& headerFields, const Vector<uint8_t>& httpBody, bool allowPopups);
  126. void update(const WebCore::IntRect& paintedRect);
  127. void proxiesForURL(const String& urlString, String& proxyString);
  128. void cookiesForURL(const String& urlString, String& cookieString);
  129. void setCookiesForURL(const String& urlString, const String& cookieString);
  130. void getAuthenticationInfo(const WebCore::ProtectionSpace&, bool& returnValue, String& username, String& password);
  131. void getPluginElementNPObject(uint64_t& pluginElementNPObjectID);
  132. void evaluate(const NPVariantData& npObjectAsVariantData, const String& scriptString, bool allowPopups, bool& returnValue, NPVariantData& resultData);
  133. void cancelStreamLoad(uint64_t streamID);
  134. void cancelManualStreamLoad();
  135. void setStatusbarText(const String& statusbarText);
  136. #if PLATFORM(MAC)
  137. void pluginFocusOrWindowFocusChanged(bool);
  138. void setComplexTextInputState(uint64_t);
  139. void setLayerHostingContextID(uint32_t);
  140. #endif
  141. #if PLUGIN_ARCHITECTURE(X11)
  142. void createPluginContainer(uint64_t& windowID);
  143. void windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID);
  144. #endif
  145. bool canInitializeAsynchronously() const;
  146. void didCreatePlugin(bool wantsWheelEvents, uint32_t remoteLayerClientID);
  147. void didFailToCreatePlugin();
  148. void didCreatePluginInternal(bool wantsWheelEvents, uint32_t remoteLayerClientID);
  149. void didFailToCreatePluginInternal();
  150. uint64_t m_pluginProcessToken;
  151. RefPtr<PluginProcessConnection> m_connection;
  152. uint64_t m_pluginInstanceID;
  153. WebCore::IntSize m_pluginSize;
  154. // The clip rect in plug-in coordinates.
  155. WebCore::IntRect m_clipRect;
  156. // A transform that can be used to convert from root view coordinates to plug-in coordinates.
  157. WebCore::AffineTransform m_pluginToRootViewTransform;
  158. // This is the backing store that we paint when we're told to paint.
  159. RefPtr<ShareableBitmap> m_backingStore;
  160. // This is the shared memory backing store that the plug-in paints into. When the plug-in tells us
  161. // that it's painted something in it, we'll blit from it to our own backing store.
  162. RefPtr<ShareableBitmap> m_pluginBackingStore;
  163. // Whether all of the plug-in backing store contains valid data.
  164. bool m_pluginBackingStoreContainsValidData;
  165. bool m_isStarted;
  166. // Whether we're called invalidate in response to an update call, and are now waiting for a paint call.
  167. bool m_waitingForPaintInResponseToUpdate;
  168. // Whether we should send wheel events to this plug-in or not.
  169. bool m_wantsWheelEvents;
  170. // The client ID for the CA layer in the plug-in process. Will be 0 if the plug-in is not a CA plug-in.
  171. uint32_t m_remoteLayerClientID;
  172. OwnPtr<PluginCreationParameters> m_pendingPluginCreationParameters;
  173. bool m_waitingOnAsynchronousInitialization;
  174. #if PLATFORM(MAC)
  175. RetainPtr<CALayer> m_pluginLayer;
  176. #endif
  177. bool m_isRestartedProcess;
  178. };
  179. } // namespace WebKit
  180. #endif // ENABLE(PLUGIN_PROCESS)
  181. #endif // PluginProxy_h