summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/extensions
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-03 21:39:26 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-03 21:39:26 +0000
commitc20210e6a0c40bce1781a42abf81b44ba627f2a9 (patch)
treee658b8111109145bc450603ac69cb0de3dd47eb2 /chrome/renderer/extensions
parent601b54022e6232875c8b24501e425b450f071217 (diff)
downloadchromium_src-c20210e6a0c40bce1781a42abf81b44ba627f2a9.zip
chromium_src-c20210e6a0c40bce1781a42abf81b44ba627f2a9.tar.gz
chromium_src-c20210e6a0c40bce1781a42abf81b44ba627f2a9.tar.bz2
- Added support for keeping track of load times.
For each document loaded we record the time the page was requested by the user (or as close as we can get to that), the time the load process started, the time the document and it's dependent resources (scripts) have been loaded (before onload()) and the time all the document's resources have been loaded. We use this data for two things: 1) We histogram the deltas between the time marks 2) We expose the times to javascript running on the page which was loaded Review URL: http://codereview.chromium.org/42527 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13116 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/extensions')
-rw-r--r--chrome/renderer/extensions/loadtimes_extension_bindings.cc91
-rw-r--r--chrome/renderer/extensions/loadtimes_extension_bindings.h24
2 files changed, 115 insertions, 0 deletions
diff --git a/chrome/renderer/extensions/loadtimes_extension_bindings.cc b/chrome/renderer/extensions/loadtimes_extension_bindings.cc
new file mode 100644
index 0000000..b0836036
--- /dev/null
+++ b/chrome/renderer/extensions/loadtimes_extension_bindings.cc
@@ -0,0 +1,91 @@
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/extensions/loadtimes_extension_bindings.h"
+
+#include "base/time.h"
+#include "v8/include/v8.h"
+#include "webkit/glue/webframe.h"
+#include "webkit/glue/webdatasource.h"
+
+namespace extensions_v8 {
+
+static const char* kLoadTimesExtensionName = "v8/LoadTimes";
+
+class LoadTimesExtensionWrapper : public v8::Extension {
+ public:
+ // Creates an extension which adds a new function, chromium.GetLoadTimes()
+ // This function returns an object containing the following members:
+ // requestTime: The time the request to load the page was received
+ // loadTime: The time the renderer started the load process
+ // finishDocumentLoadTime: The time the document itself was loaded
+ // (this is before the onload() method is fired)
+ // finishLoadTime: The time all loading is done, after the onload()
+ // method and all resources
+ // navigationType: A string describing what user action initiated the load
+ LoadTimesExtensionWrapper() :
+ v8::Extension(kLoadTimesExtensionName,
+ "var chromium;"
+ "if (!chromium)"
+ " chromium = {};"
+ "chromium.GetLoadTimes = function() {"
+ " native function GetLoadTimes();"
+ " return GetLoadTimes();"
+ "}") {}
+
+ virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
+ v8::Handle<v8::String> name) {
+ if (name->Equals(v8::String::New("GetLoadTimes"))) {
+ return v8::FunctionTemplate::New(GetLoadTimes);
+ }
+ return v8::Handle<v8::FunctionTemplate>();
+ }
+
+ static const char *GetNavigationType(WebNavigationType nav_type) {
+ switch (nav_type) {
+ case WebNavigationTypeLinkClicked: return "LinkClicked";
+ case WebNavigationTypeFormSubmitted: return "FormSubmitted";
+ case WebNavigationTypeBackForward: return "BackForward";
+ case WebNavigationTypeReload: return "Reload";
+ case WebNavigationTypeFormResubmitted: return "Resubmitted";
+ case WebNavigationTypeOther: return "Other";
+ }
+ return "";
+ }
+
+ static v8::Handle<v8::Value> GetLoadTimes(const v8::Arguments& args) {
+ WebFrame* win_frame = WebFrame::RetrieveActiveFrame();
+ if (win_frame) {
+ WebDataSource* data_source = win_frame->GetDataSource();
+ if (data_source) {
+ v8::Local<v8::Object> load_times = v8::Object::New();
+ load_times->Set(
+ v8::String::New("requestTime"),
+ v8::Number::New(data_source->GetRequestTime().ToDoubleT()));
+ load_times->Set(
+ v8::String::New("startLoadTime"),
+ v8::Number::New(data_source->GetStartLoadTime().ToDoubleT()));
+ load_times->Set(
+ v8::String::New("finishDocumentLoadTime"),
+ v8::Number::New(
+ data_source->GetFinishDocumentLoadTime().ToDoubleT()));
+ load_times->Set(
+ v8::String::New("finishLoadTime"),
+ v8::Number::New(data_source->GetFinishLoadTime().ToDoubleT()));
+ load_times->Set(
+ v8::String::New("navigationType"),
+ v8::String::New(
+ GetNavigationType(data_source->GetNavigationType())));
+ return load_times;
+ }
+ }
+ return v8::Null();
+ }
+};
+
+v8::Extension* LoadTimesExtension::Get() {
+ return new LoadTimesExtensionWrapper();
+}
+
+} // namespace extensions_v8
diff --git a/chrome/renderer/extensions/loadtimes_extension_bindings.h b/chrome/renderer/extensions/loadtimes_extension_bindings.h
new file mode 100644
index 0000000..4a6bcf5
--- /dev/null
+++ b/chrome/renderer/extensions/loadtimes_extension_bindings.h
@@ -0,0 +1,24 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// The LoadTimesExtension is a v8 extension to access the time it took
+// to load a page.
+
+#ifndef CHROME_RENDERER_EXTENSIONS_LOADTIMES_EXTENSION_BINDINGS_H_
+#define CHROME_RENDERER_EXTENSIONS_LOADTIMES_EXTENSION_BINDINGS_H_
+
+namespace v8 {
+class Extension;
+}
+
+namespace extensions_v8 {
+
+class LoadTimesExtension {
+ public:
+ static v8::Extension* Get();
+};
+
+} // namespace extensions_v8
+
+#endif // CHROME_RENDERER_EXTENSIONS_LOADTIMES_EXTENSION_BINDINGS_H_