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

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

Issue 2149933003: Pre-work for adding usage counter for chrome.loadtimes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switch to using SetAccessor Created 4 years, 5 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
« 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"
11 #include "extensions/renderer/v8_helpers.h"
11 #include "net/http/http_response_info.h" 12 #include "net/http/http_response_info.h"
12 #include "third_party/WebKit/public/web/WebLocalFrame.h" 13 #include "third_party/WebKit/public/web/WebLocalFrame.h"
13 #include "third_party/WebKit/public/web/WebPerformance.h" 14 #include "third_party/WebKit/public/web/WebPerformance.h"
14 #include "v8/include/v8.h" 15 #include "v8/include/v8.h"
15 16
16 using blink::WebDataSource; 17 using blink::WebDataSource;
17 using blink::WebLocalFrame; 18 using blink::WebLocalFrame;
18 using blink::WebNavigationType; 19 using blink::WebNavigationType;
19 using blink::WebPerformance; 20 using blink::WebPerformance;
20 using content::DocumentState; 21 using content::DocumentState;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 case blink::WebNavigationTypeBackForward: 99 case blink::WebNavigationTypeBackForward:
99 return kTransitionForwardBack; 100 return kTransitionForwardBack;
100 case blink::WebNavigationTypeReload: 101 case blink::WebNavigationTypeReload:
101 return kTransitionReload; 102 return kTransitionReload;
102 case blink::WebNavigationTypeOther: 103 case blink::WebNavigationTypeOther:
103 return kTransitionOther; 104 return kTransitionOther;
104 } 105 }
105 return kTransitionOther; 106 return kTransitionOther;
106 } 107 }
107 108
109 static void LoadtimesGetter(
110 v8::Local<v8::Name> name,
111 const v8::PropertyCallbackInfo<v8::Value>& info) {
112 // TODO(panicker): Add Usage counter.
113 info.GetReturnValue().Set(info.Data());
114 }
115
108 static void GetLoadTimes(const v8::FunctionCallbackInfo<v8::Value>& args) { 116 static void GetLoadTimes(const v8::FunctionCallbackInfo<v8::Value>& args) {
109 args.GetReturnValue().SetNull(); 117 args.GetReturnValue().SetNull();
110 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext(); 118 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext();
111 if (!frame) { 119 if (!frame) {
112 return; 120 return;
113 } 121 }
114 WebDataSource* data_source = frame->dataSource(); 122 WebDataSource* data_source = frame->dataSource();
115 if (!data_source) { 123 if (!data_source) {
116 return; 124 return;
117 } 125 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 std::string navigation_type = 165 std::string navigation_type =
158 GetNavigationType(data_source->navigationType()); 166 GetNavigationType(data_source->navigationType());
159 bool was_fetched_via_spdy = document_state->was_fetched_via_spdy(); 167 bool was_fetched_via_spdy = document_state->was_fetched_via_spdy();
160 bool was_npn_negotiated = document_state->was_npn_negotiated(); 168 bool was_npn_negotiated = document_state->was_npn_negotiated();
161 std::string npn_negotiated_protocol = 169 std::string npn_negotiated_protocol =
162 document_state->npn_negotiated_protocol(); 170 document_state->npn_negotiated_protocol();
163 bool was_alternate_protocol_available = 171 bool was_alternate_protocol_available =
164 document_state->was_alternate_protocol_available(); 172 document_state->was_alternate_protocol_available();
165 std::string connection_info = net::HttpResponseInfo::ConnectionInfoToString( 173 std::string connection_info = net::HttpResponseInfo::ConnectionInfoToString(
166 document_state->connection_info()); 174 document_state->connection_info());
175
167 // Important: |frame|, |data_source| and |document_state| should not be 176 // Important: |frame|, |data_source| and |document_state| should not be
168 // referred to below this line, as JS setters below can invalidate these 177 // referred to below this line, as JS setters below can invalidate these
169 // pointers. 178 // pointers.
170 v8::Isolate* isolate = args.GetIsolate(); 179 v8::Isolate* isolate = args.GetIsolate();
171 v8::Local<v8::Context> ctx = isolate->GetCurrentContext(); 180 v8::Local<v8::Context> ctx = isolate->GetCurrentContext();
172 v8::Local<v8::Object> load_times = v8::Object::New(isolate); 181 v8::Local<v8::Object> load_times = v8::Object::New(isolate);
adamk 2016/07/20 00:57:22 Nit: looks like indentation got off somewhere here
173 if (!load_times
174 ->Set(ctx, v8::String::NewFromUtf8(isolate, "requestTime",
175 v8::NewStringType::kNormal)
176 .ToLocalChecked(),
177 v8::Number::New(isolate, request_time))
178 .FromMaybe(false)) {
179 return;
180 }
181 182
182 if (!load_times 183 if (!load_times->SetAccessor(
183 ->Set(ctx, v8::String::NewFromUtf8(isolate, "startLoadTime", 184 ctx,
184 v8::NewStringType::kNormal) 185 v8::String::NewFromUtf8(
185 .ToLocalChecked(), 186 isolate, "requestTime", v8::NewStringType::kNormal)
186 v8::Number::New(isolate, start_load_time)) 187 .ToLocalChecked(),
187 .FromMaybe(false)) { 188 LoadtimesGetter,
188 return; 189 nullptr,
189 } 190 v8::Number::New(isolate, request_time))
190 if (!load_times 191 .FromMaybe(false)) {
191 ->Set(ctx, v8::String::NewFromUtf8(isolate, "commitLoadTime", 192 return;
192 v8::NewStringType::kNormal) 193 }
193 .ToLocalChecked(), 194 if (!load_times->SetAccessor(
194 v8::Number::New(isolate, commit_load_time)) 195 ctx,
195 .FromMaybe(false)) { 196 v8::String::NewFromUtf8(
196 return; 197 isolate, "startLoadTime", v8::NewStringType::kNormal)
197 } 198 .ToLocalChecked(),
198 if (!load_times 199 LoadtimesGetter,
199 ->Set(ctx, 200 nullptr,
200 v8::String::NewFromUtf8(isolate, "finishDocumentLoadTime", 201 v8::Number::New(isolate, start_load_time))
201 v8::NewStringType::kNormal) 202 .FromMaybe(false)) {
202 .ToLocalChecked(), 203 return;
203 v8::Number::New(isolate, finish_document_load_time)) 204 }
204 .FromMaybe(false)) { 205 if (!load_times->SetAccessor(
205 return; 206 ctx,
206 } 207 v8::String::NewFromUtf8(
207 if (!load_times 208 isolate, "commitLoadTime", v8::NewStringType::kNormal)
208 ->Set(ctx, v8::String::NewFromUtf8(isolate, "finishLoadTime", 209 .ToLocalChecked(),
209 v8::NewStringType::kNormal) 210 LoadtimesGetter,
210 .ToLocalChecked(), 211 nullptr,
211 v8::Number::New(isolate, finish_load_time)) 212 v8::Number::New(isolate, commit_load_time))
212 .FromMaybe(false)) { 213 .FromMaybe(false)) {
213 return; 214 return;
214 } 215 }
215 if (!load_times 216 if (!load_times->SetAccessor(
216 ->Set(ctx, v8::String::NewFromUtf8(isolate, "firstPaintTime", 217 ctx,
217 v8::NewStringType::kNormal) 218 v8::String::NewFromUtf8(
218 .ToLocalChecked(), 219 isolate, "finishDocumentLoadTime", v8::NewStringType::kNormal)
219 v8::Number::New(isolate, first_paint_time)) 220 .ToLocalChecked(),
220 .FromMaybe(false)) { 221 LoadtimesGetter,
221 return; 222 nullptr,
222 } 223 v8::Number::New(isolate, finish_document_load_time))
223 if (!load_times 224 .FromMaybe(false)) {
224 ->Set(ctx, 225 return;
225 v8::String::NewFromUtf8(isolate, "firstPaintAfterLoadTime", 226 }
226 v8::NewStringType::kNormal) 227 if (!load_times->SetAccessor(
227 .ToLocalChecked(), 228 ctx,
228 v8::Number::New(isolate, first_paint_after_load_time)) 229 v8::String::NewFromUtf8(
229 .FromMaybe(false)) { 230 isolate, "finishLoadTime", v8::NewStringType::kNormal)
230 return; 231 .ToLocalChecked(),
231 } 232 LoadtimesGetter,
232 if (!load_times 233 nullptr,
233 ->Set(ctx, v8::String::NewFromUtf8(isolate, "navigationType", 234 v8::Number::New(isolate, finish_load_time))
234 v8::NewStringType::kNormal) 235 .FromMaybe(false)) {
235 .ToLocalChecked(), 236 return;
236 v8::String::NewFromUtf8(isolate, navigation_type.c_str(), 237 }
237 v8::NewStringType::kNormal) 238 if (!load_times->SetAccessor(
238 .ToLocalChecked()) 239 ctx,
239 .FromMaybe(false)) { 240 v8::String::NewFromUtf8(
240 return; 241 isolate, "firstPaintTime", v8::NewStringType::kNormal)
241 } 242 .ToLocalChecked(),
242 if (!load_times 243 LoadtimesGetter,
243 ->Set(ctx, v8::String::NewFromUtf8(isolate, "wasFetchedViaSpdy", 244 nullptr,
244 v8::NewStringType::kNormal) 245 v8::Number::New(isolate, first_paint_time))
245 .ToLocalChecked(), 246 .FromMaybe(false)) {
246 v8::Boolean::New(isolate, was_fetched_via_spdy)) 247 return;
247 .FromMaybe(false)) { 248 }
248 return; 249 if (!load_times->SetAccessor(
249 } 250 ctx,
250 if (!load_times 251 v8::String::NewFromUtf8(
251 ->Set(ctx, v8::String::NewFromUtf8(isolate, "wasNpnNegotiated", 252 isolate, "firstPaintAfterLoadTime", v8::NewStringType::kNormal)
252 v8::NewStringType::kNormal) 253 .ToLocalChecked(),
253 .ToLocalChecked(), 254 LoadtimesGetter,
254 v8::Boolean::New(isolate, was_npn_negotiated)) 255 nullptr,
255 .FromMaybe(false)) { 256 v8::Number::New(isolate,first_paint_after_load_time))
256 return; 257 .FromMaybe(false)) {
257 } 258 return;
258 if (!load_times 259 }
259 ->Set(ctx, 260 if (!load_times->SetAccessor(
260 v8::String::NewFromUtf8(isolate, "npnNegotiatedProtocol", 261 ctx,
261 v8::NewStringType::kNormal) 262 v8::String::NewFromUtf8(
262 .ToLocalChecked(), 263 isolate, "navigationType", v8::NewStringType::kNormal)
263 v8::String::NewFromUtf8(isolate, 264 .ToLocalChecked(),
264 npn_negotiated_protocol.c_str(), 265 LoadtimesGetter,
265 v8::NewStringType::kNormal) 266 nullptr,
266 .ToLocalChecked()) 267 v8::String::NewFromUtf8(isolate, navigation_type.c_str(),
267 .FromMaybe(false)) { 268 v8::NewStringType::kNormal)
268 return; 269 .ToLocalChecked())
269 } 270 .FromMaybe(false)) {
270 if (!load_times 271 return;
271 ->Set(ctx, v8::String::NewFromUtf8(isolate, 272 }
272 "wasAlternateProtocolAvailable", 273 if (!load_times->SetAccessor(
273 v8::NewStringType::kNormal) 274 ctx,
274 .ToLocalChecked(), 275 v8::String::NewFromUtf8(
275 v8::Boolean::New(isolate, was_alternate_protocol_available)) 276 isolate, "wasFetchedViaSpdy", v8::NewStringType::kNormal)
276 .FromMaybe(false)) { 277 .ToLocalChecked(),
277 return; 278 LoadtimesGetter,
278 } 279 nullptr,
279 if (!load_times 280 v8::Boolean::New(isolate, was_fetched_via_spdy))
280 ->Set(ctx, v8::String::NewFromUtf8(isolate, "connectionInfo", 281 .FromMaybe(false)) {
281 v8::NewStringType::kNormal) 282 return;
282 .ToLocalChecked(), 283 }
283 v8::String::NewFromUtf8(isolate, connection_info.c_str(), 284 if (!load_times->SetAccessor(
284 v8::NewStringType::kNormal) 285 ctx,
285 .ToLocalChecked()) 286 v8::String::NewFromUtf8(
286 .FromMaybe(false)) { 287 isolate, "wasNpnNegotiated", v8::NewStringType::kNormal)
287 return; 288 .ToLocalChecked(),
288 } 289 LoadtimesGetter,
290 nullptr,
291 v8::Boolean::New(isolate, was_npn_negotiated))
292 .FromMaybe(false)) {
293 return;
294 }
295 if (!load_times->SetAccessor(
296 ctx,
297 v8::String::NewFromUtf8(
298 isolate, "npnNegotiatedProtocol", v8::NewStringType::kNormal)
299 .ToLocalChecked(),
300 LoadtimesGetter,
301 nullptr,
302 v8::String::NewFromUtf8(isolate, npn_negotiated_protocol.c_str(),
303 v8::NewStringType::kNormal)
304 .ToLocalChecked())
305 .FromMaybe(false)) {
306 return;
307 }
308 if (!load_times->SetAccessor(
309 ctx,
310 v8::String::NewFromUtf8(
311 isolate, "wasAlternateProtocolAvailable",
312 v8::NewStringType::kNormal)
313 .ToLocalChecked(),
314 LoadtimesGetter,
315 nullptr,
316 v8::Boolean::New(isolate, was_alternate_protocol_available))
317 .FromMaybe(false)) {
318 return;
319 }
320 if (!load_times->SetAccessor(
321 ctx,
322 v8::String::NewFromUtf8(
323 isolate, "connectionInfo", v8::NewStringType::kNormal)
324 .ToLocalChecked(),
325 LoadtimesGetter,
326 nullptr,
327 v8::String::NewFromUtf8(isolate, connection_info.c_str(),
328 v8::NewStringType::kNormal)
329 .ToLocalChecked())
330 .FromMaybe(false)) {
331 return;
332 }
333
289 args.GetReturnValue().Set(load_times); 334 args.GetReturnValue().Set(load_times);
290 } 335 }
291 336
292 static void GetCSI(const v8::FunctionCallbackInfo<v8::Value>& args) { 337 static void GetCSI(const v8::FunctionCallbackInfo<v8::Value>& args) {
293 args.GetReturnValue().SetNull(); 338 args.GetReturnValue().SetNull();
294 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext(); 339 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext();
295 if (!frame) { 340 if (!frame) {
296 return; 341 return;
297 } 342 }
298 WebDataSource* data_source = frame->dataSource(); 343 WebDataSource* data_source = frame->dataSource();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 391 }
347 args.GetReturnValue().Set(csi); 392 args.GetReturnValue().Set(csi);
348 } 393 }
349 }; 394 };
350 395
351 v8::Extension* LoadTimesExtension::Get() { 396 v8::Extension* LoadTimesExtension::Get() {
352 return new LoadTimesExtensionWrapper(); 397 return new LoadTimesExtensionWrapper();
353 } 398 }
354 399
355 } // namespace extensions_v8 400 } // 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