diff options
author | Patrick Scott <phanna@android.com> | 2010-11-11 13:14:26 -0500 |
---|---|---|
committer | Patrick Scott <phanna@android.com> | 2010-11-15 09:19:00 -0500 |
commit | ff1576a1bd6302d6c9988912d17e47f325242574 (patch) | |
tree | 8c80acadf120ea70ddd76dc52214b536e15e6435 /WebKit/android | |
parent | 649040c55ad0f299f58ae83062b40b29f3825fb4 (diff) | |
download | external_webkit-ff1576a1bd6302d6c9988912d17e47f325242574.zip external_webkit-ff1576a1bd6302d6c9988912d17e47f325242574.tar.gz external_webkit-ff1576a1bd6302d6c9988912d17e47f325242574.tar.bz2 |
Allow applications to intercept requests.
The api returns a response containing the mime type, encoding, and an optional
InputStream for reading data. Move the asset and content url logic into the
new api to consolidate some code.
Requires a change in frameworks/base.
Bug: 2905943
Change-Id: Ic7af410308872042c412aedf62e589f6d2095782
Diffstat (limited to 'WebKit/android')
-rw-r--r-- | WebKit/android/WebCoreSupport/UrlInterceptResponse.cpp | 125 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/UrlInterceptResponse.h | 70 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebRequest.cpp | 72 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebRequest.h | 12 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp | 29 | ||||
-rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.cpp | 38 | ||||
-rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.h | 5 |
7 files changed, 260 insertions, 91 deletions
diff --git a/WebKit/android/WebCoreSupport/UrlInterceptResponse.cpp b/WebKit/android/WebCoreSupport/UrlInterceptResponse.cpp new file mode 100644 index 0000000..ab00ba6 --- /dev/null +++ b/WebKit/android/WebCoreSupport/UrlInterceptResponse.cpp @@ -0,0 +1,125 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define LOG_TAG "UrlInterceptResponse" +#include "config.h" + +#include "JNIUtility.h" +#include "UrlInterceptResponse.h" +#include "WebCoreJni.h" + +#include <utils/Log.h> + +namespace android { + +class JavaInputStreamWrapper { +public: + JavaInputStreamWrapper(JNIEnv* env, jobject inputStream) + : m_inputStream(env->NewGlobalRef(inputStream)) + , m_buffer(0) { + LOG_ALWAYS_FATAL_IF(!inputStream); + m_inputStreamClass = env->FindClass("java/io/InputStream"); + LOG_ALWAYS_FATAL_IF(!m_inputStreamClass); + m_read = env->GetMethodID(m_inputStreamClass, "read", "([B)I"); + LOG_ALWAYS_FATAL_IF(!m_read); + m_close = env->GetMethodID(m_inputStreamClass, "close", "()V"); + LOG_ALWAYS_FATAL_IF(!m_close); + } + + ~JavaInputStreamWrapper() { + JNIEnv* env = JSC::Bindings::getJNIEnv(); + env->CallVoidMethod(m_inputStream, m_close); + checkException(env); + env->DeleteGlobalRef(m_inputStream); + // In case we never call read(). + if (m_buffer) + env->DeleteGlobalRef(m_buffer); + } + + void read(std::vector<char>* out) { + JNIEnv* env = JSC::Bindings::getJNIEnv(); + // Initialize our read buffer to the capacity of out. + if (!m_buffer) { + m_buffer = env->NewByteArray(out->capacity()); + m_buffer = (jbyteArray) env->NewGlobalRef(m_buffer); + } + int size = (int) env->CallIntMethod(m_inputStream, m_read, m_buffer); + if (checkException(env) || size < 0) + return; + // Copy from m_buffer to out. + out->resize(size); + env->GetByteArrayRegion(m_buffer, 0, size, (jbyte*)&out->front()); + } + +private: + jobject m_inputStream; + jbyteArray m_buffer; + jclass m_inputStreamClass; + jmethodID m_read; + jmethodID m_close; +}; + +UrlInterceptResponse::UrlInterceptResponse(JNIEnv* env, jobject response) { + jclass javaResponse = env->FindClass("android/webkit/WebResourceResponse"); + LOG_ALWAYS_FATAL_IF(!javaResponse); + jfieldID mimeType = env->GetFieldID(javaResponse, "mMimeType", + "Ljava/lang/String;"); + LOG_ALWAYS_FATAL_IF(!mimeType); + jfieldID encoding = env->GetFieldID(javaResponse, "mEncoding", + "Ljava/lang/String;"); + LOG_ALWAYS_FATAL_IF(!encoding); + jfieldID inputStream = env->GetFieldID(javaResponse, "mInputStream", + "Ljava/io/InputStream;"); + LOG_ALWAYS_FATAL_IF(!inputStream); + + jobject stream = env->GetObjectField(response, inputStream); + if (stream) + m_inputStream.set(new JavaInputStreamWrapper(env, stream)); + + jstring mimeStr = (jstring) env->GetObjectField(response, mimeType); + jstring encodingStr = (jstring) env->GetObjectField(response, encoding); + + m_mimeType.assign(env->GetStringUTFChars(mimeStr, NULL), + env->GetStringUTFLength(mimeStr)); + m_encoding.assign(env->GetStringUTFChars(encodingStr, NULL), + env->GetStringUTFLength(encodingStr)); + + env->DeleteLocalRef(javaResponse); + env->DeleteLocalRef(mimeStr); + env->DeleteLocalRef(encodingStr); +} + +UrlInterceptResponse::~UrlInterceptResponse() { + // Cannot be inlined because of JavaInputStreamWrapper visibility. +} + +bool UrlInterceptResponse::readStream(std::vector<char>* out) const { + if (!m_inputStream) + return false; + m_inputStream->read(out); + return true; +} + +} // namespace android diff --git a/WebKit/android/WebCoreSupport/UrlInterceptResponse.h b/WebKit/android/WebCoreSupport/UrlInterceptResponse.h new file mode 100644 index 0000000..64dad69 --- /dev/null +++ b/WebKit/android/WebCoreSupport/UrlInterceptResponse.h @@ -0,0 +1,70 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef UrlInterceptResponse_h +#define UrlInterceptResponse_h + +#include "PlatformString.h" +#include "wtf/Noncopyable.h" +#include "wtf/OwnPtr.h" + +#include <jni.h> +#include <string> +#include <vector> + +namespace android { + +class JavaInputStreamWrapper; + +class UrlInterceptResponse : public Noncopyable { +public: + UrlInterceptResponse(JNIEnv* env, jobject response); + ~UrlInterceptResponse(); + + const std::string& mimeType() const { + return m_mimeType; + } + + const std::string& encoding() const { + return m_encoding; + } + + int status() const { + return m_inputStream ? 200 : 404; + } + + // Read from the input stream. Returns false if reading failed. + // A size of 0 indicates eof. + bool readStream(std::vector<char>* out) const; + +private: + std::string m_mimeType; + std::string m_encoding; + OwnPtr<JavaInputStreamWrapper> m_inputStream; +}; + +} // namespace android + +#endif diff --git a/WebKit/android/WebCoreSupport/WebRequest.cpp b/WebKit/android/WebCoreSupport/WebRequest.cpp index 758ff31..67144cb 100644 --- a/WebKit/android/WebCoreSupport/WebRequest.cpp +++ b/WebKit/android/WebCoreSupport/WebRequest.cpp @@ -28,9 +28,11 @@ #include "JNIUtility.h" #include "MainThread.h" +#include "UrlInterceptResponse.h" #include "WebCoreFrameBridge.h" #include "WebRequestContext.h" #include "WebResourceRequest.h" +#include "WebUrlLoaderClient.h" #include "jni.h" #include <cutils/log.h> @@ -61,7 +63,6 @@ namespace { WebRequest::WebRequest(WebUrlLoaderClient* loader, const WebResourceRequest& webResourceRequest) : m_urlLoader(loader) - , m_inputStream(0) , m_androidUrl(false) , m_url(webResourceRequest.url()) , m_userAgent(webResourceRequest.userAgent()) @@ -79,15 +80,14 @@ WebRequest::WebRequest(WebUrlLoaderClient* loader, const WebResourceRequest& web // This is a special URL for Android. Query the Java InputStream // for data and send to WebCore -WebRequest::WebRequest(WebUrlLoaderClient* loader, const WebResourceRequest& webResourceRequest, int inputStream) +WebRequest::WebRequest(WebUrlLoaderClient* loader, const WebResourceRequest& webResourceRequest, UrlInterceptResponse* intercept) : m_urlLoader(loader) + , m_interceptResponse(intercept) , m_androidUrl(true) , m_url(webResourceRequest.url()) , m_userAgent(webResourceRequest.userAgent()) , m_loadState(Created) { - JNIEnv* env = JSC::Bindings::getJNIEnv(); - m_inputStream = (int)env->NewGlobalRef((_jobject*)inputStream); } WebRequest::~WebRequest() @@ -95,9 +95,6 @@ WebRequest::~WebRequest() ASSERT(m_loadState == Finished, "dtor called on a WebRequest in a different state than finished (%d)", m_loadState); m_loadState = Deleted; - JNIEnv* env = JSC::Bindings::getJNIEnv(); - if (m_inputStream) - env->DeleteGlobalRef((_jobject*)m_inputStream); } const std::string& WebRequest::getUrl() const @@ -153,8 +150,8 @@ void WebRequest::start(bool isPrivateBrowsing) m_loadState = Started; - if (m_androidUrl) - return handleAndroidURL(); + if (m_interceptResponse != NULL) + return handleInterceptedURL(); // Handle data urls before we send it off to the http stack if (m_request->url().SchemeIs("data")) @@ -188,60 +185,49 @@ void WebRequest::cancel() finish(true); } -void WebRequest::handleAndroidURL() +void WebRequest::handleInterceptedURL() { - JNIEnv* env = JSC::Bindings::getJNIEnv(); - if (m_inputStream == 0) { - m_loadState = Finished; - OwnPtr<WebResponse> webResponse(new WebResponse(m_url, "", 0, "", 0)); - m_urlLoader->maybeCallOnMainThread(NewRunnableMethod( - m_urlLoader.get(), &WebUrlLoaderClient::didFail, webResponse.release())); - return; - } - m_loadState = Response; + const std::string& mime = m_interceptResponse->mimeType(); // Get the MIME type from the URL. "text/html" is a last resort, hopefully overridden. std::string mimeType("text/html"); - - // Gmail appends the MIME to the end of the URL, with a ? separator. - size_t mimeTypeIndex = m_url.find_last_of('?'); - if (mimeTypeIndex != std::string::npos) { - mimeType.assign(m_url.begin() + mimeTypeIndex + 1, m_url.end()); + if (mime == "") { + // Gmail appends the MIME to the end of the URL, with a ? separator. + size_t mimeTypeIndex = m_url.find_last_of('?'); + if (mimeTypeIndex != std::string::npos) { + mimeType.assign(m_url.begin() + mimeTypeIndex + 1, m_url.end()); + } else { + // Get the MIME type from the file extension, if any. + FilePath path(m_url); + net::GetMimeTypeFromFile(path, &mimeType); + } } else { - // Get the MIME type from the file extension, if any. - FilePath path(m_url); - net::GetMimeTypeFromFile(path, &mimeType); + // Set from the intercept response. + mimeType = mime; } - OwnPtr<WebResponse> webResponse(new WebResponse(m_url, mimeType, 0, "", 200)); + + OwnPtr<WebResponse> webResponse(new WebResponse(m_url, mimeType, 0, m_interceptResponse->encoding(), m_interceptResponse->status())); m_urlLoader->maybeCallOnMainThread(NewRunnableMethod( m_urlLoader.get(), &WebUrlLoaderClient::didReceiveResponse, webResponse.release())); - int size = 0; - jclass bridgeClass = env->FindClass("android/webkit/BrowserFrame"); - jmethodID method = env->GetStaticMethodID(bridgeClass, "readFromStream", "(Ljava/io/InputStream;[B)I"); - - jbyteArray jb = env->NewByteArray(kInitialReadBufSize); do { - size = (int)env->CallStaticIntMethod(bridgeClass, method, m_inputStream, jb); - if (size < 0) // -1 is EOF - break; - // data is deleted in WebUrlLoaderClient::didReceiveAndroidFileData // data is sent to the webcore thread - OwnPtr<std::vector<char> > data(new std::vector<char>(size)); - env->GetByteArrayRegion(jb, 0, size, (jbyte*)&data->front()); + OwnPtr<std::vector<char> > data(new std::vector<char>); + data->reserve(kInitialReadBufSize); + + // Read returns false on error and size of 0 on eof. + if (!m_interceptResponse->readStream(data.get()) || data->size() == 0) + break; m_loadState = GotData; m_urlLoader->maybeCallOnMainThread(NewRunnableMethod( m_urlLoader.get(), &WebUrlLoaderClient::didReceiveAndroidFileData, data.release())); } while (true); - env->DeleteLocalRef(jb); - env->DeleteLocalRef(bridgeClass); - - finish(true); + finish(m_interceptResponse->status() == 200); } void WebRequest::handleDataURL(GURL url) diff --git a/WebKit/android/WebCoreSupport/WebRequest.h b/WebKit/android/WebCoreSupport/WebRequest.h index c7026a5..2bcbb92 100644 --- a/WebKit/android/WebCoreSupport/WebRequest.h +++ b/WebKit/android/WebCoreSupport/WebRequest.h @@ -27,7 +27,6 @@ #define WebRequest_h #include "ChromiumIncludes.h" -#include "WebUrlLoaderClient.h" #include "wtf/Vector.h" class MessageLoop; @@ -44,20 +43,23 @@ enum LoadState { Deleted }; +class UrlInterceptResponse; class WebResourceRequest; class WebFrame; +class WebUrlLoaderClient; // All methods in this class must be called on the io thread class WebRequest : public URLRequest::Delegate, public base::RefCountedThreadSafe<WebRequest> { public: WebRequest(WebUrlLoaderClient*, const WebResourceRequest&); - // If this is an android specific url we load it with a java input stream + // If this is an android specific url or the application wants to load + // custom data, we load the data through an input stream. // Used for: // - file:///android_asset // - file:///android_res // - content:// - WebRequest(WebUrlLoaderClient*, const WebResourceRequest&, int inputStream); + WebRequest(WebUrlLoaderClient*, const WebResourceRequest&, UrlInterceptResponse* intercept); // Optional, but if used has to be called before start void appendBytesToUpload(Vector<char>* data); @@ -88,13 +90,13 @@ private: virtual ~WebRequest(); void handleDataURL(GURL); void handleBrowserURL(GURL); - void handleAndroidURL(); + void handleInterceptedURL(); void finish(bool success); scoped_refptr<WebUrlLoaderClient> m_urlLoader; OwnPtr<URLRequest> m_request; scoped_refptr<net::IOBuffer> m_networkBuffer; - int m_inputStream; + scoped_ptr<UrlInterceptResponse> m_interceptResponse; bool m_androidUrl; std::string m_url; std::string m_userAgent; diff --git a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp index 6d8e192..7487e48 100644 --- a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp +++ b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp @@ -39,29 +39,6 @@ #include <wtf/text/CString.h> -namespace { -const char* androidAsset = "file:///android_asset/"; -const char* androidResource = "file:///android_res/"; -const char* androidContent = "content:"; -const int androidAssetLen = strlen(androidAsset); -const int androidResourceLen = strlen(androidResource); -const int androidContentLen = strlen(androidContent); - -bool isAndroidUrl(const std::string& url) -{ - if (!url.compare(0, androidAssetLen, androidAsset)) - return true; - - if (!url.compare(0, androidResourceLen, androidResource)) - return true; - - if (!url.compare(0, androidContentLen, androidContent)) - return true; - - return false; -} -} - namespace android { base::Thread* WebUrlLoaderClient::ioThread() @@ -118,9 +95,9 @@ WebUrlLoaderClient::WebUrlLoaderClient(WebFrame* webFrame, WebCore::ResourceHand , m_finished(false) { WebResourceRequest webResourceRequest(resourceRequest); - if (isAndroidUrl(webResourceRequest.url())) { - int inputStream = webFrame->inputStreamForAndroidResource(webResourceRequest.url().c_str()); - m_request = new WebRequest(this, webResourceRequest, inputStream); + UrlInterceptResponse* intercept = webFrame->shouldInterceptRequest(resourceRequest.url().string()); + if (intercept) { + m_request = new WebRequest(this, webResourceRequest, intercept); return; } diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index 85314cc..e4f942d 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -77,6 +77,7 @@ #include "SelectionController.h" #include "Settings.h" #include "SubstituteData.h" +#include "UrlInterceptResponse.h" #include "UserGestureIndicator.h" #include "WebCache.h" #include "WebCoreJni.h" @@ -191,8 +192,8 @@ struct WebFrame::JavaBrowserFrame { jweak mObj; jweak mHistoryList; // WebBackForwardList object - jmethodID mInputStreamForAndroidResource; jmethodID mStartLoadingResource; + jmethodID mShouldInterceptRequest; jmethodID mLoadStarted; jmethodID mTransitionToCommitted; jmethodID mLoadFinished; @@ -235,9 +236,11 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page* mJavaFrame = new JavaBrowserFrame; mJavaFrame->mObj = env->NewWeakGlobalRef(obj); mJavaFrame->mHistoryList = env->NewWeakGlobalRef(historyList); - mJavaFrame->mInputStreamForAndroidResource = env->GetMethodID(clazz, "inputStreamForAndroidResource", "(Ljava/lang/String;)Ljava/io/InputStream;"); mJavaFrame->mStartLoadingResource = env->GetMethodID(clazz, "startLoadingResource", "(ILjava/lang/String;Ljava/lang/String;Ljava/util/HashMap;[BJIZZZLjava/lang/String;Ljava/lang/String;)Landroid/webkit/LoadListener;"); + mJavaFrame->mShouldInterceptRequest = + env->GetMethodID(clazz, "shouldInterceptRequest", + "(Ljava/lang/String;)Landroid/webkit/WebResourceResponse;"); mJavaFrame->mLoadStarted = env->GetMethodID(clazz, "loadStarted", "(Ljava/lang/String;Landroid/graphics/Bitmap;IZ)V"); mJavaFrame->mTransitionToCommitted = env->GetMethodID(clazz, "transitionToCommitted", @@ -279,8 +282,8 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page* "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V"); env->DeleteLocalRef(clazz); - LOG_ASSERT(mJavaFrame->mInputStreamForAndroidResource, "Could not find method inputStreamForAndroidResource"); LOG_ASSERT(mJavaFrame->mStartLoadingResource, "Could not find method startLoadingResource"); + LOG_ASSERT(mJavaFrame->mShouldInterceptRequest, "Could not find method shouldInterceptRequest"); LOG_ASSERT(mJavaFrame->mLoadStarted, "Could not find method loadStarted"); LOG_ASSERT(mJavaFrame->mTransitionToCommitted, "Could not find method transitionToCommitted"); LOG_ASSERT(mJavaFrame->mLoadFinished, "Could not find method loadFinished"); @@ -383,18 +386,6 @@ private: int m_size; }; -int WebFrame::inputStreamForAndroidResource(const char* url) -{ - JNIEnv* env = getJNIEnv(); - AutoJObject obj = mJavaFrame->frame(env); - jstring jUrlStr = env->NewStringUTF(url); - - jobject jInputStream = env->CallObjectMethod(obj.get(), mJavaFrame->mInputStreamForAndroidResource, jUrlStr); - env->DeleteLocalRef(jUrlStr); - - return (int)jInputStream; -} - PassRefPtr<WebCore::ResourceLoaderAndroid> WebFrame::startLoadingResource(WebCore::ResourceHandle* loader, const WebCore::ResourceRequest& request, @@ -541,6 +532,23 @@ WebFrame::startLoadingResource(WebCore::ResourceHandle* loader, return h; } +UrlInterceptResponse* +WebFrame::shouldInterceptRequest(const WTF::String& url) +{ +#ifdef ANDROID_INSTRUMENT + TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter); +#endif + LOGV("::WebCore:: shouldInterceptRequest(%s)", url.latin1().data()); + + JNIEnv* env = getJNIEnv(); + jstring urlStr = WtfStringToJstring(env, url); + jobject response = env->CallObjectMethod(mJavaFrame->frame(env).get(), mJavaFrame->mShouldInterceptRequest, urlStr); + env->DeleteLocalRef(urlStr); + if (response == 0) + return 0; + return new UrlInterceptResponse(env, response); +} + void WebFrame::reportError(int errorCode, const WTF::String& description, const WTF::String& failingUrl) diff --git a/WebKit/android/jni/WebCoreFrameBridge.h b/WebKit/android/jni/WebCoreFrameBridge.h index 2d2b571..027c9ca 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.h +++ b/WebKit/android/jni/WebCoreFrameBridge.h @@ -50,6 +50,7 @@ namespace android { class WebViewCore; class WebUrlLoaderClient; +class UrlInterceptResponse; // one instance of WebFrame per Page for calling into Java's BrowserFrame class WebFrame : public WebCoreRefObject { @@ -60,12 +61,12 @@ class WebFrame : public WebCoreRefObject { // helper function static WebFrame* getWebFrame(const WebCore::Frame* frame); - int inputStreamForAndroidResource(const char* url); - virtual PassRefPtr<WebCore::ResourceLoaderAndroid> startLoadingResource(WebCore::ResourceHandle*, const WebCore::ResourceRequest& request, bool mainResource, bool synchronous); + UrlInterceptResponse* shouldInterceptRequest(const WTF::String& url); + void reportError(int errorCode, const WTF::String& description, const WTF::String& failingUrl); |