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 3 // found in the LICENSE file. 4 5 package org.chromium.android_webview; 6 7 import android.util.ArrayMap; 8 9 import org.chromium.android_webview.AwContentsClient; 10 import org.chromium.base.CalledByNative; 11 import org.chromium.base.JNINamespace; 12 13 /** 14 * Delegate for handling callbacks. All methods are called on the IO thread. 15 * 16 * You should create a separate instance for every WebContents that requires the 17 * provided functionality. 18 */ 19 @JNINamespace("android_webview") 20 public abstract class AwContentsIoThreadClient { 21 @CalledByNative getCacheMode()22 public abstract int getCacheMode(); 23 24 @CalledByNative shouldBlockContentUrls()25 public abstract boolean shouldBlockContentUrls(); 26 27 @CalledByNative shouldBlockFileUrls()28 public abstract boolean shouldBlockFileUrls(); 29 30 @CalledByNative shouldBlockNetworkLoads()31 public abstract boolean shouldBlockNetworkLoads(); 32 33 @CalledByNative shouldAcceptThirdPartyCookies()34 public abstract boolean shouldAcceptThirdPartyCookies(); 35 36 @CalledByNative onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength)37 public abstract void onDownloadStart(String url, String userAgent, 38 String contentDisposition, String mimeType, long contentLength); 39 40 @CalledByNative newLoginRequest(String realm, String account, String args)41 public abstract void newLoginRequest(String realm, String account, String args); 42 shouldInterceptRequest( AwContentsClient.ShouldInterceptRequestParams params)43 public abstract AwWebResourceResponse shouldInterceptRequest( 44 AwContentsClient.ShouldInterceptRequestParams params); 45 46 // Protected methods --------------------------------------------------------------------------- 47 48 @CalledByNative shouldInterceptRequest(String url, boolean isMainFrame, boolean hasUserGesture, String method, String[] requestHeaderNames, String[] requestHeaderValues)49 protected AwWebResourceResponse shouldInterceptRequest(String url, boolean isMainFrame, 50 boolean hasUserGesture, String method, String[] requestHeaderNames, 51 String[] requestHeaderValues) { 52 AwContentsClient.ShouldInterceptRequestParams params = 53 new AwContentsClient.ShouldInterceptRequestParams(); 54 params.url = url; 55 params.isMainFrame = isMainFrame; 56 params.hasUserGesture = hasUserGesture; 57 params.method = method; 58 params.requestHeaders = new ArrayMap<String, String>(requestHeaderNames.length); 59 for (int i = 0; i < requestHeaderNames.length; ++i) { 60 params.requestHeaders.put(requestHeaderNames[i], requestHeaderValues[i]); 61 } 62 return shouldInterceptRequest(params); 63 } 64 } 65