Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2967)

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java

Issue 985833004: Move NullWebViewClient implementation to chromium layer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: run time check activity + wrapper Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java b/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java
index 13313e3a108a5ac5263c439d813b738a917c94be..01d7a74466fa970aafd122bd5cc6d525356e3c25 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java
@@ -4,7 +4,13 @@
package org.chromium.android_webview;
+import android.app.Activity;
+import android.content.ActivityNotFoundException;
import android.content.Context;
+import android.content.ContextWrapper;
+import android.content.Intent;
+import android.provider.Browser;
+import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.URLUtil;
@@ -14,10 +20,14 @@ import android.widget.FrameLayout;
import org.chromium.content.browser.ContentVideoViewClient;
import org.chromium.content.browser.ContentViewClient;
+import java.net.URISyntaxException;
+
/**
* ContentViewClient implementation for WebView
*/
public class AwContentViewClient extends ContentViewClient implements ContentVideoViewClient {
+ private static final String TAG = "AwContentViewClient";
+
private final AwContentsClient mAwContentsClient;
private final AwSettings mAwSettings;
private final AwContents mAwContents;
@@ -37,10 +47,53 @@ public class AwContentViewClient extends ContentViewClient implements ContentVid
mAwContentsClient.onBackgroundColorChanged(color);
}
+ private static boolean isActivityContext(Context context) {
hush (inactive) 2015/03/06 23:43:55 ContextWrapper is already exposed to Chromium. you
boliu 2015/03/07 00:41:42 Oh nice. I'm not the first person to run into this
+ if (context instanceof Activity) {
+ return true;
+ } else if (context instanceof ContextWrapper) {
+ return isActivityContext(((ContextWrapper) context).getBaseContext());
+ } else {
+ return false;
+ }
+ }
+
@Override
public void onStartContentIntent(Context context, String contentUrl) {
- // Callback when detecting a click on a content link.
- mAwContentsClient.shouldOverrideUrlLoading(contentUrl);
+ if (mAwContentsClient.hasWebViewClient()) {
+ // Callback when detecting a click on a content link.
+ mAwContentsClient.shouldOverrideUrlLoading(contentUrl);
+ return;
+ }
+
+ Intent intent;
+ // Perform generic parsing of the URI to turn it into an Intent.
+ try {
+ intent = Intent.parseUri(contentUrl, Intent.URI_INTENT_SCHEME);
+ } catch (URISyntaxException ex) {
+ Log.w(TAG, "Bad URI " + contentUrl + ": " + ex.getMessage());
+ return;
+ }
+ // Sanitize the Intent, ensuring web pages can not bypass browser
+ // security (only access to BROWSABLE activities).
+ intent.addCategory(Intent.CATEGORY_BROWSABLE);
+ intent.setComponent(null);
+ Intent selector = intent.getSelector();
+ if (selector != null) {
+ selector.addCategory(Intent.CATEGORY_BROWSABLE);
+ selector.setComponent(null);
+ }
+ // Pass the package name as application ID so that the intent from the
+ // same application can be opened in the same tab.
+ intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
+ if (!isActivityContext(context)) {
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ }
+
+ try {
+ context.startActivity(intent);
+ } catch (ActivityNotFoundException ex) {
+ Log.w(TAG, "No application can handle " + contentUrl);
+ }
}
@Override
@@ -50,7 +103,14 @@ public class AwContentViewClient extends ContentViewClient implements ContentVid
@Override
public boolean shouldOverrideKeyEvent(KeyEvent event) {
- return mAwContentsClient.shouldOverrideKeyEvent(event);
+ if (mAwContentsClient.hasWebViewClient()) {
+ // The check below is reflecting Clank's behavior and is a workaround for
+ // http://b/7697782.
+ if (!ContentViewClient.shouldPropagateKey(event.getKeyCode())) return true;
+ return mAwContentsClient.shouldOverrideKeyEvent(event);
+ }
+
+ return super.shouldOverrideKeyEvent(event);
}
@Override

Powered by Google App Engine
This is Rietveld 408576698