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

Side by Side Diff: chrome/renderer/loadtimes_extension_bindings.cc

Issue 1422753007: Cache all chrome.loadTimes info before passing them to setters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: thestig comments Created 5 years, 1 month 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/renderer/loadtimes_extension_bindings.h" 5 #include "chrome/renderer/loadtimes_extension_bindings.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/public/renderer/document_state.h" 10 #include "content/public/renderer/document_state.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 case blink::WebNavigationTypeReload: 92 case blink::WebNavigationTypeReload:
93 return kTransitionReload; 93 return kTransitionReload;
94 case blink::WebNavigationTypeOther: 94 case blink::WebNavigationTypeOther:
95 return kTransitionOther; 95 return kTransitionOther;
96 } 96 }
97 return kTransitionOther; 97 return kTransitionOther;
98 } 98 }
99 99
100 static void GetLoadTimes(const v8::FunctionCallbackInfo<v8::Value>& args) { 100 static void GetLoadTimes(const v8::FunctionCallbackInfo<v8::Value>& args) {
101 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext(); 101 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext();
102 if (frame) { 102 if (!frame) {
103 WebDataSource* data_source = frame->dataSource(); 103 args.GetReturnValue().SetNull();
104 if (data_source) { 104 return;
105 DocumentState* document_state =
106 DocumentState::FromDataSource(data_source);
107 v8::Isolate* isolate = args.GetIsolate();
108 v8::Local<v8::Object> load_times = v8::Object::New(isolate);
109 load_times->Set(
110 v8::String::NewFromUtf8(isolate, "requestTime"),
111 v8::Number::New(isolate,
112 document_state->request_time().ToDoubleT()));
113 load_times->Set(
114 v8::String::NewFromUtf8(isolate, "startLoadTime"),
115 v8::Number::New(isolate,
116 document_state->start_load_time().ToDoubleT()));
117 load_times->Set(
118 v8::String::NewFromUtf8(isolate, "commitLoadTime"),
119 v8::Number::New(isolate,
120 document_state->commit_load_time().ToDoubleT()));
121 load_times->Set(
122 v8::String::NewFromUtf8(isolate, "finishDocumentLoadTime"),
123 v8::Number::New(
124 isolate,
125 document_state->finish_document_load_time().ToDoubleT()));
126 load_times->Set(
127 v8::String::NewFromUtf8(isolate, "finishLoadTime"),
128 v8::Number::New(isolate,
129 document_state->finish_load_time().ToDoubleT()));
130 load_times->Set(
131 v8::String::NewFromUtf8(isolate, "firstPaintTime"),
132 v8::Number::New(isolate,
133 document_state->first_paint_time().ToDoubleT()));
134 load_times->Set(
135 v8::String::NewFromUtf8(isolate, "firstPaintAfterLoadTime"),
136 v8::Number::New(
137 isolate,
138 document_state->first_paint_after_load_time().ToDoubleT()));
139 load_times->Set(
140 v8::String::NewFromUtf8(isolate, "navigationType"),
141 v8::String::NewFromUtf8(
142 isolate, GetNavigationType(data_source->navigationType())));
143 load_times->Set(
144 v8::String::NewFromUtf8(isolate, "wasFetchedViaSpdy"),
145 v8::Boolean::New(isolate, document_state->was_fetched_via_spdy()));
146 load_times->Set(
147 v8::String::NewFromUtf8(isolate, "wasNpnNegotiated"),
148 v8::Boolean::New(isolate, document_state->was_npn_negotiated()));
149 load_times->Set(
150 v8::String::NewFromUtf8(isolate, "npnNegotiatedProtocol"),
151 v8::String::NewFromUtf8(
152 isolate, document_state->npn_negotiated_protocol().c_str()));
153 load_times->Set(
154 v8::String::NewFromUtf8(isolate, "wasAlternateProtocolAvailable"),
155 v8::Boolean::New(
156 isolate, document_state->was_alternate_protocol_available()));
157 load_times->Set(v8::String::NewFromUtf8(isolate, "connectionInfo"),
158 v8::String::NewFromUtf8(
159 isolate,
160 net::HttpResponseInfo::ConnectionInfoToString(
161 document_state->connection_info()).c_str()));
162 args.GetReturnValue().Set(load_times);
163 return;
164 }
165 } 105 }
166 args.GetReturnValue().SetNull(); 106 WebDataSource* data_source = frame->dataSource();
107 if (!data_source) {
108 args.GetReturnValue().SetNull();
109 return;
110 }
111 DocumentState* document_state = DocumentState::FromDataSource(data_source);
112 if (!document_state) {
113 args.GetReturnValue().SetNull();
114 return;
115 }
116 double request_time = document_state->request_time().ToDoubleT();
117 double start_load_time = document_state->start_load_time().ToDoubleT();
118 double commit_load_time = document_state->commit_load_time().ToDoubleT();
119 double finish_document_load_time =
120 document_state->finish_document_load_time().ToDoubleT();
121 double finish_load_time = document_state->finish_load_time().ToDoubleT();
122 double first_paint_time = document_state->first_paint_time().ToDoubleT();
123 double first_paint_after_load_time =
124 document_state->first_paint_after_load_time().ToDoubleT();
125 std::string navigation_type =
126 GetNavigationType(data_source->navigationType());
127 bool was_fetched_via_spdy = document_state->was_fetched_via_spdy();
128 bool was_npn_negotiated = document_state->was_npn_negotiated();
129 std::string npn_negotiated_protocol =
130 document_state->npn_negotiated_protocol();
131 bool was_alternate_protocol_available =
132 document_state->was_alternate_protocol_available();
133 std::string connection_info = net::HttpResponseInfo::ConnectionInfoToString(
134 document_state->connection_info());
135 // Important: |frame|, |data_source| and |document_state| should not be
136 // referred to below this line, as JS setters below can invalidate these
137 // pointers.
138 v8::Isolate* isolate = args.GetIsolate();
139 v8::Local<v8::Object> load_times = v8::Object::New(isolate);
140 load_times->Set(v8::String::NewFromUtf8(isolate, "requestTime"),
141 v8::Number::New(isolate, request_time));
142 load_times->Set(v8::String::NewFromUtf8(isolate, "startLoadTime"),
143 v8::Number::New(isolate, start_load_time));
144 load_times->Set(v8::String::NewFromUtf8(isolate, "commitLoadTime"),
145 v8::Number::New(isolate, commit_load_time));
146 load_times->Set(v8::String::NewFromUtf8(isolate, "finishDocumentLoadTime"),
147 v8::Number::New(isolate, finish_document_load_time));
148 load_times->Set(v8::String::NewFromUtf8(isolate, "finishLoadTime"),
149 v8::Number::New(isolate, finish_load_time));
150 load_times->Set(v8::String::NewFromUtf8(isolate, "firstPaintTime"),
151 v8::Number::New(isolate, first_paint_time));
152 load_times->Set(v8::String::NewFromUtf8(isolate, "firstPaintAfterLoadTime"),
153 v8::Number::New(isolate, first_paint_after_load_time));
154 load_times->Set(v8::String::NewFromUtf8(isolate, "navigationType"),
155 v8::String::NewFromUtf8(isolate, navigation_type.c_str()));
156 load_times->Set(v8::String::NewFromUtf8(isolate, "wasFetchedViaSpdy"),
157 v8::Boolean::New(isolate, was_fetched_via_spdy));
158 load_times->Set(v8::String::NewFromUtf8(isolate, "wasNpnNegotiated"),
159 v8::Boolean::New(isolate, was_npn_negotiated));
160 load_times->Set(
161 v8::String::NewFromUtf8(isolate, "npnNegotiatedProtocol"),
162 v8::String::NewFromUtf8(isolate, npn_negotiated_protocol.c_str()));
163 load_times->Set(
164 v8::String::NewFromUtf8(isolate, "wasAlternateProtocolAvailable"),
165 v8::Boolean::New(isolate, was_alternate_protocol_available));
166 load_times->Set(v8::String::NewFromUtf8(isolate, "connectionInfo"),
167 v8::String::NewFromUtf8(isolate, connection_info.c_str()));
168 args.GetReturnValue().Set(load_times);
167 } 169 }
168 170
169 static void GetCSI(const v8::FunctionCallbackInfo<v8::Value>& args) { 171 static void GetCSI(const v8::FunctionCallbackInfo<v8::Value>& args) {
170 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext(); 172 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext();
171 if (frame) { 173 if (frame) {
172 WebDataSource* data_source = frame->dataSource(); 174 WebDataSource* data_source = frame->dataSource();
173 if (data_source) { 175 if (data_source) {
174 DocumentState* document_state = 176 DocumentState* document_state =
175 DocumentState::FromDataSource(data_source); 177 DocumentState::FromDataSource(data_source);
176 v8::Isolate* isolate = args.GetIsolate(); 178 v8::Isolate* isolate = args.GetIsolate();
(...skipping 22 matching lines...) Expand all
199 args.GetReturnValue().SetNull(); 201 args.GetReturnValue().SetNull();
200 return; 202 return;
201 } 203 }
202 }; 204 };
203 205
204 v8::Extension* LoadTimesExtension::Get() { 206 v8::Extension* LoadTimesExtension::Get() {
205 return new LoadTimesExtensionWrapper(); 207 return new LoadTimesExtensionWrapper();
206 } 208 }
207 209
208 } // namespace extensions_v8 210 } // namespace extensions_v8
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