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" |
| 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 Loading... | |
| 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 TestLoadtimesGetter( | |
| 110 v8::Local<v8::Name> name, | |
| 111 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
| 112 v8::Local<v8::Object> param = v8::Local<v8::Object>::Cast(info.Data()); | |
|
adamk
2016/07/14 22:09:03
Object here is the wrong type (since you might hav
| |
| 113 info.GetReturnValue().Set(param); | |
| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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()); |
| 167 // Important: |frame|, |data_source| and |document_state| should not be | 175 // Important: |frame|, |data_source| and |document_state| should not be |
| 168 // referred to below this line, as JS setters below can invalidate these | 176 // referred to below this line, as JS setters below can invalidate these |
| 169 // pointers. | 177 // pointers. |
| 170 v8::Isolate* isolate = args.GetIsolate(); | 178 v8::Isolate* isolate = args.GetIsolate(); |
| 171 v8::Local<v8::Context> ctx = isolate->GetCurrentContext(); | 179 v8::Local<v8::Context> ctx = isolate->GetCurrentContext(); |
| 172 v8::Local<v8::Object> load_times = v8::Object::New(isolate); | 180 v8::Local<v8::Object> load_times = v8::Object::New(isolate); |
| 181 | |
| 173 if (!load_times | 182 if (!load_times |
| 174 ->Set(ctx, v8::String::NewFromUtf8(isolate, "requestTime", | 183 ->SetAccessor( |
| 175 v8::NewStringType::kNormal) | 184 ctx, |
| 176 .ToLocalChecked(), | 185 extensions::v8_helpers::ToV8StringUnsafe( |
| 177 v8::Number::New(isolate, request_time)) | 186 isolate, "requestTime", v8::NewStringType::kNormal), |
| 187 TestLoadtimesGetter, | |
| 188 nullptr, | |
| 189 v8::Number::New(isolate, request_time)) | |
| 178 .FromMaybe(false)) { | 190 .FromMaybe(false)) { |
| 179 return; | 191 return; |
| 180 } | 192 } |
| 181 | 193 |
| 182 if (!load_times | 194 if (!load_times |
| 183 ->Set(ctx, v8::String::NewFromUtf8(isolate, "startLoadTime", | 195 ->Set(ctx, v8::String::NewFromUtf8(isolate, "startLoadTime", |
| 184 v8::NewStringType::kNormal) | 196 v8::NewStringType::kNormal) |
| 185 .ToLocalChecked(), | 197 .ToLocalChecked(), |
| 186 v8::Number::New(isolate, start_load_time)) | 198 v8::Number::New(isolate, start_load_time)) |
| 187 .FromMaybe(false)) { | 199 .FromMaybe(false)) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 } | 358 } |
| 347 args.GetReturnValue().Set(csi); | 359 args.GetReturnValue().Set(csi); |
| 348 } | 360 } |
| 349 }; | 361 }; |
| 350 | 362 |
| 351 v8::Extension* LoadTimesExtension::Get() { | 363 v8::Extension* LoadTimesExtension::Get() { |
| 352 return new LoadTimesExtensionWrapper(); | 364 return new LoadTimesExtensionWrapper(); |
| 353 } | 365 } |
| 354 | 366 |
| 355 } // namespace extensions_v8 | 367 } // namespace extensions_v8 |
| OLD | NEW |