Title: [138693] trunk
Revision
138693
Author
[email protected]
Date
2013-01-02 19:22:30 -0800 (Wed, 02 Jan 2013)

Log Message

[chromium] Creation of dedicated workers (isolates) leaks reference to HTMLDocument
https://bugs.webkit.org/show_bug.cgi?id=105367

Reviewed by Dmitry Titov.

Source/WebCore:

Eliminated a Chromium-specific object wrapping WorkerMessagingProxy in order to fix a
lifetime management bug, which leaked every Document which started a dedicated worker.

Test: fast/workers/worker-document-leak.html

* workers/WorkerLoaderProxy.h:
(WorkerLoaderProxy):
    Added Chromium-specific casting method to bridge two now-distinct class hierarchies.
* workers/WorkerMessagingProxy.h:
(WorkerMessagingProxy):
    Made destructor protected instead of private to allow subclassing.

Source/WebKit/chromium:

Made WebWorkerClientImpl a subclass of WorkerMessagingProxy rather than an object wrapping
WorkerMessagingProxy. WorkerMessagingProxy manages its own lifetime and it is impossible to
properly synchronize the lifetime of WebWorkerClientImpl separately.

This allowed most of WebWorkerClientImpl to be deleted, but forced a divergence in the class
hierarchies of WebWorkerClientImpl and WebSharedWorkerImpl. Conversion methods were added to
WorkerLoaderProxy and WebWorkerBase to bridge the hierarchies of in-process and
out-of-process workers.

* src/DatabaseObserver.cpp:
(WebCore::DatabaseObserver::canEstablishDatabase):
    Adjusted how WebWorkerBase is obtained from WorkerLoaderProxy.
* src/IDBFactoryBackendProxy.cpp:
(WebKit::AllowIndexedDBMainThreadBridge::signalCompleted):
    Adjusted how WorkerLoaderProxy's methods are called.
(WebKit::IDBFactoryBackendProxy::allowIndexedDB):
    Adjusted how WebWorkerBase is obtained from WorkerLoaderProxy.
* src/LocalFileSystemChromium.cpp:
(WebCore::openFileSystemHelper):
    Adjusted how WebWorkerBase is obtained from WorkerLoaderProxy.
* src/WebSharedWorkerImpl.cpp:
(WebKit::WebSharedWorkerImpl::toWebWorkerBase):
    Implemented new conversion method.
* src/WebSharedWorkerImpl.h:
(WebSharedWorkerImpl):
    Explicitly derive from WorkerLoaderProxy now that WebWorkerBase no longer does.
(WebKit::WebSharedWorkerImpl::workerLoaderProxy):
    Added new conversion method.
* src/WebWorkerBase.h:
(WebWorkerBase):
    Removed derivation from WorkerLoaderProxy. Added method to convert to WorkerLoaderProxy.
* src/WebWorkerClientImpl.cpp:
(WebKit):
    Adjusted comment.
(WebKit::WebWorkerClientImpl::createWorkerContextProxy):
    Adjusted whitespace.
(WebKit::WebWorkerClientImpl::terminateWorkerContext):
    Eliminated delegation to separate object.
(WebKit::WebWorkerClientImpl::toWebWorkerBase):
    Implemented new conversion method.
(WebKit::WebWorkerClientImpl::view):
(WebKit::WebWorkerClientImpl::allowDatabase):
(WebKit::WebWorkerClientImpl::allowFileSystem):
(WebKit::WebWorkerClientImpl::openFileSystem):
(WebKit::WebWorkerClientImpl::allowIndexedDB):
    Eliminated delegation to separate object.
(WebKit::WebWorkerClientImpl::WebWorkerClientImpl):
* src/WebWorkerClientImpl.h:
(WebKit):
    Changed to inherit from WorkerMessagingProxy directly.
(WebWorkerClientImpl):
    Deleted most methods previously overridden from WorkerContextProxy, etc.
* src/WorkerAsyncFileSystemChromium.cpp:
(WebCore::WorkerAsyncFileSystemChromium::WorkerAsyncFileSystemChromium):
(WebCore::WorkerAsyncFileSystemChromium::createWorkerFileSystemCallbacksBridge):
    Hold on to, and use, WorkerLoaderProxy rather than WebWorkerBase.
* src/WorkerAsyncFileSystemChromium.h:
(WebKit):
(WebCore):
(WorkerAsyncFileSystemChromium):
    Hold on to WorkerLoaderProxy rather than WebWorkerBase.

LayoutTests:

* fast/workers/resources/empty-worker.js: Added.
* fast/workers/resources/worker-document-leak-iframe.html: Added.
* fast/workers/worker-document-leak-expected.txt: Added.
* fast/workers/worker-document-leak.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (138692 => 138693)


--- trunk/LayoutTests/ChangeLog	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/LayoutTests/ChangeLog	2013-01-03 03:22:30 UTC (rev 138693)
@@ -1,3 +1,15 @@
+2013-01-02  Kenneth Russell  <[email protected]>
+
+        [chromium] Creation of dedicated workers (isolates) leaks reference to HTMLDocument
+        https://bugs.webkit.org/show_bug.cgi?id=105367
+
+        Reviewed by Dmitry Titov.
+
+        * fast/workers/resources/empty-worker.js: Added.
+        * fast/workers/resources/worker-document-leak-iframe.html: Added.
+        * fast/workers/worker-document-leak-expected.txt: Added.
+        * fast/workers/worker-document-leak.html: Added.
+
 2013-01-02  Ryosuke Niwa  <[email protected]>
 
         One more Mac rebaseline attempt for r138654. Also remove an entry for the bug 105514

