Changeset 81303 in webkit


Ignore:
Timestamp:
Mar 16, 2011 5:45:10 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-03-16 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. Exposes no new functionality.

  • public/WebURLLoader.h: (WebKit::WebURLLoaderOptions::WebURLLoaderOptions):
  • src/AssociatedURLLoader.cpp: (WebKit::AssociatedURLLoader::ClientAdapter::isDocumentThreadableLoaderClient): (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:
Location:
trunk/Source/WebKit/chromium
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/chromium/ChangeLog

    r81294 r81303  
     12011-03-16  Bill Budge  <bbudge@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        AssociatedURLLoader does not support Cross Origin Requests
     6        https://bugs.webkit.org/show_bug.cgi?id=53925
     7
     8        No new tests. Exposes no new functionality.
     9
     10        * public/WebURLLoader.h:
     11        (WebKit::WebURLLoaderOptions::WebURLLoaderOptions):
     12        * src/AssociatedURLLoader.cpp:
     13        (WebKit::AssociatedURLLoader::ClientAdapter::isDocumentThreadableLoaderClient):
     14        (WebKit::AssociatedURLLoader::ClientAdapter::clearClient):
     15        (WebKit::AssociatedURLLoader::ClientAdapter::create):
     16        (WebKit::AssociatedURLLoader::ClientAdapter::ClientAdapter):
     17        (WebKit::AssociatedURLLoader::ClientAdapter::willSendRequest):
     18        (WebKit::AssociatedURLLoader::ClientAdapter::didSendData):
     19        (WebKit::AssociatedURLLoader::ClientAdapter::didReceiveResponse):
     20        (WebKit::AssociatedURLLoader::ClientAdapter::didReceiveData):
     21        (WebKit::AssociatedURLLoader::ClientAdapter::didReceiveCachedMetadata):
     22        (WebKit::AssociatedURLLoader::ClientAdapter::didFinishLoading):
     23        (WebKit::AssociatedURLLoader::ClientAdapter::didFail):
     24        (WebKit::AssociatedURLLoader::AssociatedURLLoader):
     25        (WebKit::AssociatedURLLoader::~AssociatedURLLoader):
     26        (WebKit::AssociatedURLLoader::loadSynchronously):
     27        (WebKit::AssociatedURLLoader::loadAsynchronously):
     28        (WebKit::AssociatedURLLoader::cancel):
     29        (WebKit::AssociatedURLLoader::setDefersLoading):
     30        * src/AssociatedURLLoader.h:
     31
    1322011-03-16  Adam Barth  <abarth@webkit.org>
    233
  • trunk/Source/WebKit/chromium/public/WebURLLoader.h

    r81204 r81303  
    11/*
    2  * Copyright (C) 2009 Google Inc. All rights reserved.
     2 * Copyright (C) 2009, 2011 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4242struct WebURLError;
    4343
     44enum WebCrossOriginRequestPolicy {
     45    DenyCrossOriginRequests,
     46    UseAccessControl,
     47    AllowCrossOriginRequests
     48};
     49
     50struct WebURLLoaderOptions {
     51    WebURLLoaderOptions() : sniffContent(false), allowCredentials(false), forcePreflight(false), crossOriginRequestPolicy(DenyCrossOriginRequests) { }
     52
     53    bool sniffContent; // Whether to sniff content.
     54    bool allowCredentials; // Whether to send HTTP credentials and cookies with the request.
     55    bool forcePreflight; // If AccessControl is used, whether to force a preflight.
     56    WebCrossOriginRequestPolicy crossOriginRequestPolicy;
     57};
     58
    4459class WebURLLoader {
    4560public:
  • trunk/Source/WebKit/chromium/src/AssociatedURLLoader.cpp

    r81204 r81303  
    11/*
    2  * Copyright (C) 2010 Google Inc. All rights reserved.
     2 * Copyright (C) 2010, 2011 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3232#include "AssociatedURLLoader.h"
    3333
     34#include "DocumentThreadableLoader.h"
     35#include "DocumentThreadableLoaderClient.h"
     36#include "SubresourceLoader.h"
    3437#include "WebApplicationCacheHost.h"
    3538#include "WebDataSource.h"
     
    3740#include "WebKit.h"
    3841#include "WebKitClient.h"
     42#include "WebURLError.h"
     43#include "WebURLLoaderClient.h"
    3944#include "WebURLRequest.h"
     45#include "WrappedResourceRequest.h"
     46#include "WrappedResourceResponse.h"
     47
     48using namespace WebCore;
     49using namespace WebKit;
     50using namespace WTF;
    4051
    4152namespace WebKit {
    4253
     54// This class bridges the interface differences between WebCore and WebKit loader clients.
     55// It forwards its ThreadableLoaderClient notifications to a WebURLLoaderClient.
     56class AssociatedURLLoader::ClientAdapter : public DocumentThreadableLoaderClient {
     57public:
     58    static PassOwnPtr<ClientAdapter> create(AssociatedURLLoader*, WebURLLoaderClient*, bool /*downloadToFile*/);
     59
     60    virtual void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/);
     61    virtual void willSendRequest(ResourceRequest& /*newRequest*/, const ResourceResponse& /*redirectResponse*/);
     62
     63    virtual void didReceiveResponse(const ResourceResponse&);
     64    virtual void didReceiveData(const char*, int /*dataLength*/);
     65    virtual void didReceiveCachedMetadata(const char*, int /*dataLength*/);
     66    virtual void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/);
     67    virtual void didFail(const ResourceError&);
     68
     69    virtual bool isDocumentThreadableLoaderClient() { return true; }
     70
     71    // This method stops loading and releases the DocumentThreadableLoader as early as possible.
     72    void clearClient() { m_client = 0; }
     73
     74private:
     75    ClientAdapter(AssociatedURLLoader*, WebURLLoaderClient*, bool /*downloadToFile*/);
     76
     77    AssociatedURLLoader* m_loader;
     78    WebURLLoaderClient* m_client;
     79    unsigned long m_downloadLength;
     80    bool m_downloadToFile;
     81};
     82
     83PassOwnPtr<AssociatedURLLoader::ClientAdapter> AssociatedURLLoader::ClientAdapter::create(AssociatedURLLoader* loader, WebURLLoaderClient* client, bool downloadToFile)
     84{
     85    return adoptPtr(new ClientAdapter(loader, client, downloadToFile));
     86}
     87
     88AssociatedURLLoader::ClientAdapter::ClientAdapter(AssociatedURLLoader* loader, WebURLLoaderClient* client, bool downloadToFile)
     89    : m_loader(loader)
     90    , m_client(client)
     91    , m_downloadLength(0)
     92    , m_downloadToFile(downloadToFile)
     93{
     94    ASSERT(m_loader);
     95    ASSERT(m_client);
     96}
     97
     98void AssociatedURLLoader::ClientAdapter::willSendRequest(ResourceRequest& newRequest, const ResourceResponse& redirectResponse)
     99{
     100    if (!m_client)
     101        return;
     102
     103    WrappedResourceRequest wrappedNewRequest(newRequest);
     104    WrappedResourceResponse wrappedRedirectResponse(redirectResponse);
     105    m_client->willSendRequest(m_loader, wrappedNewRequest, wrappedRedirectResponse);
     106}
     107
     108void AssociatedURLLoader::ClientAdapter::didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
     109{
     110    if (!m_client)
     111        return;
     112
     113    m_client->didSendData(m_loader, bytesSent, totalBytesToBeSent);
     114}
     115
     116void AssociatedURLLoader::ClientAdapter::didReceiveResponse(const ResourceResponse& response)
     117{
     118    WrappedResourceResponse wrappedResponse(response);
     119    m_client->didReceiveResponse(m_loader, wrappedResponse);
     120}
     121
     122void AssociatedURLLoader::ClientAdapter::didReceiveData(const char* data, int lengthReceived)
     123{
     124    if (!m_client)
     125        return;
     126
     127    m_client->didReceiveData(m_loader, data, lengthReceived);
     128    m_downloadLength += lengthReceived;
     129}
     130
     131void AssociatedURLLoader::ClientAdapter::didReceiveCachedMetadata(const char* data, int lengthReceived)
     132{
     133    if (!m_client)
     134        return;
     135
     136    m_client->didReceiveCachedMetadata(m_loader, data, lengthReceived);
     137}
     138
     139void AssociatedURLLoader::ClientAdapter::didFinishLoading(unsigned long identifier, double finishTime)
     140{
     141    if (!m_client)
     142        return;
     143
     144    if (m_downloadToFile) {
     145        int downloadLength = m_downloadLength <= INT_MAX ? m_downloadLength : INT_MAX;
     146        m_client->didDownloadData(m_loader, downloadLength);
     147        // While the client could have cancelled, continue, since the load finished.
     148    }
     149
     150    m_client->didFinishLoading(m_loader, finishTime);
     151}
     152
     153void AssociatedURLLoader::ClientAdapter::didFail(const ResourceError& error)
     154{
     155    if (!m_client)
     156        return;
     157
     158    WebURLError webError(error);
     159    m_client->didFail(m_loader, webError);
     160}
     161
    43162AssociatedURLLoader::AssociatedURLLoader(PassRefPtr<WebFrameImpl> frameImpl)
    44     : m_frameImpl(frameImpl),
    45       m_realLoader(webKitClient()->createURLLoader()),
    46       m_realClient(0)
    47 {
     163    : m_frameImpl(frameImpl)
     164    , m_client(0)
     165{
     166    ASSERT(m_frameImpl);
     167
     168    m_options.sniffContent = false;
     169    m_options.allowCredentials = true;
     170    m_options.forcePreflight = false;
     171    m_options.crossOriginRequestPolicy = AllowCrossOriginRequests; // TODO(bbudge) Default should be DenyCrossOriginRequests, but this would break some tests.
     172}
     173
     174AssociatedURLLoader::AssociatedURLLoader(PassRefPtr<WebFrameImpl> frameImpl, const WebURLLoaderOptions& options)
     175    : m_frameImpl(frameImpl)
     176    , m_options(options)
     177    , m_client(0)
     178{
     179    ASSERT(m_frameImpl);
    48180}
    49181
    50182AssociatedURLLoader::~AssociatedURLLoader()
    51183{
    52 }
     184    if (m_clientAdapter)
     185        m_clientAdapter->clearClient();
     186}
     187
     188#define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, webcore_name) \
     189    COMPILE_ASSERT(static_cast<int>(WebKit::webkit_name) == static_cast<int>(WebCore::webcore_name), mismatching_enums)
     190
     191COMPILE_ASSERT_MATCHING_ENUM(DenyCrossOriginRequests, DenyCrossOriginRequests);
     192COMPILE_ASSERT_MATCHING_ENUM(UseAccessControl, UseAccessControl);
     193COMPILE_ASSERT_MATCHING_ENUM(AllowCrossOriginRequests, AllowCrossOriginRequests);
    53194
    54195void AssociatedURLLoader::loadSynchronously(const WebURLRequest& request, WebURLResponse& response, WebURLError& error, WebData& data)
    55196{
    56     ASSERT(!m_realClient);
    57 
    58     WebURLRequest requestCopy(request);
    59     prepareRequest(requestCopy);
    60 
    61     m_realLoader->loadSynchronously(requestCopy, response, error, data);
     197    ASSERT(0); // Synchronous loading is not supported.
    62198}
    63199
    64200void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, WebURLLoaderClient* client)
    65201{
    66     ASSERT(!m_realClient);
    67 
    68     WebURLRequest requestCopy(request);
    69     prepareRequest(requestCopy);
    70 
    71     m_realClient = client;
    72     m_realLoader->loadAsynchronously(requestCopy, this);
     202    ASSERT(!m_client);
     203
     204    m_client = client;
     205    ASSERT(m_client);
     206
     207    ThreadableLoaderOptions options;
     208    options.sendLoadCallbacks = true; // Always send callbacks.
     209    options.sniffContent = m_options.sniffContent;
     210    options.allowCredentials = m_options.allowCredentials;
     211    options.forcePreflight = m_options.forcePreflight;
     212    options.crossOriginRequestPolicy = static_cast<WebCore::CrossOriginRequestPolicy>(m_options.crossOriginRequestPolicy);
     213
     214    const ResourceRequest& webcoreRequest = request.toResourceRequest();
     215    Document* webcoreDocument = m_frameImpl->frame()->document();
     216    m_clientAdapter = ClientAdapter::create(this, m_client, request.downloadToFile());
     217
     218    m_loader = DocumentThreadableLoader::create(webcoreDocument, m_clientAdapter.get(), webcoreRequest, options);
    73219}
    74220
    75221void AssociatedURLLoader::cancel()
    76222{
    77     m_realLoader->cancel();
     223    if (m_loader) {
     224        m_clientAdapter->clearClient();
     225        m_loader->cancel();
     226    }
    78227}
    79228
    80229void AssociatedURLLoader::setDefersLoading(bool defersLoading)
    81230{
    82     m_realLoader->setDefersLoading(defersLoading);
    83 }
    84 
    85 void AssociatedURLLoader::prepareRequest(WebURLRequest& request)
    86 {
    87     WebApplicationCacheHost* applicationCacheHost = m_frameImpl->dataSource()->applicationCacheHost();
    88     if (applicationCacheHost)
    89         applicationCacheHost->willStartSubResourceRequest(request);
    90     m_frameImpl->dispatchWillSendRequest(request);
    91 }
    92 
    93 void AssociatedURLLoader::willSendRequest(WebURLLoader*, WebURLRequest& newRequest, const WebURLResponse& redirectResponse)
    94 {
    95     m_realClient->willSendRequest(this, newRequest, redirectResponse);
    96 }
    97 
    98 void AssociatedURLLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
    99 {
    100     m_realClient->didSendData(this, bytesSent, totalBytesToBeSent);
    101 }
    102 
    103 void AssociatedURLLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& response)
    104 {
    105     m_realClient->didReceiveResponse(this, response);
    106 }
    107 
    108 void AssociatedURLLoader::didDownloadData(WebURLLoader*, int dataLength)
    109 {
    110     m_realClient->didDownloadData(this, dataLength);
    111 }
    112 
    113 void AssociatedURLLoader::didReceiveData(WebURLLoader*, const char* data, int dataLength)
    114 {
    115     m_realClient->didReceiveData(this, data, dataLength);
    116 }
    117 
    118 void AssociatedURLLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, int dataLength)
    119 {
    120     m_realClient->didReceiveCachedMetadata(this, data, dataLength);
    121 }
    122 
    123 void AssociatedURLLoader::didFinishLoading(WebURLLoader*, double finishTime)
    124 {
    125     m_realClient->didFinishLoading(this, finishTime);
    126 }
    127 
    128 void AssociatedURLLoader::didFail(WebURLLoader*, const WebURLError& error)
    129 {
    130     m_realClient->didFail(this, error);
     231    if (m_loader)
     232        m_loader->setDefersLoading(defersLoading);
    131233}
    132234
  • trunk/Source/WebKit/chromium/src/AssociatedURLLoader.h

    r81204 r81303  
    11/*
    2  * Copyright (C) 2010 Google Inc. All rights reserved.
     2 * Copyright (C) 2010, 2011 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3333
    3434#include "WebURLLoader.h"
    35 #include "WebURLLoaderClient.h"
     35#include <wtf/Noncopyable.h>
    3636#include <wtf/OwnPtr.h>
    3737#include <wtf/RefPtr.h>
     38
     39namespace WebCore { class DocumentThreadableLoader; }
    3840
    3941namespace WebKit {
     
    4244
    4345// This class is used to implement WebFrame::createAssociatedURLLoader.
    44 // FIXME: Implement in terms of WebCore::SubresourceLoader.
    45 class AssociatedURLLoader : public WebURLLoader,
    46                             public WebURLLoaderClient {
     46class AssociatedURLLoader : public WebURLLoader {
     47    WTF_MAKE_NONCOPYABLE(AssociatedURLLoader);
    4748public:
    4849    AssociatedURLLoader(PassRefPtr<WebFrameImpl>);
     50    AssociatedURLLoader(PassRefPtr<WebFrameImpl>, const WebURLLoaderOptions&);
    4951    ~AssociatedURLLoader();
    5052
     
    5557    virtual void setDefersLoading(bool);
    5658
    57     // WebURLLoaderClient methods:
    58     virtual void willSendRequest(WebURLLoader*, WebURLRequest& newRequest, const WebURLResponse& redirectResponse);
    59     virtual void didSendData(WebURLLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
    60     virtual void didReceiveResponse(WebURLLoader*, const WebURLResponse&);
    61     virtual void didDownloadData(WebURLLoader*, int dataLength);
    62     virtual void didReceiveData(WebURLLoader*, const char* data, int dataLength);
    63     virtual void didReceiveCachedMetadata(WebURLLoader*, const char* data, int dataLength);
    64     virtual void didFinishLoading(WebURLLoader*, double finishTime);
    65     virtual void didFail(WebURLLoader*, const WebURLError&);
     59private:
    6660
    67 private:
    68     void prepareRequest(WebURLRequest&);
     61    class ClientAdapter;
    6962
    7063    RefPtr<WebFrameImpl> m_frameImpl;
    71     OwnPtr<WebURLLoader> m_realLoader;
    72     WebURLLoaderClient* m_realClient;
     64    WebURLLoaderOptions m_options;
     65    WebURLLoaderClient* m_client;
     66    OwnPtr<ClientAdapter> m_clientAdapter;
     67    RefPtr<WebCore::DocumentThreadableLoader> m_loader;
    7368};
    7469
Note: See TracChangeset for help on using the changeset viewer.