| OLD | NEW |
| 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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 static void GetCSI(const v8::FunctionCallbackInfo<v8::Value>& args) { | 339 static void GetCSI(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 340 args.GetReturnValue().SetNull(); | 340 args.GetReturnValue().SetNull(); |
| 341 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext(); | 341 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext(); |
| 342 if (!frame) { | 342 if (!frame) { |
| 343 return; | 343 return; |
| 344 } | 344 } |
| 345 WebDataSource* data_source = frame->dataSource(); | 345 WebDataSource* data_source = frame->dataSource(); |
| 346 if (!data_source) { | 346 if (!data_source) { |
| 347 return; | 347 return; |
| 348 } | 348 } |
| 349 DocumentState* document_state = DocumentState::FromDataSource(data_source); | 349 WebPerformance web_performance = frame->performance(); |
| 350 if (!document_state) { | |
| 351 return; | |
| 352 } | |
| 353 base::Time now = base::Time::Now(); | 350 base::Time now = base::Time::Now(); |
| 354 base::Time start = document_state->request_time().is_null() | 351 base::Time start = |
| 355 ? document_state->start_load_time() | 352 base::Time::FromDoubleT(web_performance.navigationStart()); |
| 356 : document_state->request_time(); | 353 |
| 357 base::Time onload = document_state->finish_document_load_time(); | 354 base::Time dom_content_loaded_end = |
| 355 base::Time::FromDoubleT(web_performance.domContentLoadedEventEnd()); |
| 358 base::TimeDelta page = now - start; | 356 base::TimeDelta page = now - start; |
| 359 int navigation_type = GetCSITransitionType(data_source->navigationType()); | 357 int navigation_type = GetCSITransitionType(data_source->navigationType()); |
| 360 // Important: |frame|, |data_source| and |document_state| should not be | 358 // Important: |frame| and |data_source| should not be referred to below this |
| 361 // referred to below this line, as JS setters below can invalidate these | 359 // line, as JS setters below can invalidate these pointers. |
| 362 // pointers. | |
| 363 v8::Isolate* isolate = args.GetIsolate(); | 360 v8::Isolate* isolate = args.GetIsolate(); |
| 364 v8::Local<v8::Context> ctx = isolate->GetCurrentContext(); | 361 v8::Local<v8::Context> ctx = isolate->GetCurrentContext(); |
| 365 v8::Local<v8::Object> csi = v8::Object::New(isolate); | 362 v8::Local<v8::Object> csi = v8::Object::New(isolate); |
| 366 if (!csi->Set(ctx, v8::String::NewFromUtf8(isolate, "startE", | 363 if (!csi->Set(ctx, v8::String::NewFromUtf8(isolate, "startE", |
| 367 v8::NewStringType::kNormal) | 364 v8::NewStringType::kNormal) |
| 368 .ToLocalChecked(), | 365 .ToLocalChecked(), |
| 369 v8::Number::New(isolate, floor(start.ToDoubleT() * 1000))) | 366 v8::Number::New(isolate, floor(start.ToDoubleT() * 1000))) |
| 370 .FromMaybe(false)) { | 367 .FromMaybe(false)) { |
| 371 return; | 368 return; |
| 372 } | 369 } |
| 370 // NOTE: historically, the CSI onload field has reported the time the |
| 371 // document finishes parsing, which is DOMContentLoaded. Thus, we continue |
| 372 // to report that here, despite the fact that the field is named onloadT. |
| 373 if (!csi->Set(ctx, v8::String::NewFromUtf8(isolate, "onloadT", | 373 if (!csi->Set(ctx, v8::String::NewFromUtf8(isolate, "onloadT", |
| 374 v8::NewStringType::kNormal) | 374 v8::NewStringType::kNormal) |
| 375 .ToLocalChecked(), | 375 .ToLocalChecked(), |
| 376 v8::Number::New(isolate, floor(onload.ToDoubleT() * 1000))) | 376 v8::Number::New(isolate, |
| 377 .FromMaybe(false)) { | 377 floor(dom_content_loaded_end.ToDoubleT() * |
| 378 1000))).FromMaybe(false)) { |
| 378 return; | 379 return; |
| 379 } | 380 } |
| 380 if (!csi->Set(ctx, v8::String::NewFromUtf8(isolate, "pageT", | 381 if (!csi->Set(ctx, v8::String::NewFromUtf8(isolate, "pageT", |
| 381 v8::NewStringType::kNormal) | 382 v8::NewStringType::kNormal) |
| 382 .ToLocalChecked(), | 383 .ToLocalChecked(), |
| 383 v8::Number::New(isolate, page.InMillisecondsF())) | 384 v8::Number::New(isolate, page.InMillisecondsF())) |
| 384 .FromMaybe(false)) { | 385 .FromMaybe(false)) { |
| 385 return; | 386 return; |
| 386 } | 387 } |
| 387 if (!csi->Set(ctx, v8::String::NewFromUtf8(isolate, "tran", | 388 if (!csi->Set(ctx, v8::String::NewFromUtf8(isolate, "tran", |
| 388 v8::NewStringType::kNormal) | 389 v8::NewStringType::kNormal) |
| 389 .ToLocalChecked(), | 390 .ToLocalChecked(), |
| 390 v8::Number::New(isolate, navigation_type)) | 391 v8::Number::New(isolate, navigation_type)) |
| 391 .FromMaybe(false)) { | 392 .FromMaybe(false)) { |
| 392 return; | 393 return; |
| 393 } | 394 } |
| 394 args.GetReturnValue().Set(csi); | 395 args.GetReturnValue().Set(csi); |
| 395 } | 396 } |
| 396 }; | 397 }; |
| 397 | 398 |
| 398 v8::Extension* LoadTimesExtension::Get() { | 399 v8::Extension* LoadTimesExtension::Get() { |
| 399 return new LoadTimesExtensionWrapper(); | 400 return new LoadTimesExtensionWrapper(); |
| 400 } | 401 } |
| 401 | 402 |
| 402 } // namespace extensions_v8 | 403 } // namespace extensions_v8 |
| OLD | NEW |