Added: trunk/LayoutTests/fast/workers/resources/empty-worker.js (0 => 138693)


--- trunk/LayoutTests/fast/workers/resources/empty-worker.js	                        (rev 0)
+++ trunk/LayoutTests/fast/workers/resources/empty-worker.js	2013-01-03 03:22:30 UTC (rev 138693)
@@ -0,0 +1,2 @@
+postMessage("closing");
+close();

Added: trunk/LayoutTests/fast/workers/resources/worker-document-leak-iframe.html (0 => 138693)


--- trunk/LayoutTests/fast/workers/resources/worker-document-leak-iframe.html	                        (rev 0)
+++ trunk/LayoutTests/fast/workers/resources/worker-document-leak-iframe.html	2013-01-03 03:22:30 UTC (rev 138693)
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+var worker = new Worker('empty-worker.js');
+worker._onmessage_ = function(event) {
+    waitUntilWorkerThreadsExit(function() {
+        parent.postMessage("done", "*");
+    });
+};
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/fast/workers/worker-document-leak-expected.txt (0 => 138693)


--- trunk/LayoutTests/fast/workers/worker-document-leak-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/workers/worker-document-leak-expected.txt	2013-01-03 03:22:30 UTC (rev 138693)
@@ -0,0 +1,4 @@
+Verify that creation of a worker does not leak its creating document.
+
+PASS: did not leak documents during test run
+

Added: trunk/LayoutTests/fast/workers/worker-document-leak.html (0 => 138693)


