Skip to content
Permalink
Browse files
Some small loader refinements and refactoring
https://bugs.webkit.org/show_bug.cgi?id=131541

Reviewed by Alexey Proskuryakov.

Cut down on use of ResourceLoader::handle, which always returns null when
using a network process. Also streamlined conditionals and did some other
small refactoring.

* loader/DocumentLoader.h: Use references rather than pointers for SchedulePair.

* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::didChangePriority): Use m_handle instead of handle(),
since we'd like to delete handle() entirely soon.
(WebCore::ResourceLoader::didReceiveAuthenticationChallenge): Ditto.
(WebCore::ResourceLoader::schedule): Added.
(WebCore::ResourceLoader::unschedule): Ditto.
* loader/ResourceLoader.h: Rearranged header to eliminate nested conditionals.
Added schedule and unschedule functions for Mac.

* loader/mac/DocumentLoaderMac.cpp:
(WebCore::scheduleAll): Changed to take a reference and call ResourceLoader::schedule.
(WebCore::unscheduleAll): Ditto.
(WebCore::DocumentLoader::schedule): Ditto.
(WebCore::DocumentLoader::unschedule): Ditto.

* page/mac/PageMac.cpp:
(WebCore::Page::addSchedulePair): Pass a reference rather than a pointer to schedule.
(WebCore::Page::removeSchedulePair): Ditto.

* platform/network/ResourceHandle.h: Did a bit of reformatting and reorganizing of
conditionals.

* platform/network/ResourceHandleInternal.h: Removed a tiny bit of unneeded declaration.

* platform/network/mac/ResourceHandleMac.mm:
(WebCore::ResourceHandle::schedule): Updated to take a reference rather than a pointer.
(WebCore::ResourceHandle::unschedule): Ditto.

Canonical link: https://commits.webkit.org/149651@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@167183 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
darinadler committed Apr 12, 2014
1 parent ed1c5ab commit ade63291be0c7ab0c3f887eb792e79f7b1f4a72c
@@ -1,3 +1,44 @@
2014-04-11 Darin Adler <darin@apple.com>

Some small loader refinements and refactoring
https://bugs.webkit.org/show_bug.cgi?id=131541

Reviewed by Alexey Proskuryakov.

Cut down on use of ResourceLoader::handle, which always returns null when
using a network process. Also streamlined conditionals and did some other
small refactoring.

* loader/DocumentLoader.h: Use references rather than pointers for SchedulePair.

* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::didChangePriority): Use m_handle instead of handle(),
since we'd like to delete handle() entirely soon.
(WebCore::ResourceLoader::didReceiveAuthenticationChallenge): Ditto.
(WebCore::ResourceLoader::schedule): Added.
(WebCore::ResourceLoader::unschedule): Ditto.
* loader/ResourceLoader.h: Rearranged header to eliminate nested conditionals.
Added schedule and unschedule functions for Mac.

* loader/mac/DocumentLoaderMac.cpp:
(WebCore::scheduleAll): Changed to take a reference and call ResourceLoader::schedule.
(WebCore::unscheduleAll): Ditto.
(WebCore::DocumentLoader::schedule): Ditto.
(WebCore::DocumentLoader::unschedule): Ditto.

* page/mac/PageMac.cpp:
(WebCore::Page::addSchedulePair): Pass a reference rather than a pointer to schedule.
(WebCore::Page::removeSchedulePair): Ditto.

* platform/network/ResourceHandle.h: Did a bit of reformatting and reorganizing of
conditionals.

* platform/network/ResourceHandleInternal.h: Removed a tiny bit of unneeded declaration.

* platform/network/mac/ResourceHandleMac.mm:
(WebCore::ResourceHandle::schedule): Updated to take a reference rather than a pointer.
(WebCore::ResourceHandle::unschedule): Ditto.

2014-04-11 Andreas Kling <akling@apple.com>

Make NodeList.length inline-cacheable by JSC.
@@ -51,15 +51,10 @@
#include <wtf/RunLoopTimer.h>
#endif

namespace WTF {
class SchedulePair;
}

