Index: chrome/renderer/loadtimes_extension_bindings.cc |
diff --git a/chrome/renderer/loadtimes_extension_bindings.cc b/chrome/renderer/loadtimes_extension_bindings.cc |
index 692b80867db37c8c199d6b0494e9eba990864b7f..4488781860b4893527763584a34f6879a0bbac92 100644 |
--- a/chrome/renderer/loadtimes_extension_bindings.cc |
+++ b/chrome/renderer/loadtimes_extension_bindings.cc |
@@ -98,19 +98,17 @@ class LoadTimesExtensionWrapper : public v8::Extension { |
} |
static void GetLoadTimes(const v8::FunctionCallbackInfo<v8::Value>& args) { |
+ args.GetReturnValue().SetNull(); |
WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext(); |
if (!frame) { |
- args.GetReturnValue().SetNull(); |
return; |
} |
WebDataSource* data_source = frame->dataSource(); |
if (!data_source) { |
- args.GetReturnValue().SetNull(); |
return; |
} |
DocumentState* document_state = DocumentState::FromDataSource(data_source); |
if (!document_state) { |
- args.GetReturnValue().SetNull(); |
return; |
} |
double request_time = document_state->request_time().ToDoubleT(); |
@@ -136,70 +134,183 @@ class LoadTimesExtensionWrapper : public v8::Extension { |
// referred to below this line, as JS setters below can invalidate these |
// pointers. |
v8::Isolate* isolate = args.GetIsolate(); |
+ v8::Local<v8::Context> ctx = isolate->GetCurrentContext(); |
v8::Local<v8::Object> load_times = v8::Object::New(isolate); |
- load_times->Set(v8::String::NewFromUtf8(isolate, "requestTime"), |
- v8::Number::New(isolate, request_time)); |
- load_times->Set(v8::String::NewFromUtf8(isolate, "startLoadTime"), |
- v8::Number::New(isolate, start_load_time)); |
- load_times->Set(v8::String::NewFromUtf8(isolate, "commitLoadTime"), |
- v8::Number::New(isolate, commit_load_time)); |
- load_times->Set(v8::String::NewFromUtf8(isolate, "finishDocumentLoadTime"), |
- v8::Number::New(isolate, finish_document_load_time)); |
- load_times->Set(v8::String::NewFromUtf8(isolate, "finishLoadTime"), |
- v8::Number::New(isolate, finish_load_time)); |
- load_times->Set(v8::String::NewFromUtf8(isolate, "firstPaintTime"), |
- v8::Number::New(isolate, first_paint_time)); |
- load_times->Set(v8::String::NewFromUtf8(isolate, "firstPaintAfterLoadTime"), |
- v8::Number::New(isolate, first_paint_after_load_time)); |
- load_times->Set(v8::String::NewFromUtf8(isolate, "navigationType"), |
- v8::String::NewFromUtf8(isolate, navigation_type.c_str())); |
- load_times->Set(v8::String::NewFromUtf8(isolate, "wasFetchedViaSpdy"), |
- v8::Boolean::New(isolate, was_fetched_via_spdy)); |
- load_times->Set(v8::String::NewFromUtf8(isolate, "wasNpnNegotiated"), |
- v8::Boolean::New(isolate, was_npn_negotiated)); |
- load_times->Set( |
- v8::String::NewFromUtf8(isolate, "npnNegotiatedProtocol"), |
- v8::String::NewFromUtf8(isolate, npn_negotiated_protocol.c_str())); |
- load_times->Set( |
- v8::String::NewFromUtf8(isolate, "wasAlternateProtocolAvailable"), |
- v8::Boolean::New(isolate, was_alternate_protocol_available)); |
- load_times->Set(v8::String::NewFromUtf8(isolate, "connectionInfo"), |
- v8::String::NewFromUtf8(isolate, connection_info.c_str())); |
+ if (!load_times |
+ ->Set(ctx, v8::String::NewFromUtf8(isolate, "requestTime", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Number::New(isolate, request_time)) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ |
+ if (!load_times |
+ ->Set(ctx, v8::String::NewFromUtf8(isolate, "startLoadTime", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Number::New(isolate, start_load_time)) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!load_times |
+ ->Set(ctx, v8::String::NewFromUtf8(isolate, "commitLoadTime", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Number::New(isolate, commit_load_time)) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!load_times |
+ ->Set(ctx, |
+ v8::String::NewFromUtf8(isolate, "finishDocumentLoadTime", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Number::New(isolate, finish_document_load_time)) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!load_times |
+ ->Set(ctx, v8::String::NewFromUtf8(isolate, "finishLoadTime", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Number::New(isolate, finish_load_time)) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!load_times |
+ ->Set(ctx, v8::String::NewFromUtf8(isolate, "firstPaintTime", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Number::New(isolate, first_paint_time)) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!load_times |
+ ->Set(ctx, |
+ v8::String::NewFromUtf8(isolate, "firstPaintAfterLoadTime", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Number::New(isolate, first_paint_after_load_time)) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!load_times |
+ ->Set(ctx, v8::String::NewFromUtf8(isolate, "navigationType", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::String::NewFromUtf8(isolate, navigation_type.c_str(), |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked()) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!load_times |
+ ->Set(ctx, v8::String::NewFromUtf8(isolate, "wasFetchedViaSpdy", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Boolean::New(isolate, was_fetched_via_spdy)) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!load_times |
+ ->Set(ctx, v8::String::NewFromUtf8(isolate, "wasNpnNegotiated", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Boolean::New(isolate, was_npn_negotiated)) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!load_times |
+ ->Set(ctx, |
+ v8::String::NewFromUtf8(isolate, "npnNegotiatedProtocol", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::String::NewFromUtf8(isolate, |
+ npn_negotiated_protocol.c_str(), |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked()) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!load_times |
+ ->Set(ctx, v8::String::NewFromUtf8(isolate, |
+ "wasAlternateProtocolAvailable", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Boolean::New(isolate, was_alternate_protocol_available)) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!load_times |
+ ->Set(ctx, v8::String::NewFromUtf8(isolate, "connectionInfo", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::String::NewFromUtf8(isolate, connection_info.c_str(), |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked()) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
args.GetReturnValue().Set(load_times); |
} |
static void GetCSI(const v8::FunctionCallbackInfo<v8::Value>& args) { |
+ args.GetReturnValue().SetNull(); |
WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext(); |
- if (frame) { |
- WebDataSource* data_source = frame->dataSource(); |
- if (data_source) { |
- DocumentState* document_state = |
- DocumentState::FromDataSource(data_source); |
- v8::Isolate* isolate = args.GetIsolate(); |
- v8::Local<v8::Object> csi = v8::Object::New(isolate); |
- base::Time now = base::Time::Now(); |
- base::Time start = document_state->request_time().is_null() ? |
- document_state->start_load_time() : |
- document_state->request_time(); |
- base::Time onload = document_state->finish_document_load_time(); |
- base::TimeDelta page = now - start; |
- csi->Set(v8::String::NewFromUtf8(isolate, "startE"), |
- v8::Number::New(isolate, floor(start.ToDoubleT() * 1000))); |
- csi->Set(v8::String::NewFromUtf8(isolate, "onloadT"), |
- v8::Number::New(isolate, floor(onload.ToDoubleT() * 1000))); |
- csi->Set(v8::String::NewFromUtf8(isolate, "pageT"), |
- v8::Number::New(isolate, page.InMillisecondsF())); |
- csi->Set( |
- v8::String::NewFromUtf8(isolate, "tran"), |
- v8::Number::New( |
- isolate, GetCSITransitionType(data_source->navigationType()))); |
- |
- args.GetReturnValue().Set(csi); |
- return; |
- } |
+ if (!frame) { |
+ return; |
} |
- args.GetReturnValue().SetNull(); |
- return; |
+ WebDataSource* data_source = frame->dataSource(); |
+ if (!data_source) { |
+ return; |
+ } |
+ DocumentState* document_state = DocumentState::FromDataSource(data_source); |
+ if (!document_state) { |
+ return; |
+ } |
+ base::Time now = base::Time::Now(); |
+ base::Time start = document_state->request_time().is_null() |
+ ? document_state->start_load_time() |
+ : document_state->request_time(); |
+ base::Time onload = document_state->finish_document_load_time(); |
+ base::TimeDelta page = now - start; |
+ int navigation_type = GetCSITransitionType(data_source->navigationType()); |
+ // Important: |frame|, |data_source| and |document_state| should not be |
+ // referred to below this line, as JS setters below can invalidate these |
+ // pointers. |
+ v8::Isolate* isolate = args.GetIsolate(); |
+ v8::Local<v8::Context> ctx = isolate->GetCurrentContext(); |
+ v8::Local<v8::Object> csi = v8::Object::New(isolate); |
+ if (!csi->Set(ctx, v8::String::NewFromUtf8(isolate, "startE", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Number::New(isolate, floor(start.ToDoubleT() * 1000))) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!csi->Set(ctx, v8::String::NewFromUtf8(isolate, "onloadT", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Number::New(isolate, floor(onload.ToDoubleT() * 1000))) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!csi->Set(ctx, v8::String::NewFromUtf8(isolate, "pageT", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Number::New(isolate, page.InMillisecondsF())) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ if (!csi->Set(ctx, v8::String::NewFromUtf8(isolate, "tran", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Number::New(isolate, navigation_type)) |
+ .FromMaybe(false)) { |
+ return; |
+ } |
+ args.GetReturnValue().Set(csi); |
} |
}; |