1 /* 2 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * Copyright (C) 2014 Opera Software ASA. 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 are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * * Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following disclaimer 13 * in the documentation and/or other materials provided with the 14 * distribution. 15 * * Neither the name of Google Inc. nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef WebPluginContainerImpl_h 33 #define WebPluginContainerImpl_h 34 35 #include "core/frame/FrameDestructionObserver.h" 36 #include "core/plugins/PluginView.h" 37 #include "platform/Widget.h" 38 #include "public/web/WebPluginContainer.h" 39 40 #include "wtf/OwnPtr.h" 41 #include "wtf/PassRefPtr.h" 42 #include "wtf/Vector.h" 43 #include "wtf/text/WTFString.h" 44 45 struct NPObject; 46 47 namespace blink { 48 49 class GestureEvent; 50 class HTMLPlugInElement; 51 class IntRect; 52 class KeyboardEvent; 53 class MouseEvent; 54 class PlatformGestureEvent; 55 class ResourceError; 56 class ResourceResponse; 57 class ScrollbarGroup; 58 class TouchEvent; 59 class WebPlugin; 60 class WebPluginLoadObserver; 61 class WebExternalTextureLayer; 62 class WheelEvent; 63 class Widget; 64 struct WebPrintParams; 65 66 class WebPluginContainerImpl FINAL 67 : public PluginView 68 , public WebPluginContainer 69 #if !ENABLE(OILPAN) 70 , public FrameDestructionObserver 71 #endif 72 { 73 public: 74 static PassRefPtr<WebPluginContainerImpl> create(HTMLPlugInElement* element, WebPlugin* webPlugin) 75 { 76 return adoptRef(new WebPluginContainerImpl(element, webPlugin)); 77 } 78 79 // PluginView methods 80 virtual WebLayer* platformLayer() const OVERRIDE; 81 virtual v8::Local<v8::Object> scriptableObject(v8::Isolate*) OVERRIDE; 82 virtual bool getFormValue(String&) OVERRIDE; 83 virtual bool supportsKeyboardFocus() const OVERRIDE; 84 virtual bool supportsInputMethod() const OVERRIDE; 85 virtual bool canProcessDrag() const OVERRIDE; 86 virtual bool wantsWheelEvents() OVERRIDE; 87 88 // Widget methods 89 virtual void setFrameRect(const IntRect&) OVERRIDE; 90 virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE; 91 virtual void invalidateRect(const IntRect&) OVERRIDE; 92 virtual void setFocus(bool) OVERRIDE; 93 virtual void show() OVERRIDE; 94 virtual void hide() OVERRIDE; 95 virtual void handleEvent(Event*) OVERRIDE; 96 virtual void frameRectsChanged() OVERRIDE; 97 virtual void setParentVisible(bool) OVERRIDE; 98 virtual void setParent(Widget*) OVERRIDE; 99 virtual void widgetPositionsUpdated() OVERRIDE; 100 virtual bool isPluginContainer() const OVERRIDE { return true; } 101 virtual void eventListenersRemoved() OVERRIDE; 102 virtual bool pluginShouldPersist() const OVERRIDE; 103 104 // WebPluginContainer methods 105 virtual WebElement element() OVERRIDE; 106 virtual void invalidate() OVERRIDE; 107 virtual void invalidateRect(const WebRect&) OVERRIDE; 108 virtual void scrollRect(const WebRect&) OVERRIDE; 109 virtual void reportGeometry() OVERRIDE; 110 virtual void allowScriptObjects() OVERRIDE; 111 virtual void clearScriptObjects() OVERRIDE; 112 virtual NPObject* scriptableObjectForElement() OVERRIDE; 113 virtual v8::Local<v8::Object> v8ObjectForElement() OVERRIDE; 114 virtual WebString executeScriptURL(const WebURL&, bool popupsAllowed) OVERRIDE; 115 virtual void loadFrameRequest(const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData) OVERRIDE; 116 virtual void zoomLevelChanged(double zoomLevel) OVERRIDE; 117 virtual bool isRectTopmost(const WebRect&) OVERRIDE; 118 virtual void requestTouchEventType(TouchEventRequestType) OVERRIDE; 119 virtual void setWantsWheelEvents(bool) OVERRIDE; 120 virtual WebPoint windowToLocalPoint(const WebPoint&) OVERRIDE; 121 virtual WebPoint localToWindowPoint(const WebPoint&) OVERRIDE; 122 123 // This cannot be null. 124 virtual WebPlugin* plugin() OVERRIDE { return m_webPlugin; } 125 virtual void setPlugin(WebPlugin*) OVERRIDE; 126 127 virtual float deviceScaleFactor() OVERRIDE; 128 virtual float pageScaleFactor() OVERRIDE; 129 virtual float pageZoomFactor() OVERRIDE; 130 131 virtual void setWebLayer(WebLayer*); 132 133 // Printing interface. The plugin can support custom printing 134 // (which means it controls the layout, number of pages etc). 135 // Whether the plugin supports its own paginated print. The other print 136 // interface methods are called only if this method returns true. 137 bool supportsPaginatedPrint() const; 138 // If the plugin content should not be scaled to the printable area of 139 // the page, then this method should return true. 140 bool isPrintScalingDisabled() const; 141 // Returns number of copies to be printed. 142 int getCopiesToPrint() const; 143 // Sets up printing at the specified WebPrintParams. Returns the number of pages to be printed at these settings. 144 int printBegin(const WebPrintParams&) const; 145 // Prints the page specified by pageNumber (0-based index) into the supplied canvas. 146 bool printPage(int pageNumber, GraphicsContext*); 147 // Ends the print operation. 148 void printEnd(); 149 150 // Copy the selected text. 151 void copy(); 152 153 // Pass the edit command to the plugin. 154 bool executeEditCommand(const WebString& name); 155 bool executeEditCommand(const WebString& name, const WebString& value); 156 157 // Resource load events for the plugin's source data: 158 virtual void didReceiveResponse(const ResourceResponse&) OVERRIDE; 159 virtual void didReceiveData(const char *data, int dataLength) OVERRIDE; 160 virtual void didFinishLoading() OVERRIDE; 161 virtual void didFailLoading(const ResourceError&) OVERRIDE; 162 163 void willDestroyPluginLoadObserver(WebPluginLoadObserver*); 164 165 ScrollbarGroup* scrollbarGroup(); 166 167 void willStartLiveResize(); 168 void willEndLiveResize(); 169 170 bool paintCustomOverhangArea(GraphicsContext*, const IntRect&, const IntRect&, const IntRect&); 171 172 #if ENABLE(OILPAN) 173 virtual void detach() OVERRIDE; 174 #endif 175 176 private: 177 WebPluginContainerImpl(HTMLPlugInElement*, WebPlugin*); 178 virtual ~WebPluginContainerImpl(); 179 180 void handleMouseEvent(MouseEvent*); 181 void handleDragEvent(MouseEvent*); 182 void handleWheelEvent(WheelEvent*); 183 void handleKeyboardEvent(KeyboardEvent*); 184 void handleTouchEvent(TouchEvent*); 185 void handleGestureEvent(GestureEvent*); 186 187 void synthesizeMouseEventIfPossible(TouchEvent*); 188 189 void focusPlugin(); 190 191 void calculateGeometry( 192 const IntRect& frameRect, 193 IntRect& windowRect, 194 IntRect& clipRect, 195 Vector<IntRect>& cutOutRects); 196 IntRect windowClipRect() const; 197 void windowCutOutRects( 198 const IntRect& frameRect, 199 Vector<IntRect>& cutOutRects); 200 201 #if ENABLE(OILPAN) 202 // FIXME: Oilpan: consider moving Widget to the heap, allowing this 203 // container object to be a FrameDestructionObserver. And thereby 204 // keep a traced member reference to the frame rather than as a 205 // bare pointer. Instead, the owning object (HTMLFrameOwnerElement) 206 // explicitly deletes this object when it is disconnected from its 207 // frame. Any access to an invalid frame via this bare pointer 208 // is therefore not possible. 209 // 210 // See the HTMLFrameOwnerElement::disconnectContentFrame comment for 211 // (even) more. 212 LocalFrame* m_frame; 213 214 LocalFrame* frame() const { return m_frame; } 215 #endif 216 217 // FIXME: see above; for the time being, a bare pointer to the owning 218 // HTMLPlugInElement and managed as such. 219 HTMLPlugInElement* m_element; 220 WebPlugin* m_webPlugin; 221 Vector<WebPluginLoadObserver*> m_pluginLoadObservers; 222 223 WebLayer* m_webLayer; 224 225 // The associated scrollbar group object, created lazily. Used for Pepper 226 // scrollbars. 227 OwnPtr<ScrollbarGroup> m_scrollbarGroup; 228 229 TouchEventRequestType m_touchEventRequestType; 230 bool m_wantsWheelEvents; 231 }; 232 233 DEFINE_TYPE_CASTS(WebPluginContainerImpl, Widget, widget, widget->isPluginContainer(), widget.isPluginContainer()); 234 // Unlike Widget, we need not worry about object type for container. 235 // WebPluginContainerImpl is the only subclass of WebPluginContainer. 236 DEFINE_TYPE_CASTS(WebPluginContainerImpl, WebPluginContainer, container, true, true); 237 238 } // namespace blink 239 240 #endif 241