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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 load_times->Set( | 163 load_times->Set( |
164 v8::String::NewFromUtf8(isolate, "wasAlternateProtocolAvailable"), | 164 v8::String::NewFromUtf8(isolate, "wasAlternateProtocolAvailable"), |
165 v8::Boolean::New(isolate, was_alternate_protocol_available)); | 165 v8::Boolean::New(isolate, was_alternate_protocol_available)); |
166 load_times->Set(v8::String::NewFromUtf8(isolate, "connectionInfo"), | 166 load_times->Set(v8::String::NewFromUtf8(isolate, "connectionInfo"), |
167 v8::String::NewFromUtf8(isolate, connection_info.c_str())); | 167 v8::String::NewFromUtf8(isolate, connection_info.c_str())); |
168 args.GetReturnValue().Set(load_times); | 168 args.GetReturnValue().Set(load_times); |
169 } | 169 } |
170 | 170 |
171 static void GetCSI(const v8::FunctionCallbackInfo<v8::Value>& args) { | 171 static void GetCSI(const v8::FunctionCallbackInfo<v8::Value>& args) { |
172 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext(); | 172 WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext(); |
173 if (frame) { | 173 if (!frame) { |
174 WebDataSource* data_source = frame->dataSource(); | 174 args.GetReturnValue().SetNull(); |
175 if (data_source) { | 175 return; |
176 DocumentState* document_state = | |
177 DocumentState::FromDataSource(data_source); | |
178 v8::Isolate* isolate = args.GetIsolate(); | |
179 v8::Local<v8::Object> csi = v8::Object::New(isolate); | |
180 base::Time now = base::Time::Now(); | |
181 base::Time start = document_state->request_time().is_null() ? | |
182 document_state->start_load_time() : | |
183 document_state->request_time(); | |
184 base::Time onload = document_state->finish_document_load_time(); | |
185 base::TimeDelta page = now - start; | |
186 csi->Set(v8::String::NewFromUtf8(isolate, "startE"), | |
187 v8::Number::New(isolate, floor(start.ToDoubleT() * 1000))); | |
188 csi->Set(v8::String::NewFromUtf8(isolate, "onloadT"), | |
189 v8::Number::New(isolate, floor(onload.ToDoubleT() * 1000))); | |
190 csi->Set(v8::String::NewFromUtf8(isolate, "pageT"), | |
191 v8::Number::New(isolate, page.InMillisecondsF())); | |
192 csi->Set( | |
193 v8::String::NewFromUtf8(isolate, "tran"), | |
194 v8::Number::New( | |
195 isolate, GetCSITransitionType(data_source->navigationType()))); | |
196 | |
197 args.GetReturnValue().Set(csi); | |
198 return; | |
199 } | |
200 } | 176 } |
201 args.GetReturnValue().SetNull(); | 177 WebDataSource* data_source = frame->dataSource(); |
202 return; | 178 if (!data_source) { |
179 args.GetReturnValue().SetNull(); | |
180 return; | |
181 } | |
182 DocumentState* document_state = DocumentState::FromDataSource(data_source); | |
183 if (!document_state) { | |
184 args.GetReturnValue().SetNull(); | |
185 return; | |
186 } | |
187 base::Time now = base::Time::Now(); | |
188 base::Time start = document_state->request_time().is_null() | |
189 ? document_state->start_load_time() | |
190 : document_state->request_time(); | |
191 base::Time onload = document_state->finish_document_load_time(); | |
192 base::TimeDelta page = now - start; | |
193 int navigation_type = GetCSITransitionType(data_source->navigationType()); | |
194 // Important: |frame|, |data_source| and |document_state| should not be | |
195 // referred to below this line, as JS setters below can invalidate these | |
196 // pointers. | |
197 v8::Isolate* isolate = args.GetIsolate(); | |
198 v8::Local<v8::Object> csi = v8::Object::New(isolate); | |
199 csi->Set(v8::String::NewFromUtf8(isolate, "startE"), | |
jochen (gone - plz use gerrit)
2016/03/02 10:48:31
please use the non-deprecated versions:
v8::Local
meacer
2016/03/02 20:46:36
Done.
| |
200 v8::Number::New(isolate, floor(start.ToDoubleT() * 1000))); | |
201 csi->Set(v8::String::NewFromUtf8(isolate, "onloadT"), | |
202 v8::Number::New(isolate, floor(onload.ToDoubleT() * 1000))); | |
203 csi->Set(v8::String::NewFromUtf8(isolate, "pageT"), | |
204 v8::Number::New(isolate, page.InMillisecondsF())); | |
205 csi->Set(v8::String::NewFromUtf8(isolate, "tran"), | |
206 v8::Number::New(isolate, navigation_type)); | |
207 args.GetReturnValue().Set(csi); | |
203 } | 208 } |
204 }; | 209 }; |
205 | 210 |
206 v8::Extension* LoadTimesExtension::Get() { | 211 v8::Extension* LoadTimesExtension::Get() { |
207 return new LoadTimesExtensionWrapper(); | 212 return new LoadTimesExtensionWrapper(); |
208 } | 213 } |
209 | 214 |
210 } // namespace extensions_v8 | 215 } // namespace extensions_v8 |
OLD | NEW |