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 "core/plugins/PluginView.h" 35#include "platform/Widget.h" 36#include "public/web/WebPluginContainer.h" 37 38#include "wtf/OwnPtr.h" 39#include "wtf/PassRefPtr.h" 40#include "wtf/Vector.h" 41#include "wtf/text/WTFString.h" 42 43struct NPObject; 44 45namespace WebCore { 46class GestureEvent; 47class HTMLPlugInElement; 48class IntRect; 49class KeyboardEvent; 50class MouseEvent; 51class PlatformGestureEvent; 52class ResourceError; 53class ResourceResponse; 54class TouchEvent; 55class WheelEvent; 56class Widget; 57} 58 59namespace blink { 60 61struct WebPrintParams; 62 63class ScrollbarGroup; 64class WebPlugin; 65class WebPluginLoadObserver; 66class WebExternalTextureLayer; 67 68class WebPluginContainerImpl FINAL : public WebCore::PluginView, public WebPluginContainer { 69public: 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&) OVERRIDE; 86 virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect&) OVERRIDE; 87 virtual void invalidateRect(const WebCore::IntRect&) OVERRIDE; 88 virtual void setFocus(bool) OVERRIDE; 89 virtual void show() OVERRIDE; 90 virtual void hide() OVERRIDE; 91 virtual void handleEvent(WebCore::Event*) OVERRIDE; 92 virtual void frameRectsChanged() OVERRIDE; 93 virtual void setParentVisible(bool) OVERRIDE; 94 virtual void setParent(WebCore::Widget*) OVERRIDE; 95 virtual void widgetPositionsUpdated() OVERRIDE; 96 virtual bool isPluginContainer() const OVERRIDE { return true; } 97 virtual void eventListenersRemoved() OVERRIDE; 98 virtual bool pluginShouldPersist() const OVERRIDE; 99 100 // WebPluginContainer methods 101 virtual WebElement element() OVERRIDE; 102 virtual void invalidate() OVERRIDE; 103 virtual void invalidateRect(const WebRect&) OVERRIDE; 104 virtual void scrollRect(int dx, int dy, const WebRect&) OVERRIDE; 105 virtual void reportGeometry() OVERRIDE; 106 virtual void allowScriptObjects() OVERRIDE; 107 virtual void clearScriptObjects() OVERRIDE; 108 virtual NPObject* scriptableObjectForElement() OVERRIDE; 109 virtual WebString executeScriptURL(const WebURL&, bool popupsAllowed) OVERRIDE; 110 virtual void loadFrameRequest(const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData) OVERRIDE; 111 virtual void zoomLevelChanged(double zoomLevel) OVERRIDE; 112 virtual bool isRectTopmost(const WebRect&) OVERRIDE; 113 virtual void requestTouchEventType(TouchEventRequestType) OVERRIDE; 114 virtual void setWantsWheelEvents(bool) OVERRIDE; 115 virtual WebPoint windowToLocalPoint(const WebPoint&) OVERRIDE; 116 virtual WebPoint localToWindowPoint(const WebPoint&) OVERRIDE; 117 118 // This cannot be null. 119 virtual WebPlugin* plugin() OVERRIDE { return m_webPlugin; } 120 virtual void setPlugin(WebPlugin*) OVERRIDE; 121 122 virtual float deviceScaleFactor() OVERRIDE; 123 virtual float pageScaleFactor() OVERRIDE; 124 virtual float pageZoomFactor() OVERRIDE; 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 165private: 166 WebPluginContainerImpl(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin); 167 virtual ~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 202DEFINE_TYPE_CASTS(WebPluginContainerImpl, WebCore::Widget, widget, widget->isPluginContainer(), widget.isPluginContainer()); 203// Unlike Widget, we need not worry about object type for container. 204// WebPluginContainerImpl is the only subclass of WebPluginContainer. 205DEFINE_TYPE_CASTS(WebPluginContainerImpl, WebPluginContainer, container, true, true); 206 207} // namespace blink 208 209#endif 210