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

Side by Side Diff: third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp

Issue 2800213002: Avoid duplicate functions/code in core/inspector.
Patch Set: Manual inlined urlWithoutFragment Created 3 years, 4 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) 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
201 201
202 RefPtr<BlobDataHandle> blob_; 202 RefPtr<BlobDataHandle> blob_;
203 String mime_type_; 203 String mime_type_;
204 String text_encoding_name_; 204 String text_encoding_name_;
205 std::unique_ptr<GetResponseBodyCallback> callback_; 205 std::unique_ptr<GetResponseBodyCallback> callback_;
206 std::unique_ptr<FileReaderLoader> loader_; 206 std::unique_ptr<FileReaderLoader> loader_;
207 RefPtr<SharedBuffer> raw_data_; 207 RefPtr<SharedBuffer> raw_data_;
208 }; 208 };
209 209
210 KURL UrlWithoutFragment(const KURL& url) {
211 KURL result = url;
212 result.RemoveFragmentIdentifier();
213 return result;
214 }
215
216 String MixedContentTypeForContextType(WebMixedContentContextType context_type) { 210 String MixedContentTypeForContextType(WebMixedContentContextType context_type) {
217 switch (context_type) { 211 switch (context_type) {
218 case WebMixedContentContextType::kNotMixedContent: 212 case WebMixedContentContextType::kNotMixedContent:
219 return protocol::Security::MixedContentTypeEnum::None; 213 return protocol::Security::MixedContentTypeEnum::None;
220 case WebMixedContentContextType::kBlockable: 214 case WebMixedContentContextType::kBlockable:
221 return protocol::Security::MixedContentTypeEnum::Blockable; 215 return protocol::Security::MixedContentTypeEnum::Blockable;
222 case WebMixedContentContextType::kOptionallyBlockable: 216 case WebMixedContentContextType::kOptionallyBlockable:
223 case WebMixedContentContextType::kShouldBeBlockable: 217 case WebMixedContentContextType::kShouldBeBlockable:
224 return protocol::Security::MixedContentTypeEnum::OptionallyBlockable; 218 return protocol::Security::MixedContentTypeEnum::OptionallyBlockable;
225 } 219 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 .setSendEnd(timing.CalculateMillisecondDelta(timing.SendEnd())) 347 .setSendEnd(timing.CalculateMillisecondDelta(timing.SendEnd()))
354 .setReceiveHeadersEnd( 348 .setReceiveHeadersEnd(
355 timing.CalculateMillisecondDelta(timing.ReceiveHeadersEnd())) 349 timing.CalculateMillisecondDelta(timing.ReceiveHeadersEnd()))
356 .setPushStart(timing.PushStart()) 350 .setPushStart(timing.PushStart())
357 .setPushEnd(timing.PushEnd()) 351 .setPushEnd(timing.PushEnd())
358 .build(); 352 .build();
359 } 353 }
360 354
361 static std::unique_ptr<protocol::Network::Request> 355 static std::unique_ptr<protocol::Network::Request>
362 BuildObjectForResourceRequest(const ResourceRequest& request) { 356 BuildObjectForResourceRequest(const ResourceRequest& request) {
357 KURL nofragment_request_url(request.Url());
358 nofragment_request_url.RemoveFragmentIdentifier();
363 std::unique_ptr<protocol::Network::Request> request_object = 359 std::unique_ptr<protocol::Network::Request> request_object =
364 protocol::Network::Request::create() 360 protocol::Network::Request::create()
365 .setUrl(UrlWithoutFragment(request.Url()).GetString()) 361 .setUrl(nofragment_request_url.GetString())
366 .setMethod(request.HttpMethod()) 362 .setMethod(request.HttpMethod())
367 .setHeaders(BuildObjectForHeaders(request.HttpHeaderFields())) 363 .setHeaders(BuildObjectForHeaders(request.HttpHeaderFields()))
368 .setInitialPriority(ResourcePriorityJSON(request.Priority())) 364 .setInitialPriority(ResourcePriorityJSON(request.Priority()))
369 .setReferrerPolicy(GetReferrerPolicy(request.GetReferrerPolicy())) 365 .setReferrerPolicy(GetReferrerPolicy(request.GetReferrerPolicy()))
370 .build(); 366 .build();
371 if (request.HttpBody() && !request.HttpBody()->IsEmpty()) { 367 if (request.HttpBody() && !request.HttpBody()->IsEmpty()) {
372 Vector<char> bytes; 368 Vector<char> bytes;
373 request.HttpBody()->Flatten(bytes); 369 request.HttpBody()->Flatten(bytes);
374 request_object->setPostData( 370 request_object->setPostData(
375 String::FromUTF8WithLatin1Fallback(bytes.data(), bytes.size())); 371 String::FromUTF8WithLatin1Fallback(bytes.data(), bytes.size()));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 } 419 }
424 420
425 // Use mime type from cached resource in case the one in response is empty. 421 // Use mime type from cached resource in case the one in response is empty.
426 String mime_type = response.MimeType(); 422 String mime_type = response.MimeType();
427 if (mime_type.IsEmpty() && cached_resource) 423 if (mime_type.IsEmpty() && cached_resource)
428 mime_type = cached_resource->GetResponse().MimeType(); 424 mime_type = cached_resource->GetResponse().MimeType();
429 425
430 if (is_empty) 426 if (is_empty)
431 *is_empty = !status && mime_type.IsEmpty() && !headers_map.size(); 427 *is_empty = !status && mime_type.IsEmpty() && !headers_map.size();
432 428
429 KURL nofragment_response_url(response.Url());
430 nofragment_response_url.RemoveFragmentIdentifier();
433 std::unique_ptr<protocol::Network::Response> response_object = 431 std::unique_ptr<protocol::Network::Response> response_object =
434 protocol::Network::Response::create() 432 protocol::Network::Response::create()
435 .setUrl(UrlWithoutFragment(response.Url()).GetString()) 433 .setUrl(nofragment_response_url.GetString())
436 .setStatus(status) 434 .setStatus(status)
437 .setStatusText(status_text) 435 .setStatusText(status_text)
438 .setHeaders(BuildObjectForHeaders(headers_map)) 436 .setHeaders(BuildObjectForHeaders(headers_map))
439 .setMimeType(mime_type) 437 .setMimeType(mime_type)
440 .setConnectionReused(response.ConnectionReused()) 438 .setConnectionReused(response.ConnectionReused())
441 .setConnectionId(response.ConnectionID()) 439 .setConnectionId(response.ConnectionID())
442 .setEncodedDataLength(encoded_data_length) 440 .setEncodedDataLength(encoded_data_length)
443 .setSecurityState(security_state) 441 .setSecurityState(security_state)
444 .build(); 442 .build();
445 443
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 MixedContentChecker::ContextTypeForInspector(loader->GetFrame(), 650 MixedContentChecker::ContextTypeForInspector(loader->GetFrame(),
653 request))); 651 request)));
654 } 652 }
655 653
656 request_info->setReferrerPolicy( 654 request_info->setReferrerPolicy(
657 GetReferrerPolicy(request.GetReferrerPolicy())); 655 GetReferrerPolicy(request.GetReferrerPolicy()));
658 if (initiator_info.is_link_preload) 656 if (initiator_info.is_link_preload)
659 request_info->setIsLinkPreload(true); 657 request_info->setIsLinkPreload(true);
660 658
661 String resource_type = InspectorPageAgent::ResourceTypeJson(type); 659 String resource_type = InspectorPageAgent::ResourceTypeJson(type);
662 String documentURL = 660 KURL nofragment_document_url(loader ? loader->Url()
663 loader ? UrlWithoutFragment(loader->Url()).GetString() 661 : execution_context->Url());
664 : UrlWithoutFragment(execution_context->Url()).GetString(); 662 nofragment_document_url.RemoveFragmentIdentifier();
663 String documentURL = nofragment_document_url.GetString();
665 Maybe<String> maybe_frame_id; 664 Maybe<String> maybe_frame_id;
666 if (!frame_id.IsEmpty()) 665 if (!frame_id.IsEmpty())
667 maybe_frame_id = frame_id; 666 maybe_frame_id = frame_id;
668 GetFrontend()->requestWillBeSent( 667 GetFrontend()->requestWillBeSent(
669 request_id, loader_id, documentURL, std::move(request_info), 668 request_id, loader_id, documentURL, std::move(request_info),
670 MonotonicallyIncreasingTime(), CurrentTime(), std::move(initiator_object), 669 MonotonicallyIncreasingTime(), CurrentTime(), std::move(initiator_object),
671 BuildObjectForResourceResponse(redirect_response), resource_type, 670 BuildObjectForResourceResponse(redirect_response), resource_type,
672 std::move(maybe_frame_id)); 671 std::move(maybe_frame_id));
673 if (pending_xhr_replay_data_ && !pending_xhr_replay_data_->Async()) 672 if (pending_xhr_replay_data_ && !pending_xhr_replay_data_->Async())
674 GetFrontend()->flush(); 673 GetFrontend()->flush();
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 const AtomicString& method, 939 const AtomicString& method,
941 const KURL& url, 940 const KURL& url,
942 bool async, 941 bool async,
943 PassRefPtr<EncodedFormData> form_data, 942 PassRefPtr<EncodedFormData> form_data,
944 const HTTPHeaderMap& headers, 943 const HTTPHeaderMap& headers,
945 bool include_credentials) { 944 bool include_credentials) {
946 DCHECK(xhr); 945 DCHECK(xhr);
947 DCHECK(!pending_request_); 946 DCHECK(!pending_request_);
948 pending_request_ = client; 947 pending_request_ = client;
949 pending_request_type_ = InspectorPageAgent::kXHRResource; 948 pending_request_type_ = InspectorPageAgent::kXHRResource;
950 pending_xhr_replay_data_ = XHRReplayData::Create( 949 KURL nofragment_url(url);
951 xhr->GetExecutionContext(), method, UrlWithoutFragment(url), async, 950 nofragment_url.RemoveFragmentIdentifier();
952 form_data.Get(), include_credentials); 951 pending_xhr_replay_data_ =
952 XHRReplayData::Create(xhr->GetExecutionContext(), method, nofragment_url,
953 async, form_data.Get(), include_credentials);
953 for (const auto& header : headers) 954 for (const auto& header : headers)
954 pending_xhr_replay_data_->AddHeader(header.key, header.value); 955 pending_xhr_replay_data_->AddHeader(header.key, header.value);
955 } 956 }
956 957
957 void InspectorNetworkAgent::DelayedRemoveReplayXHR(XMLHttpRequest* xhr) { 958 void InspectorNetworkAgent::DelayedRemoveReplayXHR(XMLHttpRequest* xhr) {
958 if (!replay_xhrs_.Contains(xhr)) 959 if (!replay_xhrs_.Contains(xhr))
959 return; 960 return;
960 replay_xhrs_to_be_deleted_.insert(xhr); 961 replay_xhrs_to_be_deleted_.insert(xhr);
961 replay_xhrs_.erase(xhr); 962 replay_xhrs_.erase(xhr);
962 remove_finished_replay_xhr_timer_.StartOneShot(0, BLINK_FROM_HERE); 963 remove_finished_replay_xhr_timer_.StartOneShot(0, BLINK_FROM_HERE);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 } 1096 }
1096 1097
1097 while (document && !document->GetScriptableDocumentParser()) 1098 while (document && !document->GetScriptableDocumentParser())
1098 document = document->LocalOwner() ? document->LocalOwner()->ownerDocument() 1099 document = document->LocalOwner() ? document->LocalOwner()->ownerDocument()
1099 : nullptr; 1100 : nullptr;
1100 if (document && document->GetScriptableDocumentParser()) { 1101 if (document && document->GetScriptableDocumentParser()) {
1101 std::unique_ptr<protocol::Network::Initiator> initiator_object = 1102 std::unique_ptr<protocol::Network::Initiator> initiator_object =
1102 protocol::Network::Initiator::create() 1103 protocol::Network::Initiator::create()
1103 .setType(protocol::Network::Initiator::TypeEnum::Parser) 1104 .setType(protocol::Network::Initiator::TypeEnum::Parser)
1104 .build(); 1105 .build();
1105 initiator_object->setUrl(UrlWithoutFragment(document->Url()).GetString()); 1106 KURL nofragment_document_url(document->Url());
1107 nofragment_document_url.RemoveFragmentIdentifier();
1108 initiator_object->setUrl(nofragment_document_url.GetString());
1106 if (TextPosition::BelowRangePosition() != initiator_info.position) 1109 if (TextPosition::BelowRangePosition() != initiator_info.position)
1107 initiator_object->setLineNumber( 1110 initiator_object->setLineNumber(
1108 initiator_info.position.line_.ZeroBasedInt()); 1111 initiator_info.position.line_.ZeroBasedInt());
1109 else 1112 else
1110 initiator_object->setLineNumber( 1113 initiator_object->setLineNumber(
1111 document->GetScriptableDocumentParser()->LineNumber().ZeroBasedInt()); 1114 document->GetScriptableDocumentParser()->LineNumber().ZeroBasedInt());
1112 return initiator_object; 1115 return initiator_object;
1113 } 1116 }
1114 1117
1115 return protocol::Network::Initiator::create() 1118 return protocol::Network::Initiator::create()
1116 .setType(protocol::Network::Initiator::TypeEnum::Other) 1119 .setType(protocol::Network::Initiator::TypeEnum::Other)
1117 .build(); 1120 .build();
1118 } 1121 }
1119 1122
1120 void InspectorNetworkAgent::DidCreateWebSocket(Document* document, 1123 void InspectorNetworkAgent::DidCreateWebSocket(Document* document,
1121 unsigned long identifier, 1124 unsigned long identifier,
1122 const KURL& request_url, 1125 const KURL& request_url,
1123 const String&) { 1126 const String&) {
1124 std::unique_ptr<v8_inspector::protocol::Runtime::API::StackTrace> 1127 std::unique_ptr<v8_inspector::protocol::Runtime::API::StackTrace>
1125 current_stack_trace = 1128 current_stack_trace =
1126 SourceLocation::Capture(document)->BuildInspectorObject(); 1129 SourceLocation::Capture(document)->BuildInspectorObject();
1130 KURL nofragment_request_url(request_url);
1131 nofragment_request_url.RemoveFragmentIdentifier();
1127 if (!current_stack_trace) { 1132 if (!current_stack_trace) {
1128 GetFrontend()->webSocketCreated( 1133 GetFrontend()->webSocketCreated(IdentifiersFactory::RequestId(identifier),
1129 IdentifiersFactory::RequestId(identifier), 1134 nofragment_request_url.GetString());
1130 UrlWithoutFragment(request_url).GetString());
1131 return; 1135 return;
1132 } 1136 }
1133 1137
1134 std::unique_ptr<protocol::Network::Initiator> initiator_object = 1138 std::unique_ptr<protocol::Network::Initiator> initiator_object =
1135 protocol::Network::Initiator::create() 1139 protocol::Network::Initiator::create()
1136 .setType(protocol::Network::Initiator::TypeEnum::Script) 1140 .setType(protocol::Network::Initiator::TypeEnum::Script)
1137 .build(); 1141 .build();
1138 initiator_object->setStack(std::move(current_stack_trace)); 1142 initiator_object->setStack(std::move(current_stack_trace));
1139 GetFrontend()->webSocketCreated(IdentifiersFactory::RequestId(identifier), 1143 GetFrontend()->webSocketCreated(IdentifiersFactory::RequestId(identifier),
1140 UrlWithoutFragment(request_url).GetString(), 1144 nofragment_request_url.GetString(),
1141 std::move(initiator_object)); 1145 std::move(initiator_object));
1142 } 1146 }
1143 1147
1144 void InspectorNetworkAgent::WillSendWebSocketHandshakeRequest( 1148 void InspectorNetworkAgent::WillSendWebSocketHandshakeRequest(
1145 Document*, 1149 Document*,
1146 unsigned long identifier, 1150 unsigned long identifier,
1147 const WebSocketHandshakeRequest* request) { 1151 const WebSocketHandshakeRequest* request) {
1148 DCHECK(request); 1152 DCHECK(request);
1149 std::unique_ptr<protocol::Network::WebSocketRequest> request_object = 1153 std::unique_ptr<protocol::Network::WebSocketRequest> request_object =
1150 protocol::Network::WebSocketRequest::create() 1154 protocol::Network::WebSocketRequest::create()
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 DCHECK((IsMainThread() && inspected_frames_ && !worker_global_scope_) || 1593 DCHECK((IsMainThread() && inspected_frames_ && !worker_global_scope_) ||
1590 (!IsMainThread() && !inspected_frames_ && worker_global_scope_)); 1594 (!IsMainThread() && !inspected_frames_ && worker_global_scope_));
1591 } 1595 }
1592 1596
1593 void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) { 1597 void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) {
1594 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) 1598 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false))
1595 *result = true; 1599 *result = true;
1596 } 1600 }
1597 1601
1598 } // namespace blink 1602 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698