2011-03-15 Bill Budge <bbudge@chromium.org>

        Reviewed by David Levin.

        AssociatedURLLoader does not support Cross Origin Requests
        https://bugs.webkit.org/show_bug.cgi?id=53925

        No new tests. No new functionality exposed.

        * public/WebURLLoader.h:
        (WebKit::WebURLLoaderOptions::WebURLLoaderOptions):
        * src/AssociatedURLLoader.cpp:
        (WebKit::AssociatedURLLoader::ClientAdapter::clearClient):
        (WebKit::AssociatedURLLoader::ClientAdapter::create):
        (WebKit::AssociatedURLLoader::ClientAdapter::ClientAdapter):
        (WebKit::AssociatedURLLoader::ClientAdapter::willSendRequest):
        (WebKit::AssociatedURLLoader::ClientAdapter::didSendData):
        (WebKit::AssociatedURLLoader::ClientAdapter::didReceiveResponse):
        (WebKit::AssociatedURLLoader::ClientAdapter::didReceiveData):
        (WebKit::AssociatedURLLoader::ClientAdapter::didReceiveCachedMetadata):
        (WebKit::AssociatedURLLoader::ClientAdapter::didFinishLoading):
        (WebKit::AssociatedURLLoader::ClientAdapter::didFail):
        (WebKit::AssociatedURLLoader::AssociatedURLLoader):
        (WebKit::AssociatedURLLoader::~AssociatedURLLoader):
        (WebKit::AssociatedURLLoader::loadSynchronously):
        (WebKit::AssociatedURLLoader::loadAsynchronously):
        (WebKit::AssociatedURLLoader::cancel):
        (WebKit::AssociatedURLLoader::setDefersLoading):
        * src/AssociatedURLLoader.h:

