CTTE: DocumentThreadableLoader always has a Document.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Feb 2014 12:02:15 +0000 (12:02 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Feb 2014 12:02:15 +0000 (12:02 +0000)
<https://webkit.org/b/128364>

DocumentThreadableLoader always has an "owner" Document, so store
that as a reference instead of a pointer. Removed some unnecessary
assertions exposed by this change.

Reviewed by Antti Koivisto.

* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::loadResourceSynchronously):
(WebCore::DocumentThreadableLoader::create):
(WebCore::DocumentThreadableLoader::DocumentThreadableLoader):
(WebCore::DocumentThreadableLoader::didReceiveResponse):
(WebCore::DocumentThreadableLoader::didReceiveData):
(WebCore::DocumentThreadableLoader::didFinishLoading):
(WebCore::DocumentThreadableLoader::didFail):
(WebCore::DocumentThreadableLoader::preflightFailure):
(WebCore::DocumentThreadableLoader::loadRequest):
(WebCore::DocumentThreadableLoader::securityOrigin):
* loader/DocumentThreadableLoader.h:
* loader/ThreadableLoader.cpp:
(WebCore::ThreadableLoader::create):
(WebCore::ThreadableLoader::loadResourceSynchronously):
* loader/WorkerThreadableLoader.cpp:
(WebCore::WorkerThreadableLoader::MainThreadBridge::mainThreadCreateLoader):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163622 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentThreadableLoader.cpp
Source/WebCore/loader/DocumentThreadableLoader.h
Source/WebCore/loader/ThreadableLoader.cpp
Source/WebCore/loader/WorkerThreadableLoader.cpp

index 788c3373c98800b7493c7b56849d15da7b094190..58fb28ce699e872de59cd768e56d21fb20052f7f 100644 (file)
@@ -1,3 +1,32 @@
+2014-02-07  Andreas Kling  <akling@apple.com>
+
+        CTTE: DocumentThreadableLoader always has a Document.
+        <https://webkit.org/b/128364>
+
+        DocumentThreadableLoader always has an "owner" Document, so store
+        that as a reference instead of a pointer. Removed some unnecessary
+        assertions exposed by this change.
+
+        Reviewed by Antti Koivisto.
+
+        * loader/DocumentThreadableLoader.cpp:
+        (WebCore::DocumentThreadableLoader::loadResourceSynchronously):
+        (WebCore::DocumentThreadableLoader::create):
+        (WebCore::DocumentThreadableLoader::DocumentThreadableLoader):
+        (WebCore::DocumentThreadableLoader::didReceiveResponse):
+        (WebCore::DocumentThreadableLoader::didReceiveData):
+        (WebCore::DocumentThreadableLoader::didFinishLoading):
+        (WebCore::DocumentThreadableLoader::didFail):
+        (WebCore::DocumentThreadableLoader::preflightFailure):
+        (WebCore::DocumentThreadableLoader::loadRequest):
+        (WebCore::DocumentThreadableLoader::securityOrigin):
+        * loader/DocumentThreadableLoader.h:
+        * loader/ThreadableLoader.cpp:
+        (WebCore::ThreadableLoader::create):
+        (WebCore::ThreadableLoader::loadResourceSynchronously):
+        * loader/WorkerThreadableLoader.cpp:
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::mainThreadCreateLoader):
+
 2014-02-07  Peter Molnar  <pmolnar.u-szeged@partner.samsung.com>
 
         Vector-effect updates require a re-layout
index 02e98ebbc6efda9e18a0c509ae37e755ecd38add..f15fc18aad7632f246a1d0176fbabb3924093fc0 100644 (file)
 
 namespace WebCore {
 
-void DocumentThreadableLoader::loadResourceSynchronously(Document* document, const ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoaderOptions& options)
+void DocumentThreadableLoader::loadResourceSynchronously(Document& document, const ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoaderOptions& options)
 {
     // The loader will be deleted as soon as this function exits.
-    RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoader(document, &client, LoadSynchronously, request, options));
+    RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoader(document, client, LoadSynchronously, request, options));
     ASSERT(loader->hasOneRef());
 }
 
-PassRefPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document* document, ThreadableLoaderClient* client, const ResourceRequest& request, const ThreadableLoaderOptions& options)
+PassRefPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document& document, ThreadableLoaderClient& client, const ResourceRequest& request, const ThreadableLoaderOptions& options)
 {
     RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoader(document, client, LoadAsynchronously, request, options));
     if (!loader->m_resource)
@@ -71,16 +71,14 @@ PassRefPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document*
     return loader.release();
 }
 
