diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-30 20:06:41 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-30 20:06:41 +0000 |
commit | c80efa1785da4bde5b5ce23b75646d603b0ec588 (patch) | |
tree | c385e6dcc22a0e8f8e21f13fa362cbc513ffbeab /chrome/renderer/loadtimes_extension_bindings.cc | |
parent | a282a138e9dce5e4d44fb7edd1ac664e8771c349 (diff) | |
download | chromium_src-c80efa1785da4bde5b5ce23b75646d603b0ec588.zip chromium_src-c80efa1785da4bde5b5ce23b75646d603b0ec588.tar.gz chromium_src-c80efa1785da4bde5b5ce23b75646d603b0ec588.tar.bz2 |
Introduce new api for the csi folks. This exposes the already existing
JS api to loadtimes in a way that's more easily digestible for them.
Review URL: http://codereview.chromium.org/150083
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19636 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/loadtimes_extension_bindings.cc')
-rw-r--r-- | chrome/renderer/loadtimes_extension_bindings.cc | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/chrome/renderer/loadtimes_extension_bindings.cc b/chrome/renderer/loadtimes_extension_bindings.cc index 11b5d89..a8afe17 100644 --- a/chrome/renderer/loadtimes_extension_bindings.cc +++ b/chrome/renderer/loadtimes_extension_bindings.cc @@ -4,14 +4,22 @@ #include "chrome/renderer/loadtimes_extension_bindings.h" +#include <math.h> + #include "base/time.h" -#include "v8/include/v8.h" #include "chrome/renderer/navigation_state.h" +#include "v8/include/v8.h" #include "webkit/glue/webframe.h" using WebKit::WebDataSource; using WebKit::WebNavigationType; +// Values for CSI "tran" property +const int kTransitionLink = 0; +const int kTransitionForwardBack = 6; +const int kTransitionOther = 15; +const int kTransitionReload = 16; + namespace extensions_v8 { static const char* kLoadTimesExtensionName = "v8/LoadTimes"; @@ -32,15 +40,21 @@ class LoadTimesExtensionWrapper : public v8::Extension { "var chrome;" "if (!chrome)" " chrome = {};" - "chrome.GetLoadTimes = function() {" + "chrome.loadTimes = function() {" " native function GetLoadTimes();" " return GetLoadTimes();" + "};" + "chrome.csi = function() {" + " native function GetCSI();" + " return GetCSI();" "}") {} virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( v8::Handle<v8::String> name) { if (name->Equals(v8::String::New("GetLoadTimes"))) { return v8::FunctionTemplate::New(GetLoadTimes); + } else if (name->Equals(v8::String::New("GetCSI"))) { + return v8::FunctionTemplate::New(GetCSI); } return v8::Handle<v8::FunctionTemplate>(); } @@ -63,6 +77,22 @@ class LoadTimesExtensionWrapper : public v8::Extension { return ""; } + static int GetCSITransitionType(WebNavigationType nav_type) { + switch (nav_type) { + case WebKit::WebNavigationTypeLinkClicked: + case WebKit::WebNavigationTypeFormSubmitted: + case WebKit::WebNavigationTypeFormResubmitted: + return kTransitionLink; + case WebKit::WebNavigationTypeBackForward: + return kTransitionForwardBack; + case WebKit::WebNavigationTypeReload: + return kTransitionReload; + case WebKit::WebNavigationTypeOther: + return kTransitionOther; + } + return kTransitionOther; + } + static v8::Handle<v8::Value> GetLoadTimes(const v8::Arguments& args) { WebFrame* frame = WebFrame::RetrieveFrameForEnteredContext(); if (frame) { @@ -91,6 +121,10 @@ class LoadTimesExtensionWrapper : public v8::Extension { v8::String::New("firstPaintTime"), v8::Number::New(navigation_state->first_paint_time().ToDoubleT())); load_times->Set( + v8::String::New("firstPaintAfterLoadTime"), + v8::Number::New( + navigation_state->first_paint_after_load_time().ToDoubleT())); + load_times->Set( v8::String::New("navigationType"), v8::String::New(GetNavigationType(data_source->navigationType()))); @@ -99,6 +133,40 @@ class LoadTimesExtensionWrapper : public v8::Extension { } return v8::Null(); } + + static v8::Handle<v8::Value> GetCSI(const v8::Arguments& args) { + WebFrame* frame = WebFrame::RetrieveFrameForEnteredContext(); + if (frame) { + WebDataSource* data_source = frame->GetDataSource(); + if (data_source) { + NavigationState* navigation_state = + NavigationState::FromDataSource(data_source); + v8::Local<v8::Object> csi = v8::Object::New(); + base::Time now = base::Time::Now(); + base::Time start = navigation_state->request_time().is_null() ? + navigation_state->start_load_time() : + navigation_state->request_time(); + base::Time onload = navigation_state->finish_document_load_time(); + base::TimeDelta page = now - start; + csi->Set( + v8::String::New("startE"), + v8::Number::New(floor(start.ToDoubleT() * 1000))); + csi->Set( + v8::String::New("onloadT"), + v8::Number::New(floor(onload.ToDoubleT() * 1000))); + csi->Set( + v8::String::New("pageT"), + v8::Number::New(page.InMillisecondsF())); + csi->Set( + v8::String::New("tran"), + v8::Number::New( + GetCSITransitionType(data_source->navigationType()))); + + return csi; + } + } + return v8::Null(); + } }; v8::Extension* LoadTimesExtension::Get() { |