git-svn-id: svn://svn.chromium.org/blink/trunk@81144 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 1dc09361
2011-03-15 Bill Budge <bbudge@chromium.org>
Reviewed by David Levin.
AssociatedURLLoader does not support Cross Origin Requests
https://bugs.webkit.org/show_bug.cgi?id=53925
No new tests. No new functionality exposed.
* public/WebURLLoader.h:
(WebKit::WebURLLoaderOptions::WebURLLoaderOptions):
* src/AssociatedURLLoader.cpp:
(WebKit::AssociatedURLLoader::ClientAdapter::clearClient):
(WebKit::AssociatedURLLoader::ClientAdapter::create):
(WebKit::AssociatedURLLoader::ClientAdapter::ClientAdapter):
(WebKit::AssociatedURLLoader::ClientAdapter::willSendRequest):
(WebKit::AssociatedURLLoader::ClientAdapter::didSendData):
(WebKit::AssociatedURLLoader::ClientAdapter::didReceiveResponse):
(WebKit::AssociatedURLLoader::ClientAdapter::didReceiveData):
(WebKit::AssociatedURLLoader::ClientAdapter::didReceiveCachedMetadata):
(WebKit::AssociatedURLLoader::ClientAdapter::didFinishLoading):
(WebKit::AssociatedURLLoader::ClientAdapter::didFail):
(WebKit::AssociatedURLLoader::AssociatedURLLoader):
(WebKit::AssociatedURLLoader::~AssociatedURLLoader):
(WebKit::AssociatedURLLoader::loadSynchronously):
(WebKit::AssociatedURLLoader::loadAsynchronously):
(WebKit::AssociatedURLLoader::cancel):
(WebKit::AssociatedURLLoader::setDefersLoading):
* src/AssociatedURLLoader.h:
2011-03-15 Alok priyadarshi <alokp@chromium.org>
Reviewed by James Robinson.
......
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
* Copyright (C) 2009, 2011 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
......@@ -41,6 +41,21 @@ class WebURLRequest;
class WebURLResponse;
struct WebURLError;
enum WebCrossOriginRequestPolicy {
DenyCrossOriginRequests,
UseAccessControl,
AllowCrossOriginRequests
};
struct WebURLLoaderOptions {
WebURLLoaderOptions() : sniffContent(false), allowCredentials(false), forcePreflight(false), crossOriginRequestPolicy(DenyCrossOriginRequests) {}
bool sniffContent; // Whether to sniff content.
bool allowCredentials; // Whether to send HTTP credentials and cookies with the request.
bool forcePreflight; // If AccessControl is used, whether to force a preflight.
WebCrossOriginRequestPolicy crossOriginRequestPolicy;
};
class WebURLLoader {
public:
// The WebURLLoader may be deleted in a call to its client.
......
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
* Copyright (C) 2010, 2011 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
......@@ -31,103 +31,203 @@
#include "config.h"
#include "AssociatedURLLoader.h"
#include "DocumentThreadableLoader.h"
#include "SubresourceLoader.h"
#include "ThreadableLoaderClient.h"
#include "WebApplicationCacheHost.h"
#include "WebDataSource.h"
#include "WebFrameImpl.h"
#include "WebKit.h"
#include "WebKitClient.h"
#include "WebURLError.h"
#include "WebURLLoaderClient.h"
#include "WebURLRequest.h"
#include "WrappedResourceRequest.h"
#include "WrappedResourceResponse.h"
using namespace WebCore;
using namespace WebKit;
using namespace WTF;
namespace WebKit {
AssociatedURLLoader::AssociatedURLLoader(PassRefPtr<WebFrameImpl> frameImpl)
: m_frameImpl(frameImpl),
m_realLoader(webKitClient()->createURLLoader()),
m_realClient(0)
// This class bridges the interface differences between WebCore and WebKit loader clients.
// It forwards its ThreadableLoaderClient notifications to a WebURLLoaderClient.
class AssociatedURLLoader::ClientAdapter : public ThreadableLoaderClient {
public:
static PassOwnPtr<ClientAdapter> create(AssociatedURLLoader*, WebURLLoaderClient*, bool /*downloadToFile*/);
virtual void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/);
virtual void willSendRequest(ResourceRequest& /*newRequest*/, const ResourceResponse& /*redirectResponse*/);
virtual void didReceiveResponse(const ResourceResponse&);
virtual void didReceiveData(const char*, int /*dataLength*/);
virtual void didReceiveCachedMetadata(const char*, int /*dataLength*/);
virtual void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/);
virtual void didFail(const ResourceError&);
// This method stops loading and releases the DocumentThreadableLoader as early as possible.
void clearClient() { m_client = 0; }
private:
ClientAdapter(AssociatedURLLoader*, WebURLLoaderClient*, bool /*downloadToFile*/);
AssociatedURLLoader* m_loader;
WebURLLoaderClient* m_client;
unsigned long m_downloadLength;
bool m_downloadToFile;
};
PassOwnPtr<AssociatedURLLoader::ClientAdapter> AssociatedURLLoader::ClientAdapter::create(AssociatedURLLoader* loader, WebURLLoaderClient* client, bool downloadToFile)
{
return adoptPtr(new ClientAdapter(loader, client, downloadToFile));
}
AssociatedURLLoader::~AssociatedURLLoader()
AssociatedURLLoader::ClientAdapter::ClientAdapter(AssociatedURLLoader* loader, WebURLLoaderClient* client, bool downloadToFile)
: m_loader(loader)
, m_client(client)
, m_downloadLength(0)
, m_downloadToFile(downloadToFile)
{
ASSERT(m_loader);
ASSERT(m_client);
}
void AssociatedURLLoader::loadSynchronously(const WebURLRequest& request, WebURLResponse& response, WebURLError& error, WebData& data)
void AssociatedURLLoader::ClientAdapter::willSendRequest(ResourceRequest& newRequest, const ResourceResponse& redirectResponse)
{
ASSERT(!m_realClient);
WebURLRequest requestCopy(request);
prepareRequest(requestCopy);
if (!m_client)
return;
m_realLoader->loadSynchronously(requestCopy, response, error, data);
WrappedResourceRequest wrappedNewRequest(newRequest);
WrappedResourceResponse wrappedRedirectResponse(redirectResponse);
m_client->willSendRequest(m_loader, wrappedNewRequest, wrappedRedirectResponse);
}
void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, WebURLLoaderClient* client)
void AssociatedURLLoader::ClientAdapter::didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
{
ASSERT(!m_realClient);
if (!m_client)
return;
WebURLRequest requestCopy(request);
prepareRequest(requestCopy);
m_client->didSendData(m_loader, bytesSent, totalBytesToBeSent);
}
m_realClient = client;
m_realLoader->loadAsynchronously(requestCopy, this);
void AssociatedURLLoader::ClientAdapter::didReceiveResponse(const ResourceResponse& response)
{
WrappedResourceResponse wrappedResponse(response);
m_client->didReceiveResponse(m_loader, wrappedResponse);
}
void AssociatedURLLoader::cancel()
void AssociatedURLLoader::ClientAdapter::didReceiveData(const char* data, int lengthReceived)
{
m_realLoader->cancel();
if (!m_client)
return;
m_client->didReceiveData(m_loader, data, lengthReceived);
m_downloadLength += lengthReceived;
}
void AssociatedURLLoader::setDefersLoading(bool defersLoading)
void AssociatedURLLoader::ClientAdapter::didReceiveCachedMetadata(const char* data, int lengthReceived)
{
m_realLoader->setDefersLoading(defersLoading);
if (!m_client)
return;
m_client->didReceiveCachedMetadata(m_loader, data, lengthReceived);
}
void AssociatedURLLoader::prepareRequest(WebURLRequest& request)
void AssociatedURLLoader::ClientAdapter::didFinishLoading(unsigned long identifier, double finishTime)
{
WebApplicationCacheHost* applicationCacheHost = m_frameImpl->dataSource()->applicationCacheHost();
if (applicationCacheHost)
applicationCacheHost->willStartSubResourceRequest(request);
m_frameImpl->dispatchWillSendRequest(request);
if (!m_client)
return;
if (m_downloadToFile) {
int downloadLength = m_downloadLength <= INT_MAX ? m_downloadLength : INT_MAX;
m_client->didDownloadData(m_loader, downloadLength);
// While the client could have cancelled, continue, since the load finished.
}
m_client->didFinishLoading(m_loader, finishTime);
}
void AssociatedURLLoader::willSendRequest(WebURLLoader*, WebURLRequest& newRequest, const WebURLResponse& redirectResponse)
void AssociatedURLLoader::ClientAdapter::didFail(const ResourceError& error)
{
m_realClient->willSendRequest(this, newRequest, redirectResponse);
if (!m_client)
return;
WebURLError webError(error);
m_client->didFail(m_loader, webError);
}
void AssociatedURLLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
AssociatedURLLoader::AssociatedURLLoader(PassRefPtr<WebFrameImpl> frameImpl)
: m_frameImpl(frameImpl)
, m_client(0)
{
m_realClient->didSendData(this, bytesSent, totalBytesToBeSent);
ASSERT(m_frameImpl);
m_options.sniffContent = false;
m_options.allowCredentials = true;
m_options.forcePreflight = false;
m_options.crossOriginRequestPolicy = AllowCrossOriginRequests; // TODO(bbudge) Default should be DenyCrossOriginRequests, but this would break some tests.
}
void AssociatedURLLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& response)
AssociatedURLLoader::AssociatedURLLoader(PassRefPtr<WebFrameImpl> frameImpl, const WebURLLoaderOptions& options)
: m_frameImpl(frameImpl)
, m_options(options)
, m_client(0)
{
m_realClient->didReceiveResponse(this, response);
ASSERT(m_frameImpl);
}
void AssociatedURLLoader::didDownloadData(WebURLLoader*, int dataLength)
AssociatedURLLoader::~AssociatedURLLoader()
{
m_realClient->didDownloadData(this, dataLength);
if (m_clientAdapter)
m_clientAdapter->clearClient();
}
void AssociatedURLLoader::didReceiveData(WebURLLoader*, const char* data, int dataLength)
#define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, webcore_name) \
COMPILE_ASSERT(static_cast<int>(WebKit::webkit_name) == static_cast<int>(WebCore::webcore_name), mismatching_enums)
COMPILE_ASSERT_MATCHING_ENUM(DenyCrossOriginRequests, DenyCrossOriginRequests);
COMPILE_ASSERT_MATCHING_ENUM(UseAccessControl, UseAccessControl);
COMPILE_ASSERT_MATCHING_ENUM(AllowCrossOriginRequests, AllowCrossOriginRequests);
void AssociatedURLLoader::loadSynchronously(const WebURLRequest& request, WebURLResponse& response, WebURLError& error, WebData& data)
{
m_realClient->didReceiveData(this, data, dataLength);
ASSERT(0); // Synchronous loading is not supported.
}
void AssociatedURLLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, int dataLength)
void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, WebURLLoaderClient* client)
{
m_realClient->didReceiveCachedMetadata(this, data, dataLength);
ASSERT(!m_client);
m_client = client;
ASSERT(m_client);
ThreadableLoaderOptions options;
options.sendLoadCallbacks = true; // Always send callbacks.
options.sniffContent = m_options.sniffContent;
options.allowCredentials = m_options.allowCredentials;
options.forcePreflight = m_options.forcePreflight;
options.crossOriginRequestPolicy = static_cast<WebCore::CrossOriginRequestPolicy>(m_options.crossOriginRequestPolicy);
const ResourceRequest& webcoreRequest = request.toResourceRequest();
Document* webcoreDocument = m_frameImpl->frame()->document();
m_clientAdapter = ClientAdapter::create(this, m_client, request.downloadToFile());
m_loader = DocumentThreadableLoader::create(webcoreDocument, m_clientAdapter.get(), webcoreRequest, options);
}
void AssociatedURLLoader::didFinishLoading(WebURLLoader*, double finishTime)
void AssociatedURLLoader::cancel()
{
m_realClient->didFinishLoading(this, finishTime);
if (m_loader) {
m_clientAdapter->clearClient();
m_loader->cancel();
}
}
void AssociatedURLLoader::didFail(WebURLLoader*, const WebURLError& error)
void AssociatedURLLoader::setDefersLoading(bool defersLoading)
{
m_realClient->didFail(this, error);
if (m_loader)
m_loader->setDefersLoading(defersLoading);
}
} // namespace WebKit
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
* Copyright (C) 2010, 2011 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
......@@ -32,20 +32,22 @@
#define AssociatedURLLoader_h
#include "WebURLLoader.h"
#include "WebURLLoaderClient.h"
#include <wtf/Noncopyable.h>
#include <wtf/OwnPtr.h>
#include <wtf/RefPtr.h>
namespace WebCore { class DocumentThreadableLoader; }
namespace WebKit {
class WebFrameImpl;
// This class is used to implement WebFrame::createAssociatedURLLoader.
// FIXME: Implement in terms of WebCore::SubresourceLoader.
class AssociatedURLLoader : public WebURLLoader,
public WebURLLoaderClient {
class AssociatedURLLoader : public WebURLLoader {
WTF_MAKE_NONCOPYABLE(AssociatedURLLoader);
public:
AssociatedURLLoader(PassRefPtr<WebFrameImpl>);
AssociatedURLLoader(PassRefPtr<WebFrameImpl>, const WebURLLoaderOptions&);
~AssociatedURLLoader();
// WebURLLoader methods:
......@@ -54,22 +56,15 @@ public:
virtual void cancel();
virtual void setDefersLoading(bool);
// WebURLLoaderClient methods:
virtual void willSendRequest(WebURLLoader*, WebURLRequest& newRequest, const WebURLResponse& redirectResponse);
virtual void didSendData(WebURLLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
virtual void didReceiveResponse(WebURLLoader*, const WebURLResponse&);
virtual void didDownloadData(WebURLLoader*, int dataLength);
virtual void didReceiveData(WebURLLoader*, const char* data, int dataLength);
virtual void didReceiveCachedMetadata(WebURLLoader*, const char* data, int dataLength);
virtual void didFinishLoading(WebURLLoader*, double finishTime);
virtual void didFail(WebURLLoader*, const WebURLError&);
private:
void prepareRequest(WebURLRequest&);
class ClientAdapter;
RefPtr<WebFrameImpl> m_frameImpl;
OwnPtr<WebURLLoader> m_realLoader;
WebURLLoaderClient* m_realClient;
WebURLLoaderOptions m_options;
WebURLLoaderClient* m_client;
OwnPtr<ClientAdapter> m_clientAdapter;
RefPtr<WebCore::DocumentThreadableLoader> m_loader;
};
} // namespace WebKit
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment