Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / WebPluginContainerImpl.h
blob99f4bad1effc0936031fc72432eab6205742687a
1 /*
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
7 * met:
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.
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/LocalFrameLifecycleObserver.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"
45 struct NPObject;
47 namespace blink {
49 class GestureEvent;
50 class HTMLPlugInElement;
51 class IntRect;
52 class KeyboardEvent;
53 class MouseEvent;
54 class ResourceError;
55 class ResourceResponse;
56 class TouchEvent;
57 class WebPlugin;
58 class WebPluginLoadObserver;
59 class WheelEvent;
60 class Widget;
61 struct WebPrintParams;
62 struct WebPrintPresetOptions;
64 class WebPluginContainerImpl final : public PluginView, public WebPluginContainer, public LocalFrameLifecycleObserver {
65 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WebPluginContainerImpl);
66 public:
67 static PassRefPtrWillBeRawPtr<WebPluginContainerImpl> create(HTMLPlugInElement* element, WebPlugin* webPlugin)
69 return adoptRefWillBeNoop(new WebPluginContainerImpl(element, webPlugin));
72 // PluginView methods
73 WebLayer* platformLayer() const override;
74 v8::Local<v8::Object> scriptableObject(v8::Isolate*) override;
75 bool getFormValue(String&) override;
76 bool supportsKeyboardFocus() const override;
77 bool supportsInputMethod() const override;
78 bool canProcessDrag() const override;
79 bool wantsWheelEvents() override;
80 void layoutIfNeeded() override;
81 void invalidatePaintIfNeeded() override { issuePaintInvalidations(); }
83 // Widget methods
84 void setFrameRect(const IntRect&) override;
85 void paint(GraphicsContext*, const IntRect&) override;
86 void invalidateRect(const IntRect&) override;
87 void setFocus(bool, WebFocusType) override;
88 void show() override;
89 void hide() override;
90 void handleEvent(Event*) override;
91 void frameRectsChanged() override;
92 void setParentVisible(bool) override;
93 void setParent(Widget*) override;
94 void widgetPositionsUpdated() override;
95 bool isPluginContainer() const override { return true; }
96 void eventListenersRemoved() override;
98 // WebPluginContainer methods
99 WebElement element() override;
100 void invalidate() override;
101 void invalidateRect(const WebRect&) override;
102 void scrollRect(const WebRect&) override;
103 void setNeedsLayout() override;
104 void reportGeometry() override;
105 void allowScriptObjects() override;
106 void clearScriptObjects() override;
107 NPObject* scriptableObjectForElement() override;
108 v8::Local<v8::Object> v8ObjectForElement() override;
109 WebString executeScriptURL(const WebURL&, bool popupsAllowed) override;
110 void loadFrameRequest(const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData) override;
111 bool isRectTopmost(const WebRect&) override;
112 void requestTouchEventType(TouchEventRequestType) override;
113 void setWantsWheelEvents(bool) override;
114 WebPoint rootFrameToLocalPoint(const WebPoint&) override;
115 WebPoint localToRootFramePoint(const WebPoint&) override;
117 // This cannot be null.
118 WebPlugin* plugin() override { return m_webPlugin; }
119 void setPlugin(WebPlugin*) override;
121 float deviceScaleFactor() override;
122 float pageScaleFactor() override;
123 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 true on success and sets the out parameter to the print preset options for the document.
136 bool getPrintPresetOptionsFromDocument(WebPrintPresetOptions*) 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 void printPage(int pageNumber, GraphicsContext*, const IntRect& paintRect);
141 // Ends the print operation.
142 void printEnd();
144 // Copy the selected text.
145 void copy();
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 void didReceiveResponse(const ResourceResponse&) override;
153 void didReceiveData(const char *data, int dataLength) override;
154 void didFinishLoading() override;
155 void didFailLoading(const ResourceError&) override;
157 void willDestroyPluginLoadObserver(WebPluginLoadObserver*);
159 DECLARE_VIRTUAL_TRACE();
160 void dispose() override;
162 #if ENABLE(OILPAN)
163 LocalFrame* pluginFrame() const override { return frame(); }
164 void shouldDisposePlugin() override;
165 #endif
167 private:
168 WebPluginContainerImpl(HTMLPlugInElement*, WebPlugin*);
169 ~WebPluginContainerImpl() override;
171 void handleMouseEvent(MouseEvent*);
172 void handleDragEvent(MouseEvent*);
173 void handleWheelEvent(WheelEvent*);
174 void handleKeyboardEvent(KeyboardEvent*);
175 void handleTouchEvent(TouchEvent*);
176 void handleGestureEvent(GestureEvent*);
178 void synthesizeMouseEventIfPossible(TouchEvent*);
180 void focusPlugin();
182 void issuePaintInvalidations();
184 void calculateGeometry(
185 IntRect& windowRect,
186 IntRect& clipRect,
187 IntRect& unobscuredRect,
188 Vector<IntRect>& cutOutRects);
189 void windowCutOutRects(
190 const IntRect& frameRect,
191 Vector<IntRect>& cutOutRects);
193 RawPtrWillBeMember<HTMLPlugInElement> m_element;
194 WebPlugin* m_webPlugin;
195 Vector<WebPluginLoadObserver*> m_pluginLoadObservers;
197 WebLayer* m_webLayer;
199 IntRect m_pendingInvalidationRect;
201 TouchEventRequestType m_touchEventRequestType;
202 bool m_wantsWheelEvents;
204 bool m_inDispose;
205 #if ENABLE(OILPAN)
206 // Oilpan: if true, the plugin container must dispose
207 // of its plugin when being finalized.
208 bool m_shouldDisposePlugin;
209 #endif
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);
217 } // namespace blink
219 #endif