OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010, 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2010, 2011, 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "platform/network/HTTPParsers.h" | 41 #include "platform/network/HTTPParsers.h" |
42 #include "platform/network/ResourceError.h" | 42 #include "platform/network/ResourceError.h" |
43 #include "public/platform/WebHTTPHeaderVisitor.h" | 43 #include "public/platform/WebHTTPHeaderVisitor.h" |
44 #include "public/platform/WebString.h" | 44 #include "public/platform/WebString.h" |
45 #include "public/platform/WebURLError.h" | 45 #include "public/platform/WebURLError.h" |
46 #include "public/platform/WebURLLoaderClient.h" | 46 #include "public/platform/WebURLLoaderClient.h" |
47 #include "public/platform/WebURLRequest.h" | 47 #include "public/platform/WebURLRequest.h" |
48 #include "public/web/WebDataSource.h" | 48 #include "public/web/WebDataSource.h" |
49 #include "web/WebLocalFrameImpl.h" | 49 #include "web/WebLocalFrameImpl.h" |
50 #include "wtf/HashSet.h" | 50 #include "wtf/HashSet.h" |
| 51 #include "wtf/PtrUtil.h" |
51 #include "wtf/text/WTFString.h" | 52 #include "wtf/text/WTFString.h" |
52 #include <limits.h> | 53 #include <limits.h> |
| 54 #include <memory> |
53 | 55 |
54 namespace blink { | 56 namespace blink { |
55 | 57 |
56 namespace { | 58 namespace { |
57 | 59 |
58 class HTTPRequestHeaderValidator : public WebHTTPHeaderVisitor { | 60 class HTTPRequestHeaderValidator : public WebHTTPHeaderVisitor { |
59 WTF_MAKE_NONCOPYABLE(HTTPRequestHeaderValidator); | 61 WTF_MAKE_NONCOPYABLE(HTTPRequestHeaderValidator); |
60 public: | 62 public: |
61 HTTPRequestHeaderValidator() : m_isSafe(true) { } | 63 HTTPRequestHeaderValidator() : m_isSafe(true) { } |
62 | 64 |
63 void visitHeader(const WebString& name, const WebString& value); | 65 void visitHeader(const WebString& name, const WebString& value); |
64 bool isSafe() const { return m_isSafe; } | 66 bool isSafe() const { return m_isSafe; } |
65 | 67 |
66 private: | 68 private: |
67 bool m_isSafe; | 69 bool m_isSafe; |
68 }; | 70 }; |
69 | 71 |
70 void HTTPRequestHeaderValidator::visitHeader(const WebString& name, const WebStr
ing& value) | 72 void HTTPRequestHeaderValidator::visitHeader(const WebString& name, const WebStr
ing& value) |
71 { | 73 { |
72 m_isSafe = m_isSafe && isValidHTTPToken(name) && !FetchUtils::isForbiddenHea
derName(name) && isValidHTTPHeaderValue(value); | 74 m_isSafe = m_isSafe && isValidHTTPToken(name) && !FetchUtils::isForbiddenHea
derName(name) && isValidHTTPHeaderValue(value); |
73 } | 75 } |
74 | 76 |
75 } // namespace | 77 } // namespace |
76 | 78 |
77 // This class bridges the interface differences between WebCore and WebKit loade
r clients. | 79 // This class bridges the interface differences between WebCore and WebKit loade
r clients. |
78 // It forwards its ThreadableLoaderClient notifications to a WebURLLoaderClient. | 80 // It forwards its ThreadableLoaderClient notifications to a WebURLLoaderClient. |
79 class AssociatedURLLoader::ClientAdapter final : public DocumentThreadableLoader
Client { | 81 class AssociatedURLLoader::ClientAdapter final : public DocumentThreadableLoader
Client { |
80 WTF_MAKE_NONCOPYABLE(ClientAdapter); | 82 WTF_MAKE_NONCOPYABLE(ClientAdapter); |
81 public: | 83 public: |
82 static PassOwnPtr<ClientAdapter> create(AssociatedURLLoader*, WebURLLoaderCl
ient*, const WebURLLoaderOptions&); | 84 static std::unique_ptr<ClientAdapter> create(AssociatedURLLoader*, WebURLLoa
derClient*, const WebURLLoaderOptions&); |
83 | 85 |
84 // ThreadableLoaderClient | 86 // ThreadableLoaderClient |
85 void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*tota
lBytesToBeSent*/) override; | 87 void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*tota
lBytesToBeSent*/) override; |
86 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W
ebDataConsumerHandle>) override; | 88 void didReceiveResponse(unsigned long, const ResourceResponse&, std::unique_
ptr<WebDataConsumerHandle>) override; |
87 void didDownloadData(int /*dataLength*/) override; | 89 void didDownloadData(int /*dataLength*/) override; |
88 void didReceiveData(const char*, unsigned /*dataLength*/) override; | 90 void didReceiveData(const char*, unsigned /*dataLength*/) override; |
89 void didReceiveCachedMetadata(const char*, int /*dataLength*/) override; | 91 void didReceiveCachedMetadata(const char*, int /*dataLength*/) override; |
90 void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/) o
verride; | 92 void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/) o
verride; |
91 void didFail(const ResourceError&) override; | 93 void didFail(const ResourceError&) override; |
92 void didFailRedirectCheck() override; | 94 void didFailRedirectCheck() override; |
93 // DocumentThreadableLoaderClient | 95 // DocumentThreadableLoaderClient |
94 void willFollowRedirect(ResourceRequest& /*newRequest*/, const ResourceRespo
nse& /*redirectResponse*/) override; | 96 void willFollowRedirect(ResourceRequest& /*newRequest*/, const ResourceRespo
nse& /*redirectResponse*/) override; |
95 | 97 |
96 // Sets an error to be reported back to the client, asychronously. | 98 // Sets an error to be reported back to the client, asychronously. |
(...skipping 19 matching lines...) Expand all Loading... |
116 AssociatedURLLoader* m_loader; | 118 AssociatedURLLoader* m_loader; |
117 WebURLLoaderClient* m_client; | 119 WebURLLoaderClient* m_client; |
118 WebURLLoaderOptions m_options; | 120 WebURLLoaderOptions m_options; |
119 WebURLError m_error; | 121 WebURLError m_error; |
120 | 122 |
121 Timer<ClientAdapter> m_errorTimer; | 123 Timer<ClientAdapter> m_errorTimer; |
122 bool m_enableErrorNotifications; | 124 bool m_enableErrorNotifications; |
123 bool m_didFail; | 125 bool m_didFail; |
124 }; | 126 }; |
125 | 127 |
126 PassOwnPtr<AssociatedURLLoader::ClientAdapter> AssociatedURLLoader::ClientAdapte
r::create(AssociatedURLLoader* loader, WebURLLoaderClient* client, const WebURLL
oaderOptions& options) | 128 std::unique_ptr<AssociatedURLLoader::ClientAdapter> AssociatedURLLoader::ClientA
dapter::create(AssociatedURLLoader* loader, WebURLLoaderClient* client, const We
bURLLoaderOptions& options) |
127 { | 129 { |
128 return adoptPtr(new ClientAdapter(loader, client, options)); | 130 return wrapUnique(new ClientAdapter(loader, client, options)); |
129 } | 131 } |
130 | 132 |
131 AssociatedURLLoader::ClientAdapter::ClientAdapter(AssociatedURLLoader* loader, W
ebURLLoaderClient* client, const WebURLLoaderOptions& options) | 133 AssociatedURLLoader::ClientAdapter::ClientAdapter(AssociatedURLLoader* loader, W
ebURLLoaderClient* client, const WebURLLoaderOptions& options) |
132 : m_loader(loader) | 134 : m_loader(loader) |
133 , m_client(client) | 135 , m_client(client) |
134 , m_options(options) | 136 , m_options(options) |
135 , m_errorTimer(this, &ClientAdapter::notifyError) | 137 , m_errorTimer(this, &ClientAdapter::notifyError) |
136 , m_enableErrorNotifications(false) | 138 , m_enableErrorNotifications(false) |
137 , m_didFail(false) | 139 , m_didFail(false) |
138 { | 140 { |
(...skipping 12 matching lines...) Expand all Loading... |
151 } | 153 } |
152 | 154 |
153 void AssociatedURLLoader::ClientAdapter::didSendData(unsigned long long bytesSen
t, unsigned long long totalBytesToBeSent) | 155 void AssociatedURLLoader::ClientAdapter::didSendData(unsigned long long bytesSen
t, unsigned long long totalBytesToBeSent) |
154 { | 156 { |
155 if (!m_client) | 157 if (!m_client) |
156 return; | 158 return; |
157 | 159 |
158 m_client->didSendData(m_loader, bytesSent, totalBytesToBeSent); | 160 m_client->didSendData(m_loader, bytesSent, totalBytesToBeSent); |
159 } | 161 } |
160 | 162 |
161 void AssociatedURLLoader::ClientAdapter::didReceiveResponse(unsigned long, const
ResourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle) | 163 void AssociatedURLLoader::ClientAdapter::didReceiveResponse(unsigned long, const
ResourceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) |
162 { | 164 { |
163 ASSERT_UNUSED(handle, !handle); | 165 ASSERT_UNUSED(handle, !handle); |
164 if (!m_client) | 166 if (!m_client) |
165 return; | 167 return; |
166 | 168 |
167 if (m_options.exposeAllResponseHeaders || m_options.crossOriginRequestPolicy
!= WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl) { | 169 if (m_options.exposeAllResponseHeaders || m_options.crossOriginRequestPolicy
!= WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl) { |
168 // Use the original ResourceResponse. | 170 // Use the original ResourceResponse. |
169 m_client->didReceiveResponse(m_loader, WrappedResourceResponse(response)
); | 171 m_client->didReceiveResponse(m_loader, WrappedResourceResponse(response)
); |
170 return; | 172 return; |
171 } | 173 } |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 // there could be a WebURLLoader instance behind the | 451 // there could be a WebURLLoader instance behind the |
450 // DocumentThreadableLoader instance. So, for safety, we chose to just | 452 // DocumentThreadableLoader instance. So, for safety, we chose to just |
451 // crash here. | 453 // crash here. |
452 RELEASE_ASSERT(ThreadState::current()); | 454 RELEASE_ASSERT(ThreadState::current()); |
453 | 455 |
454 m_observer->dispose(); | 456 m_observer->dispose(); |
455 m_observer = nullptr; | 457 m_observer = nullptr; |
456 } | 458 } |
457 | 459 |
458 } // namespace blink | 460 } // namespace blink |
OLD | NEW |