--- trunk/LayoutTests/fast/workers/worker-document-leak.html	                        (rev 0)
+++ trunk/LayoutTests/fast/workers/worker-document-leak.html	2013-01-03 03:22:30 UTC (rev 138693)
@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>Verify that creation of a worker does not leak its creating document.</p>
+<div id='console'></div>
+<script src=''></script>
+<script>
+function log(message)
+{
+    document.getElementById("console").innerHTML += message + "<br>";
+}
+
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+
+// Set this number as high as possible without introducing timeouts in debug builds.
+// Reducing it does not require rebaselines.
+var numIterations = 6;
+
+var currentIteration = 0;
+var iframe = null;
+var numLiveAtStart = 0;
+var numLiveAtEnd = 0;
+
+window._onmessage_ = function(event) {
+    if (event.data == "done") {
+        runOneIteration();
+    }
+};
+
+function startTest()
+{
+    gc();
+    if (window.internals && window.internals.numberOfLiveDocuments) {
+        numLiveAtStart = window.internals.numberOfLiveDocuments();
+        // Depending on which tests ran before this one in DumpRenderTree,
+        // their Document instances may not have been fully cleaned up yet.
+        // When this test is run in isolation, there should be only one
+        // live document at this point.
+        runOneIteration();
+    } else {
+        log("window.internals.numberOfLiveDocuments not available -- no point in running test");
+        finishTest();
+    }
+}
+
+function runOneIteration() {
+    if (currentIteration < numIterations) {
+        ++currentIteration;
+
+        var createdIframe = false;
+        if (!iframe) {
+            iframe = document.createElement("iframe");
+            createdIframe = true;
+        }
+        iframe.setAttribute("src", "resources/worker-document-leak-iframe.html");
+        if (createdIframe)
+            document.body.appendChild(iframe);
+    } else {
+        finishTest();
+    }
+}
+
+function finishTest()
+{
+    gc();
+
+    if (window.internals && window.internals.numberOfLiveDocuments) {
+        numLiveAtEnd = window.internals.numberOfLiveDocuments();
+        // Under no circumstances should the number of live documents
+        // at the end be more than 1 greater than the number at the
+        // beginning (because of the iframe).
+        if (numLiveAtEnd > numLiveAtStart + 1) {
+            log("FAIL: leaked documents during test run (started with " + numLiveAtStart + ", ended with " + numLiveAtEnd + ")");
+        } else {
+            log("PASS: did not leak documents during test run");
+        }
+    }
+
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+window._onload_ = startTest;
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (138692 => 138693)


--- trunk/Source/WebCore/ChangeLog	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebCore/ChangeLog	2013-01-03 03:22:30 UTC (rev 138693)
@@ -1,3 +1,22 @@
+2013-01-02  Kenneth Russell  <[email protected]>
+
+        [chromium] Creation of dedicated workers (isolates) leaks reference to HTMLDocument
+        https://bugs.webkit.org/show_bug.cgi?id=105367
+
+        Reviewed by Dmitry Titov.
+
+        Eliminated a Chromium-specific object wrapping WorkerMessagingProxy in order to fix a
+        lifetime management bug, which leaked every Document which started a dedicated worker.
+
+        Test: fast/workers/worker-document-leak.html
+
+        * workers/WorkerLoaderProxy.h:
+        (WorkerLoaderProxy):
+            Added Chromium-specific casting method to bridge two now-distinct class hierarchies.
+        * workers/WorkerMessagingProxy.h:
+        (WorkerMessagingProxy):
+            Made destructor protected instead of private to allow subclassing.
+
 2013-01-02  Elliott Sprehn  <[email protected]>
 
         Make ClassList::reset's purpose obvious and don't keep quirks string when not needed

Modified: trunk/Source/WebCore/workers/WorkerLoaderProxy.h (138692 => 138693)


--- trunk/Source/WebCore/workers/WorkerLoaderProxy.h	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebCore/workers/WorkerLoaderProxy.h	2013-01-03 03:22:30 UTC (rev 138693)
@@ -37,6 +37,12 @@
 #include <wtf/Forward.h>
 #include <wtf/PassOwnPtr.h>
 
+#if PLATFORM(CHROMIUM)
+namespace WebKit {
+class WebWorkerBase;
+}
+#endif // PLATFORM(CHROMIUM)
+
 namespace WebCore {
 
     // A proxy to talk to the loader context. Normally, the document on the main thread
@@ -55,6 +61,11 @@
         // specific synchronous loading requests so they can be 'nested', per spec.
         // Returns true if the task was posted successfully.
         virtual bool postTaskForModeToWorkerContext(PassOwnPtr<ScriptExecutionContext::Task>, const String& mode) = 0;
+
+#if PLATFORM(CHROMIUM)
+        // Spans divergent class hierarchies for dedicated and shared workers.
+        virtual WebKit::WebWorkerBase* toWebWorkerBase() = 0;
+#endif
     };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/WorkerMessagingProxy.h (138692 => 138693)


--- trunk/Source/WebCore/workers/WorkerMessagingProxy.h	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebCore/workers/WorkerMessagingProxy.h	2013-01-03 03:22:30 UTC (rev 138693)
@@ -89,6 +89,9 @@
         // Only use this method on the worker object thread.
         bool askedToTerminate() const { return m_askedToTerminate; }
 
+    protected:
+        virtual ~WorkerMessagingProxy();
+
     private:
         friend class MessageWorkerTask;
         friend class PostMessageToPageInspectorTask;
@@ -96,8 +99,6 @@
         friend class WorkerExceptionTask;
         friend class WorkerThreadActivityReportTask;
 
-        virtual ~WorkerMessagingProxy();
-
         void workerContextDestroyedInternal();
         static void workerObjectDestroyedInternal(ScriptExecutionContext*, WorkerMessagingProxy*);
         void reportPendingActivityInternal(bool confirmingMessage, bool hasPendingActivity);

Modified: trunk/Source/WebKit/chromium/ChangeLog (138692 => 138693)


--- trunk/Source/WebKit/chromium/ChangeLog	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebKit/chromium/ChangeLog	2013-01-03 03:22:30 UTC (rev 138693)
@@ -1,3 +1,72 @@
+2013-01-02  Kenneth Russell  <[email protected]>
+
+        [chromium] Creation of dedicated workers (isolates) leaks reference to HTMLDocument
+        https://bugs.webkit.org/show_bug.cgi?id=105367
+
+        Reviewed by Dmitry Titov.
+
+        Made WebWorkerClientImpl a subclass of WorkerMessagingProxy rather than an object wrapping
+        WorkerMessagingProxy. WorkerMessagingProxy manages its own lifetime and it is impossible to
+        properly synchronize the lifetime of WebWorkerClientImpl separately.
+
+        This allowed most of WebWorkerClientImpl to be deleted, but forced a divergence in the class
+        hierarchies of WebWorkerClientImpl and WebSharedWorkerImpl. Conversion methods were added to
+        WorkerLoaderProxy and WebWorkerBase to bridge the hierarchies of in-process and
+        out-of-process workers.
+
+        * src/DatabaseObserver.cpp:
+        (WebCore::DatabaseObserver::canEstablishDatabase):
+            Adjusted how WebWorkerBase is obtained from WorkerLoaderProxy.
+        * src/IDBFactoryBackendProxy.cpp:
+        (WebKit::AllowIndexedDBMainThreadBridge::signalCompleted):
+            Adjusted how WorkerLoaderProxy's methods are called.
+        (WebKit::IDBFactoryBackendProxy::allowIndexedDB):
+            Adjusted how WebWorkerBase is obtained from WorkerLoaderProxy.
+        * src/LocalFileSystemChromium.cpp:
+        (WebCore::openFileSystemHelper):
+            Adjusted how WebWorkerBase is obtained from WorkerLoaderProxy.
+        * src/WebSharedWorkerImpl.cpp:
+        (WebKit::WebSharedWorkerImpl::toWebWorkerBase):
+            Implemented new conversion method.
+        * src/WebSharedWorkerImpl.h:
+        (WebSharedWorkerImpl):
+            Explicitly derive from WorkerLoaderProxy now that WebWorkerBase no longer does.
+        (WebKit::WebSharedWorkerImpl::workerLoaderProxy):
+            Added new conversion method.
+        * src/WebWorkerBase.h:
+        (WebWorkerBase):
+            Removed derivation from WorkerLoaderProxy. Added method to convert to WorkerLoaderProxy.
+        * src/WebWorkerClientImpl.cpp:
+        (WebKit):
+            Adjusted comment.
+        (WebKit::WebWorkerClientImpl::createWorkerContextProxy):
+            Adjusted whitespace.
+        (WebKit::WebWorkerClientImpl::terminateWorkerContext):
+            Eliminated delegation to separate object.
+        (WebKit::WebWorkerClientImpl::toWebWorkerBase):
+            Implemented new conversion method.
+        (WebKit::WebWorkerClientImpl::view):
+        (WebKit::WebWorkerClientImpl::allowDatabase):
+        (WebKit::WebWorkerClientImpl::allowFileSystem):
+        (WebKit::WebWorkerClientImpl::openFileSystem):
+        (WebKit::WebWorkerClientImpl::allowIndexedDB):
+            Eliminated delegation to separate object.
+        (WebKit::WebWorkerClientImpl::WebWorkerClientImpl):
+        * src/WebWorkerClientImpl.h:
+        (WebKit):
+            Changed to inherit from WorkerMessagingProxy directly.
+        (WebWorkerClientImpl):
+            Deleted most methods previously overridden from WorkerContextProxy, etc.
+        * src/WorkerAsyncFileSystemChromium.cpp:
+        (WebCore::WorkerAsyncFileSystemChromium::WorkerAsyncFileSystemChromium):
+        (WebCore::WorkerAsyncFileSystemChromium::createWorkerFileSystemCallbacksBridge):
+            Hold on to, and use, WorkerLoaderProxy rather than WebWorkerBase.
+        * src/WorkerAsyncFileSystemChromium.h:
+        (WebKit):
+        (WebCore):
+        (WorkerAsyncFileSystemChromium):
+            Hold on to WorkerLoaderProxy rather than WebWorkerBase.
+
 2013-01-02  James Robinson  <[email protected]>
 
         [chromium] Remove unused transitional #defines from WebKit Client API

Modified: trunk/Source/WebKit/chromium/src/DatabaseObserver.cpp (138692 => 138693)


--- trunk/Source/WebKit/chromium/src/DatabaseObserver.cpp	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebKit/chromium/src/DatabaseObserver.cpp	2013-01-03 03:22:30 UTC (rev 138693)
@@ -164,8 +164,7 @@
     } else {
 #if ENABLE(WORKERS)
         WorkerContext* workerContext = static_cast<WorkerContext*>(scriptExecutionContext);
-        WorkerLoaderProxy* workerLoaderProxy = &workerContext->thread()->workerLoaderProxy();
-        WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerLoaderProxy);
+        WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerContext->thread()->workerLoaderProxy().toWebWorkerBase());
         WebView* view = webWorker->view();
         if (!view)
             return false;

