Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.android_webview; | 5 package org.chromium.android_webview; |
| 6 | 6 |
| 7 import android.app.Activity; | |
| 8 import android.content.ActivityNotFoundException; | |
| 7 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.ContextWrapper; | |
| 11 import android.content.Intent; | |
| 12 import android.provider.Browser; | |
| 13 import android.util.Log; | |
| 8 import android.view.KeyEvent; | 14 import android.view.KeyEvent; |
| 9 import android.view.View; | 15 import android.view.View; |
| 10 import android.webkit.URLUtil; | 16 import android.webkit.URLUtil; |
| 11 import android.webkit.WebChromeClient; | 17 import android.webkit.WebChromeClient; |
| 12 import android.widget.FrameLayout; | 18 import android.widget.FrameLayout; |
| 13 | 19 |
| 14 import org.chromium.content.browser.ContentVideoViewClient; | 20 import org.chromium.content.browser.ContentVideoViewClient; |
| 15 import org.chromium.content.browser.ContentViewClient; | 21 import org.chromium.content.browser.ContentViewClient; |
| 16 | 22 |
| 23 import java.net.URISyntaxException; | |
| 24 | |
| 17 /** | 25 /** |
| 18 * ContentViewClient implementation for WebView | 26 * ContentViewClient implementation for WebView |
| 19 */ | 27 */ |
| 20 public class AwContentViewClient extends ContentViewClient implements ContentVid eoViewClient { | 28 public class AwContentViewClient extends ContentViewClient implements ContentVid eoViewClient { |
| 29 private static final String TAG = "AwContentViewClient"; | |
| 30 | |
| 21 private final AwContentsClient mAwContentsClient; | 31 private final AwContentsClient mAwContentsClient; |
| 22 private final AwSettings mAwSettings; | 32 private final AwSettings mAwSettings; |
| 23 private final AwContents mAwContents; | 33 private final AwContents mAwContents; |
| 24 private final Context mContext; | 34 private final Context mContext; |
| 25 private FrameLayout mCustomView; | 35 private FrameLayout mCustomView; |
| 26 | 36 |
| 27 public AwContentViewClient(AwContentsClient awContentsClient, AwSettings awS ettings, | 37 public AwContentViewClient(AwContentsClient awContentsClient, AwSettings awS ettings, |
| 28 AwContents awContents, Context context) { | 38 AwContents awContents, Context context) { |
| 29 mAwContentsClient = awContentsClient; | 39 mAwContentsClient = awContentsClient; |
| 30 mAwSettings = awSettings; | 40 mAwSettings = awSettings; |
| 31 mAwContents = awContents; | 41 mAwContents = awContents; |
| 32 mContext = context; | 42 mContext = context; |
| 33 } | 43 } |
| 34 | 44 |
| 35 @Override | 45 @Override |
| 36 public void onBackgroundColorChanged(int color) { | 46 public void onBackgroundColorChanged(int color) { |
| 37 mAwContentsClient.onBackgroundColorChanged(color); | 47 mAwContentsClient.onBackgroundColorChanged(color); |
| 38 } | 48 } |
| 39 | 49 |
| 50 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
| |
| 51 if (context instanceof Activity) { | |
| 52 return true; | |
| 53 } else if (context instanceof ContextWrapper) { | |
| 54 return isActivityContext(((ContextWrapper) context).getBaseContext() ); | |
| 55 } else { | |
| 56 return false; | |
| 57 } | |
| 58 } | |
| 59 | |
| 40 @Override | 60 @Override |
| 41 public void onStartContentIntent(Context context, String contentUrl) { | 61 public void onStartContentIntent(Context context, String contentUrl) { |
| 42 // Callback when detecting a click on a content link. | 62 if (mAwContentsClient.hasWebViewClient()) { |
| 43 mAwContentsClient.shouldOverrideUrlLoading(contentUrl); | 63 // Callback when detecting a click on a content link. |
| 64 mAwContentsClient.shouldOverrideUrlLoading(contentUrl); | |
| 65 return; | |
| 66 } | |
| 67 | |
| 68 Intent intent; | |
| 69 // Perform generic parsing of the URI to turn it into an Intent. | |
| 70 try { | |
| 71 intent = Intent.parseUri(contentUrl, Intent.URI_INTENT_SCHEME); | |
| 72 } catch (URISyntaxException ex) { | |
| 73 Log.w(TAG, "Bad URI " + contentUrl + ": " + ex.getMessage()); | |
| 74 return; | |
| 75 } | |
| 76 // Sanitize the Intent, ensuring web pages can not bypass browser | |
| 77 // security (only access to BROWSABLE activities). | |
| 78 intent.addCategory(Intent.CATEGORY_BROWSABLE); | |
| 79 intent.setComponent(null); | |
| 80 Intent selector = intent.getSelector(); | |
| 81 if (selector != null) { | |
| 82 selector.addCategory(Intent.CATEGORY_BROWSABLE); | |
| 83 selector.setComponent(null); | |
| 84 } | |
| 85 // Pass the package name as application ID so that the intent from the | |
| 86 // same application can be opened in the same tab. | |
| 87 intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); | |
| 88 if (!isActivityContext(context)) { | |
| 89 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 90 } | |
| 91 | |
| 92 try { | |
| 93 context.startActivity(intent); | |
| 94 } catch (ActivityNotFoundException ex) { | |
| 95 Log.w(TAG, "No application can handle " + contentUrl); | |
| 96 } | |
| 44 } | 97 } |
| 45 | 98 |
| 46 @Override | 99 @Override |
| 47 public void onUpdateTitle(String title) { | 100 public void onUpdateTitle(String title) { |
| 48 mAwContentsClient.onReceivedTitle(title); | 101 mAwContentsClient.onReceivedTitle(title); |
| 49 } | 102 } |
| 50 | 103 |
| 51 @Override | 104 @Override |
| 52 public boolean shouldOverrideKeyEvent(KeyEvent event) { | 105 public boolean shouldOverrideKeyEvent(KeyEvent event) { |
| 53 return mAwContentsClient.shouldOverrideKeyEvent(event); | 106 if (mAwContentsClient.hasWebViewClient()) { |
| 107 // The check below is reflecting Clank's behavior and is a workaroun d for | |
| 108 // http://b/7697782. | |
| 109 if (!ContentViewClient.shouldPropagateKey(event.getKeyCode())) retur n true; | |
| 110 return mAwContentsClient.shouldOverrideKeyEvent(event); | |
| 111 } | |
| 112 | |
| 113 return super.shouldOverrideKeyEvent(event); | |
| 54 } | 114 } |
| 55 | 115 |
| 56 @Override | 116 @Override |
| 57 public final ContentVideoViewClient getContentVideoViewClient() { | 117 public final ContentVideoViewClient getContentVideoViewClient() { |
| 58 return this; | 118 return this; |
| 59 } | 119 } |
| 60 | 120 |
| 61 @Override | 121 @Override |
| 62 public boolean shouldBlockMediaRequest(String url) { | 122 public boolean shouldBlockMediaRequest(String url) { |
| 63 return mAwSettings != null | 123 return mAwSettings != null |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 @Override | 192 @Override |
| 133 public boolean isJavascriptEnabled() { | 193 public boolean isJavascriptEnabled() { |
| 134 return mAwSettings != null && mAwSettings.getJavaScriptEnabled(); | 194 return mAwSettings != null && mAwSettings.getJavaScriptEnabled(); |
| 135 } | 195 } |
| 136 | 196 |
| 137 @Override | 197 @Override |
| 138 public boolean isExternalFlingActive() { | 198 public boolean isExternalFlingActive() { |
| 139 return mAwContents.isFlingActive(); | 199 return mAwContents.isFlingActive(); |
| 140 } | 200 } |
| 141 } | 201 } |
| OLD | NEW |