Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: third_party/WebKit/Source/web/AssociatedURLLoader.cpp

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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"
52 #include "wtf/text/WTFString.h" 51 #include "wtf/text/WTFString.h"
53 #include <limits.h> 52 #include <limits.h>
54 #include <memory>
55 53
56 namespace blink { 54 namespace blink {
57 55
58 namespace { 56 namespace {
59 57
60 class HTTPRequestHeaderValidator : public WebHTTPHeaderVisitor { 58 class HTTPRequestHeaderValidator : public WebHTTPHeaderVisitor {
61 WTF_MAKE_NONCOPYABLE(HTTPRequestHeaderValidator); 59 WTF_MAKE_NONCOPYABLE(HTTPRequestHeaderValidator);
62 public: 60 public:
63 HTTPRequestHeaderValidator() : m_isSafe(true) { } 61 HTTPRequestHeaderValidator() : m_isSafe(true) { }
64 62
65 void visitHeader(const WebString& name, const WebString& value); 63 void visitHeader(const WebString& name, const WebString& value);
66 bool isSafe() const { return m_isSafe; } 64 bool isSafe() const { return m_isSafe; }
67 65
68 private: 66 private:
69 bool m_isSafe; 67 bool m_isSafe;
70 }; 68 };
71 69
72 void HTTPRequestHeaderValidator::visitHeader(const WebString& name, const WebStr ing& value) 70 void HTTPRequestHeaderValidator::visitHeader(const WebString& name, const WebStr ing& value)
73 { 71 {
74 m_isSafe = m_isSafe && isValidHTTPToken(name) && !FetchUtils::isForbiddenHea derName(name) && isValidHTTPHeaderValue(value); 72 m_isSafe = m_isSafe && isValidHTTPToken(name) && !FetchUtils::isForbiddenHea derName(name) && isValidHTTPHeaderValue(value);
75 } 73 }
76 74
77 } // namespace 75 } // namespace
78 76
79 // This class bridges the interface differences between WebCore and WebKit loade r clients. 77 // This class bridges the interface differences between WebCore and WebKit loade r clients.
80 // It forwards its ThreadableLoaderClient notifications to a WebURLLoaderClient. 78 // It forwards its ThreadableLoaderClient notifications to a WebURLLoaderClient.
81 class AssociatedURLLoader::ClientAdapter final : public DocumentThreadableLoader Client { 79 class AssociatedURLLoader::ClientAdapter final : public DocumentThreadableLoader Client {
82 WTF_MAKE_NONCOPYABLE(ClientAdapter); 80 WTF_MAKE_NONCOPYABLE(ClientAdapter);
83 public: 81 public:
84 static std::unique_ptr<ClientAdapter> create(AssociatedURLLoader*, WebURLLoa derClient*, const WebURLLoaderOptions&); 82 static PassOwnPtr<ClientAdapter> create(AssociatedURLLoader*, WebURLLoaderCl ient*, const WebURLLoaderOptions&);
85 83
86 // ThreadableLoaderClient 84 // ThreadableLoaderClient
87 void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*tota lBytesToBeSent*/) override; 85 void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*tota lBytesToBeSent*/) override;
88 void didReceiveResponse(unsigned long, const ResourceResponse&, std::unique_ ptr<WebDataConsumerHandle>) override; 86 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W ebDataConsumerHandle>) override;
89 void didDownloadData(int /*dataLength*/) override; 87 void didDownloadData(int /*dataLength*/) override;
90 void didReceiveData(const char*, unsigned /*dataLength*/) override; 88 void didReceiveData(const char*, unsigned /*dataLength*/) override;
91 void didReceiveCachedMetadata(const char*, int /*dataLength*/) override; 89 void didReceiveCachedMetadata(const char*, int /*dataLength*/) override;
92 void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/) o verride; 90 void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/) o verride;
93 void didFail(const ResourceError&) override; 91 void didFail(const ResourceError&) override;
94 void didFailRedirectCheck() override; 92 void didFailRedirectCheck() override;
95 // DocumentThreadableLoaderClient 93 // DocumentThreadableLoaderClient
96 void willFollowRedirect(ResourceRequest& /*newRequest*/, const ResourceRespo nse& /*redirectResponse*/) override; 94 void willFollowRedirect(ResourceRequest& /*newRequest*/, const ResourceRespo nse& /*redirectResponse*/) override;
97 95
98 // Sets an error to be reported back to the client, asychronously. 96 // Sets an error to be reported back to the client, asychronously.
(...skipping 19 matching lines...) Expand all
118 AssociatedURLLoader* m_loader; 116 AssociatedURLLoader* m_loader;
119 WebURLLoaderClient* m_client; 117 WebURLLoaderClient* m_client;
120 WebURLLoaderOptions m_options; 118 WebURLLoaderOptions m_options;
121 WebURLError m_error; 119 WebURLError m_error;
122 120
123 Timer<ClientAdapter> m_errorTimer; 121 Timer<ClientAdapter> m_errorTimer;
124 bool m_enableErrorNotifications; 122 bool m_enableErrorNotifications;
125 bool m_didFail; 123 bool m_didFail;
126 }; 124 };
127 125
128 std::unique_ptr<AssociatedURLLoader::ClientAdapter> AssociatedURLLoader::ClientA dapter::create(AssociatedURLLoader* loader, WebURLLoaderClient* client, const We bURLLoaderOptions& options) 126 PassOwnPtr<AssociatedURLLoader::ClientAdapter> AssociatedURLLoader::ClientAdapte r::create(AssociatedURLLoader* loader, WebURLLoaderClient* client, const WebURLL oaderOptions& options)
129 { 127 {
130 return wrapUnique(new ClientAdapter(loader, client, options)); 128 return adoptPtr(new ClientAdapter(loader, client, options));
131 } 129 }
132 130
133 AssociatedURLLoader::ClientAdapter::ClientAdapter(AssociatedURLLoader* loader, W ebURLLoaderClient* client, const WebURLLoaderOptions& options) 131 AssociatedURLLoader::ClientAdapter::ClientAdapter(AssociatedURLLoader* loader, W ebURLLoaderClient* client, const WebURLLoaderOptions& options)
134 : m_loader(loader) 132 : m_loader(loader)
135 , m_client(client) 133 , m_client(client)
136 , m_options(options) 134 , m_options(options)
137 , m_errorTimer(this, &ClientAdapter::notifyError) 135 , m_errorTimer(this, &ClientAdapter::notifyError)
138 , m_enableErrorNotifications(false) 136 , m_enableErrorNotifications(false)
139 , m_didFail(false) 137 , m_didFail(false)
140 { 138 {
(...skipping 12 matching lines...) Expand all
153 } 151 }
154 152
155 void AssociatedURLLoader::ClientAdapter::didSendData(unsigned long long bytesSen t, unsigned long long totalBytesToBeSent) 153 void AssociatedURLLoader::ClientAdapter::didSendData(unsigned long long bytesSen t, unsigned long long totalBytesToBeSent)
156 { 154 {
157 if (!m_client) 155 if (!m_client)
158 return; 156 return;
159 157
160 m_client->didSendData(m_loader, bytesSent, totalBytesToBeSent); 158 m_client->didSendData(m_loader, bytesSent, totalBytesToBeSent);
161 } 159 }
162 160
163 void AssociatedURLLoader::ClientAdapter::didReceiveResponse(unsigned long, const ResourceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) 161 void AssociatedURLLoader::ClientAdapter::didReceiveResponse(unsigned long, const ResourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle)
164 { 162 {
165 ASSERT_UNUSED(handle, !handle); 163 ASSERT_UNUSED(handle, !handle);
166 if (!m_client) 164 if (!m_client)
167 return; 165 return;
168 166
169 if (m_options.exposeAllResponseHeaders || m_options.crossOriginRequestPolicy != WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl) { 167 if (m_options.exposeAllResponseHeaders || m_options.crossOriginRequestPolicy != WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl) {
170 // Use the original ResourceResponse. 168 // Use the original ResourceResponse.
171 m_client->didReceiveResponse(m_loader, WrappedResourceResponse(response) ); 169 m_client->didReceiveResponse(m_loader, WrappedResourceResponse(response) );
172 return; 170 return;
173 } 171 }
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 // there could be a WebURLLoader instance behind the 449 // there could be a WebURLLoader instance behind the
452 // DocumentThreadableLoader instance. So, for safety, we chose to just 450 // DocumentThreadableLoader instance. So, for safety, we chose to just
453 // crash here. 451 // crash here.
454 RELEASE_ASSERT(ThreadState::current()); 452 RELEASE_ASSERT(ThreadState::current());
455 453
456 m_observer->dispose(); 454 m_observer->dispose();
457 m_observer = nullptr; 455 m_observer = nullptr;
458 } 456 }
459 457
460 } // namespace blink 458 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/AssociatedURLLoader.h ('k') | third_party/WebKit/Source/web/AssociatedURLLoaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698