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

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

Issue 42527: - Added support for keeping track of load times.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/extensions/loadtimes_extension_bindings.h"
6
7 #include "base/time.h"
8 #include "v8/include/v8.h"
9 #include "webkit/glue/webframe.h"
10 #include "webkit/glue/webdatasource.h"
11
12 namespace extensions_v8 {
13
14 static const char* kLoadTimesExtensionName = "v8/LoadTimes";
15
16 class LoadTimesExtensionWrapper : public v8::Extension {
17 public:
18 // Creates an extension which adds a new function, chromium.GetLoadTimes()
19 // This function returns an object containing the following members:
20 // requestTime: The time the request to load the page was received
21 // loadTime: The time the renderer started the load process
22 // finishDocumentLoadTime: The time the document itself was loaded
23 // (this is before the onload() method is fired)
24 // finishLoadTime: The time all loading is done, after the onload()
25 // method and all resources
26 // navigationType: A string describing what user action initiated the load
27 LoadTimesExtensionWrapper() :
28 v8::Extension(kLoadTimesExtensionName,
29 "var chromium;"
30 "if (!chromium)"
31 " chromium = {};"
32 "chromium.GetLoadTimes = function() {"
33 " native function GetLoadTimes();"
34 " return GetLoadTimes();"
35 "}") {}
36
37 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
38 v8::Handle<v8::String> name) {
39 if (name->Equals(v8::String::New("GetLoadTimes"))) {
40 return v8::FunctionTemplate::New(GetLoadTimes);
41 }
42 return v8::Handle<v8::FunctionTemplate>();
43 }
44
45 static const char *GetNavigationType(WebNavigationType nav_type) {
46 switch (nav_type) {
47 case WebNavigationTypeLinkClicked: return "LinkClicked";
48 case WebNavigationTypeFormSubmitted: return "FormSubmitted";
49 case WebNavigationTypeBackForward: return "BackForward";
50 case WebNavigationTypeReload: return "Reload";
51 case WebNavigationTypeFormResubmitted: return "Resubmitted";
52 case WebNavigationTypeOther: return "Other";
53 }
54 return "";
55 }
56
57 static v8::Handle<v8::Value> GetLoadTimes(const v8::Arguments& args) {
58 WebFrame* win_frame = WebFrame::RetrieveActiveFrame();
59 if (win_frame) {
60 WebDataSource* data_source = win_frame->GetDataSource();
61 if (data_source) {
62 v8::Local<v8::Object> load_times = v8::Object::New();
63 load_times->Set(
64 v8::String::New("requestTime"),
65 v8::Number::New(data_source->GetRequestTime().ToDoubleT()));
66 load_times->Set(
67 v8::String::New("startLoadTime"),
68 v8::Number::New(data_source->GetStartLoadTime().ToDoubleT()));
69 load_times->Set(
70 v8::String::New("finishDocumentLoadTime"),
71 v8::Number::New(
72 data_source->GetFinishDocumentLoadTime().ToDoubleT()));
73 load_times->Set(
74 v8::String::New("finishLoadTime"),
75 v8::Number::New(data_source->GetFinishLoadTime().ToDoubleT()));
76 load_times->Set(
77 v8::String::New("navigationType"),
78 v8::String::New(
79 GetNavigationType(data_source->GetNavigationType())));
80 return load_times;
81 }
82 }
83 return v8::Null();
84 }
85 };
86
87 v8::Extension* LoadTimesExtension::Get() {
88 return new LoadTimesExtensionWrapper();
89 }
90
91 } // namespace extensions_v8
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/loadtimes_extension_bindings.h ('k') | chrome/renderer/render_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698