blob: eaec99a45b437bcfd2ea2763b4c6b98bdf2a4b91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// Copyright (c) 2013 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/net_benchmarking_extension.h"
#include "chrome/common/benchmarking_messages.h"
#include "content/public/renderer/render_thread.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h"
#include "v8/include/v8.h"
using WebKit::WebCache;
const char kNetBenchmarkingExtensionName[] = "v8/NetBenchmarking";
namespace extensions_v8 {
class NetBenchmarkingWrapper : public v8::Extension {
public:
NetBenchmarkingWrapper() :
v8::Extension(kNetBenchmarkingExtensionName,
"if (typeof(chrome) == 'undefined') {"
" chrome = {};"
"};"
"if (typeof(chrome.benchmarking) == 'undefined') {"
" chrome.benchmarking = {};"
"};"
"chrome.benchmarking.clearCache = function() {"
" native function ClearCache();"
" ClearCache();"
"};"
"chrome.benchmarking.clearHostResolverCache = function() {"
" native function ClearHostResolverCache();"
" ClearHostResolverCache();"
"};"
"chrome.benchmarking.clearPredictorCache = function() {"
" native function ClearPredictorCache();"
" ClearPredictorCache();"
"};"
"chrome.benchmarking.closeConnections = function() {"
" native function CloseConnections();"
" CloseConnections();"
"};"
"chrome.benchmarking.enableSpdy = function(name) {"
" native function EnableSpdy();"
" EnableSpdy(name);"
"};"
) {}
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
v8::Handle<v8::String> name) OVERRIDE {
if (name->Equals(v8::String::New("ClearCache"))) {
return v8::FunctionTemplate::New(ClearCache);
} else if (name->Equals(v8::String::New("ClearHostResolverCache"))) {
return v8::FunctionTemplate::New(ClearHostResolverCache);
} else if (name->Equals(v8::String::New("ClearPredictorCache"))) {
return v8::FunctionTemplate::New(ClearPredictorCache);
} else if (name->Equals(v8::String::New("EnableSpdy"))) {
return v8::FunctionTemplate::New(EnableSpdy);
} else if (name->Equals(v8::String::New("CloseConnections"))) {
return v8::FunctionTemplate::New(CloseConnections);
}
return v8::Handle<v8::FunctionTemplate>();
}
static v8::Handle<v8::Value> ClearCache(const v8::Arguments& args) {
int rv;
content::RenderThread::Get()->Send(new ChromeViewHostMsg_ClearCache(&rv));
WebCache::clear();
return v8::Undefined();
}
static v8::Handle<v8::Value> ClearHostResolverCache(
const v8::Arguments& args) {
int rv;
content::RenderThread::Get()->Send(
new ChromeViewHostMsg_ClearHostResolverCache(&rv));
return v8::Undefined();
}
static v8::Handle<v8::Value> ClearPredictorCache(
const v8::Arguments& args) {
int rv;
content::RenderThread::Get()->Send(
new ChromeViewHostMsg_ClearPredictorCache(&rv));
return v8::Undefined();
}
static v8::Handle<v8::Value> CloseConnections(const v8::Arguments& args) {
content::RenderThread::Get()->Send(
new ChromeViewHostMsg_CloseCurrentConnections());
return v8::Undefined();
}
static v8::Handle<v8::Value> EnableSpdy(const v8::Arguments& args) {
if (!args.Length() || !args[0]->IsBoolean())
return v8::Undefined();
content::RenderThread::Get()->Send(new ChromeViewHostMsg_EnableSpdy(
args[0]->BooleanValue()));
return v8::Undefined();
}
};
v8::Extension* NetBenchmarkingExtension::Get() {
return new NetBenchmarkingWrapper();
}
} // namespace extensions_v8
|