Modified: trunk/Source/WebKit/chromium/src/IDBFactoryBackendProxy.cpp (138692 => 138693)


--- trunk/Source/WebKit/chromium/src/IDBFactoryBackendProxy.cpp	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebKit/chromium/src/IDBFactoryBackendProxy.cpp	2013-01-03 03:22:30 UTC (rev 138693)
@@ -111,7 +111,7 @@
     {
         MutexLocker locker(m_mutex);
         if (m_webWorkerBase)
-            m_webWorkerBase->postTaskForModeToWorkerContext(createCallbackTask(&didComplete, this, result), mode);
+            m_webWorkerBase->workerLoaderProxy()->postTaskForModeToWorkerContext(createCallbackTask(&didComplete, this, result), mode);
     }
 
 private:
@@ -172,7 +172,7 @@
         allowed = !webView->permissionClient() || webView->permissionClient()->allowIndexedDB(webFrame, name, origin);
     } else {
         WorkerContext* workerContext = static_cast<WorkerContext*>(context);
-        WebWorkerBase* webWorkerBase = static_cast<WebWorkerBase*>(&workerContext->thread()->workerLoaderProxy());
+        WebWorkerBase* webWorkerBase = static_cast<WebWorkerBase*>(workerContext->thread()->workerLoaderProxy().toWebWorkerBase());
         WorkerRunLoop& runLoop = workerContext->thread()->runLoop();
 
         String mode = allowIndexedDBMode;

Modified: trunk/Source/WebKit/chromium/src/LocalFileSystemChromium.cpp (138692 => 138693)


--- trunk/Source/WebKit/chromium/src/LocalFileSystemChromium.cpp	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebKit/chromium/src/LocalFileSystemChromium.cpp	2013-01-03 03:22:30 UTC (rev 138693)
@@ -203,8 +203,7 @@
     } else {
 #if ENABLE(WORKERS)
         WorkerContext* workerContext = static_cast<WorkerContext*>(context);
-        WorkerLoaderProxy* workerLoaderProxy = &workerContext->thread()->workerLoaderProxy();
-        WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerLoaderProxy);
+        WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerContext->thread()->workerLoaderProxy().toWebWorkerBase());
         if (!allowFileSystemForWorker(webWorker->commonClient()))
             allowed = false;
         else

Modified: trunk/Source/WebKit/chromium/src/WebSharedWorkerImpl.cpp (138692 => 138693)


