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 : public PluginView, public WebPluginContainer, public FrameDestructionObserver {
68 static PassRefPtr<WebPluginContainerImpl> create(HTMLPlugInElement* element, WebPlugin* webPlugin)
70 return adoptRef(new WebPluginContainerImpl(element, webPlugin));
74 virtual WebLayer* platformLayer() const OVERRIDE;
75 virtual v8::Local<v8::Object> scriptableObject(v8::Isolate*) OVERRIDE;
76 virtual bool getFormValue(String&) OVERRIDE;
77 virtual bool supportsKeyboardFocus() const OVERRIDE;
78 virtual bool supportsInputMethod() const OVERRIDE;
79 virtual bool canProcessDrag() const OVERRIDE;
80 virtual bool wantsWheelEvents() OVERRIDE;
83 virtual void setFrameRect(const IntRect&) OVERRIDE;
84 virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE;
85 virtual void invalidateRect(const IntRect&) OVERRIDE;
86 virtual void setFocus(bool) OVERRIDE;
87 virtual void show() OVERRIDE;
88 virtual void hide() OVERRIDE;
89 virtual void handleEvent(Event*) OVERRIDE;
90 virtual void frameRectsChanged() OVERRIDE;
91 virtual void setParentVisible(bool) OVERRIDE;
92 virtual void setParent(Widget*) OVERRIDE;
93 virtual void widgetPositionsUpdated() OVERRIDE;
94 virtual bool isPluginContainer() const OVERRIDE { return true; }
95 virtual void eventListenersRemoved() OVERRIDE;
96 virtual bool pluginShouldPersist() const OVERRIDE;
98 // WebPluginContainer methods
99 virtual WebElement element() OVERRIDE;
100 virtual void invalidate() OVERRIDE;
101 virtual void invalidateRect(const WebRect&) OVERRIDE;
102 virtual void scrollRect(const WebRect&) OVERRIDE;
103 virtual void reportGeometry() OVERRIDE;
104 virtual void allowScriptObjects() OVERRIDE;
105 virtual void clearScriptObjects() OVERRIDE;
106 virtual NPObject* scriptableObjectForElement() OVERRIDE;
107 virtual v8::Local<v8::Object> v8ObjectForElement() OVERRIDE;
108 virtual WebString executeScriptURL(const WebURL&, bool popupsAllowed) OVERRIDE;
109 virtual void loadFrameRequest(const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData) OVERRIDE;
110 virtual void zoomLevelChanged(double zoomLevel) OVERRIDE;
111 virtual bool isRectTopmost(const WebRect&) OVERRIDE;
112 virtual void requestTouchEventType(TouchEventRequestType) OVERRIDE;
113 virtual void setWantsWheelEvents(bool) OVERRIDE;
114 virtual WebPoint windowToLocalPoint(const WebPoint&) OVERRIDE;
115 virtual WebPoint localToWindowPoint(const WebPoint&) OVERRIDE;
117 // This cannot be null.
118 virtual WebPlugin* plugin() OVERRIDE { return m_webPlugin; }
119 virtual void setPlugin(WebPlugin*) OVERRIDE;
121 virtual float deviceScaleFactor() OVERRIDE;
122 virtual float pageScaleFactor() OVERRIDE;
123 virtual float pageZoomFactor() OVERRIDE;
125 virtual void setWebLayer(WebLayer*);
127 // Printing interface. The plugin can support custom printing
128 // (which means it controls the layout, number of pages etc).
129 // Whether the plugin supports its own paginated print. The other print
130 // interface methods are called only if this method returns true.
131 bool supportsPaginatedPrint() const;
132 // If the plugin content should not be scaled to the printable area of
133 // the page, then this method should return true.
134 bool isPrintScalingDisabled() const;
135 // Returns number of copies to be printed.
136 int getCopiesToPrint() const;
137 // Sets up printing at the specified WebPrintParams. Returns the number of pages to be printed at these settings.
138 int printBegin(const WebPrintParams&) const;
139 // Prints the page specified by pageNumber (0-based index) into the supplied canvas.
140 bool printPage(int pageNumber, GraphicsContext*);
141 // Ends the print operation.
144 // Copy the selected text.
147 // Pass the edit command to the plugin.
148 bool executeEditCommand(const WebString& name);
149 bool executeEditCommand(const WebString& name, const WebString& value);
151 // Resource load events for the plugin's source data:
152 virtual void didReceiveResponse(const ResourceResponse&) OVERRIDE;
153 virtual void didReceiveData(const char *data, int dataLength) OVERRIDE;
154 virtual void didFinishLoading() OVERRIDE;
155 virtual void didFailLoading(const ResourceError&) OVERRIDE;
157 void willDestroyPluginLoadObserver(WebPluginLoadObserver*);
159 ScrollbarGroup* scrollbarGroup();
161 void willStartLiveResize();
162 void willEndLiveResize();
164 bool paintCustomOverhangArea(GraphicsContext*, const IntRect&, const IntRect&, const IntRect&);
167 virtual void detach() OVERRIDE;
171 WebPluginContainerImpl(HTMLPlugInElement*, WebPlugin*);
172 virtual ~WebPluginContainerImpl();
174 void handleMouseEvent(MouseEvent*);
175 void handleDragEvent(MouseEvent*);
176 void handleWheelEvent(WheelEvent*);
177 void handleKeyboardEvent(KeyboardEvent*);
178 void handleTouchEvent(TouchEvent*);
179 void handleGestureEvent(GestureEvent*);
181 void synthesizeMouseEventIfPossible(TouchEvent*);
185 void calculateGeometry(
186 const IntRect& frameRect,
189 Vector<IntRect>& cutOutRects);
190 IntRect windowClipRect() const;
191 void windowCutOutRects(
192 const IntRect& frameRect,
193 Vector<IntRect>& cutOutRects);
195 // FIXME: Oilpan: consider moving Widget to the heap and turn this
196 // into a traced member. For the time being, it is a bare pointer
197 // of its owning PlugInElement and managed as such.
198 HTMLPlugInElement* m_element;
199 WebPlugin* m_webPlugin;
200 Vector<WebPluginLoadObserver*> m_pluginLoadObservers;
202 WebLayer* m_webLayer;
204 // The associated scrollbar group object, created lazily. Used for Pepper
206 OwnPtr<ScrollbarGroup> m_scrollbarGroup;
208 TouchEventRequestType m_touchEventRequestType;
209 bool m_wantsWheelEvents;
212 DEFINE_TYPE_CASTS(WebPluginContainerImpl, Widget, widget, widget->isPluginContainer(), widget.isPluginContainer());
213 // Unlike Widget, we need not worry about object type for container.
214 // WebPluginContainerImpl is the only subclass of WebPluginContainer.
215 DEFINE_TYPE_CASTS(WebPluginContainerImpl, WebPluginContainer, container, true, true);