Switching from activity based full screen plugins to a view system overlay.

This commit is contained in:
Derek Sollenberger
2009-12-07 16:15:13 -05:00
parent 7e42e8f334
commit 51ef573a83
5 changed files with 103 additions and 91 deletions

View File

@@ -108,6 +108,8 @@ class CallbackProxy extends Handler {
private static final int RECEIVED_TOUCH_ICON_URL = 132;
private static final int GET_VISITED_HISTORY = 133;
private static final int OPEN_FILE_CHOOSER = 134;
private static final int SHOW_CUSTOM_VIEW = 135;
private static final int HIDE_CUSTOM_VIEW = 136;
// Message triggered by the client to resume execution
private static final int NOTIFY = 200;
@@ -679,6 +681,23 @@ class CallbackProxy extends Handler {
mWebChromeClient.openFileChooser((UploadFile) msg.obj);
}
break;
case SHOW_CUSTOM_VIEW:
if (mWebChromeClient != null) {
HashMap<String, Object> map =
(HashMap<String, Object>) msg.obj;
View view = (View) map.get("view");
WebChromeClient.CustomViewCallback callback =
(WebChromeClient.CustomViewCallback) map.get("callback");
mWebChromeClient.onShowCustomView(view, callback);
}
break;
case HIDE_CUSTOM_VIEW:
if (mWebChromeClient != null) {
mWebChromeClient.onHideCustomView();
}
break;
}
}
@@ -1385,4 +1404,24 @@ class CallbackProxy extends Handler {
}
return uploadFile.getResult();
}
/* package */ void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {
if (mWebChromeClient == null) {
return;
}
Message msg = obtainMessage(SHOW_CUSTOM_VIEW);
HashMap<String, Object> map = new HashMap();
map.put("view", view);
map.put("callback", callback);
msg.obj = map;
sendMessage(msg);
}
/* package */ void hideCustomView() {
if (mWebChromeClient == null) {
return;
}
Message msg = obtainMessage(HIDE_CUSTOM_VIEW);
sendMessage(msg);
}
}

View File

@@ -1,83 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.webkit;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.plugin.SurfaceDrawingModel;
import android.webkit.plugin.WebkitPlugin;
/**
* This activity is invoked when a plugin elects to go into full screen mode.
* @hide
*/
public class PluginActivity extends Activity {
private static final String LOGTAG = "PluginActivity";
/* package */ static final String INTENT_EXTRA_NPP_INSTANCE =
"android.webkit.plugin.NPP_INSTANCE";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = getIntent();
if (intent == null) {
Log.e(LOGTAG, "Unable to retrieve the intent responsible for this activity");
finish();
return;
}
final int npp = intent.getIntExtra(INTENT_EXTRA_NPP_INSTANCE, -1);
if (npp == -1) {
Log.e(LOGTAG, "The intent did not include the NPP pointer");
finish();
return;
}
// retrieve the plugin's existing java object instead of creating a new one
WebkitPlugin plugin = nativeGetWebkitPlugin(npp);
if (plugin == null) {
Log.e(LOGTAG, "Unable to retrieve the plugin's java interface");
finish();
return;
}
SurfaceDrawingModel fullScreenSurface = plugin.getFullScreenSurface();
if (fullScreenSurface == null) {
Log.e(LOGTAG, "The plugin returned a null value for the full-screen interface");
finish();
return;
}
View pluginView = fullScreenSurface.getSurface();
if (pluginView != null) {
setContentView(pluginView);
} else {
// No custom full-sreen view returned by the plugin, odd but
// just in case, finish the activity.
Log.e(LOGTAG, "The plugin's full-screen interface returned a null view");
finish();
}
}
native WebkitPlugin nativeGetWebkitPlugin(int npp);
}

View File

@@ -41,6 +41,7 @@ import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.webkit.plugin.FullScreenDrawingModel;
import android.webkit.plugin.SurfaceDrawingModel;
import android.webkit.plugin.WebkitPlugin;
@@ -2214,16 +2215,36 @@ final class WebViewCore {
return pluginManager.getPluginInstance(pkgName, npp);
}
// called by JNI. PluginWidget function to launch an activity and overlays
// the activity with the View provided by the plugin class.
private void startFullScreenPluginActivity(int npp) {
// called by JNI. PluginWidget function to launch a full-screen view using a
// View object provided by the plugin class.
private void showFullScreenPlugin(WebkitPlugin webkitPlugin) {
if (mWebView == null) {
return;
}
Intent intent = new Intent("android.intent.webkit.PLUGIN");
intent.putExtra(PluginActivity.INTENT_EXTRA_NPP_INSTANCE, npp);
mWebView.getContext().startActivity(intent);
final FullScreenDrawingModel surface = webkitPlugin.getFullScreenSurface();
if(surface == null) {
Log.e(LOGTAG, "Attempted to create an full-screen surface with a null drawing model");
return;
}
WebChromeClient.CustomViewCallback callback = new WebChromeClient.CustomViewCallback() {
public void onCustomViewHidden() {
if (surface != null) {
surface.onSurfaceRemoved();
}
}
};
mCallbackProxy.showCustomView(surface.getSurface(), callback);
}
private void hideFullScreenPlugin() {
if (mWebView == null) {
return;
}
mCallbackProxy.hideCustomView();
}
// called by JNI. PluginWidget functions for creating an embedded View for

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2009, The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package android.webkit.plugin;
/**
*
* @hide pending API solidification
*/
public interface FullScreenDrawingModel extends SurfaceDrawingModel {
public void onSurfaceRemoved();
}

View File

@@ -30,7 +30,7 @@ package android.webkit.plugin;
*/
public interface WebkitPlugin {
SurfaceDrawingModel getEmbeddedSurface();
SurfaceDrawingModel getFullScreenSurface();
SurfaceDrawingModel getEmbeddedSurface();
FullScreenDrawingModel getFullScreenSurface();
}