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