Commit 40d9a46b authored by japhet@chromium.org's avatar japhet@chromium.org

Source/WebCore: Change a bunch of nondescript bools to

descriptive enums in ResourceLoaderOptions and
ThreadableLoaderOptions.
https://bugs.webkit.org/show_bug.cgi?id=66984

Reviewed by David Levin.

No new tests, no functionality change intended.

* WebCore.exp.in:
* fileapi/FileReaderLoader.cpp:
* html/MediaDocument.cpp:
* html/PluginDocument.cpp:
* loader/CrossOriginAccessControl.cpp:
* loader/CrossOriginAccessControl.h:
* loader/CrossOriginPreflightResultCache.cpp:
* loader/CrossOriginPreflightResultCache.h:
* loader/DocumentThreadableLoader.cpp:
* loader/FrameLoader.h:
* loader/ImageLoader.cpp:
* loader/MainResourceLoader.cpp:
* loader/NetscapePlugInStreamLoader.cpp:
* loader/ResourceLoadScheduler.h:
* loader/ResourceLoader.cpp:
* loader/ResourceLoader.h:
* loader/ResourceLoaderOptions.h:
* loader/ThreadableLoader.h:
* loader/cache/CachedResource.cpp:
* loader/cache/CachedResourceRequest.cpp:
* loader/cf/ResourceLoaderCFNet.cpp:
* loader/mac/ResourceLoaderMac.mm:
* page/EventSource.cpp:
* platform/network/ResourceHandle.h:
* workers/WorkerScriptLoader.cpp:
* xml/XMLHttpRequest.cpp:

Source/WebKit/chromium: Use enums instead of bools for ThreadableLoaderOptions
variables.
https://bugs.webkit.org/show_bug.cgi?id=66984

Reviewed by David Levin.

