2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * Copyright (C) 2014 Opera Software ASA. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #ifndef WebPluginContainerImpl_h
33 #define WebPluginContainerImpl_h
35 #include "core/frame/FrameDestructionObserver.h"
36 #include "core/plugins/PluginView.h"
37 #include "platform/Widget.h"
38 #include "public/web/WebPluginContainer.h"
40 #include "wtf/OwnPtr.h"
41 #include "wtf/PassRefPtr.h"
42 #include "wtf/Vector.h"
43 #include "wtf/text/WTFString.h"
50 class HTMLPlugInElement;
54 class PlatformGestureEvent;
56 class ResourceResponse;
60 class WebPluginLoadObserver;
61 class WebExternalTextureLayer;
64 struct WebPrintParams;
66 class WebPluginContainerImpl FINAL
68 , public WebPluginContainer
70 , public FrameDestructionObserver
74 static PassRefPtr<WebPluginContainerImpl> create(HTMLPlugInElement* element, WebPlugin* webPlugin)
76 return adoptRef(new WebPluginContainerImpl(element, webPlugin));
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;
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;
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;
123 // This cannot be null.
124 virtual WebPlugin* plugin() OVERRIDE { return m_webPlugin; }
125 virtual void setPlugin(WebPlugin*) OVERRIDE;
127 virtual float deviceScaleFactor() OVERRIDE;
128 virtual float pageScaleFactor() OVERRIDE;
129 virtual float pageZoomFactor() OVERRIDE;
131 virtual void setWebLayer(WebLayer*);
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.
150 // Copy the selected text.
153 // Pass the edit command to the plugin.
154 bool executeEditCommand(const WebString& name);
155 bool executeEditCommand(const WebString& name, const WebString& value);
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;
163 void willDestroyPluginLoadObserver(WebPluginLoadObserver*);
165 ScrollbarGroup* scrollbarGroup();
167 void willStartLiveResize();
168 void willEndLiveResize();
170 bool paintCustomOverhangArea(GraphicsContext*, const IntRect&, const IntRect&, const IntRect&);
173 virtual void detach() OVERRIDE;
177 WebPluginContainerImpl(HTMLPlugInElement*, WebPlugin*);
178 virtual ~WebPluginContainerImpl();
180 void handleMouseEvent(MouseEvent*);
181 void handleDragEvent(MouseEvent*);
182 void handleWheelEvent(WheelEvent*);
183 void handleKeyboardEvent(KeyboardEvent*);
184 void handleTouchEvent(TouchEvent*);
185 void handleGestureEvent(GestureEvent*);
187 void synthesizeMouseEventIfPossible(TouchEvent*);
191 void calculateGeometry(
192 const IntRect& frameRect,
195 Vector<IntRect>& cutOutRects);
196 IntRect windowClipRect() const;
197 void windowCutOutRects(
198 const IntRect& frameRect,
199 Vector<IntRect>& cutOutRects);
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.
210 // See the HTMLFrameOwnerElement::disconnectContentFrame comment for
214 LocalFrame* frame() const { return m_frame; }
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;
223 WebLayer* m_webLayer;
225 // The associated scrollbar group object, created lazily. Used for Pepper
227 OwnPtr<ScrollbarGroup> m_scrollbarGroup;
229 TouchEventRequestType m_touchEventRequestType;
230 bool m_wantsWheelEvents;
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);