OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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.Context; | |
8 import android.content.pm.ActivityInfo; | 7 import android.content.pm.ActivityInfo; |
9 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
10 import android.graphics.Picture; | 9 import android.graphics.Picture; |
11 import android.graphics.Rect; | |
12 import android.graphics.RectF; | |
13 import android.net.http.SslError; | 10 import android.net.http.SslError; |
14 import android.os.Handler; | |
15 import android.os.Looper; | 11 import android.os.Looper; |
16 import android.os.Message; | 12 import android.os.Message; |
17 import android.util.Log; | |
18 import android.view.KeyEvent; | 13 import android.view.KeyEvent; |
19 import android.view.View; | 14 import android.view.View; |
20 import android.webkit.ConsoleMessage; | 15 import android.webkit.ConsoleMessage; |
21 import android.webkit.GeolocationPermissions; | 16 import android.webkit.GeolocationPermissions; |
22 import android.webkit.SslErrorHandler; | |
23 import android.webkit.ValueCallback; | 17 import android.webkit.ValueCallback; |
24 import android.webkit.WebChromeClient; | 18 import android.webkit.WebChromeClient; |
25 | 19 |
26 import org.chromium.content.browser.ContentVideoView; | |
27 import org.chromium.content.browser.ContentVideoViewClient; | |
28 import org.chromium.content.browser.ContentVideoViewControls; | |
29 import org.chromium.content.browser.ContentViewClient; | |
30 import org.chromium.content.browser.ContentViewCore; | 20 import org.chromium.content.browser.ContentViewCore; |
31 import org.chromium.content.browser.WebContentsObserverAndroid; | 21 import org.chromium.content.browser.WebContentsObserverAndroid; |
32 import org.chromium.net.NetError; | 22 import org.chromium.net.NetError; |
33 | 23 |
34 /** | 24 /** |
35 * Base-class that an AwContents embedder derives from to receive callbacks. | 25 * Base-class that an AwContents embedder derives from to receive callbacks. |
36 * This extends ContentViewClient, as in many cases we want to pass-thru Content
ViewCore | 26 * This extends ContentViewClient, as in many cases we want to pass-thru Content
ViewCore |
37 * callbacks right to our embedder, and this setup facilities that. | 27 * callbacks right to our embedder, and this setup facilities that. |
38 * For any other callbacks we need to make transformations of (e.g. adapt parame
ters | 28 * For any other callbacks we need to make transformations of (e.g. adapt parame
ters |
39 * or perform filtering) we can provide final overrides for methods here, and th
en introduce | 29 * or perform filtering) we can provide final overrides for methods here, and th
en introduce |
40 * new abstract methods that the our own client must implement. | 30 * new abstract methods that the our own client must implement. |
41 * i.e.: all methods in this class should either be final, or abstract. | 31 * i.e.: all methods in this class should either be final, or abstract. |
42 */ | 32 */ |
43 public abstract class AwContentsClient { | 33 public abstract class AwContentsClient { |
44 | 34 |
45 private static final String TAG = "AwContentsClient"; | 35 private static final String TAG = "AwContentsClient"; |
46 private final AwContentsClientCallbackHelper mCallbackHelper; | 36 private final AwContentsClientCallbackHelper mCallbackHelper; |
47 | 37 |
48 private AwWebContentsObserver mWebContentsObserver; | 38 private AwWebContentsObserver mWebContentsObserver; |
49 | 39 |
50 private AwContentViewClient mContentViewClient = new AwContentViewClient(); | |
51 | |
52 // Last background color reported from the renderer. Holds the sentinal valu
e INVALID_COLOR | 40 // Last background color reported from the renderer. Holds the sentinal valu
e INVALID_COLOR |
53 // if not valid. | 41 // if not valid. |
54 private int mCachedRendererBackgroundColor = INVALID_COLOR; | 42 private int mCachedRendererBackgroundColor = INVALID_COLOR; |
55 | 43 |
56 private static final int INVALID_COLOR = 0; | 44 private static final int INVALID_COLOR = 0; |
57 | 45 |
58 public AwContentsClient() { | 46 public AwContentsClient() { |
59 this(Looper.myLooper()); | 47 this(Looper.myLooper()); |
60 } | 48 } |
61 | 49 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 ErrorCodeConversionHelper.convertErrorCode(errorCode), descr
iption, failingUrl); | 82 ErrorCodeConversionHelper.convertErrorCode(errorCode), descr
iption, failingUrl); |
95 } | 83 } |
96 | 84 |
97 @Override | 85 @Override |
98 public void didNavigateAnyFrame(String url, String baseUrl, boolean isRe
load) { | 86 public void didNavigateAnyFrame(String url, String baseUrl, boolean isRe
load) { |
99 AwContentsClient.this.doUpdateVisitedHistory(url, isReload); | 87 AwContentsClient.this.doUpdateVisitedHistory(url, isReload); |
100 } | 88 } |
101 | 89 |
102 } | 90 } |
103 | 91 |
104 private class AwContentViewClient extends ContentViewClient { | |
105 @Override | |
106 public void onBackgroundColorChanged(int color) { | |
107 // Avoid storing the sentinal INVALID_COLOR (note that both 0 and 1
are both | |
108 // fully transparent so this transpose makes no visible difference). | |
109 mCachedRendererBackgroundColor = color == INVALID_COLOR ? 1 : color; | |
110 } | |
111 | |
112 @Override | |
113 public void onStartContentIntent(Context context, String contentUrl) { | |
114 // Callback when detecting a click on a content link. | |
115 AwContentsClient.this.shouldOverrideUrlLoading(contentUrl); | |
116 } | |
117 | |
118 @Override | |
119 public void onRendererCrash(boolean crashedWhileOomProtected) { | |
120 // This is not possible so long as the webview is run single process
! | |
121 throw new RuntimeException("Renderer crash reported."); | |
122 } | |
123 | |
124 @Override | |
125 public void onUpdateTitle(String title) { | |
126 AwContentsClient.this.onReceivedTitle(title); | |
127 } | |
128 | |
129 @Override | |
130 public boolean shouldOverrideKeyEvent(KeyEvent event) { | |
131 return AwContentsClient.this.shouldOverrideKeyEvent(event); | |
132 } | |
133 | |
134 @Override | |
135 final public ContentVideoViewClient getContentVideoViewClient() { | |
136 return new AwContentVideoViewClient(); | |
137 } | |
138 } | |
139 | |
140 final void installWebContentsObserver(ContentViewCore contentViewCore) { | 92 final void installWebContentsObserver(ContentViewCore contentViewCore) { |
141 if (mWebContentsObserver != null) { | 93 if (mWebContentsObserver != null) { |
142 mWebContentsObserver.detachFromWebContents(); | 94 mWebContentsObserver.detachFromWebContents(); |
143 } | 95 } |
144 mWebContentsObserver = new AwWebContentsObserver(contentViewCore); | 96 mWebContentsObserver = new AwWebContentsObserver(contentViewCore); |
145 } | 97 } |
146 | 98 |
147 private class AwContentVideoViewClient implements ContentVideoViewClient { | |
148 @Override | |
149 public void onShowCustomView(View view) { | |
150 WebChromeClient.CustomViewCallback cb = new WebChromeClient.CustomVi
ewCallback() { | |
151 @Override | |
152 public void onCustomViewHidden() { | |
153 ContentVideoView contentVideoView = ContentVideoView.getCont
entVideoView(); | |
154 if (contentVideoView != null) | |
155 contentVideoView.exitFullscreen(false); | |
156 } | |
157 }; | |
158 AwContentsClient.this.onShowCustomView(view, cb); | |
159 } | |
160 | |
161 @Override | |
162 public void onDestroyContentVideoView() { | |
163 AwContentsClient.this.onHideCustomView(); | |
164 } | |
165 | |
166 @Override | |
167 public View getVideoLoadingProgressView() { | |
168 return AwContentsClient.this.getVideoLoadingProgressView(); | |
169 } | |
170 | |
171 @Override | |
172 public ContentVideoViewControls createControls() { | |
173 return null; | |
174 } | |
175 } | |
176 | |
177 final AwContentsClientCallbackHelper getCallbackHelper() { | 99 final AwContentsClientCallbackHelper getCallbackHelper() { |
178 return mCallbackHelper; | 100 return mCallbackHelper; |
179 } | 101 } |
180 | 102 |
181 final ContentViewClient getContentViewClient() { | |
182 return mContentViewClient; | |
183 } | |
184 | |
185 final int getCachedRendererBackgroundColor() { | 103 final int getCachedRendererBackgroundColor() { |
186 assert isCachedRendererBackgroundColorValid(); | 104 assert isCachedRendererBackgroundColorValid(); |
187 return mCachedRendererBackgroundColor; | 105 return mCachedRendererBackgroundColor; |
188 } | 106 } |
189 | 107 |
190 final boolean isCachedRendererBackgroundColorValid() { | 108 final boolean isCachedRendererBackgroundColorValid() { |
191 return mCachedRendererBackgroundColor != INVALID_COLOR; | 109 return mCachedRendererBackgroundColor != INVALID_COLOR; |
192 } | 110 } |
193 | 111 |
| 112 final void onBackgroundColorChanged(int color) { |
| 113 // Avoid storing the sentinal INVALID_COLOR (note that both 0 and 1 are
both |
| 114 // fully transparent so this transpose makes no visible difference). |
| 115 mCachedRendererBackgroundColor = color == INVALID_COLOR ? 1 : color; |
| 116 } |
| 117 |
194 //--------------------------------------------------------------------------
------------------ | 118 //--------------------------------------------------------------------------
------------------ |
195 // WebView specific methods that map directly to WebViewClient /
WebChromeClient | 119 // WebView specific methods that map directly to WebViewClient /
WebChromeClient |
196 //--------------------------------------------------------------------------
------------------ | 120 //--------------------------------------------------------------------------
------------------ |
197 | 121 |
198 public static class FileChooserParams { | 122 public static class FileChooserParams { |
199 public int mode; | 123 public int mode; |
200 public String acceptTypes; | 124 public String acceptTypes; |
201 public String title; | 125 public String title; |
202 public String defaultFilename; | 126 public String defaultFilename; |
203 public boolean capture; | 127 public boolean capture; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 public abstract void onFindResultReceived(int activeMatchOrdinal, int number
OfMatches, | 221 public abstract void onFindResultReceived(int activeMatchOrdinal, int number
OfMatches, |
298 boolean isDoneCounting); | 222 boolean isDoneCounting); |
299 | 223 |
300 /** | 224 /** |
301 * Called whenever there is a new content picture available. | 225 * Called whenever there is a new content picture available. |
302 * @param picture New picture. | 226 * @param picture New picture. |
303 */ | 227 */ |
304 public abstract void onNewPicture(Picture picture); | 228 public abstract void onNewPicture(Picture picture); |
305 | 229 |
306 } | 230 } |
OLD | NEW |