Home | History | Annotate | Download | only in web
      1 /*
      2  * Copyright (C) 2009 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 WebPluginContainer_h
     33 #define WebPluginContainer_h
     34 
     35 #include "../platform/WebCommon.h"
     36 #include <v8.h>
     37 
     38 struct NPObject;
     39 
     40 namespace blink {
     41 
     42 class WebElement;
     43 class WebPlugin;
     44 class WebString;
     45 class WebURL;
     46 class WebURLRequest;
     47 class WebLayer;
     48 struct WebPoint;
     49 struct WebRect;
     50 
     51 class WebPluginContainer {
     52 public:
     53     enum TouchEventRequestType {
     54         TouchEventRequestTypeNone,
     55         TouchEventRequestTypeRaw,
     56         TouchEventRequestTypeSynthesizedMouse,
     57     };
     58 
     59     // Returns the element containing this plugin.
     60     virtual WebElement element() = 0;
     61 
     62     virtual void invalidate() = 0;
     63     virtual void invalidateRect(const WebRect&) = 0;
     64     virtual void scrollRect(const WebRect&) = 0;
     65 
     66     // Causes the container to report its current geometry via
     67     // WebPlugin::updateGeometry.
     68     virtual void reportGeometry() = 0;
     69 
     70     // Allow the plugin to pass script objects to the browser. The container
     71     // tracks ownership of script objects in order to allow browser references
     72     // to them to be dropped when clearScriptObjects is called.
     73     virtual void allowScriptObjects() = 0;
     74 
     75     // Drop any references to script objects allocated by the plugin.
     76     // These are objects derived from WebPlugin::scriptableObject.  This is
     77     // called when the plugin is being destroyed or if it needs to be
     78     // re-initialized.
     79     virtual void clearScriptObjects() = 0;
     80 
     81     // Returns the scriptable object associated with the DOM element
     82     // containing the plugin.
     83     virtual NPObject* scriptableObjectForElement() = 0;
     84 
     85     // Returns the scriptable object associated with the DOM element
     86     // containing the plugin as a native v8 object.
     87     virtual v8::Local<v8::Object> v8ObjectForElement() = 0;
     88 
     89     // Executes a "javascript:" URL on behalf of the plugin in the context
     90     // of the frame containing the plugin.  Returns the result of script
     91     // execution, if any.
     92     virtual WebString executeScriptURL(const WebURL&, bool popupsAllowed) = 0;
     93 
     94     // Loads an URL in the specified frame (or the frame containing this
     95     // plugin if target is empty).  If notifyNeeded is true, then upon
     96     // completion, WebPlugin::didFinishLoadingFrameRequest is called if the
     97     // load was successful or WebPlugin::didFailLoadingFrameRequest is
     98     // called if the load failed.  The given notifyData is passed along to
     99     // the callback.
    100     virtual void loadFrameRequest(
    101         const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData) = 0;
    102 
    103     // Notifies that the zoom level has changed.
    104     // Note, this does NOT affect pageScaleFactor or pageZoomFactor
    105     virtual void zoomLevelChanged(double zoomLevel) = 0;
    106 
    107     // Determines whether the given rectangle in this plugin is above all other
    108     // content. The rectangle is in the plugin's coordinate system.
    109     virtual bool isRectTopmost(const WebRect&) = 0;
    110 
    111     // Notifies when the plugin changes the kind of touch-events it accepts.
    112     virtual void requestTouchEventType(TouchEventRequestType) = 0;
    113 
    114     // Notifies when the plugin starts/stops accepting wheel events. Without
    115     // calling the function with true, the container might not always able to
    116     // receive wheel events in some cases (such as when threaded compositing
    117     // is in use but a scroll bar is not in use).
    118     virtual void setWantsWheelEvents(bool) = 0;
    119 
    120     // Converts view's window coordinates to plugin's local coordinates.
    121     virtual WebPoint windowToLocalPoint(const WebPoint&) = 0;
    122 
    123     // Converts plugin's local coordinate to view's window coordinates.
    124     virtual WebPoint localToWindowPoint(const WebPoint&) = 0;
    125 
    126     virtual WebPlugin* plugin() = 0;
    127     virtual void setPlugin(WebPlugin*) = 0;
    128 
    129     virtual float deviceScaleFactor() = 0;
    130     virtual float pageScaleFactor() = 0;
    131     virtual float pageZoomFactor() = 0;
    132 
    133     // Sets the layer representing the plugin for compositing. The
    134     // WebPluginContainer does *not* take ownership.
    135     virtual void setWebLayer(WebLayer*) = 0;
    136 
    137 protected:
    138     ~WebPluginContainer() { }
    139 };
    140 
    141 } // namespace blink
    142 
    143 #endif
    144