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

Side by Side Diff: content/browser/devtools/protocol/network_handler.cc

Issue 2720543002: Fix headless_browsertests failures with PlzNavigate. (Closed)
Patch Set: review comments Created 3 years, 9 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/devtools/protocol/network_handler.h" 5 #include "content/browser/devtools/protocol/network_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/process/process_handle.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "content/browser/devtools/devtools_session.h" 16 #include "content/browser/devtools/devtools_session.h"
16 #include "content/browser/devtools/protocol/page.h" 17 #include "content/browser/devtools/protocol/page.h"
17 #include "content/browser/devtools/protocol/security.h" 18 #include "content/browser/devtools/protocol/security.h"
18 #include "content/browser/frame_host/frame_tree_node.h" 19 #include "content/browser/frame_host/frame_tree_node.h"
19 #include "content/browser/frame_host/render_frame_host_impl.h" 20 #include "content/browser/frame_host/render_frame_host_impl.h"
21 #include "content/common/navigation_params.h"
20 #include "content/common/resource_request.h" 22 #include "content/common/resource_request.h"
21 #include "content/common/resource_request_completion_status.h" 23 #include "content/common/resource_request_completion_status.h"
22 #include "content/public/browser/browser_context.h" 24 #include "content/public/browser/browser_context.h"
23 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/content_browser_client.h" 26 #include "content/public/browser/content_browser_client.h"
25 #include "content/public/browser/render_process_host.h" 27 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/resource_context.h" 28 #include "content/public/browser/resource_context.h"
27 #include "content/public/browser/site_instance.h" 29 #include "content/public/browser/site_instance.h"
28 #include "content/public/browser/storage_partition.h" 30 #include "content/public/browser/storage_partition.h"
29 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
30 #include "content/public/common/content_client.h" 32 #include "content/public/common/content_client.h"
31 #include "content/public/common/content_switches.h" 33 #include "content/public/common/content_switches.h"
32 #include "content/public/common/resource_devtools_info.h" 34 #include "content/public/common/resource_devtools_info.h"
33 #include "content/public/common/resource_response.h" 35 #include "content/public/common/resource_response.h"
36 #include "net/base/net_errors.h"
34 #include "net/cookies/cookie_store.h" 37 #include "net/cookies/cookie_store.h"
35 #include "net/http/http_response_headers.h" 38 #include "net/http/http_response_headers.h"
36 #include "net/url_request/url_request_context.h" 39 #include "net/url_request/url_request_context.h"
37 #include "net/url_request/url_request_context_getter.h" 40 #include "net/url_request/url_request_context_getter.h"
38 41
39 namespace content { 42 namespace content {
40 namespace protocol { 43 namespace protocol {
41 namespace { 44 namespace {
42 45
43 using ProtocolCookieArray = Array<Network::Cookie>; 46 using ProtocolCookieArray = Array<Network::Cookie>;
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 static_cast<double>(base::Time::kMicrosecondsPerSecond), 667 static_cast<double>(base::Time::kMicrosecondsPerSecond),
665 Page::ResourceTypeEnum::Other, "Navigation Preload Error", 668 Page::ResourceTypeEnum::Other, "Navigation Preload Error",
666 completion_status.error_code == net::Error::ERR_ABORTED); 669 completion_status.error_code == net::Error::ERR_ABORTED);
667 } 670 }
668 frontend_->LoadingFinished( 671 frontend_->LoadingFinished(
669 request_id, base::TimeTicks::Now().ToInternalValue() / 672 request_id, base::TimeTicks::Now().ToInternalValue() /
670 static_cast<double>(base::Time::kMicrosecondsPerSecond), 673 static_cast<double>(base::Time::kMicrosecondsPerSecond),
671 completion_status.encoded_data_length); 674 completion_status.encoded_data_length);
672 } 675 }
673 676
677 void NetworkHandler::NavigationFailed(
678 const CommonNavigationParams& common_params,
679 const BeginNavigationParams& begin_params,
680 net::Error error_code) {
681 if (!enabled_)
682 return;
683
684 static int next_id = 0;
685 std::string request_id = base::IntToString(base::GetCurrentProcId()) + "." +
686 base::IntToString(++next_id);
687 std::string error_string = net::ErrorToString(error_code);
688 bool cancelled = error_code == net::Error::ERR_ABORTED;
689
690 std::unique_ptr<DictionaryValue> headers_dict(DictionaryValue::create());
691 net::HttpRequestHeaders headers;
692 headers.AddHeadersFromString(begin_params.headers);
693 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();)
694 headers_dict->setString(it.name(), it.value());
695 frontend_->RequestWillBeSent(
696 request_id, request_id /* frameId */, request_id /* loaderId */,
697 common_params.url.spec(),
698 Network::Request::Create()
699 .SetUrl(common_params.url.spec())
700 .SetMethod(common_params.method)
701 .SetHeaders(Object::fromValue(headers_dict.get(), nullptr))
702 // Note: the priority value is copied from
703 // ResourceDispatcherHostImpl::BeginNavigationRequest but there isn't
704 // a good way of sharing this.
705 .SetInitialPriority(resourcePriority(net::HIGHEST))
706 .SetReferrerPolicy(referrerPolicy(common_params.referrer.policy))
707 .Build(),
708 base::TimeTicks::Now().ToInternalValue() /
709 static_cast<double>(base::Time::kMicrosecondsPerSecond),
710 base::Time::Now().ToDoubleT(),
711 Network::Initiator::Create()
712 .SetType(Network::Initiator::TypeEnum::Parser)
713 .Build(),
714 std::unique_ptr<Network::Response>(),
715 std::string(Page::ResourceTypeEnum::Document));
716
717 frontend_->LoadingFailed(
718 request_id,
719 base::TimeTicks::Now().ToInternalValue() /
720 static_cast<double>(base::Time::kMicrosecondsPerSecond),
721 Page::ResourceTypeEnum::Document, error_string, cancelled);
722 }
723
674 std::string NetworkHandler::UserAgentOverride() const { 724 std::string NetworkHandler::UserAgentOverride() const {
675 return enabled_ ? user_agent_ : std::string(); 725 return enabled_ ? user_agent_ : std::string();
676 } 726 }
677 727
678 } // namespace protocol 728 } // namespace protocol
679 } // namespace content 729 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/protocol/network_handler.h ('k') | content/browser/devtools/render_frame_devtools_agent_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698