diff options
author | Andrei Popescu <andreip@google.com> | 2009-12-08 18:37:43 +0000 |
---|---|---|
committer | Andrei Popescu <andreip@google.com> | 2009-12-11 18:37:33 +0000 |
commit | 80e68b43c3da64848db8edc7d8e8fe095888e42e (patch) | |
tree | aa79280373d0f3cba88bfc75c8a9da71c0771c78 /WebKit/android | |
parent | f84950ed043a9a6a88b154b77590d15a5fc1c680 (diff) | |
download | external_webkit-80e68b43c3da64848db8edc7d8e8fe095888e42e.zip external_webkit-80e68b43c3da64848db8edc7d8e8fe095888e42e.tar.gz external_webkit-80e68b43c3da64848db8edc7d8e8fe095888e42e.tar.bz2 |
Break the WebCore -> WebKit dependency in ResourceHandleAndroid.cpp.
Diffstat (limited to 'WebKit/android')
-rw-r--r-- | WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp | 3 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/ResourceLoaderAndroid.cpp | 50 | ||||
-rw-r--r-- | WebKit/android/benchmark/Intercept.cpp | 41 | ||||
-rw-r--r-- | WebKit/android/benchmark/Intercept.h | 11 | ||||
-rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.cpp | 6 | ||||
-rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.h | 5 | ||||
-rw-r--r-- | WebKit/android/jni/WebCoreResourceLoader.cpp | 5 | ||||
-rw-r--r-- | WebKit/android/jni/WebCoreResourceLoader.h | 15 |
8 files changed, 101 insertions, 35 deletions
diff --git a/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp b/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp index 265dfb4..ae3d582 100644 --- a/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp +++ b/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp @@ -870,8 +870,7 @@ bool FrameLoaderClientAndroid::canCachePage() const { void FrameLoaderClientAndroid::download(ResourceHandle* handle, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&) { // Get the C++ side of the load listener and tell it to handle the download - WebCoreResourceLoader* loader = handle->getInternal()->m_loader; - loader->downloadFile(); + handle->getInternal()->m_loader->downloadFile(); } WTF::PassRefPtr<WebCore::Frame> FrameLoaderClientAndroid::createFrame(const KURL& url, const String& name, diff --git a/WebKit/android/WebCoreSupport/ResourceLoaderAndroid.cpp b/WebKit/android/WebCoreSupport/ResourceLoaderAndroid.cpp new file mode 100644 index 0000000..2b2ad95 --- /dev/null +++ b/WebKit/android/WebCoreSupport/ResourceLoaderAndroid.cpp @@ -0,0 +1,50 @@ +/* + * Copyright 2009, 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. + */ + +#include <config.h> + +#include <ResourceLoaderAndroid.h> + +#include "FrameLoaderClientAndroid.h" +#include "WebCoreFrameBridge.h" +#include "WebCoreResourceLoader.h" + +using namespace android; + +namespace WebCore { + +PassRefPtr<ResourceLoaderAndroid> ResourceLoaderAndroid::start( + ResourceHandle* handle, const ResourceRequest& request, FrameLoaderClient* client, bool isMainResource, bool isSync) +{ + FrameLoaderClientAndroid* clientAndroid = static_cast<FrameLoaderClientAndroid*> (client); + return clientAndroid->webFrame()->startLoadingResource(handle, request, isMainResource, isSync); +} + +bool ResourceLoaderAndroid::willLoadFromCache(const WebCore::KURL& url, int64_t identifier) +{ + return WebCoreResourceLoader::willLoadFromCache(url, identifier); +} + +} diff --git a/WebKit/android/benchmark/Intercept.cpp b/WebKit/android/benchmark/Intercept.cpp index 90cf1e1..d657353 100644 --- a/WebKit/android/benchmark/Intercept.cpp +++ b/WebKit/android/benchmark/Intercept.cpp @@ -39,14 +39,21 @@ #include <utils/Log.h> #include <wtf/HashMap.h> -void MyResourceLoader::handleRequest() { +PassRefPtr<MyResourceLoader> MyResourceLoader::create(ResourceHandle* handle, String url) +{ + return adoptRef(new MyResourceLoader(handle, url)); +} + +void MyResourceLoader::handleRequest() +{ if (protocolIs(m_url, "data")) loadData(m_url.substring(5)); // 5 for data: else if (protocolIs(m_url, "file")) loadFile(m_url.substring(7)); // 7 for file:// } -void MyResourceLoader::loadData(const String& data) { +void MyResourceLoader::loadData(const String& data) +{ LOGD("Loading data (%s) ...", data.latin1().data()); ResourceHandleClient* client = m_handle->client(); int index = data.find(','); @@ -105,7 +112,8 @@ void MyResourceLoader::loadData(const String& data) { } client->didFinishLoading(m_handle); } -static String mimeTypeForExtension(const String& file) { +static String mimeTypeForExtension(const String& file) +{ static HashMap<String, String, CaseFoldingHash> extensionToMime; if (extensionToMime.isEmpty()) { extensionToMime.set("txt", "text/plain"); @@ -128,7 +136,8 @@ static String mimeTypeForExtension(const String& file) { return mime; } -void MyResourceLoader::loadFile(const String& file) { +void MyResourceLoader::loadFile(const String& file) +{ LOGD("Loading file (%s) ...", file.latin1().data()); FILE* f = fopen(file.latin1().data(), "r"); ResourceHandleClient* client = m_handle->client(); @@ -152,25 +161,25 @@ void MyResourceLoader::loadFile(const String& file) { } } -WebCoreResourceLoader* MyWebFrame::startLoadingResource(ResourceHandle* handle, - const ResourceRequest& req, bool ignore) { - MyResourceLoader* loader = new MyResourceLoader(handle, req.url().string()); - Retain(loader); +PassRefPtr<MyResourceLoader> MyWebFrame::startLoadingResource(ResourceHandle* handle, + const ResourceRequest& req, bool ignore) +{ + RefPtr<MyResourceLoader> loader = MyResourceLoader::create(handle, req.url().string()); m_requests.append(loader); if (!m_timer.isActive()) m_timer.startOneShot(0); - return loader; + return loader.release(); } -void MyWebFrame::timerFired(Timer<MyWebFrame>*) { +void MyWebFrame::timerFired(Timer<MyWebFrame>*) +{ LOGD("Handling requests..."); - Vector<MyResourceLoader*> reqs; + Vector<RefPtr<MyResourceLoader> > reqs; reqs.swap(m_requests); - Vector<MyResourceLoader*>::iterator i = reqs.begin(); - Vector<MyResourceLoader*>::iterator end = reqs.end(); - for (; i != end; i++) { + Vector<RefPtr<MyResourceLoader> >::iterator i = reqs.begin(); + Vector<RefPtr<MyResourceLoader> >::iterator end = reqs.end(); + for (; i != end; i++) (*i)->handleRequest(); - Release(*i); - } + LOGD("...done"); } diff --git a/WebKit/android/benchmark/Intercept.h b/WebKit/android/benchmark/Intercept.h index 2ae7f7b..6981e51 100644 --- a/WebKit/android/benchmark/Intercept.h +++ b/WebKit/android/benchmark/Intercept.h @@ -46,14 +46,15 @@ using namespace WTF; class MyResourceLoader : public WebCoreResourceLoader { public: + static PassRefPtr<MyResourceLoader> create(ResourceHandle* handle, String url); + void handleRequest(); + +private: MyResourceLoader(ResourceHandle* handle, String url) : WebCoreResourceLoader(JSC::Bindings::getJNIEnv(), MY_JOBJECT) , m_handle(handle) , m_url(url) {} - void handleRequest(); - -private: void loadData(const String&); void loadFile(const String&); ResourceHandle* m_handle; @@ -66,14 +67,14 @@ public: : WebFrame(JSC::Bindings::getJNIEnv(), MY_JOBJECT, MY_JOBJECT, page) , m_timer(this, &MyWebFrame::timerFired) {} - virtual WebCoreResourceLoader* startLoadingResource(ResourceHandle* handle, + virtual PassRefPtr<MyResourceLoader> startLoadingResource(ResourceHandle* handle, const ResourceRequest& req, bool); virtual bool canHandleRequest(const ResourceRequest&) { return true; } private: void timerFired(Timer<MyWebFrame>*); - Vector<MyResourceLoader*> m_requests; + Vector<RefPtr<MyResourceLoader> > m_requests; Timer<MyWebFrame> m_timer; }; diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index 646c5b8..f25e4a6 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -320,7 +320,7 @@ private: int m_size; }; -WebCoreResourceLoader* +PassRefPtr<WebCore::ResourceLoaderAndroid> WebFrame::startLoadingResource(WebCore::ResourceHandle* loader, const WebCore::ResourceRequest& request, bool mainResource, @@ -454,9 +454,9 @@ WebFrame::startLoadingResource(WebCore::ResourceHandle* loader, if (checkException(env)) return NULL; - WebCoreResourceLoader* h = NULL; + PassRefPtr<WebCore::ResourceLoaderAndroid> h; if (jLoadListener) - h = new WebCoreResourceLoader(env, jLoadListener); + h = WebCoreResourceLoader::create(env, jLoadListener); env->DeleteLocalRef(jLoadListener); return h; } diff --git a/WebKit/android/jni/WebCoreFrameBridge.h b/WebKit/android/jni/WebCoreFrameBridge.h index 1fdf140..7d18c40 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.h +++ b/WebKit/android/jni/WebCoreFrameBridge.h @@ -32,6 +32,7 @@ #include "PlatformString.h" #include "WebCoreRefObject.h" #include <jni.h> +#include <wtf/RefCounted.h> namespace WebCore { class HistoryItem; @@ -39,12 +40,12 @@ namespace WebCore { class Page; class RenderPart; class ResourceHandle; + class ResourceLoaderAndroid; class ResourceRequest; } namespace android { -class WebCoreResourceLoader; class WebViewCore; // one instance of WebFrame per Page for calling into Java's BrowserFrame @@ -62,7 +63,7 @@ class WebFrame : public WebCoreRefObject { // helper function static WebFrame* getWebFrame(const WebCore::Frame* frame); - virtual WebCoreResourceLoader* startLoadingResource(WebCore::ResourceHandle*, + virtual PassRefPtr<WebCore::ResourceLoaderAndroid> startLoadingResource(WebCore::ResourceHandle*, const WebCore::ResourceRequest& request, bool mainResource, bool synchronous); diff --git a/WebKit/android/jni/WebCoreResourceLoader.cpp b/WebKit/android/jni/WebCoreResourceLoader.cpp index fa8040a..55af52d 100644 --- a/WebKit/android/jni/WebCoreResourceLoader.cpp +++ b/WebKit/android/jni/WebCoreResourceLoader.cpp @@ -68,6 +68,11 @@ static struct resourceloader_t { //----------------------------------------------------------------------------- // ResourceLoadHandler +PassRefPtr<WebCore::ResourceLoaderAndroid> WebCoreResourceLoader::create(JNIEnv *env, jobject jLoadListener) +{ + return adoptRef<WebCore::ResourceLoaderAndroid>(new WebCoreResourceLoader(env, jLoadListener)); +} + WebCoreResourceLoader::WebCoreResourceLoader(JNIEnv *env, jobject jLoadListener) { mJLoader = env->NewGlobalRef(jLoadListener); diff --git a/WebKit/android/jni/WebCoreResourceLoader.h b/WebKit/android/jni/WebCoreResourceLoader.h index 8a4d8d8..d24a43e 100644 --- a/WebKit/android/jni/WebCoreResourceLoader.h +++ b/WebKit/android/jni/WebCoreResourceLoader.h @@ -26,29 +26,28 @@ #ifndef ANDROID_WEBKIT_RESOURCELOADLISTENER_H #define ANDROID_WEBKIT_RESOURCELOADLISTENER_H -#include "KURL.h" - -#include "WebCoreRefObject.h" +#include <KURL.h> +#include <ResourceLoaderAndroid.h> #include <jni.h> namespace android { -class WebCoreResourceLoader : public WebCoreRefObject +class WebCoreResourceLoader : public WebCore::ResourceLoaderAndroid { public: - WebCoreResourceLoader(JNIEnv *env, jobject jLoadListener); + static PassRefPtr<WebCore::ResourceLoaderAndroid> create(JNIEnv *env, jobject jLoadListener); virtual ~WebCoreResourceLoader(); /** * Call to java to cancel the current load. */ - void cancel(); + virtual void cancel(); /** * Call to java to download the current load rather than feed it * back to WebCore */ - void downloadFile(); + virtual void downloadFile(); /** * Call to java to find out if this URL is in the cache @@ -65,6 +64,8 @@ public: static jstring RedirectedToUrl(JNIEnv*, jobject, jstring, jstring, jint); static void Error(JNIEnv*, jobject, jint, jstring, jstring); +protected: + WebCoreResourceLoader(JNIEnv *env, jobject jLoadListener); private: jobject mJLoader; }; |