• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2008, The Android Open Source Project
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *  * Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  *  * Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 // must include config.h first for webkit to fiddle with new/delete
27 #include "config.h"
28 #include "SkANP.h"
29 #include "WebViewCore.h"
30 #include "PluginView.h"
31 #include "PluginWidgetAndroid.h"
32 
pluginViewForInstance(NPP instance)33 static PluginView* pluginViewForInstance(NPP instance) {
34     if (instance && instance->ndata)
35         return static_cast<PluginView*>(instance->ndata);
36     return PluginView::currentPluginView();
37 }
38 
anp_setVisibleRects(NPP instance,const ANPRectI rects[],int32_t count)39 static void anp_setVisibleRects(NPP instance, const ANPRectI rects[], int32_t count) {
40     PluginView* pluginView = pluginViewForInstance(instance);
41     PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
42     pluginWidget->setVisibleRects(rects, count);
43 }
44 
anp_clearVisibleRects(NPP instance)45 static void anp_clearVisibleRects(NPP instance) {
46     anp_setVisibleRects(instance, NULL, 0);
47 }
48 
anp_showKeyboard(NPP instance,bool value)49 static void anp_showKeyboard(NPP instance, bool value) {
50     PluginView* pluginView = pluginViewForInstance(instance);
51     PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
52     if(pluginWidget->hasFocus())
53         pluginWidget->webViewCore()->requestKeyboard(value);
54 }
55 
anp_requestFullScreen(NPP instance)56 static void anp_requestFullScreen(NPP instance) {
57     PluginView* pluginView = pluginViewForInstance(instance);
58     // call focusPluginElement() so that the pluginView receives keyboard events
59     pluginView->focusPluginElement();
60     PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
61     pluginWidget->requestFullScreen();
62 }
63 
anp_exitFullScreen(NPP instance)64 static void anp_exitFullScreen(NPP instance) {
65     PluginView* pluginView = pluginViewForInstance(instance);
66     PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
67     pluginWidget->exitFullScreen(true);
68 }
69 
anp_requestCenterFitZoom(NPP instance)70 static void anp_requestCenterFitZoom(NPP instance) {
71     PluginView* pluginView = pluginViewForInstance(instance);
72     PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
73     pluginWidget->requestCenterFitZoom();
74 }
75 
anp_visibleRect(NPP instance)76 static ANPRectI anp_visibleRect(NPP instance) {
77     PluginView* pluginView = pluginViewForInstance(instance);
78     PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
79     return pluginWidget->visibleRect();
80 }
81 
anp_requestFullScreenOrientation(NPP instance,ANPScreenOrientation orientation)82 static void anp_requestFullScreenOrientation(NPP instance, ANPScreenOrientation orientation) {
83     PluginView* pluginView = pluginViewForInstance(instance);
84     PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
85     pluginWidget->setFullScreenOrientation(orientation);
86 }
87 
88 ///////////////////////////////////////////////////////////////////////////////
89 
90 #define ASSIGN(obj, name)   (obj)->name = anp_##name
91 
ANPWindowInterfaceV0_Init(ANPInterface * value)92 void ANPWindowInterfaceV0_Init(ANPInterface* value) {
93     ANPWindowInterfaceV0* i = reinterpret_cast<ANPWindowInterfaceV0*>(value);
94 
95     ASSIGN(i, setVisibleRects);
96     ASSIGN(i, clearVisibleRects);
97     ASSIGN(i, showKeyboard);
98     ASSIGN(i, requestFullScreen);
99     ASSIGN(i, exitFullScreen);
100     ASSIGN(i, requestCenterFitZoom);
101 }
102 
ANPWindowInterfaceV1_Init(ANPInterface * value)103 void ANPWindowInterfaceV1_Init(ANPInterface* value) {
104     // initialize the functions from the previous interface
105     ANPWindowInterfaceV0_Init(value);
106     // add any new functions or override existing functions
107     ANPWindowInterfaceV1* i = reinterpret_cast<ANPWindowInterfaceV1*>(value);
108     ASSIGN(i, visibleRect);
109 }
110 
ANPWindowInterfaceV2_Init(ANPInterface * value)111 void ANPWindowInterfaceV2_Init(ANPInterface* value) {
112     // initialize the functions from the previous interface
113     ANPWindowInterfaceV1_Init(value);
114     // add any new functions or override existing functions
115     ANPWindowInterfaceV2* i = reinterpret_cast<ANPWindowInterfaceV2*>(value);
116     ASSIGN(i, requestFullScreenOrientation);
117 }
118