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

Side by Side Diff: third_party/WebKit/Source/core/loader/PingLoader.cpp

Issue 2567933003: Remove DOMWindowProperty from PingLoaderImpl (Closed)
Patch Set: temp Created 4 years 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
« no previous file with comments | « third_party/WebKit/Source/core/loader/PingLoader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 21 matching lines...) Expand all
32 #include "core/loader/PingLoader.h" 32 #include "core/loader/PingLoader.h"
33 33
34 #include "core/dom/DOMArrayBufferView.h" 34 #include "core/dom/DOMArrayBufferView.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/SecurityContext.h" 36 #include "core/dom/SecurityContext.h"
37 #include "core/fetch/CrossOriginAccessControl.h" 37 #include "core/fetch/CrossOriginAccessControl.h"
38 #include "core/fetch/FetchContext.h" 38 #include "core/fetch/FetchContext.h"
39 #include "core/fetch/FetchInitiatorTypeNames.h" 39 #include "core/fetch/FetchInitiatorTypeNames.h"
40 #include "core/fetch/FetchUtils.h" 40 #include "core/fetch/FetchUtils.h"
41 #include "core/fetch/ResourceFetcher.h" 41 #include "core/fetch/ResourceFetcher.h"
42 #include "core/fetch/ResourceLoaderOptions.h"
42 #include "core/fetch/UniqueIdentifier.h" 43 #include "core/fetch/UniqueIdentifier.h"
43 #include "core/fileapi/File.h" 44 #include "core/fileapi/File.h"
44 #include "core/frame/FrameConsole.h" 45 #include "core/frame/FrameConsole.h"
45 #include "core/frame/LocalFrame.h" 46 #include "core/frame/LocalFrame.h"
46 #include "core/frame/csp/ContentSecurityPolicy.h" 47 #include "core/frame/csp/ContentSecurityPolicy.h"
47 #include "core/html/FormData.h" 48 #include "core/html/FormData.h"
48 #include "core/inspector/ConsoleMessage.h" 49 #include "core/inspector/ConsoleMessage.h"
49 #include "core/inspector/InspectorInstrumentation.h" 50 #include "core/inspector/InspectorInstrumentation.h"
50 #include "core/inspector/InspectorTraceEvents.h" 51 #include "core/inspector/InspectorTraceEvents.h"
51 #include "core/loader/FrameLoader.h" 52 #include "core/loader/FrameLoader.h"
52 #include "core/loader/FrameLoaderClient.h" 53 #include "core/loader/FrameLoaderClient.h"
53 #include "core/loader/MixedContentChecker.h" 54 #include "core/loader/MixedContentChecker.h"
54 #include "core/page/Page.h" 55 #include "core/page/Page.h"
56 #include "platform/Timer.h"
55 #include "platform/WebFrameScheduler.h" 57 #include "platform/WebFrameScheduler.h"
56 #include "platform/exported/WrappedResourceRequest.h" 58 #include "platform/exported/WrappedResourceRequest.h"
57 #include "platform/exported/WrappedResourceResponse.h" 59 #include "platform/exported/WrappedResourceResponse.h"
60 #include "platform/heap/Handle.h"
61 #include "platform/heap/SelfKeepAlive.h"
58 #include "platform/network/EncodedFormData.h" 62 #include "platform/network/EncodedFormData.h"
59 #include "platform/network/ParsedContentType.h" 63 #include "platform/network/ParsedContentType.h"
60 #include "platform/network/ResourceError.h" 64 #include "platform/network/ResourceError.h"
61 #include "platform/network/ResourceRequest.h" 65 #include "platform/network/ResourceRequest.h"
62 #include "platform/network/ResourceResponse.h" 66 #include "platform/network/ResourceResponse.h"
63 #include "platform/weborigin/SecurityOrigin.h" 67 #include "platform/weborigin/SecurityOrigin.h"
64 #include "platform/weborigin/SecurityPolicy.h" 68 #include "platform/weborigin/SecurityPolicy.h"
65 #include "public/platform/Platform.h" 69 #include "public/platform/Platform.h"
66 #include "public/platform/WebURLLoader.h" 70 #include "public/platform/WebURLLoader.h"
71 #include "public/platform/WebURLLoaderClient.h"
67 #include "public/platform/WebURLRequest.h" 72 #include "public/platform/WebURLRequest.h"
68 #include "public/platform/WebURLResponse.h" 73 #include "public/platform/WebURLResponse.h"
69 #include "wtf/Compiler.h" 74 #include "wtf/Compiler.h"
70 #include "wtf/Functional.h" 75 #include "wtf/Functional.h"
76 #include "wtf/Noncopyable.h"
71 #include "wtf/PtrUtil.h" 77 #include "wtf/PtrUtil.h"
72 78
73 namespace blink { 79 namespace blink {
74 80
75 namespace { 81 namespace {
76 82
77 class Beacon { 83 class Beacon {
78 STACK_ALLOCATED(); 84 STACK_ALLOCATED();
79 85
80 public: 86 public:
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 186
181 const AtomicString getContentType() const { return m_contentType; } 187 const AtomicString getContentType() const { return m_contentType; }
182 188
183 private: 189 private:
184 const Member<FormData> m_data; 190 const Member<FormData> m_data;
185 RefPtr<EncodedFormData> m_entityBody; 191 RefPtr<EncodedFormData> m_entityBody;
186 AtomicString m_contentType; 192 AtomicString m_contentType;
187 }; 193 };
188 194
189 class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>, 195 class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>,
190 public DOMWindowProperty,
191 private WebURLLoaderClient { 196 private WebURLLoaderClient {
192 USING_GARBAGE_COLLECTED_MIXIN(PingLoaderImpl);
193 WTF_MAKE_NONCOPYABLE(PingLoaderImpl); 197 WTF_MAKE_NONCOPYABLE(PingLoaderImpl);
194 198
195 public: 199 public:
196 PingLoaderImpl(LocalFrame*, 200 PingLoaderImpl(LocalFrame*,
197 ResourceRequest&, 201 ResourceRequest&,
198 const AtomicString&, 202 const AtomicString&,
199 StoredCredentials, 203 StoredCredentials,
200 bool); 204 bool);
201 ~PingLoaderImpl() override; 205 ~PingLoaderImpl() override;
202 206
203 DECLARE_VIRTUAL_TRACE(); 207 DECLARE_VIRTUAL_TRACE();
204 208
205 private: 209 private:
206 void dispose(); 210 void dispose();
207 211
208 // WebURLLoaderClient 212 // WebURLLoaderClient
209 bool willFollowRedirect(WebURLRequest&, const WebURLResponse&) override; 213 bool willFollowRedirect(WebURLRequest&, const WebURLResponse&) override;
210 void didReceiveResponse(const WebURLResponse&) final; 214 void didReceiveResponse(const WebURLResponse&) final;
211 void didReceiveData(const char*, int) final; 215 void didReceiveData(const char*, int) final;
212 void didFinishLoading(double, int64_t, int64_t) final; 216 void didFinishLoading(double, int64_t, int64_t) final;
213 void didFail(const WebURLError&, int64_t, int64_t) final; 217 void didFail(const WebURLError&, int64_t, int64_t) final;
214 218
215 void timeout(TimerBase*); 219 void timeout(TimerBase*);
216 220
217 void didFailLoading(LocalFrame*); 221 void didFailLoading(LocalFrame*);
218 222
223 WeakMember<LocalFrame> m_frame;
219 std::unique_ptr<WebURLLoader> m_loader; 224 std::unique_ptr<WebURLLoader> m_loader;
220 Timer<PingLoaderImpl> m_timeout; 225 Timer<PingLoaderImpl> m_timeout;
221 String m_url; 226 String m_url;
222 unsigned long m_identifier; 227 unsigned long m_identifier;
223 SelfKeepAlive<PingLoaderImpl> m_keepAlive; 228 SelfKeepAlive<PingLoaderImpl> m_keepAlive;
224 229
225 bool m_isBeacon; 230 bool m_isBeacon;
226 231
227 RefPtr<SecurityOrigin> m_origin; 232 RefPtr<SecurityOrigin> m_origin;
228 CORSEnabled m_corsMode; 233 CORSEnabled m_corsMode;
229 }; 234 };
230 235
231 PingLoaderImpl::PingLoaderImpl(LocalFrame* frame, 236 PingLoaderImpl::PingLoaderImpl(LocalFrame* frame,
232 ResourceRequest& request, 237 ResourceRequest& request,
233 const AtomicString& initiator, 238 const AtomicString& initiator,
234 StoredCredentials credentialsAllowed, 239 StoredCredentials credentialsAllowed,
235 bool isBeacon) 240 bool isBeacon)
236 : DOMWindowProperty(frame), 241 : m_frame(frame),
237 m_timeout(this, &PingLoaderImpl::timeout), 242 m_timeout(this, &PingLoaderImpl::timeout),
238 m_url(request.url()), 243 m_url(request.url()),
239 m_identifier(createUniqueIdentifier()), 244 m_identifier(createUniqueIdentifier()),
240 m_keepAlive(this), 245 m_keepAlive(this),
241 m_isBeacon(isBeacon), 246 m_isBeacon(isBeacon),
242 m_origin(frame->document()->getSecurityOrigin()), 247 m_origin(frame->document()->getSecurityOrigin()),
243 m_corsMode(IsCORSEnabled) { 248 m_corsMode(IsCORSEnabled) {
244 const AtomicString contentType = request.httpContentType(); 249 const AtomicString contentType = request.httpContentType();
245 if (!contentType.isNull() && 250 if (!contentType.isNull() &&
246 FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType)) 251 FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType))
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 DCHECK(!newRequest.isNull()); 311 DCHECK(!newRequest.isNull());
307 DCHECK(!redirectResponse.isNull()); 312 DCHECK(!redirectResponse.isNull());
308 313
309 String errorDescription; 314 String errorDescription;
310 ResourceLoaderOptions options; 315 ResourceLoaderOptions options;
311 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it 316 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it
312 // on the next time. 317 // on the next time.
313 if (!CrossOriginAccessControl::handleRedirect( 318 if (!CrossOriginAccessControl::handleRedirect(
314 m_origin, newRequest, redirectResponse, AllowStoredCredentials, 319 m_origin, newRequest, redirectResponse, AllowStoredCredentials,
315 options, errorDescription)) { 320 options, errorDescription)) {
316 if (LocalFrame* localFrame = frame()) { 321 if (m_frame) {
317 if (localFrame->document()) { 322 if (Document* document = m_frame->document()) {
318 localFrame->document()->addConsoleMessage(ConsoleMessage::create( 323 document->addConsoleMessage(ConsoleMessage::create(
319 JSMessageSource, ErrorMessageLevel, errorDescription)); 324 JSMessageSource, ErrorMessageLevel, errorDescription));
320 } 325 }
321 } 326 }
322 // Cancel the load and self destruct. 327 // Cancel the load and self destruct.
323 dispose(); 328 dispose();
324 329
325 return false; 330 return false;
326 } 331 }
327 // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of 332 // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of
328 // Origin: following this successful redirect. 333 // Origin: following this successful redirect.
329 334
330 return true; 335 return true;
331 } 336 }
332 337
333 void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) { 338 void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) {
334 if (LocalFrame* frame = this->frame()) { 339 if (m_frame) {
335 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", 340 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data",
336 InspectorResourceFinishEvent::data(m_identifier, 0, true)); 341 InspectorResourceFinishEvent::data(m_identifier, 0, true));
337 const ResourceResponse& resourceResponse = response.toResourceResponse(); 342 const ResourceResponse& resourceResponse = response.toResourceResponse();
338 InspectorInstrumentation::didReceiveResourceResponse(frame, m_identifier, 0, 343 InspectorInstrumentation::didReceiveResourceResponse(
339 resourceResponse, 0); 344 m_frame, m_identifier, 0, resourceResponse, 0);
340 didFailLoading(frame); 345 didFailLoading(m_frame);
341 } 346 }
342 dispose(); 347 dispose();
343 } 348 }
344 349
345 void PingLoaderImpl::didReceiveData(const char*, int) { 350 void PingLoaderImpl::didReceiveData(const char*, int) {
346 if (LocalFrame* frame = this->frame()) { 351 if (m_frame) {
347 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", 352 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data",
348 InspectorResourceFinishEvent::data(m_identifier, 0, true)); 353 InspectorResourceFinishEvent::data(m_identifier, 0, true));
349 didFailLoading(frame); 354 didFailLoading(m_frame);
350 } 355 }
351 dispose(); 356 dispose();
352 } 357 }
353 358
354 void PingLoaderImpl::didFinishLoading(double, int64_t, int64_t) { 359 void PingLoaderImpl::didFinishLoading(double, int64_t, int64_t) {
355 if (LocalFrame* frame = this->frame()) { 360 if (m_frame) {
356 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", 361 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data",
357 InspectorResourceFinishEvent::data(m_identifier, 0, true)); 362 InspectorResourceFinishEvent::data(m_identifier, 0, true));
358 didFailLoading(frame); 363 didFailLoading(m_frame);
359 } 364 }
360 dispose(); 365 dispose();
361 } 366 }
362 367
363 void PingLoaderImpl::didFail(const WebURLError& resourceError, 368 void PingLoaderImpl::didFail(const WebURLError& resourceError,
364 int64_t, 369 int64_t,
365 int64_t) { 370 int64_t) {
366 if (LocalFrame* frame = this->frame()) { 371 if (m_frame) {
367 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", 372 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data",
368 InspectorResourceFinishEvent::data(m_identifier, 0, true)); 373 InspectorResourceFinishEvent::data(m_identifier, 0, true));
369 didFailLoading(frame); 374 didFailLoading(m_frame);
370 } 375 }
371 dispose(); 376 dispose();
372 } 377 }
373 378
374 void PingLoaderImpl::timeout(TimerBase*) { 379 void PingLoaderImpl::timeout(TimerBase*) {
375 if (LocalFrame* frame = this->frame()) { 380 if (m_frame) {
376 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", 381 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data",
377 InspectorResourceFinishEvent::data(m_identifier, 0, true)); 382 InspectorResourceFinishEvent::data(m_identifier, 0, true));
378 didFailLoading(frame); 383 didFailLoading(m_frame);
379 } 384 }
380 dispose(); 385 dispose();
381 } 386 }
382 387
383 void PingLoaderImpl::didFailLoading(LocalFrame* frame) { 388 void PingLoaderImpl::didFailLoading(LocalFrame* frame) {
384 InspectorInstrumentation::didFailLoading( 389 InspectorInstrumentation::didFailLoading(
385 frame, m_identifier, ResourceError::cancelledError(m_url)); 390 frame, m_identifier, ResourceError::cancelledError(m_url));
386 frame->console().didFailLoading(m_identifier, 391 frame->console().didFailLoading(m_identifier,
387 ResourceError::cancelledError(m_url)); 392 ResourceError::cancelledError(m_url));
388 } 393 }
389 394
390 DEFINE_TRACE(PingLoaderImpl) { 395 DEFINE_TRACE(PingLoaderImpl) {
391 DOMWindowProperty::trace(visitor); 396 visitor->trace(m_frame);
392 } 397 }
393 398
394 void finishPingRequestInitialization( 399 void finishPingRequestInitialization(
395 ResourceRequest& request, 400 ResourceRequest& request,
396 LocalFrame* frame, 401 LocalFrame* frame,
397 WebURLRequest::RequestContext requestContext) { 402 WebURLRequest::RequestContext requestContext) {
398 request.setRequestContext(requestContext); 403 request.setRequestContext(requestContext);
399 FetchContext& fetchContext = frame->document()->fetcher()->context(); 404 FetchContext& fetchContext = frame->document()->fetcher()->context();
400 fetchContext.addAdditionalRequestHeaders(request, FetchSubresource); 405 fetchContext.addAdditionalRequestHeaders(request, FetchSubresource);
401 fetchContext.populateRequestData(request); 406 fetchContext.populateRequestData(request);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 bool PingLoader::sendBeacon(LocalFrame* frame, 558 bool PingLoader::sendBeacon(LocalFrame* frame,
554 int allowance, 559 int allowance,
555 const KURL& beaconURL, 560 const KURL& beaconURL,
556 Blob* data, 561 Blob* data,
557 int& payloadLength) { 562 int& payloadLength) {
558 BeaconBlob beacon(data); 563 BeaconBlob beacon(data);
559 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); 564 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength);
560 } 565 }
561 566
562 } // namespace blink 567 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/PingLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698