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

Side by Side Diff: Source/core/inspector/InspectorResourceAgent.cpp

Issue 1179903003: [DevTools] Log failed XHR requests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 490
491 if (client == m_pendingEventSource) { 491 if (client == m_pendingEventSource) {
492 m_eventSourceRequestIdMap.set(client, identifier); 492 m_eventSourceRequestIdMap.set(client, identifier);
493 m_pendingEventSource = nullptr; 493 m_pendingEventSource = nullptr;
494 } 494 }
495 495
496 if (client == m_pendingXHR) { 496 if (client == m_pendingXHR) {
497 String requestId = IdentifiersFactory::requestId(identifier); 497 String requestId = IdentifiersFactory::requestId(identifier);
498 m_resourcesData->setResourceType(requestId, InspectorPageAgent::XHRResou rce); 498 m_resourcesData->setResourceType(requestId, InspectorPageAgent::XHRResou rce);
499 m_resourcesData->setXHRReplayData(requestId, m_pendingXHRReplayData.get( )); 499 m_resourcesData->setXHRReplayData(requestId, m_pendingXHRReplayData.get( ));
500 m_xhrRequestIdMap.set(client, identifier);
500 m_pendingXHR = nullptr; 501 m_pendingXHR = nullptr;
501 m_pendingXHRReplayData.clear(); 502 m_pendingXHRReplayData.clear();
502 } 503 }
503 } 504 }
504 505
505 void InspectorResourceAgent::willLoadXHR(XMLHttpRequest* xhr, ThreadableLoaderCl ient* client, const AtomicString& method, const KURL& url, bool async, PassRefPt r<FormData> formData, const HTTPHeaderMap& headers, bool includeCredentials) 506 void InspectorResourceAgent::willLoadXHR(XMLHttpRequest* xhr, ThreadableLoaderCl ient* client, const AtomicString& method, const KURL& url, bool async, PassRefPt r<FormData> formData, const HTTPHeaderMap& headers, bool includeCredentials)
506 { 507 {
507 ASSERT(xhr); 508 ASSERT(xhr);
508 m_pendingXHR = client; 509 m_pendingXHR = client;
509 m_pendingXHRReplayData = XHRReplayData::create(xhr->executionContext(), meth od, urlWithoutFragment(url), async, formData.get(), includeCredentials); 510 m_pendingXHRReplayData = XHRReplayData::create(xhr->executionContext(), meth od, urlWithoutFragment(url), async, formData.get(), includeCredentials);
510 for (const auto& header : headers) 511 for (const auto& header : headers)
511 m_pendingXHRReplayData->addHeader(header.key, header.value); 512 m_pendingXHRReplayData->addHeader(header.key, header.value);
512 } 513 }
513 514
514 void InspectorResourceAgent::delayedRemoveReplayXHR(XMLHttpRequest* xhr) 515 void InspectorResourceAgent::delayedRemoveReplayXHR(XMLHttpRequest* xhr)
515 { 516 {
516 if (!m_replayXHRs.contains(xhr)) 517 if (!m_replayXHRs.contains(xhr))
517 return; 518 return;
518 519
519 m_replayXHRsToBeDeleted.add(xhr); 520 m_replayXHRsToBeDeleted.add(xhr);
520 m_replayXHRs.remove(xhr); 521 m_replayXHRs.remove(xhr);
521 m_removeFinishedReplayXHRTimer.startOneShot(0, FROM_HERE); 522 m_removeFinishedReplayXHRTimer.startOneShot(0, FROM_HERE);
522 } 523 }
523 524
524 void InspectorResourceAgent::didFailXHRLoading(XMLHttpRequest* xhr, ThreadableLo aderClient* client) 525 void InspectorResourceAgent::didFailXHRLoading(ExecutionContext* context, XMLHtt pRequest* xhr, ThreadableLoaderClient* client, const AtomicString& method, const String& url)
526 {
527 didFinishXHRInternal(context, xhr, client, method, url, false);
528 }
529
530 void InspectorResourceAgent::didFinishXHRLoading(ExecutionContext* context, XMLH ttpRequest* xhr, ThreadableLoaderClient* client, const AtomicString& method, con st String& url)
531 {
532 didFinishXHRInternal(context, xhr, client, method, url, true);
533 }
534
535 void InspectorResourceAgent::didFinishXHRInternal(ExecutionContext* context, XML HttpRequest* xhr, ThreadableLoaderClient* client, const AtomicString& method, co nst String& url, bool success)
525 { 536 {
526 m_pendingXHR = nullptr; 537 m_pendingXHR = nullptr;
527 m_pendingXHRReplayData.clear(); 538 m_pendingXHRReplayData.clear();
528 539
529 // This method will be called from the XHR. 540 // This method will be called from the XHR.
530 // We delay deleting the replay XHR, as deleting here may delete the caller. 541 // We delay deleting the replay XHR, as deleting here may delete the caller.
531 delayedRemoveReplayXHR(xhr); 542 delayedRemoveReplayXHR(xhr);
532 }
533 543
534 void InspectorResourceAgent::didFinishXHRLoading(ExecutionContext* context, XMLH ttpRequest* xhr, ThreadableLoaderClient* client, unsigned long identifier, Scrip tString sourceString, const AtomicString& method, const String& url) 544 ThreadableLoaderClientRequestIdMap::iterator it = m_xhrRequestIdMap.find(cli ent);
535 {
536 m_pendingXHR = nullptr;
537 m_pendingXHRReplayData.clear();
538 545
539 // See comments on |didFailXHRLoading| for why we are delaying delete. 546 if (m_state->getBoolean(ResourceAgentState::monitoringXHR) && it != m_eventS ourceRequestIdMap.end()) {
540 delayedRemoveReplayXHR(xhr); 547 String message = (success ? "XHR finished loading: " : "XHR failed loadi ng: ") + method + " \"" + url + "\".";
541
542 if (m_state->getBoolean(ResourceAgentState::monitoringXHR)) {
543 String message = "XHR finished loading: " + method + " \"" + url + "\"." ;
544 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::crea te(NetworkMessageSource, DebugMessageLevel, message); 548 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::crea te(NetworkMessageSource, DebugMessageLevel, message);
545 consoleMessage->setRequestIdentifier(identifier); 549 consoleMessage->setRequestIdentifier(it->value);
546 m_pageAgent->frameHost()->consoleMessageStorage().reportMessage(context, consoleMessage.release()); 550 m_pageAgent->frameHost()->consoleMessageStorage().reportMessage(context, consoleMessage.release());
547 } 551 }
552
553 m_xhrRequestIdMap.remove(client);
548 } 554 }
549 555
550 void InspectorResourceAgent::willSendEventSourceRequest(ThreadableLoaderClient* eventSource) 556 void InspectorResourceAgent::willSendEventSourceRequest(ThreadableLoaderClient* eventSource)
551 { 557 {
552 m_pendingEventSource = eventSource; 558 m_pendingEventSource = eventSource;
553 } 559 }
554 560
555 void InspectorResourceAgent::willDispachEventSourceEvent(ThreadableLoaderClient* eventSource, const AtomicString& eventName, const AtomicString& eventId, const Vector<UChar>& data) 561 void InspectorResourceAgent::willDispachEventSourceEvent(ThreadableLoaderClient* eventSource, const AtomicString& eventName, const AtomicString& eventId, const Vector<UChar>& data)
556 { 562 {
557 EventSourceRequestIdMap::iterator it = m_eventSourceRequestIdMap.find(eventS ource); 563 ThreadableLoaderClientRequestIdMap::iterator it = m_eventSourceRequestIdMap. find(eventSource);
558 if (it == m_eventSourceRequestIdMap.end()) 564 if (it == m_eventSourceRequestIdMap.end())
559 return; 565 return;
560 frontend()->eventSourceMessageReceived(IdentifiersFactory::requestId(it->val ue), monotonicallyIncreasingTime(), eventName.string(), eventId.string(), String (data)); 566 frontend()->eventSourceMessageReceived(IdentifiersFactory::requestId(it->val ue), monotonicallyIncreasingTime(), eventName.string(), eventId.string(), String (data));
561 } 567 }
562 568
563 void InspectorResourceAgent::didFinishEventSourceRequest(ThreadableLoaderClient* eventSource) 569 void InspectorResourceAgent::didFinishEventSourceRequest(ThreadableLoaderClient* eventSource)
564 { 570 {
565 m_eventSourceRequestIdMap.remove(eventSource); 571 m_eventSourceRequestIdMap.remove(eventSource);
566 if (eventSource == m_pendingEventSource) 572 if (eventSource == m_pendingEventSource)
567 m_pendingEventSource = nullptr; 573 m_pendingEventSource = nullptr;
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish edReplayXHRFired) 924 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish edReplayXHRFired)
919 { 925 {
920 } 926 }
921 927
922 bool InspectorResourceAgent::shouldForceCORSPreflight() 928 bool InspectorResourceAgent::shouldForceCORSPreflight()
923 { 929 {
924 return m_state->getBoolean(ResourceAgentState::cacheDisabled); 930 return m_state->getBoolean(ResourceAgentState::cacheDisabled);
925 } 931 }
926 932
927 } // namespace blink 933 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorResourceAgent.h ('k') | Source/core/xmlhttprequest/XMLHttpRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698