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