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

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/AwContentsClient.java

Issue 52463004: Block media loading when AwSettings.setBlockNetworkLoads is true. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: disable failed test Created 7 years, 1 month 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 unified diff | Download patch
OLDNEW
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
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 onUpdateTitle(String title) {
120 AwContentsClient.this.onReceivedTitle(title);
121 }
122
123 @Override
124 public boolean shouldOverrideKeyEvent(KeyEvent event) {
125 return AwContentsClient.this.shouldOverrideKeyEvent(event);
126 }
127
128 @Override
129 final public ContentVideoViewClient getContentVideoViewClient() {
130 return new AwContentVideoViewClient();
131 }
132 }
133
134 final void installWebContentsObserver(ContentViewCore contentViewCore) { 92 final void installWebContentsObserver(ContentViewCore contentViewCore) {
135 if (mWebContentsObserver != null) { 93 if (mWebContentsObserver != null) {
136 mWebContentsObserver.detachFromWebContents(); 94 mWebContentsObserver.detachFromWebContents();
137 } 95 }
138 mWebContentsObserver = new AwWebContentsObserver(contentViewCore); 96 mWebContentsObserver = new AwWebContentsObserver(contentViewCore);
139 } 97 }
140 98
141 private class AwContentVideoViewClient implements ContentVideoViewClient {
142 @Override
143 public void onShowCustomView(View view) {
144 WebChromeClient.CustomViewCallback cb = new WebChromeClient.CustomVi ewCallback() {
145 @Override
146 public void onCustomViewHidden() {
147 ContentVideoView contentVideoView = ContentVideoView.getCont entVideoView();
148 if (contentVideoView != null)
149 contentVideoView.exitFullscreen(false);
150 }
151 };
152 AwContentsClient.this.onShowCustomView(view, cb);
153 }
154
155 @Override
156 public void onDestroyContentVideoView() {
157 AwContentsClient.this.onHideCustomView();
158 }
159
160 @Override
161 public View getVideoLoadingProgressView() {
162 return AwContentsClient.this.getVideoLoadingProgressView();
163 }
164
165 @Override
166 public ContentVideoViewControls createControls() {
167 return null;
168 }
169 }
170
171 final AwContentsClientCallbackHelper getCallbackHelper() { 99 final AwContentsClientCallbackHelper getCallbackHelper() {
172 return mCallbackHelper; 100 return mCallbackHelper;
173 } 101 }
174 102
175 final ContentViewClient getContentViewClient() {
176 return mContentViewClient;
177 }
178
179 final int getCachedRendererBackgroundColor() { 103 final int getCachedRendererBackgroundColor() {
180 assert isCachedRendererBackgroundColorValid(); 104 assert isCachedRendererBackgroundColorValid();
181 return mCachedRendererBackgroundColor; 105 return mCachedRendererBackgroundColor;
182 } 106 }
183 107
184 final boolean isCachedRendererBackgroundColorValid() { 108 final boolean isCachedRendererBackgroundColorValid() {
185 return mCachedRendererBackgroundColor != INVALID_COLOR; 109 return mCachedRendererBackgroundColor != INVALID_COLOR;
186 } 110 }
187 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
188 //-------------------------------------------------------------------------- ------------------ 118 //-------------------------------------------------------------------------- ------------------
189 // WebView specific methods that map directly to WebViewClient / WebChromeClient 119 // WebView specific methods that map directly to WebViewClient / WebChromeClient
190 //-------------------------------------------------------------------------- ------------------ 120 //-------------------------------------------------------------------------- ------------------
191 121
192 public static class FileChooserParams { 122 public static class FileChooserParams {
193 public int mode; 123 public int mode;
194 public String acceptTypes; 124 public String acceptTypes;
195 public String title; 125 public String title;
196 public String defaultFilename; 126 public String defaultFilename;
197 public boolean capture; 127 public boolean capture;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 public abstract void onFindResultReceived(int activeMatchOrdinal, int number OfMatches, 221 public abstract void onFindResultReceived(int activeMatchOrdinal, int number OfMatches,
292 boolean isDoneCounting); 222 boolean isDoneCounting);
293 223
294 /** 224 /**
295 * Called whenever there is a new content picture available. 225 * Called whenever there is a new content picture available.
296 * @param picture New picture. 226 * @param picture New picture.
297 */ 227 */
298 public abstract void onNewPicture(Picture picture); 228 public abstract void onNewPicture(Picture picture);
299 229
300 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698