forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android_webview] Move the glue layer into android_webview/glue
This checks in a copy of the WebView glue layer from master-chromium at revision d519b07bd3cb09b571689b00250cb5de977b4dfc. Changes to make the code adhere to the style guide, fix up warnigns and actually switch over to this from the copy in third_party will be made as subsequent CLs. BUG=440792 TEST=None R=torne@chromium.org Review URL: https://codereview.chromium.org/784973004 Cr-Commit-Position: refs/heads/master@{#307732}
- Loading branch information
Marcin Kosiba
committed
Dec 10, 2014
1 parent
f827854
commit d6d785a
Showing
26 changed files
with
5,703 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+6.89 KB
android_webview/glue/java/res/drawable-hdpi/ic_media_video_poster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.44 KB
android_webview/glue/java/res/drawable-ldpi/ic_media_video_poster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.42 KB
android_webview/glue/java/res/drawable-mdpi/ic_media_video_poster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.36 KB
android_webview/glue/java/res/drawable-xhdpi/ic_media_video_poster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
606 changes: 606 additions & 0 deletions
606
android_webview/glue/java/src/com/android/webview/chromium/ContentSettingsAdapter.java
Large diffs are not rendered by default.
Oops, something went wrong.
148 changes: 148 additions & 0 deletions
148
android_webview/glue/java/src/com/android/webview/chromium/CookieManagerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package com.android.webview.chromium; | ||
|
||
import android.net.ParseException; | ||
import android.net.WebAddress; | ||
import android.util.Log; | ||
import android.webkit.CookieManager; | ||
import android.webkit.ValueCallback; | ||
import android.webkit.WebView; | ||
|
||
import org.chromium.android_webview.AwCookieManager; | ||
|
||
public class CookieManagerAdapter extends CookieManager { | ||
|
||
private static final String LOGTAG = "CookieManager"; | ||
|
||
AwCookieManager mChromeCookieManager; | ||
|
||
public CookieManagerAdapter(AwCookieManager chromeCookieManager) { | ||
mChromeCookieManager = chromeCookieManager; | ||
} | ||
|
||
@Override | ||
public synchronized void setAcceptCookie(boolean accept) { | ||
mChromeCookieManager.setAcceptCookie(accept); | ||
} | ||
|
||
@Override | ||
public synchronized boolean acceptCookie() { | ||
return mChromeCookieManager.acceptCookie(); | ||
} | ||
|
||
@Override | ||
public synchronized void setAcceptThirdPartyCookies(WebView webView, boolean accept) { | ||
webView.getSettings().setAcceptThirdPartyCookies(accept); | ||
} | ||
|
||
@Override | ||
public synchronized boolean acceptThirdPartyCookies(WebView webView) { | ||
return webView.getSettings().getAcceptThirdPartyCookies(); | ||
} | ||
|
||
@Override | ||
public void setCookie(String url, String value) { | ||
try { | ||
mChromeCookieManager.setCookie(fixupUrl(url), value); | ||
} catch (ParseException e) { | ||
Log.e(LOGTAG, "Not setting cookie due to error parsing URL: " + url, e); | ||
} | ||
} | ||
|
||
@Override | ||
public void setCookie(String url, String value, ValueCallback<Boolean> callback) { | ||
try { | ||
mChromeCookieManager.setCookie(fixupUrl(url), value, callback); | ||
} catch (ParseException e) { | ||
Log.e(LOGTAG, "Not setting cookie due to error parsing URL: " + url, e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getCookie(String url) { | ||
try { | ||
return mChromeCookieManager.getCookie(fixupUrl(url)); | ||
} catch (ParseException e) { | ||
Log.e(LOGTAG, "Unable to get cookies due to error parsing URL: " + url, e); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public String getCookie(String url, boolean privateBrowsing) { | ||
return getCookie(url); | ||
} | ||
|
||
// TODO(igsolla): remove this override once the WebView apk does not longer need | ||
// to be binary compatibility with the API 21 version of the framework | ||
/** | ||
* IMPORTANT: This override is required for compatibility with the API 21 version of | ||
* {@link CookieManager}. | ||
*/ | ||
@Override | ||
public synchronized String getCookie(WebAddress uri) { | ||
return mChromeCookieManager.getCookie(uri.toString()); | ||
} | ||
|
||
@Override | ||
public void removeSessionCookie() { | ||
mChromeCookieManager.removeSessionCookies(); | ||
} | ||
|
||
@Override | ||
public void removeSessionCookies(ValueCallback<Boolean> callback) { | ||
mChromeCookieManager.removeSessionCookies(callback); | ||
} | ||
|
||
@Override | ||
public void removeAllCookie() { | ||
mChromeCookieManager.removeAllCookies(); | ||
} | ||
|
||
@Override | ||
public void removeAllCookies(ValueCallback<Boolean> callback) { | ||
mChromeCookieManager.removeAllCookies(callback); | ||
} | ||
|
||
@Override | ||
public synchronized boolean hasCookies() { | ||
return mChromeCookieManager.hasCookies(); | ||
} | ||
|
||
@Override | ||
public synchronized boolean hasCookies(boolean privateBrowsing) { | ||
return mChromeCookieManager.hasCookies(); | ||
} | ||
|
||
@Override | ||
public void removeExpiredCookie() { | ||
mChromeCookieManager.removeExpiredCookie(); | ||
} | ||
|
||
@Override | ||
public void flush() { | ||
mChromeCookieManager.flushCookieStore(); | ||
} | ||
|
||
@Override | ||
protected boolean allowFileSchemeCookiesImpl() { | ||
return mChromeCookieManager.allowFileSchemeCookies(); | ||
} | ||
|
||
@Override | ||
protected void setAcceptFileSchemeCookiesImpl(boolean accept) { | ||
mChromeCookieManager.setAcceptFileSchemeCookies(accept); | ||
} | ||
|
||
private static String fixupUrl(String url) throws ParseException { | ||
// WebAddress is a private API in the android framework and a "quirk" | ||
// of the Classic WebView implementation that allowed embedders to | ||
// be relaxed about what URLs they passed into the CookieManager, so we | ||
// do the same normalisation before entering the chromium stack. | ||
return new WebAddress(url).toString(); | ||
} | ||
|
||
} |
112 changes: 112 additions & 0 deletions
112
android_webview/glue/java/src/com/android/webview/chromium/DrawGLFunctor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package com.android.webview.chromium; | ||
|
||
import android.view.View; | ||
import android.graphics.Canvas; | ||
import android.util.Log; | ||
|
||
import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate; | ||
|
||
import org.chromium.content.common.CleanupReference; | ||
|
||
// Simple Java abstraction and wrapper for the native DrawGLFunctor flow. | ||
// An instance of this class can be constructed, bound to a single view context (i.e. AwContennts) | ||
// and then drawn and detached from the view tree any number of times (using requestDrawGL and | ||
// detach respectively). Then when finished with, it can be explicitly released by calling | ||
// destroy() or will clean itself up as required via finalizer / CleanupReference. | ||
class DrawGLFunctor { | ||
|
||
private static final String TAG = DrawGLFunctor.class.getSimpleName(); | ||
|
||
// Pointer to native side instance | ||
private CleanupReference mCleanupReference; | ||
private DestroyRunnable mDestroyRunnable; | ||
private WebViewDelegate mWebViewDelegate; | ||
|
||
public DrawGLFunctor(long viewContext, WebViewDelegate webViewDelegate) { | ||
mDestroyRunnable = new DestroyRunnable(nativeCreateGLFunctor(viewContext), webViewDelegate); | ||
mCleanupReference = new CleanupReference(this, mDestroyRunnable); | ||
mWebViewDelegate = webViewDelegate; | ||
} | ||
|
||
public void destroy() { | ||
detach(); | ||
if (mCleanupReference != null) { | ||
mCleanupReference.cleanupNow(); | ||
mCleanupReference = null; | ||
mDestroyRunnable = null; | ||
mWebViewDelegate = null; | ||
} | ||
} | ||
|
||
public void detach() { | ||
mDestroyRunnable.detachNativeFunctor(); | ||
} | ||
|
||
public boolean requestDrawGL(Canvas canvas, View containerView, | ||
boolean waitForCompletion) { | ||
if (mDestroyRunnable.mNativeDrawGLFunctor == 0) { | ||
throw new RuntimeException("requested DrawGL on already destroyed DrawGLFunctor"); | ||
} | ||
|
||
if (canvas != null && waitForCompletion) { | ||
throw new IllegalArgumentException("requested a blocking DrawGL with a not null canvas."); | ||
} | ||
|
||
if (!mWebViewDelegate.canInvokeDrawGlFunctor(containerView)) { | ||
return false; | ||
} | ||
|
||
mDestroyRunnable.mContainerView = containerView; | ||
|
||
if (canvas == null) { | ||
mWebViewDelegate.invokeDrawGlFunctor(containerView, | ||
mDestroyRunnable.mNativeDrawGLFunctor, waitForCompletion); | ||
return true; | ||
} | ||
|
||
mWebViewDelegate.callDrawGlFunction(canvas, mDestroyRunnable.mNativeDrawGLFunctor); | ||
return true; | ||
} | ||
|
||
public static void setChromiumAwDrawGLFunction(long functionPointer) { | ||
nativeSetChromiumAwDrawGLFunction(functionPointer); | ||
} | ||
|
||
// Holds the core resources of the class, everything required to correctly cleanup. | ||
// IMPORTANT: this class must not hold any reference back to the outer DrawGLFunctor | ||
// instance, as that will defeat GC of that object. | ||
private static final class DestroyRunnable implements Runnable { | ||
private WebViewDelegate mWebViewDelegate; | ||
View mContainerView; | ||
long mNativeDrawGLFunctor; | ||
DestroyRunnable(long nativeDrawGLFunctor, WebViewDelegate webViewDelegate) { | ||
mNativeDrawGLFunctor = nativeDrawGLFunctor; | ||
mWebViewDelegate = webViewDelegate; | ||
} | ||
|
||
// Called when the outer DrawGLFunctor instance has been GC'ed, i.e this is its finalizer. | ||
@Override | ||
public void run() { | ||
detachNativeFunctor(); | ||
nativeDestroyGLFunctor(mNativeDrawGLFunctor); | ||
mNativeDrawGLFunctor = 0; | ||
} | ||
|
||
void detachNativeFunctor() { | ||
if (mNativeDrawGLFunctor != 0 && mContainerView != null | ||
&& mWebViewDelegate != null) { | ||
mWebViewDelegate.detachDrawGlFunctor(mContainerView, mNativeDrawGLFunctor); | ||
} | ||
mContainerView = null; | ||
mWebViewDelegate = null; | ||
} | ||
} | ||
|
||
private static native long nativeCreateGLFunctor(long viewContext); | ||
private static native void nativeDestroyGLFunctor(long functor); | ||
private static native void nativeSetChromiumAwDrawGLFunction(long functionPointer); | ||
} |
77 changes: 77 additions & 0 deletions
77
android_webview/glue/java/src/com/android/webview/chromium/FileChooserParamsAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package com.android.webview.chromium; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.webkit.WebChromeClient.FileChooserParams; | ||
|
||
import org.chromium.android_webview.AwContentsClient; | ||
|
||
public class FileChooserParamsAdapter extends FileChooserParams { | ||
private AwContentsClient.FileChooserParams mParams; | ||
|
||
public static Uri[] parseFileChooserResult(int resultCode, Intent intent) { | ||
if (resultCode == Activity.RESULT_CANCELED) { | ||
return null; | ||
} | ||
Uri result = intent == null || resultCode != Activity.RESULT_OK ? null | ||
: intent.getData(); | ||
|
||
Uri[] uris = null; | ||
if (result != null) { | ||
uris = new Uri[1]; | ||
uris[0] = result; | ||
} | ||
return uris; | ||
} | ||
|
||
FileChooserParamsAdapter(AwContentsClient.FileChooserParams params, Context context) { | ||
mParams = params; | ||
} | ||
|
||
@Override | ||
public int getMode() { | ||
return mParams.mode; | ||
} | ||
|
||
@Override | ||
public String[] getAcceptTypes() { | ||
if (mParams.acceptTypes == null) | ||
return new String[0]; | ||
return mParams.acceptTypes.split(";"); | ||
} | ||
|
||
@Override | ||
public boolean isCaptureEnabled() { | ||
return mParams.capture; | ||
} | ||
|
||
@Override | ||
public CharSequence getTitle() { | ||
return mParams.title; | ||
} | ||
|
||
@Override | ||
public String getFilenameHint() { | ||
return mParams.defaultFilename; | ||
} | ||
|
||
@Override | ||
public Intent createIntent() { | ||
// TODO: Move this code to Aw. Once code is moved | ||
// and merged to M37 get rid of this. | ||
String mimeType = "*/*"; | ||
if (mParams.acceptTypes != null && !mParams.acceptTypes.trim().isEmpty()) | ||
mimeType = mParams.acceptTypes.split(";")[0]; | ||
|
||
Intent i = new Intent(Intent.ACTION_GET_CONTENT); | ||
i.addCategory(Intent.CATEGORY_OPENABLE); | ||
i.setType(mimeType); | ||
return i; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...oid_webview/glue/java/src/com/android/webview/chromium/GeolocationPermissionsAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package com.android.webview.chromium; | ||
|
||
import android.webkit.GeolocationPermissions; | ||
import android.webkit.ValueCallback; | ||
|
||
import org.chromium.android_webview.AwGeolocationPermissions; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Chromium implementation of GeolocationPermissions -- forwards calls to the | ||
* chromium internal implementation. | ||
*/ | ||
final class GeolocationPermissionsAdapter extends GeolocationPermissions { | ||
|
||
private AwGeolocationPermissions mChromeGeolocationPermissions; | ||
|
||
public GeolocationPermissionsAdapter(AwGeolocationPermissions chromeGeolocationPermissions) { | ||
mChromeGeolocationPermissions = chromeGeolocationPermissions; | ||
} | ||
|
||
@Override | ||
public void allow(String origin) { | ||
mChromeGeolocationPermissions.allow(origin); | ||
} | ||
|
||
@Override | ||
public void clear(String origin) { | ||
mChromeGeolocationPermissions.clear(origin); | ||
} | ||
|
||
@Override | ||
public void clearAll() { | ||
mChromeGeolocationPermissions.clearAll(); | ||
} | ||
|
||
@Override | ||
public void getAllowed(String origin, ValueCallback<Boolean> callback) { | ||
mChromeGeolocationPermissions.getAllowed(origin, callback); | ||
} | ||
|
||
@Override | ||
public void getOrigins(ValueCallback<Set<String>> callback) { | ||
mChromeGeolocationPermissions.getOrigins(callback); | ||
} | ||
} |
Oops, something went wrong.