1/* 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2014 Opera Software ASA. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 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. 18 * 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. 30 */ 31 32#ifndef WebPlugin_h 33#define WebPlugin_h 34 35#include "../platform/WebCanvas.h" 36#include "../platform/WebString.h" 37#include "../platform/WebURL.h" 38#include "WebDragOperation.h" 39#include "WebDragStatus.h" 40#include "WebWidget.h" 41#include <v8.h> 42 43struct NPObject; 44struct _NPP; 45 46namespace blink { 47 48class WebDataSource; 49class WebDragData; 50class WebInputEvent; 51class WebPluginContainer; 52class WebURLResponse; 53struct WebCompositionUnderline; 54struct WebCursorInfo; 55struct WebPluginParams; 56struct WebPrintParams; 57struct WebPoint; 58struct WebRect; 59struct WebTextInputInfo; 60struct WebURLError; 61template <typename T> class WebVector; 62 63class WebPlugin { 64public: 65 virtual bool initialize(WebPluginContainer*) = 0; 66 virtual void destroy() = 0; 67 68 virtual WebPluginContainer* container() const { return 0; } 69 virtual void containerDidDetachFromParent() { } 70 71 virtual NPObject* scriptableObject() { return 0; } 72 virtual struct _NPP* pluginNPP() { return 0; } 73 74 // The same as scriptableObject() but allows to expose scriptable interface 75 // through plain v8 object instead of NPObject. 76 // If you override this function, you must return nullptr in scriptableObject(). 77 virtual v8::Local<v8::Object> v8ScriptableObject(v8::Isolate*) { return v8::Local<v8::Object>(); } 78 79 // Returns true if the form submission value is successfully obtained 80 // from the plugin. The value would be associated with the name attribute 81 // of the corresponding object element. 82 virtual bool getFormValue(WebString&) { return false; } 83 virtual bool supportsKeyboardFocus() const { return false; } 84 virtual bool supportsEditCommands() const { return false; } 85 // Returns true if this plugin supports input method, which implements 86 // setComposition() and confirmComposition() below. 87 virtual bool supportsInputMethod() const { return false; } 88 89 virtual bool canProcessDrag() const { return false; } 90 91 virtual void paint(WebCanvas*, const WebRect&) = 0; 92 93 // Coordinates are relative to the containing window. 94 virtual void updateGeometry( 95 const WebRect& frameRect, const WebRect& clipRect, 96 const WebVector<WebRect>& cutOutsRects, bool isVisible) = 0; 97 98 virtual void updateFocus(bool) = 0; 99 virtual void updateVisibility(bool) = 0; 100 101 virtual bool acceptsInputEvents() = 0; 102 virtual bool handleInputEvent(const WebInputEvent&, WebCursorInfo&) = 0; 103 104 virtual bool handleDragStatusUpdate(WebDragStatus, const WebDragData&, WebDragOperationsMask, const WebPoint& position, const WebPoint& screenPosition) { return false; } 105 106 virtual void didReceiveResponse(const WebURLResponse&) = 0; 107 virtual void didReceiveData(const char* data, int dataLength) = 0; 108 virtual void didFinishLoading() = 0; 109 virtual void didFailLoading(const WebURLError&) = 0; 110 111 // Called in response to WebPluginContainer::loadFrameRequest 112 virtual void didFinishLoadingFrameRequest( 113 const WebURL&, void* notifyData) = 0; 114 virtual void didFailLoadingFrameRequest( 115 const WebURL&, void* notifyData, const WebURLError&) = 0; 116 117 // Printing interface. 118 // Whether the plugin supports its own paginated print. The other print 119 // interface methods are called only if this method returns true. 120 virtual bool supportsPaginatedPrint() { return false; } 121 // Returns true if the printed content should not be scaled to 122 // the printer's printable area. 123 virtual bool isPrintScalingDisabled() { return false; } 124 // Returns number of copies to be printed. 125 virtual int getCopiesToPrint() { return 1; } 126 127 // Sets up printing with the specified printParams. Returns the number of 128 // pages to be printed at these settings. 129 virtual int printBegin(const WebPrintParams& printParams) { return 0; } 130 131 // Prints the page specified by pageNumber (0-based index) into the supplied canvas. 132 virtual bool printPage(int pageNumber, WebCanvas* canvas) { return false; } 133 // Ends the print operation. 134 virtual void printEnd() { } 135 136 virtual bool hasSelection() const { return false; } 137 virtual WebString selectionAsText() const { return WebString(); } 138 virtual WebString selectionAsMarkup() const { return WebString(); } 139 140 virtual bool executeEditCommand(const WebString& name) { return false; } 141 virtual bool executeEditCommand(const WebString& name, const WebString& value) { return false; } 142 143 // Sets composition text from input method, and returns true if the 144 // composition is set successfully. 145 virtual bool setComposition(const WebString& text, const WebVector<WebCompositionUnderline>& underlines, int selectionStart, int selectionEnd) { return false; } 146 // Confirms an ongoing composition and returns true if there is an ongoing 147 // composition or the text is inserted. 148 virtual bool confirmComposition(const WebString& text, WebWidget::ConfirmCompositionBehavior selectionBehavior) { return false; } 149 // Deletes the current selection plus the specified number of characters 150 // before and after the selection or caret. 151 virtual void extendSelectionAndDelete(int before, int after) { } 152 // If the given position is over a link, returns the absolute url. 153 // Otherwise an empty url is returned. 154 virtual WebURL linkAtPosition(const WebPoint& position) const { return WebURL(); } 155 156 // Used for zooming of full page plugins. 157 virtual void setZoomLevel(double level, bool textOnly) { } 158 159 // Find interface. 160 // Start a new search. The plugin should search for a little bit at a time so that it 161 // doesn't block the thread in case of a large document. The results, along with the 162 // find's identifier, should be sent asynchronously to WebFrameClient's reportFindInPage* methods. 163 // Returns true if the search started, or false if the plugin doesn't support search. 164 virtual bool startFind(const WebString& searchText, bool caseSensitive, int identifier) { return false; } 165 // Tells the plugin to jump forward or backward in the list of find results. 166 virtual void selectFindResult(bool forward) { } 167 // Tells the plugin that the user has stopped the find operation. 168 virtual void stopFind() { } 169 170 // View rotation types. 171 enum RotationType { 172 RotationType90Clockwise, 173 RotationType90Counterclockwise 174 }; 175 // Whether the plugin can rotate the view of its content. 176 virtual bool canRotateView() { return false; } 177 // Rotates the plugin's view of its content. 178 virtual void rotateView(RotationType type) { } 179 180 virtual bool isPlaceholder() { return true; } 181 virtual bool shouldPersist() const { return false; } 182 183protected: 184 ~WebPlugin() { } 185}; 186 187} // namespace blink 188 189#endif 190