| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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.h" | 9 #include "base/time.h" |
| 10 #include "chrome/renderer/navigation_state.h" | 10 #include "chrome/renderer/navigation_state.h" |
| 11 #include "webkit/api/public/WebFrame.h" |
| 11 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
| 12 #include "webkit/glue/webframe.h" | |
| 13 | 13 |
| 14 using WebKit::WebDataSource; | 14 using WebKit::WebDataSource; |
| 15 using WebKit::WebFrame; |
| 15 using WebKit::WebNavigationType; | 16 using WebKit::WebNavigationType; |
| 16 | 17 |
| 17 // Values for CSI "tran" property | 18 // Values for CSI "tran" property |
| 18 const int kTransitionLink = 0; | 19 const int kTransitionLink = 0; |
| 19 const int kTransitionForwardBack = 6; | 20 const int kTransitionForwardBack = 6; |
| 20 const int kTransitionOther = 15; | 21 const int kTransitionOther = 15; |
| 21 const int kTransitionReload = 16; | 22 const int kTransitionReload = 16; |
| 22 | 23 |
| 23 namespace extensions_v8 { | 24 namespace extensions_v8 { |
| 24 | 25 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 return kTransitionForwardBack; | 88 return kTransitionForwardBack; |
| 88 case WebKit::WebNavigationTypeReload: | 89 case WebKit::WebNavigationTypeReload: |
| 89 return kTransitionReload; | 90 return kTransitionReload; |
| 90 case WebKit::WebNavigationTypeOther: | 91 case WebKit::WebNavigationTypeOther: |
| 91 return kTransitionOther; | 92 return kTransitionOther; |
| 92 } | 93 } |
| 93 return kTransitionOther; | 94 return kTransitionOther; |
| 94 } | 95 } |
| 95 | 96 |
| 96 static v8::Handle<v8::Value> GetLoadTimes(const v8::Arguments& args) { | 97 static v8::Handle<v8::Value> GetLoadTimes(const v8::Arguments& args) { |
| 97 WebFrame* frame = WebFrame::RetrieveFrameForEnteredContext(); | 98 WebFrame* frame = WebFrame::frameForEnteredContext(); |
| 98 if (frame) { | 99 if (frame) { |
| 99 WebDataSource* data_source = frame->GetDataSource(); | 100 WebDataSource* data_source = frame->dataSource(); |
| 100 if (data_source) { | 101 if (data_source) { |
| 101 NavigationState* navigation_state = | 102 NavigationState* navigation_state = |
| 102 NavigationState::FromDataSource(data_source); | 103 NavigationState::FromDataSource(data_source); |
| 103 v8::Local<v8::Object> load_times = v8::Object::New(); | 104 v8::Local<v8::Object> load_times = v8::Object::New(); |
| 104 load_times->Set( | 105 load_times->Set( |
| 105 v8::String::New("requestTime"), | 106 v8::String::New("requestTime"), |
| 106 v8::Number::New(navigation_state->request_time().ToDoubleT())); | 107 v8::Number::New(navigation_state->request_time().ToDoubleT())); |
| 107 load_times->Set( | 108 load_times->Set( |
| 108 v8::String::New("startLoadTime"), | 109 v8::String::New("startLoadTime"), |
| 109 v8::Number::New(navigation_state->start_load_time().ToDoubleT())); | 110 v8::Number::New(navigation_state->start_load_time().ToDoubleT())); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 128 v8::String::New("navigationType"), | 129 v8::String::New("navigationType"), |
| 129 v8::String::New(GetNavigationType(data_source->navigationType()))); | 130 v8::String::New(GetNavigationType(data_source->navigationType()))); |
| 130 | 131 |
| 131 return load_times; | 132 return load_times; |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 return v8::Null(); | 135 return v8::Null(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 static v8::Handle<v8::Value> GetCSI(const v8::Arguments& args) { | 138 static v8::Handle<v8::Value> GetCSI(const v8::Arguments& args) { |
| 138 WebFrame* frame = WebFrame::RetrieveFrameForEnteredContext(); | 139 WebFrame* frame = WebFrame::frameForEnteredContext(); |
| 139 if (frame) { | 140 if (frame) { |
| 140 WebDataSource* data_source = frame->GetDataSource(); | 141 WebDataSource* data_source = frame->dataSource(); |
| 141 if (data_source) { | 142 if (data_source) { |
| 142 NavigationState* navigation_state = | 143 NavigationState* navigation_state = |
| 143 NavigationState::FromDataSource(data_source); | 144 NavigationState::FromDataSource(data_source); |
| 144 v8::Local<v8::Object> csi = v8::Object::New(); | 145 v8::Local<v8::Object> csi = v8::Object::New(); |
| 145 base::Time now = base::Time::Now(); | 146 base::Time now = base::Time::Now(); |
| 146 base::Time start = navigation_state->request_time().is_null() ? | 147 base::Time start = navigation_state->request_time().is_null() ? |
| 147 navigation_state->start_load_time() : | 148 navigation_state->start_load_time() : |
| 148 navigation_state->request_time(); | 149 navigation_state->request_time(); |
| 149 base::Time onload = navigation_state->finish_document_load_time(); | 150 base::Time onload = navigation_state->finish_document_load_time(); |
| 150 base::TimeDelta page = now - start; | 151 base::TimeDelta page = now - start; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 167 } | 168 } |
| 168 return v8::Null(); | 169 return v8::Null(); |
| 169 } | 170 } |
| 170 }; | 171 }; |
| 171 | 172 |
| 172 v8::Extension* LoadTimesExtension::Get() { | 173 v8::Extension* LoadTimesExtension::Get() { |
| 173 return new LoadTimesExtensionWrapper(); | 174 return new LoadTimesExtensionWrapper(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 } // namespace extensions_v8 | 177 } // namespace extensions_v8 |
| OLD | NEW |