Changeset 81144 in webkit


Ignore:
Timestamp:
Mar 15, 2011 10:24:32 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

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:
Location:
trunk/Source/WebKit/chromium
Files:
4 edited

Legend:

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

    r81143 r81144  
     12011-03-15  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. No new functionality exposed.
     9
     10        * public/WebURLLoader.h:
     11        (WebKit::WebURLLoaderOptions::WebURLLoaderOptions):
     12        * src/AssociatedURLLoader.cpp:
     13        (WebKit::AssociatedURLLoader::ClientAdapter::clearClient):
     14        (WebKit::AssociatedURLLoader::ClientAdapter::create):
     15        (WebKit::AssociatedURLLoader::ClientAdapter::ClientAdapter):
     16        (WebKit::AssociatedURLLoader::ClientAdapter::willSendRequest):
     17        (WebKit::AssociatedURLLoader::ClientAdapter::didSendData):
     18        (WebKit::AssociatedURLLoader::ClientAdapter::didReceiveResponse):
     19        (WebKit::AssociatedURLLoader::ClientAdapter::didReceiveData):
     20        (WebKit::AssociatedURLLoader::ClientAdapter::didReceiveCachedMetadata):
     21        (WebKit::AssociatedURLLoader::ClientAdapter::didFinishLoading):
     22        (WebKit::AssociatedURLLoader::ClientAdapter::didFail):
     23        (WebKit::AssociatedURLLoader::AssociatedURLLoader):
     24        (WebKit::AssociatedURLLoader::~AssociatedURLLoader):
     25        (WebKit::AssociatedURLLoader::loadSynchronously):
     26        (WebKit::AssociatedURLLoader::loadAsynchronously):
     27        (WebKit::AssociatedURLLoader::cancel):
     28        (WebKit::AssociatedURLLoader::setDefersLoading):
     29        * src/AssociatedURLLoader.h:
     30
    1312011-03-15  Alok priyadarshi  <alokp@chromium.org>
    232
  • trunk/Source/WebKit/chromium/public/WebURLLoader.h

    r50682 r81144  
    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

    r80461 r81144  
    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 "SubresourceLoader.h"
     36#include "ThreadableLoaderClient.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 ThreadableLoaderClient {
     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    // This method stops loading and releases the DocumentThreadableLoader as early as possible.
     70    void clearClient() { m_client = 0; }
     71
     72private:
     73    ClientAdapter(AssociatedURLLoader*, WebURLLoaderClient*, bool /*downloadToFile*/);
     74
     75    AssociatedURLLoader* m_loader;
     76    WebURLLoaderClient* m_client;
     77    unsigned long m_downloadLength;
     78    bool m_downloadToFile;
     79};
     80
     81PassOwnPtr<AssociatedURLLoader::ClientAdapter> AssociatedURLLoader::ClientAdapter::create(AssociatedURLLoader* loader, WebURLLoaderClient* client, bool downloadToFile)
     82{
     83    return adoptPtr(new ClientAdapter(loader, client, downloadToFile));
     84}
     85
     86AssociatedURLLoader::ClientAdapter::ClientAdapter(AssociatedURLLoader* loader, WebURLLoaderClient* client, bool downloadToFile)
     87    : m_loader(loader)
     88    , m_client(client)
     89    , m_downloadLength(0)
     90    , m_downloadToFile(downloadToFile)
     91{
     92    ASSERT(m_loader);
     93    ASSERT(m_client);
     94}
     95
     96void AssociatedURLLoader::ClientAdapter::willSendRequest(ResourceRequest& newRequest, const ResourceResponse& redirectResponse)
     97{
     98    if (!m_client)
     99        return;
     100
     101    WrappedResourceRequest wrappedNewRequest(newRequest);
     102    WrappedResourceResponse wrappedRedirectResponse(redirectResponse);
     103    m_client->willSendRequest(m_loader, wrappedNewRequest, wrappedRedirectResponse);
     104}
     105
     106void AssociatedURLLoader::ClientAdapter::didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
     107{
     108    if (!m_client)
     109        return;
     110
     111    m_client->didSendData(m_loader, bytesSent, totalBytesToBeSent);
     112}
     113
     114void AssociatedURLLoader::ClientAdapter::didReceiveResponse(const ResourceResponse& response)
     115{
     116    WrappedResourceResponse wrappedResponse(response);
     117    m_client->didReceiveResponse(m_loader, wrappedResponse);
     118}
     119
     120void AssociatedURLLoader::ClientAdapter::didReceiveData(const char* data, int lengthReceived)
     121{
     122    if (!m_client)
     123        return;
     124
     125    m_client->didReceiveData(m_loader, data, lengthReceived);
     126    m_downloadLength += lengthReceived;
     127}
     128
     129void AssociatedURLLoader::ClientAdapter::didReceiveCachedMetadata(const char* data, int lengthReceived)
     130{
     131    if (!m_client)
     132        return;
     133
     134    m_client->didReceiveCachedMetadata(m_loader, data, lengthReceived);
     135}
     136
     137void AssociatedURLLoader::ClientAdapter::didFinishLoading(unsigned long identifier, double finishTime)
     138{
     139    if (!m_client)
     140        return;
     141
     142    if (m_downloadToFile) {
     143        int downloadLength = m_downloadLength <= INT_MAX ? m_downloadLength : INT_MAX;
     144        m_client->didDownloadData(m_loader, downloadLength);
     145        // While the client could have cancelled, continue, since the load finished.
     146    }
     147
     148    m_client->didFinishLoading(m_loader, finishTime);
     149}
     150
     151void AssociatedURLLoader::ClientAdapter::didFail(const ResourceError& error)
     152{
     153    if (!m_client)
     154        return;
     155
     156    WebURLError webError(error);
     157    m_client->didFail(m_loader, webError);
     158}
     159
    43160AssociatedURLLoader::AssociatedURLLoader(PassRefPtr<WebFrameImpl> frameImpl)
    44     : m_frameImpl(frameImpl),
    45       m_realLoader(webKitClient()->createURLLoader()),
    46       m_realClient(0)
    47 {
     161    : m_frameImpl(frameImpl)
     162    , m_client(0)
     163{
     164    ASSERT(m_frameImpl);
     165
     166    m_options.sniffContent = false;
     167    m_options.allowCredentials = true;
     168    m_options.forcePreflight = false;
     169    m_options.crossOriginRequestPolicy = AllowCrossOriginRequests; // TODO(bbudge) Default should be DenyCrossOriginRequests, but this would break some tests.
     170}
     171
     172AssociatedURLLoader::AssociatedURLLoader(PassRefPtr<WebFrameImpl> frameImpl, const WebURLLoaderOptions& options)
     173    : m_frameImpl(frameImpl)
     174    , m_options(options)
     175    , m_client(0)
     176{
     177    ASSERT(m_frameImpl);
    48178}
    49179
    50180AssociatedURLLoader::~AssociatedURLLoader()
    51181{
    52 }
     182    if (m_clientAdapter)
     183        m_clientAdapter->clearClient();
     184}
     185
     186#define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, webcore_name) \
     187    COMPILE_ASSERT(static_cast<int>(WebKit::webkit_name) == static_cast<int>(WebCore::webcore_name), mismatching_enums)
     188
     189COMPILE_ASSERT_MATCHING_ENUM(DenyCrossOriginRequests, DenyCrossOriginRequests);
     190COMPILE_ASSERT_MATCHING_ENUM(UseAccessControl, UseAccessControl);
     191COMPILE_ASSERT_MATCHING_ENUM(AllowCrossOriginRequests, AllowCrossOriginRequests);
    53192
    54193void AssociatedURLLoader::loadSynchronously(const WebURLRequest& request, WebURLResponse& response, WebURLError& error, WebData& data)
    55194{
    56     ASSERT(!m_realClient);
    57 
    58     WebURLRequest requestCopy(request);
    59     prepareRequest(requestCopy);
    60 
    61     m_realLoader->loadSynchronously(requestCopy, response, error, data);
     195    ASSERT(0); // Synchronous loading is not supported.
    62196}
    63197
    64198void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, WebURLLoaderClient* client)
    65199{
    66     ASSERT(!m_realClient);
    67 
    68     WebURLRequest requestCopy(request);
    69     prepareRequest(requestCopy);
    70 
    71     m_realClient = client;
    72     m_realLoader->loadAsynchronously(requestCopy, this);
     200    ASSERT(!m_client);
     201
     202    m_client = client;
     203    ASSERT(m_client);
     204
     205    ThreadableLoaderOptions options;
     206    options.sendLoadCallbacks = true; // Always send callbacks.
     207    options.sniffContent = m_options.sniffContent;
     208    options.allowCredentials = m_options.allowCredentials;
     209    options.forcePreflight = m_options.forcePreflight;
     210    options.crossOriginRequestPolicy = static_cast<WebCore::CrossOriginRequestPolicy>(m_options.crossOriginRequestPolicy);
     211
     212    const ResourceRequest& webcoreRequest = request.toResourceRequest();
     213    Document* webcoreDocument = m_frameImpl->frame()->document();
     214    m_clientAdapter = ClientAdapter::create(this, m_client, request.downloadToFile());
     215
     216    m_loader = DocumentThreadableLoader::create(webcoreDocument, m_clientAdapter.get(), webcoreRequest, options);
    73217}
    74218
    75219void AssociatedURLLoader::cancel()
    76220{
    77     m_realLoader->cancel();
     221    if (m_loader) {
     222        m_clientAdapter->clearClient();
     223        m_loader->cancel();
     224    }
    78225}
    79226
    80227void AssociatedURLLoader::setDefersLoading(bool defersLoading)
    81228{
    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);
     229    if (m_loader)
     230        m_loader->setDefersLoading(defersLoading);
    131231}
    132232
  • trunk/Source/WebKit/chromium/src/AssociatedURLLoader.h

    r80461 r81144  
    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.