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

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

Issue 2586063002: DevTools: Show redirects from navigator.sendBeacon() (Closed)
Patch Set: 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 | « no previous file | 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 void timeout(TimerBase*); 213 void timeout(TimerBase*);
214 214
215 void didFailLoading(LocalFrame*); 215 void didFailLoading(LocalFrame*);
216 216
217 WeakMember<LocalFrame> m_frame; 217 WeakMember<LocalFrame> m_frame;
218 std::unique_ptr<WebURLLoader> m_loader; 218 std::unique_ptr<WebURLLoader> m_loader;
219 Timer<PingLoaderImpl> m_timeout; 219 Timer<PingLoaderImpl> m_timeout;
220 String m_url; 220 String m_url;
221 unsigned long m_identifier; 221 unsigned long m_identifier;
222 SelfKeepAlive<PingLoaderImpl> m_keepAlive; 222 SelfKeepAlive<PingLoaderImpl> m_keepAlive;
223 AtomicString m_initiator;
223 224
224 bool m_isBeacon; 225 bool m_isBeacon;
225 226
226 RefPtr<SecurityOrigin> m_origin; 227 RefPtr<SecurityOrigin> m_origin;
227 CORSEnabled m_corsMode; 228 CORSEnabled m_corsMode;
228 }; 229 };
229 230
230 PingLoaderImpl::PingLoaderImpl(LocalFrame* frame, 231 PingLoaderImpl::PingLoaderImpl(LocalFrame* frame,
231 ResourceRequest& request, 232 ResourceRequest& request,
232 const AtomicString& initiator, 233 const AtomicString& initiator,
233 StoredCredentials credentialsAllowed, 234 StoredCredentials credentialsAllowed,
234 bool isBeacon) 235 bool isBeacon)
235 : m_frame(frame), 236 : m_frame(frame),
236 m_timeout(this, &PingLoaderImpl::timeout), 237 m_timeout(this, &PingLoaderImpl::timeout),
237 m_url(request.url()), 238 m_url(request.url()),
238 m_identifier(createUniqueIdentifier()), 239 m_identifier(createUniqueIdentifier()),
239 m_keepAlive(this), 240 m_keepAlive(this),
241 m_initiator(initiator),
240 m_isBeacon(isBeacon), 242 m_isBeacon(isBeacon),
241 m_origin(frame->document()->getSecurityOrigin()), 243 m_origin(frame->document()->getSecurityOrigin()),
242 m_corsMode(IsCORSEnabled) { 244 m_corsMode(IsCORSEnabled) {
243 const AtomicString contentType = request.httpContentType(); 245 const AtomicString contentType = request.httpContentType();
244 if (!contentType.isNull() && 246 if (!contentType.isNull() &&
245 FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType)) 247 FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType))
246 m_corsMode = NotCORSEnabled; 248 m_corsMode = NotCORSEnabled;
247 249
248 frame->loader().client()->didDispatchPingLoader(request.url()); 250 frame->loader().client()->didDispatchPingLoader(request.url());
249 251
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 m_loader->cancel(); 285 m_loader->cancel();
284 m_loader = nullptr; 286 m_loader = nullptr;
285 } 287 }
286 m_timeout.stop(); 288 m_timeout.stop();
287 m_keepAlive.clear(); 289 m_keepAlive.clear();
288 } 290 }
289 291
290 bool PingLoaderImpl::willFollowRedirect( 292 bool PingLoaderImpl::willFollowRedirect(
291 WebURLRequest& passedNewRequest, 293 WebURLRequest& passedNewRequest,
292 const WebURLResponse& passedRedirectResponse) { 294 const WebURLResponse& passedRedirectResponse) {
293 if (!m_isBeacon) 295 if (m_isBeacon && m_corsMode == IsCORSEnabled) {
294 return true; 296 DCHECK(passedNewRequest.allowStoredCredentials());
295 297
296 if (m_corsMode == NotCORSEnabled) 298 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest());
297 return true; 299 const ResourceResponse& redirectResponse(
300 passedRedirectResponse.toResourceResponse());
298 301
299 DCHECK(passedNewRequest.allowStoredCredentials()); 302 DCHECK(!newRequest.isNull());
303 DCHECK(!redirectResponse.isNull());
300 304
301 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); 305 String errorDescription;
302 const ResourceResponse& redirectResponse( 306 ResourceLoaderOptions options;
303 passedRedirectResponse.toResourceResponse()); 307 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it
308 // on the next time.
309 if (!CrossOriginAccessControl::handleRedirect(
310 m_origin, newRequest, redirectResponse, AllowStoredCredentials,
311 options, errorDescription)) {
312 if (m_frame) {
313 if (m_frame->document()) {
314 m_frame->document()->addConsoleMessage(ConsoleMessage::create(
315 JSMessageSource, ErrorMessageLevel, errorDescription));
316 }
317 }
318 // Cancel the load and self destruct.
319 dispose();
304 320
305 DCHECK(!newRequest.isNull()); 321 return false;
306 DCHECK(!redirectResponse.isNull());
307
308 String errorDescription;
309 ResourceLoaderOptions options;
310 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it
311 // on the next time.
312 if (!CrossOriginAccessControl::handleRedirect(
313 m_origin, newRequest, redirectResponse, AllowStoredCredentials,
314 options, errorDescription)) {
315 if (m_frame) {
316 if (m_frame->document()) {
317 m_frame->document()->addConsoleMessage(ConsoleMessage::create(
318 JSMessageSource, ErrorMessageLevel, errorDescription));
319 }
320 } 322 }
321 // Cancel the load and self destruct.
322 dispose();
323
324 return false;
325 } 323 }
326 // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of 324 // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of
327 // Origin: following this successful redirect. 325 // Origin: following this successful redirect.
328 326
327 if (m_frame && m_frame->document()) {
allada 2016/12/20 02:35:54 nit: I am not sure about code style for this area,
ahmetemirercin 2016/12/20 07:09:07 It seems line 312 is result of this refactoring bu
328 FetchInitiatorInfo initiatorInfo;
329 initiatorInfo.name = m_initiator;
330 FetchContext& fetchContext = m_frame->document()->fetcher()->context();
331 fetchContext.dispatchWillSendRequest(
332 m_identifier, passedNewRequest.toMutableResourceRequest(),
333 passedRedirectResponse.toResourceResponse(), initiatorInfo);
334 }
335
329 return true; 336 return true;
330 } 337 }
331 338
332 void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) { 339 void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) {
333 if (m_frame) { 340 if (m_frame) {
334 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", 341 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data",
335 InspectorResourceFinishEvent::data(m_identifier, 0, true)); 342 InspectorResourceFinishEvent::data(m_identifier, 0, true));
336 const ResourceResponse& resourceResponse = response.toResourceResponse(); 343 const ResourceResponse& resourceResponse = response.toResourceResponse();
337 InspectorInstrumentation::didReceiveResourceResponse( 344 InspectorInstrumentation::didReceiveResourceResponse(
338 m_frame, m_identifier, 0, resourceResponse, 0); 345 m_frame, m_identifier, 0, resourceResponse, 0);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 bool PingLoader::sendBeacon(LocalFrame* frame, 559 bool PingLoader::sendBeacon(LocalFrame* frame,
553 int allowance, 560 int allowance,
554 const KURL& beaconURL, 561 const KURL& beaconURL,
555 Blob* data, 562 Blob* data,
556 int& payloadLength) { 563 int& payloadLength) {
557 BeaconBlob beacon(data); 564 BeaconBlob beacon(data);
558 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); 565 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength);
559 } 566 }
560 567
561 } // namespace blink 568 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698