Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Side by Side Diff: chrome/renderer/loadtimes_extension_bindings.cc

Issue 8404018: chrome.loadTimes() shouldn't be affected by in-document navigation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and merge Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "content/public/renderer/navigation_state.h" 10 #include "content/public/renderer/document_state.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
12 #include "v8/include/v8.h" 12 #include "v8/include/v8.h"
13 13
14 using WebKit::WebDataSource; 14 using WebKit::WebDataSource;
15 using WebKit::WebFrame; 15 using WebKit::WebFrame;
16 using WebKit::WebNavigationType; 16 using WebKit::WebNavigationType;
17 using content::NavigationState; 17 using content::DocumentState;
18 18
19 // Values for CSI "tran" property 19 // Values for CSI "tran" property
20 const int kTransitionLink = 0; 20 const int kTransitionLink = 0;
21 const int kTransitionForwardBack = 6; 21 const int kTransitionForwardBack = 6;
22 const int kTransitionOther = 15; 22 const int kTransitionOther = 15;
23 const int kTransitionReload = 16; 23 const int kTransitionReload = 16;
24 24
25 namespace extensions_v8 { 25 namespace extensions_v8 {
26 26
27 static const char* const kLoadTimesExtensionName = "v8/LoadTimes"; 27 static const char* const kLoadTimesExtensionName = "v8/LoadTimes";
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return kTransitionOther; 93 return kTransitionOther;
94 } 94 }
95 return kTransitionOther; 95 return kTransitionOther;
96 } 96 }
97 97
98 static v8::Handle<v8::Value> GetLoadTimes(const v8::Arguments& args) { 98 static v8::Handle<v8::Value> GetLoadTimes(const v8::Arguments& args) {
99 WebFrame* frame = WebFrame::frameForCurrentContext(); 99 WebFrame* frame = WebFrame::frameForCurrentContext();
100 if (frame) { 100 if (frame) {
101 WebDataSource* data_source = frame->dataSource(); 101 WebDataSource* data_source = frame->dataSource();
102 if (data_source) { 102 if (data_source) {
103 NavigationState* navigation_state = 103 DocumentState* document_state =
104 NavigationState::FromDataSource(data_source); 104 DocumentState::FromDataSource(data_source);
105 v8::Local<v8::Object> load_times = v8::Object::New(); 105 v8::Local<v8::Object> load_times = v8::Object::New();
106 load_times->Set( 106 load_times->Set(
107 v8::String::New("requestTime"), 107 v8::String::New("requestTime"),
108 v8::Number::New(navigation_state->request_time().ToDoubleT())); 108 v8::Number::New(document_state->request_time().ToDoubleT()));
109 load_times->Set( 109 load_times->Set(
110 v8::String::New("startLoadTime"), 110 v8::String::New("startLoadTime"),
111 v8::Number::New(navigation_state->start_load_time().ToDoubleT())); 111 v8::Number::New(document_state->start_load_time().ToDoubleT()));
112 load_times->Set( 112 load_times->Set(
113 v8::String::New("commitLoadTime"), 113 v8::String::New("commitLoadTime"),
114 v8::Number::New(navigation_state->commit_load_time().ToDoubleT())); 114 v8::Number::New(document_state->commit_load_time().ToDoubleT()));
115 load_times->Set( 115 load_times->Set(
116 v8::String::New("finishDocumentLoadTime"), 116 v8::String::New("finishDocumentLoadTime"),
117 v8::Number::New( 117 v8::Number::New(
118 navigation_state->finish_document_load_time().ToDoubleT())); 118 document_state->finish_document_load_time().ToDoubleT()));
119 load_times->Set( 119 load_times->Set(
120 v8::String::New("finishLoadTime"), 120 v8::String::New("finishLoadTime"),
121 v8::Number::New(navigation_state->finish_load_time().ToDoubleT())); 121 v8::Number::New(document_state->finish_load_time().ToDoubleT()));
122 load_times->Set( 122 load_times->Set(
123 v8::String::New("firstPaintTime"), 123 v8::String::New("firstPaintTime"),
124 v8::Number::New(navigation_state->first_paint_time().ToDoubleT())); 124 v8::Number::New(document_state->first_paint_time().ToDoubleT()));
125 load_times->Set( 125 load_times->Set(
126 v8::String::New("firstPaintAfterLoadTime"), 126 v8::String::New("firstPaintAfterLoadTime"),
127 v8::Number::New( 127 v8::Number::New(
128 navigation_state->first_paint_after_load_time().ToDoubleT())); 128 document_state->first_paint_after_load_time().ToDoubleT()));
129 load_times->Set( 129 load_times->Set(
130 v8::String::New("navigationType"), 130 v8::String::New("navigationType"),
131 v8::String::New(GetNavigationType(data_source->navigationType()))); 131 v8::String::New(GetNavigationType(data_source->navigationType())));
132 load_times->Set( 132 load_times->Set(
133 v8::String::New("wasFetchedViaSpdy"), 133 v8::String::New("wasFetchedViaSpdy"),
134 v8::Boolean::New(navigation_state->was_fetched_via_spdy())); 134 v8::Boolean::New(document_state->was_fetched_via_spdy()));
135 load_times->Set( 135 load_times->Set(
136 v8::String::New("wasNpnNegotiated"), 136 v8::String::New("wasNpnNegotiated"),
137 v8::Boolean::New(navigation_state->was_npn_negotiated())); 137 v8::Boolean::New(document_state->was_npn_negotiated()));
138 load_times->Set( 138 load_times->Set(
139 v8::String::New("wasAlternateProtocolAvailable"), 139 v8::String::New("wasAlternateProtocolAvailable"),
140 v8::Boolean::New( 140 v8::Boolean::New(
141 navigation_state->was_alternate_protocol_available())); 141 document_state->was_alternate_protocol_available()));
142 return load_times; 142 return load_times;
143 } 143 }
144 } 144 }
145 return v8::Null(); 145 return v8::Null();
146 } 146 }
147 147
148 static v8::Handle<v8::Value> GetCSI(const v8::Arguments& args) { 148 static v8::Handle<v8::Value> GetCSI(const v8::Arguments& args) {
149 WebFrame* frame = WebFrame::frameForCurrentContext(); 149 WebFrame* frame = WebFrame::frameForCurrentContext();
150 if (frame) { 150 if (frame) {
151 WebDataSource* data_source = frame->dataSource(); 151 WebDataSource* data_source = frame->dataSource();
152 if (data_source) { 152 if (data_source) {
153 NavigationState* navigation_state = 153 DocumentState* document_state =
154 NavigationState::FromDataSource(data_source); 154 DocumentState::FromDataSource(data_source);
155 v8::Local<v8::Object> csi = v8::Object::New(); 155 v8::Local<v8::Object> csi = v8::Object::New();
156 base::Time now = base::Time::Now(); 156 base::Time now = base::Time::Now();
157 base::Time start = navigation_state->request_time().is_null() ? 157 base::Time start = document_state->request_time().is_null() ?
158 navigation_state->start_load_time() : 158 document_state->start_load_time() :
159 navigation_state->request_time(); 159 document_state->request_time();
160 base::Time onload = navigation_state->finish_document_load_time(); 160 base::Time onload = document_state->finish_document_load_time();
161 base::TimeDelta page = now - start; 161 base::TimeDelta page = now - start;
162 csi->Set( 162 csi->Set(
163 v8::String::New("startE"), 163 v8::String::New("startE"),
164 v8::Number::New(floor(start.ToDoubleT() * 1000))); 164 v8::Number::New(floor(start.ToDoubleT() * 1000)));
165 csi->Set( 165 csi->Set(
166 v8::String::New("onloadT"), 166 v8::String::New("onloadT"),
167 v8::Number::New(floor(onload.ToDoubleT() * 1000))); 167 v8::Number::New(floor(onload.ToDoubleT() * 1000)));
168 csi->Set( 168 csi->Set(
169 v8::String::New("pageT"), 169 v8::String::New("pageT"),
170 v8::Number::New(page.InMillisecondsF())); 170 v8::Number::New(page.InMillisecondsF()));
171 csi->Set( 171 csi->Set(
172 v8::String::New("tran"), 172 v8::String::New("tran"),
173 v8::Number::New( 173 v8::Number::New(
174 GetCSITransitionType(data_source->navigationType()))); 174 GetCSITransitionType(data_source->navigationType())));
175 175
176 return csi; 176 return csi;
177 } 177 }
178 } 178 }
179 return v8::Null(); 179 return v8::Null();
180 } 180 }
181 }; 181 };
182 182
183 v8::Extension* LoadTimesExtension::Get() { 183 v8::Extension* LoadTimesExtension::Get() {
184 return new LoadTimesExtensionWrapper(); 184 return new LoadTimesExtensionWrapper();
185 } 185 }
186 186
187 } // namespace extensions_v8 187 } // namespace extensions_v8
OLDNEW
« no previous file with comments | « chrome/renderer/content_settings_observer.cc ('k') | chrome/renderer/loadtimes_extension_bindings_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698