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

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: 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..aa050604420ee1124cd175c29bb919c26d362d3a 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;
@@ -14,10 +18,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;
@@ -39,8 +47,39 @@ 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());
+ 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 +89,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
sgurun-gerrit only 2015/03/07 00:11:35 s/Clank/Chrome for Android/. seems forgotten in gl
boliu 2015/03/07 00:41:42 Just chrome is fine I think :p
+ // 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