diff options
| author | Patrick Scott <phanna@android.com> | 2010-11-11 13:16:44 -0500 |
|---|---|---|
| committer | Patrick Scott <phanna@android.com> | 2010-11-15 09:19:38 -0500 |
| commit | c12544a201667383bc3dfb4bd3ad62d98cacd24f (patch) | |
| tree | 07cb73580be76718cc11bd98b48cb83a0ab3fbec /core/java/android/webkit/BrowserFrame.java | |
| parent | 83d4a23c280bdcaf6c301651b76ddc6fbf08949c (diff) | |
Offer a callback to intercept url requests.
The new callback allows applications to return a response for a particular url.
Deprecate onLoadResource in favor of the new api. onLoadResource is not
currently being used by the new network stack and applications can post a
message from shouldInterceptRequest to handle onLoadResource.
Bug: 2905943
Change-Id: Icf48ab3110d85d76112b3c3b4a1a8c8a333b82f0
Diffstat (limited to 'core/java/android/webkit/BrowserFrame.java')
| -rw-r--r-- | core/java/android/webkit/BrowserFrame.java | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/core/java/android/webkit/BrowserFrame.java b/core/java/android/webkit/BrowserFrame.java index ed5663e0f610..d3c0ffd17e14 100644 --- a/core/java/android/webkit/BrowserFrame.java +++ b/core/java/android/webkit/BrowserFrame.java @@ -654,23 +654,6 @@ class BrowserFrame extends Handler { } /** - * Called by JNI. - * Read from an InputStream into a supplied byte[] - * This method catches any exceptions so they don't crash the JVM. - * @param inputStream InputStream to read from. - * @param output Bytearray that gets the output. - * @return the number of bytes read, or -i if then end of stream has been reached - */ - private static int readFromStream(InputStream inputStream, byte[] output) { - try { - return inputStream.read(output); - } catch(java.io.IOException e) { - // If we get an exception, return end of stream - return -1; - } - } - - /** * Get the InputStream for an Android resource * There are three different kinds of android resources: * - file:///android_res @@ -859,8 +842,6 @@ class BrowserFrame extends Handler { this, url, loaderHandle, synchronous, isMainFramePage, mainResource, userGesture, postDataIdentifier, username, password); - mCallbackProxy.onLoadResource(url); - if (LoadListener.getNativeLoaderCount() > MAX_OUTSTANDING_REQUESTS) { // send an error message, so that loadListener can be deleted // after this is returned. This is important as LoadListener's @@ -872,7 +853,11 @@ class BrowserFrame extends Handler { return loadListener; } - FrameLoader loader = new FrameLoader(loadListener, mSettings, method); + // Note that we are intentionally skipping + // inputStreamForAndroidResource. This is so that FrameLoader will use + // the various StreamLoader classes to handle assets. + FrameLoader loader = new FrameLoader(loadListener, mSettings, method, + mCallbackProxy.shouldInterceptRequest(url)); loader.setHeaders(headers); loader.setPostData(postData); // Set the load mode to the mode used for the current page. @@ -889,6 +874,15 @@ class BrowserFrame extends Handler { return !synchronous ? loadListener : null; } + // Called by jni from the chrome network stack. + private WebResourceResponse shouldInterceptRequest(String url) { + InputStream androidResource = inputStreamForAndroidResource(url); + if (androidResource != null) { + return new WebResourceResponse(null, null, androidResource); + } + return mCallbackProxy.shouldInterceptRequest(url); + } + /** * Set the progress for the browser activity. Called by native code. * Uses a delay so it does not happen too often. |