namespace WebCore {

class ApplicationCacheHost;
#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
class Archive;
#endif
class ArchiveResource;
class ArchiveResourceCollection;
class CachedRawResource;
@@ -144,9 +139,9 @@ namespace WebCore {
void setTitle(const StringWithDirection&);
const String& overrideEncoding() const { return m_overrideEncoding; }

#if PLATFORM(COCOA)
void schedule(WTF::SchedulePair*);
void unschedule(WTF::SchedulePair*);
#if PLATFORM(MAC)
void schedule(SchedulePair&);
void unschedule(SchedulePair&);
#endif

#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
@@ -157,7 +152,7 @@ namespace WebCore {
SharedBuffer* parsedArchiveData() const;

bool scheduleArchiveLoad(ResourceLoader*, const ResourceRequest&);
#endif // ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
#endif

// Return the ArchiveResource for the URL only when loading an Archive
ArchiveResource* archiveResourceForURL(const URL&) const;
@@ -396,8 +396,8 @@ void ResourceLoader::cleanupForError(const ResourceError& error)

void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority)
{
if (handle())
handle()->didChangePriority(loadPriority);
if (m_handle)
m_handle->didChangePriority(loadPriority);
}

void ResourceLoader::cancel()
@@ -536,7 +536,7 @@ bool ResourceLoader::shouldUseCredentialStorage()

void ResourceLoader::didReceiveAuthenticationChallenge(const AuthenticationChallenge& challenge)
{
ASSERT(handle()->hasAuthenticationChallenge());
ASSERT(m_handle->hasAuthenticationChallenge());

// Protect this in this delegate method since the additional processing can do
// anything including possibly derefing this; one example of this is Radar 3266216.
@@ -552,7 +552,7 @@ void ResourceLoader::didReceiveAuthenticationChallenge(const AuthenticationChall
// If we can't continue with credentials, we need to cancel the load altogether.
#if PLATFORM(COCOA) || USE(CFNETWORK) || USE(CURL) || PLATFORM(GTK) || PLATFORM(EFL)
challenge.authenticationClient()->receivedRequestToContinueWithoutCredential(challenge);
ASSERT(!handle() || !handle()->hasAuthenticationChallenge());
ASSERT(!m_handle || !m_handle->hasAuthenticationChallenge());
#else
didFail(blockedError());
#endif
@@ -567,23 +567,43 @@ void ResourceLoader::didCancelAuthenticationChallenge(const AuthenticationChalle
}

#if USE(PROTECTION_SPACE_AUTH_CALLBACK)

bool ResourceLoader::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace)
{
Ref<ResourceLoader> protect(*this);
return frameLoader()->client().canAuthenticateAgainstProtectionSpace(documentLoader(), identifier(), protectionSpace);
}

#endif

#if PLATFORM(IOS)

RetainPtr<CFDictionaryRef> ResourceLoader::connectionProperties(ResourceHandle*)
{
return frameLoader()->connectionProperties(this);
}

#endif

void ResourceLoader::receivedCancellation(const AuthenticationChallenge&)
{
cancel();
}

#if PLATFORM(MAC)

void ResourceLoader::schedule(SchedulePair& pair)
{
if (m_handle)
m_handle->schedule(pair);
}

void ResourceLoader::unschedule(SchedulePair& pair)
{
if (m_handle)
m_handle->unschedule(pair);
}

#endif

}
@@ -34,14 +34,16 @@
#include "ResourceLoaderTypes.h"
#include "ResourceRequest.h"
#include "ResourceResponse.h"

#include <wtf/Forward.h>
#include <wtf/RefCounted.h>

#if USE(QUICK_LOOK)
#include "QuickLook.h"
#endif

namespace WTF {
class SchedulePair;
}

namespace WebCore {

class AuthenticationChallenge;
@@ -50,7 +52,6 @@ class Frame;
class FrameLoader;
class URL;
class ResourceBuffer;
class ResourceHandle;

class ResourceLoader : public RefCounted<ResourceLoader>, protected ResourceHandleClient {
public:
@@ -126,26 +127,30 @@ class ResourceLoader : public RefCounted<ResourceLoader>, protected ResourceHand
virtual bool shouldUseCredentialStorage(ResourceHandle*) override { return shouldUseCredentialStorage(); }
virtual void didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge& challenge) override { didReceiveAuthenticationChallenge(challenge); }
virtual void didCancelAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge& challenge) override { didCancelAuthenticationChallenge(challenge); }
virtual void receivedCancellation(ResourceHandle*, const AuthenticationChallenge& challenge) override { receivedCancellation(challenge); }

#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
virtual void didReceiveDataArray(ResourceHandle*, CFArrayRef dataArray) override;
#endif

#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
virtual bool canAuthenticateAgainstProtectionSpace(ResourceHandle*, const ProtectionSpace& protectionSpace) override { return canAuthenticateAgainstProtectionSpace(protectionSpace); }
#endif
virtual void receivedCancellation(ResourceHandle*, const AuthenticationChallenge& challenge) override { receivedCancellation(challenge); }
#if PLATFORM(COCOA)
#if USE(CFNETWORK)

#if PLATFORM(COCOA) && USE(CFNETWORK)
virtual CFCachedURLResponseRef willCacheResponse(ResourceHandle*, CFCachedURLResponseRef) override;
#else
virtual NSCachedURLResponse* willCacheResponse(ResourceHandle*, NSCachedURLResponse*) override;
#endif
#endif // PLATFORM(COCOA)

#if PLATFORM(WIN) && USE(CFNETWORK)
// FIXME: Windows should use willCacheResponse - <https://bugs.webkit.org/show_bug.cgi?id=57257>.
virtual bool shouldCacheResponse(ResourceHandle*, CFCachedURLResponseRef) override;
#endif

const URL& url() const { return m_request.url(); }
#if PLATFORM(COCOA) && !USE(CFNETWORK)
virtual NSCachedURLResponse* willCacheResponse(ResourceHandle*, NSCachedURLResponse*) override;
#endif

const URL& url() const { return m_request.url(); }
ResourceHandle* handle() const { return m_handle.get(); }
bool shouldSendResourceLoadCallbacks() const { return m_options.sendLoadCallbacks == SendCallbacks; }
void setSendCallbackPolicy(SendCallbackPolicy sendLoadCallbacks) { m_options.sendLoadCallbacks = sendLoadCallbacks; }
@@ -163,6 +168,11 @@ class ResourceLoader : public RefCounted<ResourceLoader>, protected ResourceHand
void setQuickLookHandle(PassOwnPtr<QuickLookHandle> handle) { m_quickLookHandle = handle; }
#endif

#if PLATFORM(MAC)
void schedule(WTF::SchedulePair&);
void unschedule(WTF::SchedulePair&);
#endif

protected:
ResourceLoader(Frame*, ResourceLoaderOptions);

@@ -28,58 +28,47 @@

#include "config.h"
#include "DocumentLoader.h"
#include "ResourceHandle.h"

#include "ResourceLoader.h"
#include <wtf/SchedulePair.h>

namespace WebCore {

#if !PLATFORM(IOS)
static void scheduleAll(const ResourceLoaderMap& loaders, SchedulePair* pair)
#if PLATFORM(MAC)

static void scheduleAll(const ResourceLoaderMap& loaders, SchedulePair& pair)
{
Vector<RefPtr<ResourceLoader>> loadersCopy;
copyValuesToVector(loaders, loadersCopy);
for (auto& loader : loadersCopy) {
if (ResourceHandle* handle = loader->handle())
handle->schedule(pair);
}
for (auto& loader : loadersCopy)
loader->schedule(pair);
}

static void unscheduleAll(const ResourceLoaderMap& loaders, SchedulePair* pair)
static void unscheduleAll(const ResourceLoaderMap& loaders, SchedulePair& pair)
{
Vector<RefPtr<ResourceLoader>> loadersCopy;
copyValuesToVector(loaders, loadersCopy);
for (auto& loader : loadersCopy) {
if (ResourceHandle* handle = loader->handle())
handle->unschedule(pair);
}
for (auto& loader : loadersCopy)
loader->unschedule(pair);
}
#endif

void DocumentLoader::schedule(SchedulePair* pair)
void DocumentLoader::schedule(SchedulePair& pair)
{
#if !PLATFORM(IOS)
if (mainResourceLoader() && mainResourceLoader()->handle())
mainResourceLoader()->handle()->schedule(pair);
if (mainResourceLoader())
mainResourceLoader()->schedule(pair);
scheduleAll(m_subresourceLoaders, pair);
scheduleAll(m_plugInStreamLoaders, pair);
scheduleAll(m_multipartSubresourceLoaders, pair);
#else
UNUSED_PARAM(pair);
#endif
}

void DocumentLoader::unschedule(SchedulePair* pair)
void DocumentLoader::unschedule(SchedulePair& pair)
{
#if !PLATFORM(IOS)
if (mainResourceLoader() && mainResourceLoader()->handle())
mainResourceLoader()->handle()->unschedule(pair);
if (mainResourceLoader())
mainResourceLoader()->unschedule(pair);
unscheduleAll(m_subresourceLoaders, pair);
unscheduleAll(m_plugInStreamLoaders, pair);
unscheduleAll(m_multipartSubresourceLoaders, pair);
#else
UNUSED_PARAM(pair);
#endif
}

#endif

} // namespace
@@ -47,9 +47,9 @@ void Page::addSchedulePair(PassRefPtr<SchedulePair> prpPair)
#if !PLATFORM(IOS)
for (Frame* frame = m_mainFrame.get(); frame; frame = frame->tree().traverseNext()) {
if (DocumentLoader* documentLoader = frame->loader().documentLoader())
documentLoader->schedule(pair.get());
documentLoader->schedule(*pair);
if (DocumentLoader* documentLoader = frame->loader().provisionalDocumentLoader())
documentLoader->schedule(pair.get());
documentLoader->schedule(*pair);
}
#endif

@@ -68,9 +68,9 @@ void Page::removeSchedulePair(PassRefPtr<SchedulePair> prpPair)
#if !PLATFORM(IOS)
for (Frame* frame = m_mainFrame.get(); frame; frame = frame->tree().traverseNext()) {
if (DocumentLoader* documentLoader = frame->loader().documentLoader())
documentLoader->unschedule(pair.get());
documentLoader->unschedule(*pair);
if (DocumentLoader* documentLoader = frame->loader().provisionalDocumentLoader())
documentLoader->unschedule(pair.get());
documentLoader->unschedule(*pair);
}
#endif
}

0 comments on commit ade6329

Please sign in to comment.