Chromium Code Reviews| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) { |
|
Lei Zhang
2015/10/30 20:30:57
Would you mind rewriting the code using early retu
| |
| 103 WebDataSource* data_source = frame->dataSource(); | 103 WebDataSource* data_source = frame->dataSource(); |
| 104 if (data_source) { | 104 if (data_source) { |
| 105 DocumentState* document_state = | 105 DocumentState* document_state = |
| 106 DocumentState::FromDataSource(data_source); | 106 DocumentState::FromDataSource(data_source); |
| 107 | |
| 108 double request_time = document_state->request_time().ToDoubleT(); | |
| 109 double start_load_time = document_state->start_load_time().ToDoubleT(); | |
| 110 double commit_load_time = | |
| 111 document_state->commit_load_time().ToDoubleT(); | |
| 112 double finish_document_load_time = | |
| 113 document_state->finish_document_load_time().ToDoubleT(); | |
| 114 double finish_load_time = | |
| 115 document_state->finish_load_time().ToDoubleT(); | |
| 116 double first_paint_time = | |
| 117 document_state->first_paint_time().ToDoubleT(); | |
| 118 double first_paint_after_load_time = | |
| 119 document_state->first_paint_after_load_time().ToDoubleT(); | |
| 120 std::string navigation_type = | |
| 121 GetNavigationType(data_source->navigationType()); | |
| 122 bool was_fetched_via_spdy = document_state->was_fetched_via_spdy(); | |
| 123 bool was_npn_negotiated = document_state->was_npn_negotiated(); | |
| 124 std::string npn_negotiated_protocol = | |
| 125 document_state->npn_negotiated_protocol(); | |
| 126 bool was_alternate_protocol_available = | |
| 127 document_state->was_alternate_protocol_available(); | |
| 128 std::string connection_info = | |
| 129 net::HttpResponseInfo::ConnectionInfoToString( | |
| 130 document_state->connection_info()); | |
| 131 // Important: |frame|, |data_source| and |document_state| should not be | |
| 132 // referred to below this line, as JS setters below can invalidate these | |
| 133 // pointers. | |
| 107 v8::Isolate* isolate = args.GetIsolate(); | 134 v8::Isolate* isolate = args.GetIsolate(); |
| 108 v8::Local<v8::Object> load_times = v8::Object::New(isolate); | 135 v8::Local<v8::Object> load_times = v8::Object::New(isolate); |
| 109 load_times->Set( | 136 load_times->Set(v8::String::NewFromUtf8(isolate, "requestTime"), |
| 110 v8::String::NewFromUtf8(isolate, "requestTime"), | 137 v8::Number::New(isolate, request_time)); |
| 111 v8::Number::New(isolate, | 138 load_times->Set(v8::String::NewFromUtf8(isolate, "startLoadTime"), |
| 112 document_state->request_time().ToDoubleT())); | 139 v8::Number::New(isolate, start_load_time)); |
| 113 load_times->Set( | 140 load_times->Set(v8::String::NewFromUtf8(isolate, "commitLoadTime"), |
| 114 v8::String::NewFromUtf8(isolate, "startLoadTime"), | 141 v8::Number::New(isolate, commit_load_time)); |
| 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( | 142 load_times->Set( |
| 122 v8::String::NewFromUtf8(isolate, "finishDocumentLoadTime"), | 143 v8::String::NewFromUtf8(isolate, "finishDocumentLoadTime"), |
| 123 v8::Number::New( | 144 v8::Number::New(isolate, finish_document_load_time)); |
| 124 isolate, | 145 load_times->Set(v8::String::NewFromUtf8(isolate, "finishLoadTime"), |
| 125 document_state->finish_document_load_time().ToDoubleT())); | 146 v8::Number::New(isolate, finish_load_time)); |
| 126 load_times->Set( | 147 load_times->Set(v8::String::NewFromUtf8(isolate, "firstPaintTime"), |
| 127 v8::String::NewFromUtf8(isolate, "finishLoadTime"), | 148 v8::Number::New(isolate, first_paint_time)); |
| 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( | 149 load_times->Set( |
| 135 v8::String::NewFromUtf8(isolate, "firstPaintAfterLoadTime"), | 150 v8::String::NewFromUtf8(isolate, "firstPaintAfterLoadTime"), |
| 136 v8::Number::New( | 151 v8::Number::New(isolate, first_paint_after_load_time)); |
| 137 isolate, | |
| 138 document_state->first_paint_after_load_time().ToDoubleT())); | |
| 139 load_times->Set( | 152 load_times->Set( |
| 140 v8::String::NewFromUtf8(isolate, "navigationType"), | 153 v8::String::NewFromUtf8(isolate, "navigationType"), |
| 141 v8::String::NewFromUtf8( | 154 v8::String::NewFromUtf8(isolate, navigation_type.c_str())); |
| 142 isolate, GetNavigationType(data_source->navigationType()))); | 155 load_times->Set(v8::String::NewFromUtf8(isolate, "wasFetchedViaSpdy"), |
| 143 load_times->Set( | 156 v8::Boolean::New(isolate, was_fetched_via_spdy)); |
| 144 v8::String::NewFromUtf8(isolate, "wasFetchedViaSpdy"), | 157 load_times->Set(v8::String::NewFromUtf8(isolate, "wasNpnNegotiated"), |
| 145 v8::Boolean::New(isolate, document_state->was_fetched_via_spdy())); | 158 v8::Boolean::New(isolate, was_npn_negotiated)); |
| 146 load_times->Set( | |
| 147 v8::String::NewFromUtf8(isolate, "wasNpnNegotiated"), | |
| 148 v8::Boolean::New(isolate, document_state->was_npn_negotiated())); | |
| 149 load_times->Set( | 159 load_times->Set( |
| 150 v8::String::NewFromUtf8(isolate, "npnNegotiatedProtocol"), | 160 v8::String::NewFromUtf8(isolate, "npnNegotiatedProtocol"), |
| 151 v8::String::NewFromUtf8( | 161 v8::String::NewFromUtf8(isolate, npn_negotiated_protocol.c_str())); |
| 152 isolate, document_state->npn_negotiated_protocol().c_str())); | |
| 153 load_times->Set( | 162 load_times->Set( |
| 154 v8::String::NewFromUtf8(isolate, "wasAlternateProtocolAvailable"), | 163 v8::String::NewFromUtf8(isolate, "wasAlternateProtocolAvailable"), |
| 155 v8::Boolean::New( | 164 v8::Boolean::New(isolate, was_alternate_protocol_available)); |
| 156 isolate, document_state->was_alternate_protocol_available())); | 165 load_times->Set( |
| 157 load_times->Set(v8::String::NewFromUtf8(isolate, "connectionInfo"), | 166 v8::String::NewFromUtf8(isolate, "connectionInfo"), |
| 158 v8::String::NewFromUtf8( | 167 v8::String::NewFromUtf8(isolate, connection_info.c_str())); |
| 159 isolate, | |
| 160 net::HttpResponseInfo::ConnectionInfoToString( | |
| 161 document_state->connection_info()).c_str())); | |
| 162 args.GetReturnValue().Set(load_times); | 168 args.GetReturnValue().Set(load_times); |
| 163 return; | 169 return; |
| 164 } | 170 } |
| 165 } | 171 } |
| 166 args.GetReturnValue().SetNull(); | 172 args.GetReturnValue().SetNull(); |
| 167 } | 173 } |
| 168 | 174 |
| 169 static void GetCSI(const v8::FunctionCallbackInfo<v8::Value>& args) { | 175 static void GetCSI(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 170 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext(); | 176 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext(); |
| 171 if (frame) { | 177 if (frame) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 199 args.GetReturnValue().SetNull(); | 205 args.GetReturnValue().SetNull(); |
| 200 return; | 206 return; |
| 201 } | 207 } |
| 202 }; | 208 }; |
| 203 | 209 |
| 204 v8::Extension* LoadTimesExtension::Get() { | 210 v8::Extension* LoadTimesExtension::Get() { |
| 205 return new LoadTimesExtensionWrapper(); | 211 return new LoadTimesExtensionWrapper(); |
| 206 } | 212 } |
| 207 | 213 |
| 208 } // namespace extensions_v8 | 214 } // namespace extensions_v8 |
| OLD | NEW |