OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.content.pm.ActivityInfo; | 7 import android.content.pm.ActivityInfo; |
8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
9 import android.graphics.Picture; | 9 import android.graphics.Picture; |
10 import android.net.http.SslError; | 10 import android.net.http.SslError; |
11 import android.os.Looper; | 11 import android.os.Looper; |
12 import android.os.Message; | 12 import android.os.Message; |
13 import android.view.KeyEvent; | 13 import android.view.KeyEvent; |
14 import android.view.View; | 14 import android.view.View; |
15 import android.webkit.ConsoleMessage; | 15 import android.webkit.ConsoleMessage; |
16 import android.webkit.GeolocationPermissions; | 16 import android.webkit.GeolocationPermissions; |
17 import android.webkit.ValueCallback; | 17 import android.webkit.ValueCallback; |
18 import android.webkit.WebChromeClient; | 18 import android.webkit.WebChromeClient; |
19 | 19 |
20 import org.chromium.android_webview.permission.AwPermissionRequest; | 20 import org.chromium.android_webview.permission.AwPermissionRequest; |
21 import org.chromium.content.browser.WebContentsObserverAndroid; | |
22 import org.chromium.content_public.browser.WebContents; | |
23 import org.chromium.net.NetError; | |
24 | 21 |
25 import java.security.Principal; | 22 import java.security.Principal; |
26 import java.util.HashMap; | 23 import java.util.HashMap; |
27 | 24 |
28 /** | 25 /** |
29 * Base-class that an AwContents embedder derives from to receive callbacks. | 26 * Base-class that an AwContents embedder derives from to receive callbacks. |
30 * This extends ContentViewClient, as in many cases we want to pass-thru Content
ViewCore | 27 * This extends ContentViewClient, as in many cases we want to pass-thru Content
ViewCore |
31 * callbacks right to our embedder, and this setup facilities that. | 28 * callbacks right to our embedder, and this setup facilities that. |
32 * For any other callbacks we need to make transformations of (e.g. adapt parame
ters | 29 * For any other callbacks we need to make transformations of (e.g. adapt parame
ters |
33 * or perform filtering) we can provide final overrides for methods here, and th
en introduce | 30 * or perform filtering) we can provide final overrides for methods here, and th
en introduce |
34 * new abstract methods that the our own client must implement. | 31 * new abstract methods that the our own client must implement. |
35 * i.e.: all methods in this class should either be final, or abstract. | 32 * i.e.: all methods in this class should either be final, or abstract. |
36 */ | 33 */ |
37 public abstract class AwContentsClient { | 34 public abstract class AwContentsClient { |
38 | 35 |
39 private final AwContentsClientCallbackHelper mCallbackHelper; | 36 private final AwContentsClientCallbackHelper mCallbackHelper; |
40 | 37 |
41 private AwWebContentsObserver mWebContentsObserver; | |
42 | |
43 // Last background color reported from the renderer. Holds the sentinal valu
e INVALID_COLOR | 38 // Last background color reported from the renderer. Holds the sentinal valu
e INVALID_COLOR |
44 // if not valid. | 39 // if not valid. |
45 private int mCachedRendererBackgroundColor = INVALID_COLOR; | 40 private int mCachedRendererBackgroundColor = INVALID_COLOR; |
46 | 41 |
47 private static final int INVALID_COLOR = 0; | 42 private static final int INVALID_COLOR = 0; |
48 | 43 |
49 public AwContentsClient() { | 44 public AwContentsClient() { |
50 this(Looper.myLooper()); | 45 this(Looper.myLooper()); |
51 } | 46 } |
52 | 47 |
53 // Alllow injection of the callback thread, for testing. | 48 // Alllow injection of the callback thread, for testing. |
54 public AwContentsClient(Looper looper) { | 49 public AwContentsClient(Looper looper) { |
55 mCallbackHelper = new AwContentsClientCallbackHelper(looper, this); | 50 mCallbackHelper = new AwContentsClientCallbackHelper(looper, this); |
56 } | 51 } |
57 | 52 |
58 class AwWebContentsObserver extends WebContentsObserverAndroid { | |
59 public AwWebContentsObserver(WebContents webContents) { | |
60 super(webContents); | |
61 } | |
62 | |
63 @Override | |
64 public void didFinishLoad(long frameId, String validatedUrl, boolean isM
ainFrame) { | |
65 String unreachableWebDataUrl = AwContentsStatics.getUnreachableWebDa
taUrl(); | |
66 boolean isErrorUrl = | |
67 unreachableWebDataUrl != null && unreachableWebDataUrl.equal
s(validatedUrl); | |
68 if (isMainFrame && !isErrorUrl) { | |
69 AwContentsClient.this.onPageFinished(validatedUrl); | |
70 } | |
71 } | |
72 | |
73 @Override | |
74 public void didFailLoad(boolean isProvisionalLoad, | |
75 boolean isMainFrame, int errorCode, String description, String f
ailingUrl) { | |
76 String unreachableWebDataUrl = AwContentsStatics.getUnreachableWebDa
taUrl(); | |
77 boolean isErrorUrl = | |
78 unreachableWebDataUrl != null && unreachableWebDataUrl.equal
s(failingUrl); | |
79 if (isMainFrame && !isErrorUrl) { | |
80 if (errorCode != NetError.ERR_ABORTED) { | |
81 // This error code is generated for the following reasons: | |
82 // - WebView.stopLoading is called, | |
83 // - the navigation is intercepted by the embedder via shoul
dOverrideNavigation. | |
84 // | |
85 // The Android WebView does not notify the embedder of these
situations using | |
86 // this error code with the WebViewClient.onReceivedError ca
llback. | |
87 AwContentsClient.this.onReceivedError( | |
88 ErrorCodeConversionHelper.convertErrorCode(errorCode
), description, | |
89 failingUrl); | |
90 } | |
91 // Need to call onPageFinished after onReceivedError (if there i
s an error) for | |
92 // backwards compatibility with the classic webview. | |
93 AwContentsClient.this.onPageFinished(failingUrl); | |
94 } | |
95 } | |
96 | |
97 @Override | |
98 public void didNavigateMainFrame(String url, String baseUrl, | |
99 boolean isNavigationToDifferentPage, boolean isFragmentNavigatio
n) { | |
100 // This is here to emulate the Classic WebView firing onPageFinished
for main frame | |
101 // navigations where only the hash fragment changes. | |
102 if (isFragmentNavigation) { | |
103 AwContentsClient.this.onPageFinished(url); | |
104 } | |
105 } | |
106 | |
107 @Override | |
108 public void didNavigateAnyFrame(String url, String baseUrl, boolean isRe
load) { | |
109 AwContentsClient.this.doUpdateVisitedHistory(url, isReload); | |
110 } | |
111 | |
112 } | |
113 | |
114 final void installWebContentsObserver(WebContents webContents) { | |
115 if (mWebContentsObserver != null) { | |
116 mWebContentsObserver.detachFromWebContents(); | |
117 } | |
118 mWebContentsObserver = new AwWebContentsObserver(webContents); | |
119 } | |
120 | |
121 final AwContentsClientCallbackHelper getCallbackHelper() { | 53 final AwContentsClientCallbackHelper getCallbackHelper() { |
122 return mCallbackHelper; | 54 return mCallbackHelper; |
123 } | 55 } |
124 | 56 |
125 final int getCachedRendererBackgroundColor() { | 57 final int getCachedRendererBackgroundColor() { |
126 assert isCachedRendererBackgroundColorValid(); | 58 assert isCachedRendererBackgroundColorValid(); |
127 return mCachedRendererBackgroundColor; | 59 return mCachedRendererBackgroundColor; |
128 } | 60 } |
129 | 61 |
130 final boolean isCachedRendererBackgroundColorValid() { | 62 final boolean isCachedRendererBackgroundColorValid() { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 public abstract void onFindResultReceived(int activeMatchOrdinal, int number
OfMatches, | 208 public abstract void onFindResultReceived(int activeMatchOrdinal, int number
OfMatches, |
277 boolean isDoneCounting); | 209 boolean isDoneCounting); |
278 | 210 |
279 /** | 211 /** |
280 * Called whenever there is a new content picture available. | 212 * Called whenever there is a new content picture available. |
281 * @param picture New picture. | 213 * @param picture New picture. |
282 */ | 214 */ |
283 public abstract void onNewPicture(Picture picture); | 215 public abstract void onNewPicture(Picture picture); |
284 | 216 |
285 } | 217 } |
OLD | NEW |