* src/AssociatedURLLoader.cpp:
(WebKit::AssociatedURLLoader::loadAsynchronously):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@93886 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 25261d93
2011-08-26 Nate Chapin <japhet@chromium.org>
Change a bunch of nondescript bools to
descriptive enums in ResourceLoaderOptions and
ThreadableLoaderOptions.
https://bugs.webkit.org/show_bug.cgi?id=66984
Reviewed by David Levin.
No new tests, no functionality change intended.
* WebCore.exp.in:
* fileapi/FileReaderLoader.cpp:
* html/MediaDocument.cpp:
* html/PluginDocument.cpp:
* loader/CrossOriginAccessControl.cpp:
* loader/CrossOriginAccessControl.h:
* loader/CrossOriginPreflightResultCache.cpp:
* loader/CrossOriginPreflightResultCache.h:
* loader/DocumentThreadableLoader.cpp:
* loader/FrameLoader.h:
* loader/ImageLoader.cpp:
* loader/MainResourceLoader.cpp:
* loader/NetscapePlugInStreamLoader.cpp:
* loader/ResourceLoadScheduler.h:
* loader/ResourceLoader.cpp:
* loader/ResourceLoader.h:
* loader/ResourceLoaderOptions.h:
* loader/ThreadableLoader.h:
* loader/cache/CachedResource.cpp:
* loader/cache/CachedResourceRequest.cpp:
* loader/cf/ResourceLoaderCFNet.cpp:
* loader/mac/ResourceLoaderMac.mm:
* page/EventSource.cpp:
* platform/network/ResourceHandle.h:
* workers/WorkerScriptLoader.cpp:
* xml/XMLHttpRequest.cpp:
2011-08-26 Andreas Kling <kling@webkit.org>
HTMLMetaElement: Don't cache "http-equiv" and "content" attributes.
......@@ -364,7 +364,6 @@ __ZN7WebCore14FrameSelectionC1EPNS_5FrameE
__ZN7WebCore14ResourceHandle20forceContentSniffingEv
__ZN7WebCore14ResourceHandle26synchronousLoadRunLoopModeEv
__ZN7WebCore14ResourceLoader14cancelledErrorEv
__ZN7WebCore14ResourceLoader19setShouldBufferDataEb
__ZN7WebCore14SVGSMILElement13isSMILElementEPNS_4NodeE
__ZN7WebCore14SchemeRegistry24registerURLSchemeAsLocalERKN3WTF6StringE
__ZN7WebCore14SchemeRegistry25registerURLSchemeAsSecureERKN3WTF6StringE
......
......@@ -49,6 +49,7 @@
#include "npruntime_priv.h"
#include "NPV8Object.h"
#include "ScriptSourceCode.h"
#include "SecurityOrigin.h"
#include "Settings.h"
#include "UserGestureIndicator.h"
#include "V8Binding.h"
......
......@@ -86,10 +86,10 @@ void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, Blo
request.setHTTPMethod("GET");
ThreadableLoaderOptions options;
options.sendLoadCallbacks = true;
options.sniffContent = false;
options.sendLoadCallbacks = SendCallbacks;
options.sniffContent = DoNotSniffContent;
options.preflightPolicy = ConsiderPreflight;
options.allowCredentials = true;
options.allowCredentials = AllowStoredCredentials;
options.crossOriginRequestPolicy = DenyCrossOriginRequests;
if (m_client)
......
......@@ -101,7 +101,7 @@ void MediaDocumentParser::createDocumentStructure()
if (!frame)
return;
frame->loader()->activeDocumentLoader()->mainResourceLoader()->setShouldBufferData(false);
frame->loader()->activeDocumentLoader()->mainResourceLoader()->setShouldBufferData(DoNotBufferData);
}
void MediaDocumentParser::appendBytes(DocumentWriter*, const char*, size_t)
......
......@@ -132,7 +132,7 @@ void PluginDocumentParser::appendBytes(DocumentWriter*, const char*, size_t)
// In a plugin document, the main resource is the plugin. If we have a null widget, that means
// the loading of the plugin was cancelled, which gives us a null mainResourceLoader(), so we
// need to have this call in a null check of the widget or of mainResourceLoader().
frame->loader()->activeDocumentLoader()->mainResourceLoader()->setShouldBufferData(false);
frame->loader()->activeDocumentLoader()->mainResourceLoader()->setShouldBufferData(DoNotBufferData);
}
}
......
......@@ -97,14 +97,14 @@ bool isOnAccessControlResponseHeaderWhitelist(const String& name)
return allowedCrossOriginResponseHeaders->contains(name);
}
void updateRequestForAccessControl(ResourceRequest& request, SecurityOrigin* securityOrigin, bool allowCredentials)
void updateRequestForAccessControl(ResourceRequest& request, SecurityOrigin* securityOrigin, StoredCredentials allowCredentials)
{
request.removeCredentials();
request.setAllowCookies(allowCredentials);
request.setAllowCookies(allowCredentials == AllowStoredCredentials);
request.setHTTPOrigin(securityOrigin->toString());
}
ResourceRequest createAccessControlPreflightRequest(const ResourceRequest& request, SecurityOrigin* securityOrigin, bool allowCredentials)
ResourceRequest createAccessControlPreflightRequest(const ResourceRequest& request, SecurityOrigin* securityOrigin, StoredCredentials allowCredentials)
{
ResourceRequest preflightRequest(request.url());
updateRequestForAccessControl(preflightRequest, securityOrigin, allowCredentials);
......@@ -133,12 +133,12 @@ ResourceRequest createAccessControlPreflightRequest(const ResourceRequest& reque
return preflightRequest;
}
bool passesAccessControlCheck(const ResourceResponse& response, bool includeCredentials, SecurityOrigin* securityOrigin, String& errorDescription)
bool passesAccessControlCheck(const ResourceResponse& response, StoredCredentials includeCredentials, SecurityOrigin* securityOrigin, String& errorDescription)
{
// A wildcard Access-Control-Allow-Origin can not be used if credentials are to be sent,
// even with Access-Control-Allow-Credentials set to true.
const String& accessControlOriginString = response.httpHeaderField("Access-Control-Allow-Origin");
if (accessControlOriginString == "*" && !includeCredentials)
if (accessControlOriginString == "*" && includeCredentials == DoNotAllowStoredCredentials)
return true;
if (securityOrigin->isUnique()) {
......@@ -156,7 +156,7 @@ bool passesAccessControlCheck(const ResourceResponse& response, bool includeCred
return false;
}
if (includeCredentials) {
if (includeCredentials == AllowStoredCredentials) {
const String& accessControlCredentialsString = response.httpHeaderField("Access-Control-Allow-Credentials");
if (accessControlCredentialsString != "true") {
errorDescription = "Credentials flag is true, but Access-Control-Allow-Credentials is not \"true\".";
......
......@@ -27,6 +27,7 @@
#ifndef CrossOriginAccessControl_h
#define CrossOriginAccessControl_h
#include "ResourceHandle.h"
#include "ResourceRequest.h"
#include <wtf/Forward.h>
......@@ -41,10 +42,10 @@ bool isOnAccessControlSimpleRequestMethodWhitelist(const String&);
bool isOnAccessControlSimpleRequestHeaderWhitelist(const String& name, const String& value);
bool isOnAccessControlResponseHeaderWhitelist(const String&);
void updateRequestForAccessControl(ResourceRequest&, SecurityOrigin*, bool allowCredentials);
ResourceRequest createAccessControlPreflightRequest(const ResourceRequest&, SecurityOrigin*, bool allowCredentials);
void updateRequestForAccessControl(ResourceRequest&, SecurityOrigin*, StoredCredentials);
ResourceRequest createAccessControlPreflightRequest(const ResourceRequest&, SecurityOrigin*, StoredCredentials);
bool passesAccessControlCheck(const ResourceResponse&, bool includeCredentials, SecurityOrigin*, String& errorDescription);
bool passesAccessControlCheck(const ResourceResponse&, StoredCredentials, SecurityOrigin*, String& errorDescription);
} // namespace WebCore
......
......@@ -135,12 +135,12 @@ bool CrossOriginPreflightResultCacheItem::allowsCrossOriginHeaders(const HTTPHea
return true;
}
bool CrossOriginPreflightResultCacheItem::allowsRequest(bool includeCredentials, const String& method, const HTTPHeaderMap& requestHeaders) const
bool CrossOriginPreflightResultCacheItem::allowsRequest(StoredCredentials includeCredentials, const String& method, const HTTPHeaderMap& requestHeaders) const
{
String ignoredExplanation;
if (m_absoluteExpiryTime < currentTime())
return false;
if (includeCredentials && !m_credentials)
if (includeCredentials == AllowStoredCredentials && m_credentials == DoNotAllowStoredCredentials)
return false;
if (!allowsCrossOriginMethod(method, ignoredExplanation))
return false;
......@@ -167,7 +167,7 @@ void CrossOriginPreflightResultCache::appendEntry(const String& origin, const KU
}
}
bool CrossOriginPreflightResultCache::canSkipPreflight(const String& origin, const KURL& url, bool includeCredentials, const String& method, const HTTPHeaderMap& requestHeaders)
bool CrossOriginPreflightResultCache::canSkipPreflight(const String& origin, const KURL& url, StoredCredentials includeCredentials, const String& method, const HTTPHeaderMap& requestHeaders)
{
ASSERT(isMainThread());
CrossOriginPreflightResultHashMap::iterator cacheIt = m_preflightHashMap.find(std::make_pair(origin, url));
......
......@@ -28,6 +28,7 @@
#define CrossOriginPreflightResultCache_h
#include "KURLHash.h"
#include "ResourceHandle.h"
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/PassOwnPtr.h>
......@@ -41,7 +42,7 @@ namespace WebCore {
class CrossOriginPreflightResultCacheItem {
WTF_MAKE_NONCOPYABLE(CrossOriginPreflightResultCacheItem); WTF_MAKE_FAST_ALLOCATED;
public:
CrossOriginPreflightResultCacheItem(bool credentials)
CrossOriginPreflightResultCacheItem(StoredCredentials credentials)
: m_absoluteExpiryTime(0)
, m_credentials(credentials)
{
......@@ -50,7 +51,7 @@ namespace WebCore {
bool parse(const ResourceResponse&, String& errorDescription);
bool allowsCrossOriginMethod(const String&, String& errorDescription) const;
bool allowsCrossOriginHeaders(const HTTPHeaderMap&, String& errorDescription) const;
bool allowsRequest(bool includeCredentials, const String& method, const HTTPHeaderMap& requestHeaders) const;
bool allowsRequest(StoredCredentials, const String& method, const HTTPHeaderMap& requestHeaders) const;
private:
typedef HashSet<String, CaseFoldingHash> HeadersSet;
......@@ -59,7 +60,7 @@ namespace WebCore {
// to start a timer for the expiration delta that removes this from the cache when
// it fires.
double m_absoluteExpiryTime;
bool m_credentials;
StoredCredentials m_credentials;
HashSet<String> m_methods;
HeadersSet m_headers;
};
......@@ -70,7 +71,7 @@ namespace WebCore {
static CrossOriginPreflightResultCache& shared();
void appendEntry(const String& origin, const KURL&, PassOwnPtr<CrossOriginPreflightResultCacheItem>);
bool canSkipPreflight(const String& origin, const KURL&, bool includeCredentials, const String& method, const HTTPHeaderMap& requestHeaders);
bool canSkipPreflight(const String& origin, const KURL&, StoredCredentials, const String& method, const HTTPHeaderMap& requestHeaders);
void empty();
......
......@@ -292,7 +292,7 @@ bool DocumentThreadableLoader::getShouldUseCredentialStorage(SubresourceLoader*
{
ASSERT_UNUSED(loader, loader == m_loader || !m_loader);
if (!m_options.allowCredentials) {
if (m_options.allowCredentials == DoNotAllowStoredCredentials) {
shouldUseCredentialStorage = false;
return true;
}
......@@ -345,10 +345,10 @@ void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Secur
ThreadableLoaderOptions options = m_options;
if (m_actualRequest) {
// Don't sniff content or send load callbacks for the preflight request.
options.sendLoadCallbacks = false;
options.sniffContent = false;
options.sendLoadCallbacks = DoNotSendCallbacks;
options.sniffContent = DoNotSniffContent;
// Keep buffering the data for the preflight request.
options.shouldBufferData = true;
options.shouldBufferData = BufferData;
}
#if ENABLE(INSPECTOR)
......@@ -368,14 +368,12 @@ void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Secur
}
// FIXME: ThreadableLoaderOptions.sniffContent is not supported for synchronous requests.
StoredCredentials storedCredentials = m_options.allowCredentials ? AllowStoredCredentials : DoNotAllowStoredCredentials;
Vector<char> data;
ResourceError error;
ResourceResponse response;
unsigned long identifier = std::numeric_limits<unsigned long>::max();
if (m_document->frame())
identifier = m_document->frame()->loader()->loadResourceSynchronously(request, storedCredentials, error, response, data);
identifier = m_document->frame()->loader()->loadResourceSynchronously(request, m_options.allowCredentials, error, response, data);
// 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.
......
......@@ -38,9 +38,9 @@
#include "IconController.h"
#include "IconURL.h"
#include "PolicyChecker.h"
#include "ResourceHandle.h"
#include "ResourceLoadNotifier.h"
#include "SubframeLoader.h"
#include "ThreadableLoader.h"
#include "Timer.h"
#include <wtf/Forward.h>
#include <wtf/HashSet.h>
......
......@@ -168,7 +168,7 @@ void ImageLoader::updateFromElement()
String crossOriginMode = m_element->fastGetAttribute(HTMLNames::crossoriginAttr);
if (!crossOriginMode.isNull()) {
bool allowCredentials = equalIgnoringCase(crossOriginMode, "use-credentials");
StoredCredentials allowCredentials = equalIgnoringCase(crossOriginMode, "use-credentials") ? AllowStoredCredentials : DoNotAllowStoredCredentials;
updateRequestForAccessControl(request, document->securityOrigin(), allowCredentials);
}
......
......@@ -60,7 +60,7 @@
namespace WebCore {
MainResourceLoader::MainResourceLoader(Frame* frame)
: ResourceLoader(frame, ResourceLoaderOptions(true, true, true))
: ResourceLoader(frame, ResourceLoaderOptions(SendCallbacks, SniffContent, BufferData))
, m_dataLoadTimer(this, &MainResourceLoader::handleDataLoadNow)
, m_loadingMultipartContent(false)
, m_waitingForContentPolicy(false)
......
......@@ -36,7 +36,7 @@
namespace WebCore {
NetscapePlugInStreamLoader::NetscapePlugInStreamLoader(Frame* frame, NetscapePlugInStreamLoaderClient* client)
: ResourceLoader(frame, ResourceLoaderOptions(true, true, true))
: ResourceLoader(frame, ResourceLoaderOptions(SendCallbacks, SniffContent, DoNotBufferData))
, m_client(client)
{
}
......@@ -48,7 +48,6 @@ NetscapePlugInStreamLoader::~NetscapePlugInStreamLoader()
PassRefPtr<NetscapePlugInStreamLoader> NetscapePlugInStreamLoader::create(Frame* frame, NetscapePlugInStreamLoaderClient* client, const ResourceRequest& request)
{
RefPtr<NetscapePlugInStreamLoader> loader(adoptRef(new NetscapePlugInStreamLoader(frame, client)));
loader->setShouldBufferData(false);
loader->documentLoader()->addPlugInStreamLoader(loader.get());
if (!loader->init(request))
return 0;
......
......@@ -51,7 +51,7 @@ class ResourceLoadScheduler {
public:
friend ResourceLoadScheduler* resourceLoadScheduler();
PassRefPtr<SubresourceLoader> scheduleSubresourceLoad(Frame*, SubresourceLoaderClient*, const ResourceRequest&, ResourceLoadPriority = ResourceLoadPriorityLow, SecurityCheckPolicy = DoSecurityCheck, const ResourceLoaderOptions& = ResourceLoaderOptions(true, true, true));
PassRefPtr<SubresourceLoader> scheduleSubresourceLoad(Frame*, SubresourceLoaderClient*, const ResourceRequest&, ResourceLoadPriority = ResourceLoadPriorityLow, SecurityCheckPolicy = DoSecurityCheck, const ResourceLoaderOptions& = ResourceLoaderOptions(SendCallbacks, SniffContent, BufferData));
PassRefPtr<NetscapePlugInStreamLoader> schedulePluginStreamLoad(Frame*, NetscapePlugInStreamLoaderClient*, const ResourceRequest&);
void addMainResourceLoad(ResourceLoader*);
void remove(ResourceLoader*);
......
......@@ -160,7 +160,7 @@ void ResourceLoader::start()
}
if (!m_reachedTerminalState)
m_handle = ResourceHandle::create(m_frame->loader()->networkingContext(), m_request, this, m_defersLoading, m_options.sniffContent);
m_handle = ResourceHandle::create(m_frame->loader()->networkingContext(), m_request, this, m_defersLoading, m_options.sniffContent == SniffContent);
}
void ResourceLoader::setDefersLoading(bool defers)
......@@ -182,7 +182,7 @@ FrameLoader* ResourceLoader::frameLoader() const
return m_frame->loader();
}
void ResourceLoader::setShouldBufferData(bool shouldBufferData)
void ResourceLoader::setShouldBufferData(DataBufferingPolicy shouldBufferData)
{
m_options.shouldBufferData = shouldBufferData;
......@@ -194,7 +194,7 @@ void ResourceLoader::setShouldBufferData(bool shouldBufferData)
void ResourceLoader::addData(const char* data, int length, bool allAtOnce)
{
if (!m_options.shouldBufferData)
if (m_options.shouldBufferData == DoNotBufferData)
return;
if (allAtOnce) {
......@@ -234,7 +234,7 @@ void ResourceLoader::willSendRequest(ResourceRequest& request, const ResourceRes
ASSERT(!m_reachedTerminalState);
if (m_options.sendLoadCallbacks) {
if (m_options.sendLoadCallbacks == SendCallbacks) {
if (!m_identifier) {
m_identifier = m_frame->page()->progress()->createUniqueIdentifier();
frameLoader()->notifier()->assignIdentifierToInitialRequest(m_identifier, documentLoader(), request);
......@@ -277,7 +277,7 @@ void ResourceLoader::didReceiveResponse(const ResourceResponse& r)
if (FormData* data = m_request.httpBody())
data->removeGeneratedFilesIfNeeded();
if (m_options.sendLoadCallbacks)
if (m_options.sendLoadCallbacks == SendCallbacks)
frameLoader()->notifier()->didReceiveResponse(this, m_response);
}
......@@ -303,13 +303,13 @@ void ResourceLoader::didReceiveData(const char* data, int length, long long enco
// FIXME: If we get a resource with more than 2B bytes, this code won't do the right thing.
// However, with today's computers and networking speeds, this won't happen in practice.
// Could be an issue with a giant local file.
if (m_options.sendLoadCallbacks && m_frame)
if (m_options.sendLoadCallbacks == SendCallbacks && m_frame)
frameLoader()->notifier()->didReceiveData(this, data, length, static_cast<int>(encodedDataLength));
}
void ResourceLoader::willStopBufferingData(const char* data, int length)
{
if (!m_options.shouldBufferData)
if (m_options.shouldBufferData == DoNotBufferData)
return;
ASSERT(!m_resourceData);
......@@ -337,7 +337,7 @@ void ResourceLoader::didFinishLoadingOnePart(double finishTime)
if (m_calledDidFinishLoad)
return;
m_calledDidFinishLoad = true;
if (m_options.sendLoadCallbacks)
if (m_options.sendLoadCallbacks == SendCallbacks)
frameLoader()->notifier()->didFinishLoad(this, finishTime);
}
......@@ -354,7 +354,7 @@ void ResourceLoader::didFail(const ResourceError& error)
if (FormData* data = m_request.httpBody())
data->removeGeneratedFilesIfNeeded();
if (m_options.sendLoadCallbacks && !m_calledDidFinishLoad)
if (m_options.sendLoadCallbacks == SendCallbacks && !m_calledDidFinishLoad)
frameLoader()->notifier()->didFailToLoad(this, error);
releaseResources();
......@@ -402,7 +402,7 @@ void ResourceLoader::cancel(const ResourceError& error)
m_handle = 0;
}
if (m_options.sendLoadCallbacks && m_identifier && !m_calledDidFinishLoad)
if (m_options.sendLoadCallbacks == SendCallbacks && m_identifier && !m_calledDidFinishLoad)
frameLoader()->notifier()->didFailToLoad(this, nonNullError);
}
......
......@@ -139,7 +139,7 @@ namespace WebCore {
bool reachedTerminalState() const { return m_reachedTerminalState; }
void setShouldBufferData(bool shouldBufferData);
void setShouldBufferData(DataBufferingPolicy);
protected:
ResourceLoader(Frame*, ResourceLoaderOptions);
......
......@@ -33,12 +33,27 @@
namespace WebCore {
enum SendCallbackPolicy {
SendCallbacks,
DoNotSendCallbacks
};
enum ContentSniffingPolicy {
SniffContent,
DoNotSniffContent
};
enum DataBufferingPolicy {
BufferData,
DoNotBufferData
};
struct ResourceLoaderOptions {
ResourceLoaderOptions() : sendLoadCallbacks(false), sniffContent(false), shouldBufferData(true) { }
ResourceLoaderOptions(bool sendLoadCallbacksArg, bool sniffContentArg, bool shouldBufferDataArg) : sendLoadCallbacks(sendLoadCallbacksArg), sniffContent(sniffContentArg), shouldBufferData(shouldBufferDataArg) { }
bool sendLoadCallbacks;
bool sniffContent;
bool shouldBufferData;
ResourceLoaderOptions() : sendLoadCallbacks(DoNotSendCallbacks), sniffContent(DoNotSniffContent), shouldBufferData(BufferData) { }
ResourceLoaderOptions(SendCallbackPolicy sendLoadCallbacksArg, ContentSniffingPolicy sniffContentArg, DataBufferingPolicy shouldBufferDataArg) : sendLoadCallbacks(sendLoadCallbacksArg), sniffContent(sniffContentArg), shouldBufferData(shouldBufferDataArg) { }
SendCallbackPolicy sendLoadCallbacks;
ContentSniffingPolicy sniffContent;
DataBufferingPolicy shouldBufferData;
};
} // namespace WebCore
......
......@@ -31,6 +31,7 @@
#ifndef ThreadableLoader_h
#define ThreadableLoader_h
#include "ResourceHandle.h"
#include "ResourceLoaderOptions.h"
#include "SecurityOrigin.h"
#include <wtf/Noncopyable.h>
......@@ -45,11 +46,6 @@ namespace WebCore {
class ResourceResponse;
class ScriptExecutionContext;
class ThreadableLoaderClient;
enum StoredCredentials {
AllowStoredCredentials,
DoNotAllowStoredCredentials
};
enum CrossOriginRequestPolicy {
DenyCrossOriginRequests,
......@@ -64,8 +60,8 @@ namespace WebCore {
};
struct ThreadableLoaderOptions : public ResourceLoaderOptions {
ThreadableLoaderOptions() : allowCredentials(false), preflightPolicy(ConsiderPreflight), crossOriginRequestPolicy(DenyCrossOriginRequests) { }
bool allowCredentials; // Whether HTTP credentials and cookies are sent with the request.
ThreadableLoaderOptions() : allowCredentials(DoNotAllowStoredCredentials), preflightPolicy(ConsiderPreflight), crossOriginRequestPolicy(DenyCrossOriginRequests) { }
StoredCredentials allowCredentials; // Whether HTTP credentials and cookies are sent with the request.
PreflightPolicy preflightPolicy; // If AccessControl is used, how to determine if a preflight is needed.
CrossOriginRequestPolicy crossOriginRequestPolicy;
RefPtr<SecurityOrigin> securityOrigin;
......
......@@ -179,7 +179,7 @@ void CachedResource::finish()
bool CachedResource::passesAccessControlCheck(SecurityOrigin* securityOrigin)
{
String errorDescription;
return WebCore::passesAccessControlCheck(m_response, resourceRequest().allowCookies(), securityOrigin, errorDescription);
return WebCore::passesAccessControlCheck(m_response, resourceRequest().allowCookies() ? AllowStoredCredentials : DoNotAllowStoredCredentials, securityOrigin, errorDescription);
}
bool CachedResource::isExpired() const
......
......@@ -124,8 +124,8 @@ PassOwnPtr<CachedResourceRequest> CachedResourceRequest::load(CachedResourceLoad
ResourceLoadPriority priority = resource->loadPriority();
resourceRequest.setPriority(priority);
RefPtr<SubresourceLoader> loader = resourceLoadScheduler()->scheduleSubresourceLoad(cachedResourceLoader->document()->frame(),
request.get(), resourceRequest, priority, securityCheck, ResourceLoaderOptions(sendResourceLoadCallbacks, true, true));
RefPtr<SubresourceLoader> loader = resourceLoadScheduler()->scheduleSubresourceLoad(cachedResourceLoader->document()->frame(), request.get(), resourceRequest, priority, securityCheck,
ResourceLoaderOptions(sendResourceLoadCallbacks ? SendCallbacks : DoNotSendCallbacks, SniffContent, BufferData));
if (!loader || loader->reachedTerminalState()) {
// FIXME: What if resources in other frames were waiting for this revalidation?
LOG(ResourceLoading, "Cannot start loading '%s'", resource->url().string().latin1().data());
......
......@@ -37,7 +37,7 @@ namespace WebCore {
bool ResourceLoader::shouldCacheResponse(ResourceHandle*, CFCachedURLResponseRef cachedResponse)
{
if (!m_options.sendLoadCallbacks)
if (m_options.sendLoadCallbacks == DoNotSendCallbacks)
return 0;
CFURLResponseRef response = CFCachedURLResponseGetWrappedResponse(cachedResponse);
......
......@@ -90,7 +90,7 @@ void ResourceLoader::didReceiveDataArray(CFArrayRef dataArray)
// FIXME: If we get a resource with more than 2B bytes, this code won't do the right thing.
// However, with today's computers and networking speeds, this won't happen in practice.
// Could be an issue with a giant local file.
if (m_sendResourceLoadCallbacks && m_frame)
if (m_options.sendLoadCallbacks == SendCallbacks && m_frame)
frameLoader()->notifier()->didReceiveData(this, reinterpret_cast<const char*>(CFDataGetBytePtr(data)), dataLen, dataLen);
}
}
......
......@@ -166,8 +166,8 @@ void Notification::startLoading()
setPendingActivity(this);
m_state = Loading;
ThreadableLoaderOptions options;
options.sendLoadCallbacks = false;
options.sniffContent = false;
options.sendLoadCallbacks = DoNotSendCallbacks;
options.sniffContent = DoNotSniffContent;
options.preflightPolicy = ConsiderPreflight;
options.allowCredentials = AllowStoredCredentials;
options.crossOriginRequestPolicy = AllowCrossOriginRequests;
......
......@@ -113,10 +113,10 @@ void EventSource::connect()
request.setHTTPHeaderField("Last-Event-ID", m_lastEventId);
ThreadableLoaderOptions options;
options.sendLoadCallbacks = true;
options.sniffContent = false;
options.allowCredentials = true;
options.shouldBufferData = false;
options.sendLoadCallbacks = SendCallbacks;
options.sniffContent = DoNotSniffContent;
options.allowCredentials = AllowStoredCredentials;
options.shouldBufferData = DoNotBufferData;
m_loader = ThreadableLoader::create(scriptExecutionContext(), this, request, options);
......
......@@ -30,7 +30,6 @@
#include "AuthenticationClient.h"
#include "HTTPHeaderMap.h"
#include "NetworkingContext.h"
#include "ThreadableLoader.h"
#include <wtf/OwnPtr.h>
#if USE(SOUP)
......@@ -91,6 +90,11 @@ class ResourceResponse;
class SchedulePair;
class SharedBuffer;
enum StoredCredentials {
AllowStoredCredentials,
DoNotAllowStoredCredentials
};
template <typename T> class Timer;
class ResourceHandle : public RefCounted<ResourceHandle>
......
......@@ -72,9 +72,9 @@ void WorkerScriptLoader::loadSynchronously(ScriptExecutionContext* scriptExecuti
ASSERT(scriptExecutionContext->isWorkerContext());
ThreadableLoaderOptions options;
options.allowCredentials = true;
options.allowCredentials = AllowStoredCredentials;
options.crossOriginRequestPolicy = crossOriginRequestPolicy;
options.sendLoadCallbacks = true;
options.sendLoadCallbacks = SendCallbacks;
WorkerThreadableLoader::loadResourceSynchronously(static_cast<WorkerContext*>(scriptExecutionContext), *request, *this, options);
}
......@@ -90,9 +90,9 @@ void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext* scriptExecut
return;
ThreadableLoaderOptions options;
options.allowCredentials = true;
options.allowCredentials = AllowStoredCredentials;
options.crossOriginRequestPolicy = crossOriginRequestPolicy;
options.sendLoadCallbacks = true;
options.sendLoadCallbacks = SendCallbacks;
// During create, callbacks may happen which remove the last reference to this object.
RefPtr<WorkerScriptLoader> protect(this);
......
......@@ -650,10 +650,10 @@ void XMLHttpRequest::createRequest(ExceptionCode& ec)
request.addHTTPHeaderFields(m_requestHeaders);
ThreadableLoaderOptions options;
options.sendLoadCallbacks = true;
options.sniffContent = false;
options.sendLoadCallbacks = SendCallbacks;
options.sniffContent = DoNotSniffContent;
options.preflightPolicy = uploadEvents ? ForcePreflight : ConsiderPreflight;
options.allowCredentials = m_sameOriginRequest || m_includeCredentials;
options.allowCredentials = (m_sameOriginRequest || m_includeCredentials) ? AllowStoredCredentials : DoNotAllowStoredCredentials;
options.crossOriginRequestPolicy = UseAccessControl;