Changeset 81144 in webkit
- Timestamp:
- Mar 15, 2011 10:24:32 AM (13 years ago)
- Location:
- trunk/Source/WebKit/chromium
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/chromium/ChangeLog
r81143 r81144 1 2011-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 1 31 2011-03-15 Alok priyadarshi <alokp@chromium.org> 2 32 -
trunk/Source/WebKit/chromium/public/WebURLLoader.h
r50682 r81144 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
r80461 r81144 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 "SubresourceLoader.h" 36 #include "ThreadableLoaderClient.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 ThreadableLoaderClient { 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 // This method stops loading and releases the DocumentThreadableLoader as early as possible. 70 void clearClient() { m_client = 0; } 71 72 private: 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 81 PassOwnPtr<AssociatedURLLoader::ClientAdapter> AssociatedURLLoader::ClientAdapter::create(AssociatedURLLoader* loader, WebURLLoaderClient* client, bool downloadToFile) 82 { 83 return adoptPtr(new ClientAdapter(loader, client, downloadToFile)); 84 } 85 86 AssociatedURLLoader::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 96 void 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 106 void 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 114 void AssociatedURLLoader::ClientAdapter::didReceiveResponse(const ResourceResponse& response) 115 { 116 WrappedResourceResponse wrappedResponse(response); 117 m_client->didReceiveResponse(m_loader, wrappedResponse); 118 } 119 120 void 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 129 void 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 137 void 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 151 void 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 43 160 AssociatedURLLoader::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 172 AssociatedURLLoader::AssociatedURLLoader(PassRefPtr<WebFrameImpl> frameImpl, const WebURLLoaderOptions& options) 173 : m_frameImpl(frameImpl) 174 , m_options(options) 175 , m_client(0) 176 { 177 ASSERT(m_frameImpl); 48 178 } 49 179 50 180 AssociatedURLLoader::~AssociatedURLLoader() 51 181 { 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 189 COMPILE_ASSERT_MATCHING_ENUM(DenyCrossOriginRequests, DenyCrossOriginRequests); 190 COMPILE_ASSERT_MATCHING_ENUM(UseAccessControl, UseAccessControl); 191 COMPILE_ASSERT_MATCHING_ENUM(AllowCrossOriginRequests, AllowCrossOriginRequests); 53 192 54 193 void AssociatedURLLoader::loadSynchronously(const WebURLRequest& request, WebURLResponse& response, WebURLError& error, WebData& data) 55 194 { 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. 62 196 } 63 197 64 198 void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, WebURLLoaderClient* client) 65 199 { 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); 73 217 } 74 218 75 219 void AssociatedURLLoader::cancel() 76 220 { 77 m_realLoader->cancel(); 221 if (m_loader) { 222 m_clientAdapter->clearClient(); 223 m_loader->cancel(); 224 } 78 225 } 79 226 80 227 void AssociatedURLLoader::setDefersLoading(bool defersLoading) 81 228 { 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); 131 231 } 132 232 -
trunk/Source/WebKit/chromium/src/AssociatedURLLoader.h
r80461 r81144 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.