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/benchmark | |
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/benchmark')
-rw-r--r-- | WebKit/android/benchmark/Intercept.cpp | 41 | ||||
-rw-r--r-- | WebKit/android/benchmark/Intercept.h | 11 |
2 files changed, 31 insertions, 21 deletions
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; }; |