-DocumentThreadableLoader::DocumentThreadableLoader(Document* document, ThreadableLoaderClient* client, BlockingBehavior blockingBehavior, const ResourceRequest& request, const ThreadableLoaderOptions& options)
-    : m_client(client)
+DocumentThreadableLoader::DocumentThreadableLoader(Document& document, ThreadableLoaderClient& client, BlockingBehavior blockingBehavior, const ResourceRequest& request, const ThreadableLoaderOptions& options)
+    : m_client(&client)
     , m_document(document)
     , m_options(options)
     , m_sameOriginRequest(securityOrigin()->canRequest(request.url()))
     , m_simpleRequest(true)
     , m_async(blockingBehavior == LoadAsynchronously)
 {
-    ASSERT(document);
-    ASSERT(client);
     // Setting an outgoing referer is only supported in the async code path.
     ASSERT(m_async || request.httpReferrer().isEmpty());
 
@@ -248,8 +246,8 @@ void DocumentThreadableLoader::didReceiveResponse(unsigned long identifier, cons
     String accessControlErrorDescription;
     if (m_actualRequest) {
 #if ENABLE(INSPECTOR)
-        DocumentLoader* loader = m_document->frame()->loader().documentLoader();
-        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willReceiveResourceResponse(m_document->frame(), identifier, response);
+        DocumentLoader* loader = m_document.frame()->loader().documentLoader();
+        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willReceiveResourceResponse(m_document.frame(), identifier, response);
         InspectorInstrumentation::didReceiveResourceResponse(cookie, identifier, loader, response, 0);
 #endif
 
@@ -293,7 +291,7 @@ void DocumentThreadableLoader::didReceiveData(unsigned long identifier, const ch
     // Preflight data should be invisible to clients.
     if (m_actualRequest) {
 #if ENABLE(INSPECTOR)
-        InspectorInstrumentation::didReceiveData(m_document->frame(), identifier, 0, 0, dataLength);
+        InspectorInstrumentation::didReceiveData(m_document.frame(), identifier, 0, 0, dataLength);
 #else
         UNUSED_PARAM(identifier);
 #endif
@@ -318,7 +316,7 @@ void DocumentThreadableLoader::didFinishLoading(unsigned long identifier, double
 {
     if (m_actualRequest) {
 #if ENABLE(INSPECTOR)
-        InspectorInstrumentation::didFinishLoading(m_document->frame(), m_document->frame()->loader().documentLoader(), identifier, finishTime);
+        InspectorInstrumentation::didFinishLoading(m_document.frame(), m_document.frame()->loader().documentLoader(), identifier, finishTime);
 #endif
         ASSERT(!m_sameOriginRequest);
         ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl);
@@ -331,7 +329,7 @@ void DocumentThreadableLoader::didFail(unsigned long identifier, const ResourceE
 {
 #if ENABLE(INSPECTOR)
     if (m_actualRequest)
-        InspectorInstrumentation::didFailLoading(m_document->frame(), m_document->frame()->loader().documentLoader(), identifier, error);
+        InspectorInstrumentation::didFailLoading(m_document.frame(), m_document.frame()->loader().documentLoader(), identifier, error);
 #else
     UNUSED_PARAM(identifier);
 #endif
@@ -357,7 +355,7 @@ void DocumentThreadableLoader::preflightFailure(unsigned long identifier, const
     ResourceError error(errorDomainWebKitInternal, 0, url, errorDescription);
 #if ENABLE(INSPECTOR)
     if (m_actualRequest)
-        InspectorInstrumentation::didFailLoading(m_document->frame(), m_document->frame()->loader().documentLoader(), identifier, error);
+        InspectorInstrumentation::didFailLoading(m_document.frame(), m_document.frame()->loader().documentLoader(), identifier, error);
 #else
     UNUSED_PARAM(identifier);
 #endif
@@ -389,12 +387,12 @@ void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Secur
         newRequest.setInitiator(m_options.initiator);
 #endif
         ASSERT(!m_resource);
-        m_resource = m_document->cachedResourceLoader()->requestRawResource(newRequest);
+        m_resource = m_document.cachedResourceLoader()->requestRawResource(newRequest);
         if (m_resource) {
 #if ENABLE(INSPECTOR)
             if (m_resource->loader()) {
                 unsigned long identifier = m_resource->loader()->identifier();
-                InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient(m_document, identifier, m_client);
+                InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient(&m_document, identifier, m_client);
             }
 #endif
             m_resource->addClient(this);
@@ -407,10 +405,10 @@ void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Secur
     ResourceError error;
     ResourceResponse response;
     unsigned long identifier = std::numeric_limits<unsigned long>::max();
-    if (m_document->frame())
-        identifier = m_document->frame()->loader().loadResourceSynchronously(request, m_options.allowCredentials, m_options.clientCredentialPolicy, error, response, data);
+    if (m_document.frame())
+        identifier = m_document.frame()->loader().loadResourceSynchronously(request, m_options.allowCredentials, m_options.clientCredentialPolicy, error, response, data);
 
-    InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient(m_document, identifier, m_client);
+    InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient(&m_document, identifier, m_client);
 
     // No exception for file:/// resources, see <rdar://problem/4962298>.
     // Also, if we have an HTTP response, then it wasn't a network error in fact.
@@ -446,7 +444,7 @@ bool DocumentThreadableLoader::isAllowedRedirect(const URL& url)
 
 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const
 {
-    return m_options.securityOrigin ? m_options.securityOrigin.get() : m_document->securityOrigin();
+    return m_options.securityOrigin ? m_options.securityOrigin.get() : m_document.securityOrigin();
 }
 
 } // namespace WebCore
index 7eb33eaac1a69d60d4ce45b1916a494ceb5cd20b..fabcd3d26d5a8c868a6993c8d48cefbabdbd7be9 100644 (file)
@@ -53,8 +53,8 @@ namespace WebCore {
     class DocumentThreadableLoader : public RefCounted<DocumentThreadableLoader>, public ThreadableLoader, private CachedRawResourceClient  {
         WTF_MAKE_FAST_ALLOCATED;
     public:
-        static void loadResourceSynchronously(Document*, const ResourceRequest&, ThreadableLoaderClient&, const ThreadableLoaderOptions&);
-        static PassRefPtr<DocumentThreadableLoader> create(Document*, ThreadableLoaderClient*, const ResourceRequest&, const ThreadableLoaderOptions&);
+        static void loadResourceSynchronously(Document&, const ResourceRequest&, ThreadableLoaderClient&, const ThreadableLoaderOptions&);
+        static PassRefPtr<DocumentThreadableLoader> create(Document&, ThreadableLoaderClient&, const ResourceRequest&, const ThreadableLoaderOptions&);
         virtual ~DocumentThreadableLoader();
 
         virtual void cancel();
@@ -73,7 +73,7 @@ namespace WebCore {
             LoadAsynchronously
         };
 
-        DocumentThreadableLoader(Document*, ThreadableLoaderClient*, BlockingBehavior, const ResourceRequest&, const ThreadableLoaderOptions&);
+        DocumentThreadableLoader(Document&, ThreadableLoaderClient&, BlockingBehavior, const ResourceRequest&, const ThreadableLoaderOptions&);
 
         void clearResource();
 
@@ -101,7 +101,7 @@ namespace WebCore {
 
         CachedResourceHandle<CachedRawResource> m_resource;
         ThreadableLoaderClient* m_client;
-        Document* m_document;
+        Document& m_document;
         ThreadableLoaderOptions m_options;
         bool m_sameOriginRequest;
         bool m_simpleRequest;
index 8a3a985767142fc7866d5c83cee77d387a3c4f97..55efefaa5940ed411f75374e1fb6c06e4e5d835e 100644 (file)
@@ -59,7 +59,7 @@ PassRefPtr<ThreadableLoader> ThreadableLoader::create(ScriptExecutionContext* co
     if (context->isWorkerGlobalScope())
         return WorkerThreadableLoader::create(static_cast<WorkerGlobalScope*>(context), client, WorkerRunLoop::defaultMode(), request, options);
 
-    return DocumentThreadableLoader::create(toDocument(context), client, request, options);
+    return DocumentThreadableLoader::create(toDocument(*context), *client, request, options);
 }
 
 void ThreadableLoader::loadResourceSynchronously(ScriptExecutionContext* context, const ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoaderOptions& options)
@@ -71,7 +71,7 @@ void ThreadableLoader::loadResourceSynchronously(ScriptExecutionContext* context
         return;
     }
 
-    DocumentThreadableLoader::loadResourceSynchronously(toDocument(context), request, client, options);
+    DocumentThreadableLoader::loadResourceSynchronously(*toDocument(context), request, client, options);
 }
 
 } // namespace WebCore
index d10ef7ed21fc639b7c23b33c9c24373f44175650..0ebba6120545106c5ac4044348fcbd4cfaa2fc94 100644 (file)
@@ -110,7 +110,7 @@ void WorkerThreadableLoader::MainThreadBridge::mainThreadCreateLoader(ScriptExec
     // FIXME: If the a site requests a local resource, then this will return a non-zero value but the sync path
     // will return a 0 value.  Either this should return 0 or the other code path should do a callback with
     // a failure.
-    thisPtr->m_mainThreadLoader = DocumentThreadableLoader::create(document, thisPtr, *request, options);
+    thisPtr->m_mainThreadLoader = DocumentThreadableLoader::create(*document, *thisPtr, *request, options);
     ASSERT(thisPtr->m_mainThreadLoader);
 }