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