Changeset 81303 in webkit
- Timestamp:
- Mar 16, 2011 5:45:10 PM (13 years ago)
- Location:
- trunk/Source/WebKit/chromium
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/chromium/ChangeLog
r81294 r81303 1 2011-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 1 32 2011-03-16 Adam Barth <abarth@webkit.org> 2 33 -
trunk/Source/WebKit/chromium/public/WebURLLoader.h
r81204 r81303 1 1 /* 2 * Copyright (C) 2009 Google Inc. All rights reserved.2 * Copyright (C) 2009, 2011 Google Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 42 42 struct WebURLError; 43 43 44 enum WebCrossOriginRequestPolicy { 45 DenyCrossOriginRequests, 46 UseAccessControl, 47 AllowCrossOriginRequests 48 }; 49 50 struct 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 44 59 class WebURLLoader { 45 60 public: -
trunk/Source/WebKit/chromium/src/AssociatedURLLoader.cpp
r81204 r81303 1 1 /* 2 * Copyright (C) 2010 Google Inc. All rights reserved.2 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 32 32 #include "AssociatedURLLoader.h" 33 33 34 #include "DocumentThreadableLoader.h" 35 #include "DocumentThreadableLoaderClient.h" 36 #include "SubresourceLoader.h" 34 37 #include "WebApplicationCacheHost.h" 35 38 #include "WebDataSource.h" … … 37 40 #include "WebKit.h" 38 41 #include "WebKitClient.h" 42 #include "WebURLError.h" 43 #include "WebURLLoaderClient.h" 39 44 #include "WebURLRequest.h" 45 #include "WrappedResourceRequest.h" 46 #include "WrappedResourceResponse.h" 47 48 using namespace WebCore; 49 using namespace WebKit; 50 using namespace WTF; 40 51 41 52 namespace WebKit { 42 53 54 // This class bridges the interface differences between WebCore and WebKit loader clients. 55 // It forwards its ThreadableLoaderClient notifications to a WebURLLoaderClient. 56 class AssociatedURLLoader::ClientAdapter : public DocumentThreadableLoaderClient { 57 public: 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 74 private: 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 83 PassOwnPtr<AssociatedURLLoader::ClientAdapter> AssociatedURLLoader::ClientAdapter::create(AssociatedURLLoader* loader, WebURLLoaderClient* client, bool downloadToFile) 84 { 85 return adoptPtr(new ClientAdapter(loader, client, downloadToFile)); 86 } 87 88 AssociatedURLLoader::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 98 void 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 108 void 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 116 void AssociatedURLLoader::ClientAdapter::didReceiveResponse(const ResourceResponse& response) 117 { 118 WrappedResourceResponse wrappedResponse(response); 119 m_client->didReceiveResponse(m_loader, wrappedResponse); 120 } 121 122 void 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 131 void 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 139 void 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 153 void 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 43 162 AssociatedURLLoader::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 174 AssociatedURLLoader::AssociatedURLLoader(PassRefPtr<WebFrameImpl> frameImpl, const WebURLLoaderOptions& options) 175 : m_frameImpl(frameImpl) 176 , m_options(options) 177 , m_client(0) 178 { 179 ASSERT(m_frameImpl); 48 180 } 49 181 50 182 AssociatedURLLoader::~AssociatedURLLoader() 51 183 { 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 191 COMPILE_ASSERT_MATCHING_ENUM(DenyCrossOriginRequests, DenyCrossOriginRequests); 192 COMPILE_ASSERT_MATCHING_ENUM(UseAccessControl, UseAccessControl); 193 COMPILE_ASSERT_MATCHING_ENUM(AllowCrossOriginRequests, AllowCrossOriginRequests); 53 194 54 195 void AssociatedURLLoader::loadSynchronously(const WebURLRequest& request, WebURLResponse& response, WebURLError& error, WebData& data) 55 196 { 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. 62 198 } 63 199 64 200 void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, WebURLLoaderClient* client) 65 201 { 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); 73 219 } 74 220 75 221 void AssociatedURLLoader::cancel() 76 222 { 77 m_realLoader->cancel(); 223 if (m_loader) { 224 m_clientAdapter->clearClient(); 225 m_loader->cancel(); 226 } 78 227 } 79 228 80 229 void AssociatedURLLoader::setDefersLoading(bool defersLoading) 81 230 { 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); 131 233 } 132 234 -
trunk/Source/WebKit/chromium/src/AssociatedURLLoader.h
r81204 r81303 1 1 /* 2 * Copyright (C) 2010 Google Inc. All rights reserved.2 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 33 33 34 34 #include "WebURLLoader.h" 35 #include "WebURLLoaderClient.h"35 #include <wtf/Noncopyable.h> 36 36 #include <wtf/OwnPtr.h> 37 37 #include <wtf/RefPtr.h> 38 39 namespace WebCore { class DocumentThreadableLoader; } 38 40 39 41 namespace WebKit { … … 42 44 43 45 // This class is used to implement WebFrame::createAssociatedURLLoader. 44 // FIXME: Implement in terms of WebCore::SubresourceLoader. 45 class AssociatedURLLoader : public WebURLLoader, 46 public WebURLLoaderClient { 46 class AssociatedURLLoader : public WebURLLoader { 47 WTF_MAKE_NONCOPYABLE(AssociatedURLLoader); 47 48 public: 48 49 AssociatedURLLoader(PassRefPtr<WebFrameImpl>); 50 AssociatedURLLoader(PassRefPtr<WebFrameImpl>, const WebURLLoaderOptions&); 49 51 ~AssociatedURLLoader(); 50 52 … … 55 57 virtual void setDefersLoading(bool); 56 58 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&); 59 private: 66 60 67 private: 68 void prepareRequest(WebURLRequest&); 61 class ClientAdapter; 69 62 70 63 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; 73 68 }; 74 69
Note: See TracChangeset
for help on using the changeset viewer.