| Index: content/renderer/gpu/gpu_benchmarking_extension.cc | 
| diff --git a/content/renderer/gpu/gpu_benchmarking_extension.cc b/content/renderer/gpu/gpu_benchmarking_extension.cc | 
| index 8590e1116b855eaadbe95d5ba3ac47d569435e58..d62f6b91c9938920a9e808c8b5e4b9754773c2e6 100644 | 
| --- a/content/renderer/gpu/gpu_benchmarking_extension.cc | 
| +++ b/content/renderer/gpu/gpu_benchmarking_extension.cc | 
| @@ -3,14 +3,22 @@ | 
| // found in the LICENSE file. | 
|  | 
| #include "content/renderer/gpu/gpu_benchmarking_extension.h" | 
| + | 
| +#include <string> | 
| + | 
| +#include "content/public/renderer/all_rendering_benchmarks.h" | 
| +#include "content/public/renderer/render_thread.h" | 
| +#include "content/public/renderer/rendering_benchmark_results.h" | 
| #include "content/renderer/render_view_impl.h" | 
| #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h" | 
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSupport.h" | 
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 
| -#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 
| #include "v8/include/v8.h" | 
|  | 
| using WebKit::WebFrame; | 
| +using WebKit::WebPrivatePtr; | 
| +using WebKit::WebViewBenchmarkSupport; | 
| using WebKit::WebRenderingStats; | 
| using WebKit::WebView; | 
|  | 
| @@ -21,6 +29,33 @@ using WebKit::WebView; | 
|  | 
| namespace content { | 
|  | 
| +// Benchmark results object that populates a v8 array. | 
| +class V8BenchmarkResults : public content::RenderingBenchmarkResults { | 
| + public: | 
| +  explicit V8BenchmarkResults(v8::Handle<v8::Array> results_array) | 
| +    : results_array_(results_array) { } | 
| +  virtual ~V8BenchmarkResults() {} | 
| + | 
| +  void addResult(const std::string& benchmark_name, | 
| +                 const std::string& result_name, | 
| +                 const std::string& time_unit, | 
| +                 double time) { | 
| +    v8::Handle<v8::Object> result = v8::Object::New(); | 
| +    result->Set(v8::String::New("benchmarkName", 13), | 
| +                v8::String::New(benchmark_name.c_str(), -1)); | 
| +    result->Set(v8::String::New("resultName", 10), | 
| +                v8::String::New(result_name.c_str(), -1)); | 
| +    result->Set(v8::String::New("timeUnit", 8), | 
| +                v8::String::New(time_unit.c_str(), -1)); | 
| +    result->Set(v8::String::New("time", 4), v8::Number::New(time)); | 
| +    int size = results_array_->Length(); | 
| +    results_array_->Set(size, result); | 
| +  } | 
| + | 
| + private: | 
| +  v8::Handle<v8::Array> results_array_; | 
| +}; | 
| + | 
| class GpuBenchmarkingWrapper : public v8::Extension { | 
| public: | 
| GpuBenchmarkingWrapper() : | 
| @@ -45,6 +80,10 @@ class GpuBenchmarkingWrapper : public v8::Extension { | 
| "  scroll_far = scroll_far || false;" | 
| "  native function BeginSmoothScroll();" | 
| "  return BeginSmoothScroll(false, scroll_far);" | 
| +          "};" | 
| +          "chrome.gpuBenchmarking.runRenderingBenchmarks = function(filter) {" | 
| +          "  native function RunRenderingBenchmarks();" | 
| +          "  return RunRenderingBenchmarks(filter);" | 
| "};") {} | 
|  | 
| virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 
| @@ -53,7 +92,8 @@ class GpuBenchmarkingWrapper : public v8::Extension { | 
| return v8::FunctionTemplate::New(GetRenderingStats); | 
| if (name->Equals(v8::String::New("BeginSmoothScroll"))) | 
| return v8::FunctionTemplate::New(BeginSmoothScroll); | 
| - | 
| +    if (name->Equals(v8::String::New("RunRenderingBenchmarks"))) | 
| +      return v8::FunctionTemplate::New(RunRenderingBenchmarks); | 
| return v8::Handle<v8::FunctionTemplate>(); | 
| } | 
|  | 
| @@ -103,6 +143,42 @@ class GpuBenchmarkingWrapper : public v8::Extension { | 
| render_view_impl->BeginSmoothScroll(scroll_down, scroll_far); | 
| return v8::True(); | 
| } | 
| + | 
| +  static v8::Handle<v8::Value> RunRenderingBenchmarks( | 
| +        const v8::Arguments& args) { | 
| +    // for our name filter, the argument can be undefined or null to run | 
| +    // all benchmarks, or a string for filtering by name | 
| +    if (!args.Length() || | 
| +        (!args[0]->IsString() && | 
| +            !(args[0]->IsNull() || args[0]->IsUndefined()))) | 
| +      return v8::Undefined(); | 
| + | 
| +    WebFrame* web_frame = WebFrame::frameForEnteredContext(); | 
| +    if (!web_frame) | 
| +      return v8::Undefined(); | 
| + | 
| +    WebView* web_view = web_frame->view(); | 
| +    if (!web_view) | 
| +      return v8::Undefined(); | 
| + | 
| +    v8::Handle<v8::Array> resultsArray = v8::Array::New(0); | 
| +    V8BenchmarkResults results(resultsArray); | 
| +    std::string nameFilter; | 
| +    if (args[0]->IsNull() || args[0]->IsUndefined()) { | 
| +      nameFilter = ""; | 
| +    } else { | 
| +      char filter[256]; | 
| +      args[0]->ToString()->WriteAscii(filter, 0, sizeof(filter)-1); | 
| +      nameFilter = std::string(filter); | 
| +    } | 
| +    WebViewBenchmarkSupport* support = | 
| +        web_view->benchmarkSupport(); | 
| +    content::AllRenderingBenchmarks allBenchmarks(&results, nameFilter); | 
| +    allBenchmarks.SetUp(support); | 
| +    allBenchmarks.Run(support); | 
| +    allBenchmarks.TearDown(support); | 
| +    return resultsArray; | 
| +  } | 
| }; | 
|  | 
| v8::Extension* GpuBenchmarkingExtension::Get() { | 
|  |