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

Unified Diff: content/renderer/gpu/gpu_benchmarking_extension.cc

Issue 10837330: Add a completion callback to gpuBenchmarking.beginSmoothScroll (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: virtual and todo note Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/port/browser/smooth_scroll_gesture.h ('k') | content/renderer/render_widget.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6f4fccc4bf99f77475c63c588a7392a0493e6801..2e0f1aed7064486d94fcb5ecfd0d5dd24375abc1 100644
--- a/content/renderer/gpu/gpu_benchmarking_extension.cc
+++ b/content/renderer/gpu/gpu_benchmarking_extension.cc
@@ -135,15 +135,18 @@ class GpuBenchmarkingWrapper : public v8::Extension {
" return PrintToSkPicture(dirname);"
"};"
"chrome.gpuBenchmarking.beginSmoothScrollDown = "
- " function(scroll_far) {"
+ " function(scroll_far, opt_callback) {"
" scroll_far = scroll_far || false;"
+ " callback = opt_callback || function() { };"
" native function BeginSmoothScroll();"
- " return BeginSmoothScroll(true, scroll_far);"
+ " return BeginSmoothScroll(true, scroll_far, callback);"
"};"
- "chrome.gpuBenchmarking.beginSmoothScrollUp = function(scroll_far) {"
+ "chrome.gpuBenchmarking.beginSmoothScrollUp = "
+ " function(scroll_far, opt_callback) {"
" scroll_far = scroll_far || false;"
+ " callback = opt_callback || function() { };"
" native function BeginSmoothScroll();"
- " return BeginSmoothScroll(false, scroll_far);"
+ " return BeginSmoothScroll(false, scroll_far, callback);"
"};"
"chrome.gpuBenchmarking.runRenderingBenchmarks = function(filter) {"
" native function RunRenderingBenchmarks();"
@@ -230,6 +233,21 @@ class GpuBenchmarkingWrapper : public v8::Extension {
return v8::Undefined();
}
+ static void OnSmoothScrollCompleted(v8::Persistent<v8::Function> callback,
+ v8::Persistent<v8::Context> context) {
+ v8::HandleScope scope;
+ v8::Context::Scope context_scope(context);
+ WebFrame* frame = WebFrame::frameForContext(context);
+ if (frame) {
+ frame->callFunctionEvenIfScriptDisabled(callback,
+ v8::Object::New(),
+ 0,
+ NULL);
+ }
+ callback.Dispose();
+ context.Dispose();
+ }
+
static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) {
WebFrame* web_frame = WebFrame::frameForEnteredContext();
if (!web_frame)
@@ -243,13 +261,31 @@ class GpuBenchmarkingWrapper : public v8::Extension {
if (!render_view_impl)
return v8::Undefined();
- if (args.Length() != 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean())
+ if (args.Length() != 3 ||
+ !args[0]->IsBoolean() ||
+ !args[1]->IsBoolean() ||
+ !args[2]->IsFunction())
return v8::False();
bool scroll_down = args[0]->BooleanValue();
bool scroll_far = args[1]->BooleanValue();
+ v8::Local<v8::Function> callback_local =
+ v8::Local<v8::Function>(v8::Function::Cast(*args[2]));
+ v8::Persistent<v8::Function> callback =
+ v8::Persistent<v8::Function>::New(callback_local);
+ v8::Persistent<v8::Context> context =
+ v8::Persistent<v8::Context>::New(web_frame->mainWorldScriptContext());
+
+ // TODO(nduca): If the render_view_impl is destroyed while the gesture is in
+ // progress, we will leak the callback and context. This needs to be fixed,
+ // somehow.
+ render_view_impl->BeginSmoothScroll(
+ scroll_down,
+ scroll_far,
+ base::Bind(&OnSmoothScrollCompleted,
+ callback,
+ context));
- render_view_impl->BeginSmoothScroll(scroll_down, scroll_far);
return v8::True();
}
« no previous file with comments | « content/port/browser/smooth_scroll_gesture.h ('k') | content/renderer/render_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698