--- trunk/Source/WebKit/chromium/src/WebSharedWorkerImpl.cpp	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebKit/chromium/src/WebSharedWorkerImpl.cpp	2013-01-03 03:22:30 UTC (rev 138693)
@@ -324,6 +324,10 @@
     return true;
 }
 
+WebWorkerBase* WebSharedWorkerImpl::toWebWorkerBase()
+{
+    return this;
+}
 
 
 bool WebSharedWorkerImpl::isStarted()

Modified: trunk/Source/WebKit/chromium/src/WebSharedWorkerImpl.h (138692 => 138693)


--- trunk/Source/WebKit/chromium/src/WebSharedWorkerImpl.h	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebKit/chromium/src/WebSharedWorkerImpl.h	2013-01-03 03:22:30 UTC (rev 138693)
@@ -61,10 +61,12 @@
 // It can't use it directly since it uses WebKit types, so this class converts the data types.
 // When the WebCore::SharedWorker object wants to call WebCore::WorkerReportingProxy, this class will
 // convert to Chrome data types first and then call the supplied WebCommonWorkerClient.
-class WebSharedWorkerImpl : public WebCore::WorkerObjectProxy
-                          , public WebWorkerBase
-                          , public WebFrameClient
-                          , public WebSharedWorker {
+class WebSharedWorkerImpl
+    : public WebCore::WorkerObjectProxy
+    , public WebCore::WorkerLoaderProxy
+    , public WebWorkerBase
+    , public WebFrameClient
+    , public WebSharedWorker {
 public:
     explicit WebSharedWorkerImpl(WebSharedWorkerClient*);
 
@@ -88,6 +90,7 @@
     virtual void postTaskToLoader(PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
     virtual bool postTaskForModeToWorkerContext(
         PassOwnPtr<WebCore::ScriptExecutionContext::Task>, const WTF::String& mode);
+    virtual WebWorkerBase* toWebWorkerBase() OVERRIDE;
 
     // WebFrameClient methods to support resource loading thru the 'shadow page'.
     virtual void didCreateDataSource(WebFrame*, WebDataSource*);
@@ -111,7 +114,8 @@
     virtual void dispatchDevToolsMessage(const WebString&);
 
 
-    // NewWebWorkerBase methods:
+    // WebWorkerBase methods:
+    WebCore::WorkerLoaderProxy* workerLoaderProxy() { return this; }
     WebCommonWorkerClient* commonClient() { return m_client; }
 
 private:

Modified: trunk/Source/WebKit/chromium/src/WebWorkerBase.h (138692 => 138693)


--- trunk/Source/WebKit/chromium/src/WebWorkerBase.h	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebKit/chromium/src/WebWorkerBase.h	2013-01-03 03:22:30 UTC (rev 138693)
@@ -48,8 +48,9 @@
 // containing common interface for shared workers and dedicated in-proc workers implementation.
 //
 // FIXME: Rename this class into WebWorkerBase, merge existing WebWorkerBase and WebSharedWorker.
-class WebWorkerBase : public WebCore::WorkerLoaderProxy {
+class WebWorkerBase {
 public:
+    virtual WebCore::WorkerLoaderProxy* workerLoaderProxy() = 0;
     virtual WebCommonWorkerClient* commonClient() = 0;
     virtual WebView* view() const = 0;
 

Modified: trunk/Source/WebKit/chromium/src/WebWorkerClientImpl.cpp (138692 => 138693)


--- trunk/Source/WebKit/chromium/src/WebWorkerClientImpl.cpp	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebKit/chromium/src/WebWorkerClientImpl.cpp	2013-01-03 03:22:30 UTC (rev 138693)
@@ -69,8 +69,7 @@
 
 namespace WebKit {
 
-// Chromium-specific wrapper over WorkerMessagingProxy.
-// Delegates implementation of Worker{Loader,Context,Object}Proxy to WorkerMessagingProxy.
+// Chromium-specific decorator of WorkerMessagingProxy.
 
 // static
 WorkerContextProxy* WebWorkerClientImpl::createWorkerContextProxy(Worker* worker)
@@ -79,127 +78,43 @@
         Document* document = static_cast<Document*>(worker->scriptExecutionContext());
         WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame());
         WebWorkerClientImpl* proxy = new WebWorkerClientImpl(worker, webFrame);
-        return proxy; 
-    } 
+        return proxy;
+    }
     ASSERT_NOT_REACHED();
     return 0;
 }
 
-void WebWorkerClientImpl::startWorkerContext(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode)
-{
-    ASSERT(m_scriptExecutionContext->isDocument());
-    Document* document = static_cast<Document*>(m_scriptExecutionContext.get());
-    GroupSettings* settings = 0;
-    if (document->page())
-        settings = document->page()->group().groupSettings();
-    RefPtr<DedicatedWorkerThread> thread = DedicatedWorkerThread::create(scriptURL, userAgent, settings, sourceCode, *this, *this, startMode,
-                                                                         document->contentSecurityPolicy()->deprecatedHeader(),
-                                                                         document->contentSecurityPolicy()->deprecatedHeaderType(),
-                                                                         document->topDocument()->securityOrigin());
-    m_proxy->workerThreadCreated(thread);
-    thread->start();
-    InspectorInstrumentation::didStartWorkerContext(m_scriptExecutionContext.get(), m_proxy, scriptURL);
-}
-
 void WebWorkerClientImpl::terminateWorkerContext()
 {
     m_webFrame = 0;
-    m_proxy->terminateWorkerContext();
+    WebCore::WorkerMessagingProxy::terminateWorkerContext();
 }
 
-void WebWorkerClientImpl::postMessageToWorkerContext(
-    PassRefPtr<SerializedScriptValue> value, 
-    PassOwnPtr<MessagePortChannelArray> ports)
+WebWorkerBase* WebWorkerClientImpl::toWebWorkerBase()
 {
-    m_proxy->postMessageToWorkerContext(value, ports);
+    return this;
 }
 
-bool WebWorkerClientImpl::hasPendingActivity() const
+WebView* WebWorkerClientImpl::view() const
 {
-    return m_proxy->hasPendingActivity();
+    if (askedToTerminate())
+        return 0;
+    return m_webFrame->view();
 }
 
-void WebWorkerClientImpl::workerObjectDestroyed()
+bool WebWorkerClientImpl::allowDatabase(WebFrame*, const WebString& name, const WebString& displayName, unsigned long estimatedSize)
 {
-    m_proxy->workerObjectDestroyed();
+    if (askedToTerminate())
+        return false;
+    WebKit::WebViewImpl* webView = m_webFrame->viewImpl();
+    if (!webView)
+        return false;
+    return !webView->permissionClient() || webView->permissionClient()->allowDatabase(m_webFrame, name, displayName, estimatedSize);
 }
 
-#if ENABLE(INSPECTOR)
-void WebWorkerClientImpl::connectToInspector(PageInspector* inspector)
-{
-    m_proxy->connectToInspector(inspector);
-}
-
-void WebWorkerClientImpl::disconnectFromInspector()
-{
-    m_proxy->disconnectFromInspector();
-}
-
-void WebWorkerClientImpl::sendMessageToInspector(const String& message)
-{
-    m_proxy->sendMessageToInspector(message);
-}
-
-void WebWorkerClientImpl::postMessageToPageInspector(const String& message)
-{
-    m_proxy->postMessageToPageInspector(message);
-}
-
-void WebWorkerClientImpl::updateInspectorStateCookie(const String& cookie)
-{
-    m_proxy->updateInspectorStateCookie(cookie);
-}
-#endif // ENABLE(INSPECTOR)
-
-
-void WebWorkerClientImpl::postTaskToLoader(PassOwnPtr<ScriptExecutionContext::Task> task)
-{
-    m_proxy->postTaskToLoader(task);
-}
-
-bool WebWorkerClientImpl::postTaskForModeToWorkerContext(PassOwnPtr<ScriptExecutionContext::Task> task, const String& mode)
-{
-    return m_proxy->postTaskForModeToWorkerContext(task, mode);
-}
-
-void WebWorkerClientImpl::postMessageToWorkerObject(PassRefPtr<SerializedScriptValue> value, PassOwnPtr<MessagePortChannelArray> ports)
-{
-    m_proxy->postMessageToWorkerObject(value, ports);
-}
-
-void WebWorkerClientImpl::confirmMessageFromWorkerObject(bool hasPendingActivity)
-{
-    m_proxy->confirmMessageFromWorkerObject(hasPendingActivity);
-}
-
-void WebWorkerClientImpl::reportPendingActivity(bool hasPendingActivity)
-{
-    m_proxy->reportPendingActivity(hasPendingActivity);
-}
-
-void WebWorkerClientImpl::workerContextClosed()
-{
-    m_proxy->workerContextClosed();
-}
-
-void WebWorkerClientImpl::postExceptionToWorkerObject(const String& errorMessage, int lineNumber, const String& sourceURL)
-{
-    m_proxy->postExceptionToWorkerObject(errorMessage, lineNumber, sourceURL);
-}
-
-void WebWorkerClientImpl::postConsoleMessageToWorkerObject(MessageSource source, MessageLevel level, const String& message, int lineNumber, const String& sourceURL)
-{
-    m_proxy->postConsoleMessageToWorkerObject(source, level, message, lineNumber, sourceURL);
-}
-
-void WebWorkerClientImpl::workerContextDestroyed()
-{
-    m_proxy->workerContextDestroyed();
-}
-
 bool WebWorkerClientImpl::allowFileSystem()
 {
-    if (m_proxy->askedToTerminate())
+    if (askedToTerminate())
         return false;
     WebKit::WebViewImpl* webView = m_webFrame->viewImpl();
     if (!webView)
@@ -207,47 +122,29 @@
     return !webView->permissionClient() || webView->permissionClient()->allowFileSystem(m_webFrame);
 }
 
-void WebWorkerClientImpl::openFileSystem(WebFileSystem::Type type, long long size, bool create, 
+void WebWorkerClientImpl::openFileSystem(WebFileSystem::Type type, long long size, bool create,
                                          WebFileSystemCallbacks* callbacks)
 {
-    if (m_proxy->askedToTerminate()) {
+    if (askedToTerminate()) {
         callbacks->didFail(WebFileErrorAbort);
         return;
     }
     m_webFrame->client()->openFileSystem(m_webFrame, type, size, create, callbacks);
 }
 
-bool WebWorkerClientImpl::allowDatabase(WebFrame*, const WebString& name, const WebString& displayName, unsigned long estimatedSize) 
-{
-    if (m_proxy->askedToTerminate())
-        return false;
-    WebKit::WebViewImpl* webView = m_webFrame->viewImpl();
-    if (!webView)
-        return false;
-    return !webView->permissionClient() || webView->permissionClient()->allowDatabase(m_webFrame, name, displayName, estimatedSize);
-}
-
 bool WebWorkerClientImpl::allowIndexedDB(const WebString& name)
 {
-    if (m_proxy->askedToTerminate())
+    if (askedToTerminate())
         return false;
     WebKit::WebViewImpl* webView = m_webFrame->viewImpl();
     if (!webView)
         return false;
     return !webView->permissionClient() || webView->permissionClient()->allowIndexedDB(m_webFrame, name, WebSecurityOrigin());
 }
- 
-WebView* WebWorkerClientImpl::view() const 
-{
-    if (m_proxy->askedToTerminate())
-        return 0;
-    return m_webFrame->view(); 
-}
 
 WebWorkerClientImpl::WebWorkerClientImpl(Worker* worker, WebFrameImpl* webFrame)
-    : m_proxy(new WorkerMessagingProxy(worker))
-    , m_scriptExecutionContext(worker->scriptExecutionContext())
-    , m_webFrame(webFrame)    
+    : WebCore::WorkerMessagingProxy(worker)
+    , m_webFrame(webFrame)
 {
 }
 

Modified: trunk/Source/WebKit/chromium/src/WebWorkerClientImpl.h (138692 => 138693)


--- trunk/Source/WebKit/chromium/src/WebWorkerClientImpl.h	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebKit/chromium/src/WebWorkerClientImpl.h	2013-01-03 03:22:30 UTC (rev 138693)
@@ -54,9 +54,13 @@
 // for in-proc dedicated workers. It also acts as a bridge for workers to chromium implementation of file systems,
 // databases and other related functionality.
 //
-// In essence, this class wraps WorkerMessagingProxy.
-class WebWorkerClientImpl : public WebCore::WorkerContextProxy
-                          , public WebCore::WorkerObjectProxy
+// In essence, this class decorates WorkerMessagingProxy.
+//
+// It is imperative that this class inherit from WorkerMessagingProxy rather than delegate to an instance of
+// WorkerMessagingProxy, because that class tracks and reports its activity to outside callers, and manages
+// its own lifetime, via calls to workerObjectDestroyed, workerContextDestroyed, workerContextClosed, etc. It
+// is basically impossible to correctly manage the lifetime of this class separately from WorkerMessagingProxy.
+class WebWorkerClientImpl : public WebCore::WorkerMessagingProxy
                           , public WebWorkerBase
                           , public WebCommonWorkerClient {
 public:
@@ -66,57 +70,27 @@
     // WebCore::WorkerContextProxy methods:
     // These are called on the thread that created the worker.  In the renderer
     // process, this will be the main WebKit thread.
-    virtual void startWorkerContext(const WebCore::KURL&,
-                                    const WTF::String&,
-                                    const WTF::String&,
-                                    WebCore::WorkerThreadStartMode) OVERRIDE;
     virtual void terminateWorkerContext() OVERRIDE;
-    virtual void postMessageToWorkerContext(
-        PassRefPtr<WebCore::SerializedScriptValue> message,
-        PassOwnPtr<WebCore::MessagePortChannelArray> channels) OVERRIDE;
-    virtual bool hasPendingActivity() const OVERRIDE;
-    virtual void workerObjectDestroyed() OVERRIDE;
 
-#if ENABLE(INSPECTOR)
-    virtual void connectToInspector(WebCore::WorkerContextProxy::PageInspector*) OVERRIDE;
-    virtual void disconnectFromInspector() OVERRIDE;
-    virtual void sendMessageToInspector(const String&) OVERRIDE;
-    virtual void postMessageToPageInspector(const String&) OVERRIDE;
-    virtual void updateInspectorStateCookie(const String&) OVERRIDE;
-#endif
-    // WebCore::WorkerLoaderProxy methods:
-    virtual void postTaskToLoader(PassOwnPtr<WebCore::ScriptExecutionContext::Task>) OVERRIDE;
-    virtual bool postTaskForModeToWorkerContext(PassOwnPtr<WebCore::ScriptExecutionContext::Task>, const String& mode) OVERRIDE;
+    // WebCore::WorkerLoaderProxy methods
+    virtual WebWorkerBase* toWebWorkerBase() OVERRIDE;
 
-    // WebCore::WorkerObjectProxy methods:
-    virtual void postMessageToWorkerObject(PassRefPtr<WebCore::SerializedScriptValue>, PassOwnPtr<WebCore::MessagePortChannelArray>) OVERRIDE;
-    virtual void postExceptionToWorkerObject(const String& errorMessage, int lineNumber, const String& sourceURL) OVERRIDE;
+    // WebWorkerBase methods:
+    virtual WebCore::WorkerLoaderProxy* workerLoaderProxy() OVERRIDE { return this; }
+    virtual WebCommonWorkerClient* commonClient() OVERRIDE { return this; }
+    virtual WebView* view() const OVERRIDE;
 
-    virtual void postConsoleMessageToWorkerObject(WebCore::MessageSource, WebCore::MessageLevel,
-                                                  const String& message, int lineNumber, const String& sourceURL) OVERRIDE;
-    virtual void confirmMessageFromWorkerObject(bool) OVERRIDE;
-    virtual void reportPendingActivity(bool) OVERRIDE;
-    virtual void workerContextClosed() OVERRIDE;
-    virtual void workerContextDestroyed() OVERRIDE;
-
-    // WebWorkerClientBase methods:
+    // WebCommonWorkerClient methods:
     virtual bool allowDatabase(WebFrame*, const WebString& name, const WebString& displayName, unsigned long estimatedSize) OVERRIDE;
     virtual bool allowFileSystem();
     virtual void openFileSystem(WebFileSystem::Type, long long size, bool create,
                                 WebFileSystemCallbacks*) OVERRIDE;
     virtual bool allowIndexedDB(const WebString& name) OVERRIDE;
 
-    // WebCommentWorkerBase methods:
-    virtual WebCommonWorkerClient* commonClient() OVERRIDE { return this; }
-    virtual WebView* view() const OVERRIDE;
-
 private:
     WebWorkerClientImpl(WebCore::Worker*, WebFrameImpl*);
     virtual ~WebWorkerClientImpl();
 
-    WebCore::WorkerMessagingProxy* m_proxy;
-    // Guard against context from being destroyed before a worker exits.
-    RefPtr<WebCore::ScriptExecutionContext> m_scriptExecutionContext;
     WebFrameImpl* m_webFrame;
 };
 

Modified: trunk/Source/WebKit/chromium/src/WorkerAsyncFileSystemChromium.cpp (138692 => 138693)


--- trunk/Source/WebKit/chromium/src/WorkerAsyncFileSystemChromium.cpp	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebKit/chromium/src/WorkerAsyncFileSystemChromium.cpp	2013-01-03 03:22:30 UTC (rev 138693)
@@ -40,7 +40,6 @@
 #include "NotImplemented.h"
 #include "WebFileSystemCallbacksImpl.h"
 #include "WebFileWriter.h"
-#include "WebWorkerBase.h"
 #include "WorkerAsyncFileWriterChromium.h"
 #include "WorkerContext.h"
 #include "WorkerFileSystemCallbacksBridge.h"
@@ -62,8 +61,7 @@
 {
     ASSERT(m_scriptExecutionContext->isWorkerContext());
 
-    WorkerLoaderProxy* workerLoaderProxy = &m_workerContext->thread()->workerLoaderProxy();
-    m_worker = static_cast<WebWorkerBase*>(workerLoaderProxy);
+    m_workerLoaderProxy = &m_workerContext->thread()->workerLoaderProxy();
 }
 
 WorkerAsyncFileSystemChromium::~WorkerAsyncFileSystemChromium()
@@ -194,7 +192,7 @@
     m_modeForCurrentOperation = fileSystemOperationsMode;
     m_modeForCurrentOperation.append(String::number(m_workerContext->thread()->runLoop().createUniqueId()));
 
-    m_bridgeForCurrentOperation = WorkerFileSystemCallbacksBridge::create(m_worker, m_scriptExecutionContext, new WebKit::WebFileSystemCallbacksImpl(callbacks));
+    m_bridgeForCurrentOperation = WorkerFileSystemCallbacksBridge::create(m_workerLoaderProxy, m_scriptExecutionContext, new WebKit::WebFileSystemCallbacksImpl(callbacks));
     return m_bridgeForCurrentOperation;
 }
 

Modified: trunk/Source/WebKit/chromium/src/WorkerAsyncFileSystemChromium.h (138692 => 138693)


--- trunk/Source/WebKit/chromium/src/WorkerAsyncFileSystemChromium.h	2013-01-03 03:09:22 UTC (rev 138692)
+++ trunk/Source/WebKit/chromium/src/WorkerAsyncFileSystemChromium.h	2013-01-03 03:22:30 UTC (rev 138693)
@@ -41,7 +41,6 @@
 namespace WebKit {
 class WebFileSystem;
 class WebURL;
-class WebWorkerBase;
 class WorkerFileSystemCallbacksBridge;
 }
 
@@ -50,6 +49,7 @@
 class AsyncFileSystemCallbacks;
 class ScriptExecutionContext;
 class WorkerContext;
+class WorkerLoaderProxy;
 
 class WorkerAsyncFileSystemChromium : public AsyncFileSystemChromium {
 public:
@@ -82,7 +82,7 @@
     PassRefPtr<WebKit::WorkerFileSystemCallbacksBridge> createWorkerFileSystemCallbacksBridge(PassOwnPtr<AsyncFileSystemCallbacks>);
 
     ScriptExecutionContext* m_scriptExecutionContext;
-    WebKit::WebWorkerBase* m_worker;
+    WorkerLoaderProxy* m_workerLoaderProxy;
     WorkerContext* m_workerContext;
     RefPtr<WebKit::WorkerFileSystemCallbacksBridge> m_bridgeForCurrentOperation;
     String m_modeForCurrentOperation;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to