OSDN Git Service

Add a new API on the resource loader to pause the current load. We use this when...
authorBen Murdoch <benm@google.com>
Fri, 12 Mar 2010 20:46:03 +0000 (20:46 +0000)
committerBen Murdoch <benm@google.com>
Mon, 22 Mar 2010 20:50:51 +0000 (20:50 +0000)
buffering the data that the plugin can't take. This can result in a crash if the buffer gets too big (when watching an HD movie clip in
flash, for example).

Requires a frameworks/base change.

Change-Id: Ibb63d38df1014ff70fa4d65275613cbf3a217c1a

WebCore/loader/ResourceLoader.cpp
WebCore/loader/ResourceLoader.h
WebCore/platform/network/ResourceHandle.h
WebCore/platform/network/android/ResourceHandleAndroid.cpp
WebCore/platform/network/android/ResourceLoaderAndroid.h
WebCore/plugins/PluginStream.cpp
WebKit/android/jni/WebCoreResourceLoader.cpp
WebKit/android/jni/WebCoreResourceLoader.h

index 95ce209..d14afc8 100644 (file)
@@ -149,6 +149,15 @@ void ResourceLoader::setDefersLoading(bool defers)
     }
 }
 
+#if PLATFORM(ANDROID)
+// TODO: This needs upstreaming to WebKit.
+void ResourceLoader::pauseLoad(bool pause)
+{
+    if (m_handle)
+        m_handle->pauseLoad(pause);
+}
+#endif
+
 FrameLoader* ResourceLoader::frameLoader() const
 {
     if (!m_frame)
index 5239289..3178eb4 100644 (file)
@@ -64,6 +64,10 @@ namespace WebCore {
         ResourceError cannotShowURLError();
         
         virtual void setDefersLoading(bool);
+#if PLATFORM(ANDROID)
+// TODO: This needs upstreaming to WebKit.
+        virtual void pauseLoad(bool);
+#endif
 
         void setIdentifier(unsigned long identifier) { m_identifier = identifier; }
         unsigned long identifier() const { return m_identifier; }
index b764add..e340aca 100644 (file)
@@ -189,7 +189,11 @@ public:
     void setClient(ResourceHandleClient*);
 
     void setDefersLoading(bool);
-      
+#if PLATFORM(ANDROID)
+// TODO: this needs upstreaming.
+    void pauseLoad(bool);
+#endif
+
     const ResourceRequest& request() const;
 
     void fireFailure(Timer<ResourceHandle>*);
index 1154b47..6759852 100644 (file)
@@ -84,6 +84,15 @@ bool ResourceHandle::supportsBufferedData()
     return false;
 }
 
+#if PLATFORM(ANDROID)
+// TODO: this needs upstreaming.
+void ResourceHandle::pauseLoad(bool pause)
+{
+    if (d->m_loader)
+        d->m_loader->pauseLoad(pause);
+}
+#endif
+
 void ResourceHandle::setDefersLoading(bool defers)
 {
     notImplemented();
index 004675e..f627d62 100644 (file)
@@ -42,6 +42,9 @@ public:
 
     virtual void cancel() = 0;
     virtual void downloadFile() = 0;
+    // ANDROID TODO: This needs to be upstreamed.
+    virtual void pauseLoad(bool) = 0;
+    // END ANDROID TODO
 
     // Call to java to find out if this URL is in the cache
     static bool willLoadFromCache(const WebCore::KURL&, int64_t identifier);
index bf35ba4..1e91c51 100644 (file)
@@ -345,6 +345,11 @@ void PluginStream::deliverData()
         int32 deliveryBytes = m_pluginFuncs->writeready(m_instance, &m_stream);
 
         if (deliveryBytes <= 0) {
+#if PLATFORM(ANDROID)
+// TODO: This needs to be upstreamed.
+            if (m_loader)
+                m_loader->pauseLoad(true);
+#endif
             m_delayDeliveryTimer.startOneShot(0);
             break;
         } else {
@@ -373,6 +378,11 @@ void PluginStream::deliverData()
             memmove(m_deliveryData->data(), m_deliveryData->data() + totalBytesDelivered, remainingBytes);
             m_deliveryData->resize(remainingBytes);
         } else {
+#if PLATFORM(ANDROID)
+//TODO: This needs to be upstreamed to WebKit.
+            if (m_loader)
+                m_loader->pauseLoad(false);
+#endif
             m_deliveryData->resize(0);
             if (m_reason != WebReasonNone)
                 destroyStream();
index b17c9a7..cf32c09 100644 (file)
@@ -56,6 +56,7 @@ static struct resourceloader_t {
     jmethodID   mCancelMethodID;
     jmethodID   mDownloadFileMethodID;
     jmethodID   mWillLoadFromCacheMethodID;
+    jmethodID   mPauseLoadMethodID;
 } gResourceLoader;
 
 // ----------------------------------------------------------------------------
@@ -72,6 +73,7 @@ PassRefPtr<WebCore::ResourceLoaderAndroid> WebCoreResourceLoader::create(JNIEnv
 }
 
 WebCoreResourceLoader::WebCoreResourceLoader(JNIEnv *env, jobject jLoadListener)
+    : mPausedLoad(false)
 {
     mJLoader = env->NewGlobalRef(jLoadListener);
 }
@@ -98,6 +100,17 @@ void WebCoreResourceLoader::downloadFile()
     checkException(env);
 }
 
+void WebCoreResourceLoader::pauseLoad(bool pause)
+{
+    if (mPausedLoad == pause)
+        return;
+
+    mPausedLoad = pause;
+    JNIEnv* env = JSC::Bindings::getJNIEnv();
+    env->CallVoidMethod(mJLoader, gResourceLoader.mPauseLoadMethodID, pause);
+    checkException(env);
+}
+
 /*
 * This static method is called to check to see if a POST response is in
 * the cache. This may be slow, but is only used during a navigation to
@@ -320,6 +333,11 @@ int register_resource_loader(JNIEnv* env)
     LOG_FATAL_IF(gResourceLoader.mDownloadFileMethodID == NULL, 
         "Could not find method downloadFile on LoadListener");
 
+    gResourceLoader.mPauseLoadMethodID =
+        env->GetMethodID(resourceLoader, "pauseLoad", "(Z)V");
+    LOG_FATAL_IF(gResourceLoader.mPauseLoadMethodID == NULL,
+        "Could not find method pauseLoad on LoadListener");
+
     gResourceLoader.mWillLoadFromCacheMethodID = 
         env->GetStaticMethodID(resourceLoader, "willLoadFromCache", "(Ljava/lang/String;J)Z");
     LOG_FATAL_IF(gResourceLoader.mWillLoadFromCacheMethodID == NULL, 
index d24a43e..c60b3f5 100644 (file)
@@ -49,6 +49,8 @@ public:
     */
     virtual void downloadFile();
 
+    virtual void pauseLoad(bool);
+
     /**
     * Call to java to find out if this URL is in the cache
     */
@@ -68,6 +70,7 @@ protected:
     WebCoreResourceLoader(JNIEnv *env, jobject jLoadListener);
 private:
     jobject     mJLoader;
+    bool        mPausedLoad;
 };
 
 } // end namespace android