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