| 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..79acc82e24f643adce9074a9e021c21338d4212a 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,11 @@
|
|
|
| package org.chromium.android_webview;
|
|
|
| +import android.content.ActivityNotFoundException;
|
| import android.content.Context;
|
| +import android.content.Intent;
|
| +import android.provider.Browser;
|
| +import android.util.Log;
|
| import android.view.KeyEvent;
|
| import android.view.View;
|
| import android.webkit.URLUtil;
|
| @@ -13,11 +17,16 @@ import android.widget.FrameLayout;
|
|
|
| import org.chromium.content.browser.ContentVideoViewClient;
|
| import org.chromium.content.browser.ContentViewClient;
|
| +import org.chromium.content.browser.ContentViewCore;
|
| +
|
| +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;
|
| @@ -39,8 +48,41 @@ public class AwContentViewClient extends ContentViewClient implements ContentVid
|
|
|
| @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 (ContentViewCore.activityFromContext(context) == null) {
|
| + 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 +92,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 Chrome'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
|
|
|