OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/gpu/gpu_benchmarking_extension.h" | 5 #include "content/renderer/gpu/gpu_benchmarking_extension.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 v8::Persistent<v8::Context> context) { | 240 v8::Persistent<v8::Context> context) { |
241 v8::HandleScope scope; | 241 v8::HandleScope scope; |
242 v8::Context::Scope context_scope(context); | 242 v8::Context::Scope context_scope(context); |
243 WebFrame* frame = WebFrame::frameForContext(context); | 243 WebFrame* frame = WebFrame::frameForContext(context); |
244 if (frame) { | 244 if (frame) { |
245 frame->callFunctionEvenIfScriptDisabled(callback, | 245 frame->callFunctionEvenIfScriptDisabled(callback, |
246 v8::Object::New(), | 246 v8::Object::New(), |
247 0, | 247 0, |
248 NULL); | 248 NULL); |
249 } | 249 } |
250 callback.Dispose(); | 250 v8::Isolate* isolate = context->GetIsolate(); |
251 context.Dispose(); | 251 callback.Dispose(isolate); |
| 252 context.Dispose(isolate); |
252 } | 253 } |
253 | 254 |
254 static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) { | 255 static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) { |
255 WebFrame* web_frame = WebFrame::frameForCurrentContext(); | 256 WebFrame* web_frame = WebFrame::frameForCurrentContext(); |
256 if (!web_frame) | 257 if (!web_frame) |
257 return v8::Undefined(); | 258 return v8::Undefined(); |
258 | 259 |
259 WebView* web_view = web_frame->view(); | 260 WebView* web_view = web_frame->view(); |
260 if (!web_view) | 261 if (!web_view) |
261 return v8::Undefined(); | 262 return v8::Undefined(); |
262 | 263 |
263 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); | 264 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); |
264 if (!render_view_impl) | 265 if (!render_view_impl) |
265 return v8::Undefined(); | 266 return v8::Undefined(); |
266 | 267 |
267 // Account for the 2 optional arguments, mouse_event_x and mouse_event_y. | 268 // Account for the 2 optional arguments, mouse_event_x and mouse_event_y. |
268 int arglen = args.Length(); | 269 int arglen = args.Length(); |
269 if (arglen < 3 || | 270 if (arglen < 3 || |
270 !args[0]->IsBoolean() || | 271 !args[0]->IsBoolean() || |
271 !args[1]->IsFunction() || | 272 !args[1]->IsFunction() || |
272 !args[2]->IsNumber()) | 273 !args[2]->IsNumber()) |
273 return v8::False(); | 274 return v8::False(); |
274 | 275 |
275 bool scroll_down = args[0]->BooleanValue(); | 276 bool scroll_down = args[0]->BooleanValue(); |
276 v8::Local<v8::Function> callback_local = | 277 v8::Local<v8::Function> callback_local = |
277 v8::Local<v8::Function>(v8::Function::Cast(*args[1])); | 278 v8::Local<v8::Function>(v8::Function::Cast(*args[1])); |
| 279 v8::Isolate* isolate = args.GetIsolate(); |
278 v8::Persistent<v8::Function> callback = | 280 v8::Persistent<v8::Function> callback = |
279 v8::Persistent<v8::Function>::New(callback_local); | 281 v8::Persistent<v8::Function>::New(isolate, callback_local); |
280 v8::Persistent<v8::Context> context = | 282 v8::Persistent<v8::Context> context = |
281 v8::Persistent<v8::Context>::New(web_frame->mainWorldScriptContext()); | 283 v8::Persistent<v8::Context>::New(isolate, |
| 284 web_frame->mainWorldScriptContext()); |
282 | 285 |
283 int pixels_to_scroll = args[2]->IntegerValue(); | 286 int pixels_to_scroll = args[2]->IntegerValue(); |
284 | 287 |
285 int mouse_event_x = 0; | 288 int mouse_event_x = 0; |
286 int mouse_event_y = 0; | 289 int mouse_event_y = 0; |
287 | 290 |
288 if (arglen == 3) { | 291 if (arglen == 3) { |
289 WebKit::WebRect rect = render_view_impl->windowRect(); | 292 WebKit::WebRect rect = render_view_impl->windowRect(); |
290 mouse_event_x = rect.x + rect.width / 2; | 293 mouse_event_x = rect.x + rect.width / 2; |
291 mouse_event_y = rect.y + rect.height / 2; | 294 mouse_event_y = rect.y + rect.height / 2; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 result = v8::Null(); | 406 result = v8::Null(); |
404 } | 407 } |
405 | 408 |
406 v8::Handle<v8::Value> argv[] = { result }; | 409 v8::Handle<v8::Value> argv[] = { result }; |
407 | 410 |
408 frame->callFunctionEvenIfScriptDisabled(callback, | 411 frame->callFunctionEvenIfScriptDisabled(callback, |
409 v8::Object::New(), | 412 v8::Object::New(), |
410 1, | 413 1, |
411 argv); | 414 argv); |
412 } | 415 } |
413 callback.Dispose(); | 416 v8::Isolate* isolate = context->GetIsolate(); |
414 context.Dispose(); | 417 callback.Dispose(isolate); |
| 418 context.Dispose(isolate); |
415 } | 419 } |
416 | 420 |
417 static v8::Handle<v8::Value> BeginWindowSnapshotPNG( | 421 static v8::Handle<v8::Value> BeginWindowSnapshotPNG( |
418 const v8::Arguments& args) { | 422 const v8::Arguments& args) { |
419 WebFrame* web_frame = WebFrame::frameForCurrentContext(); | 423 WebFrame* web_frame = WebFrame::frameForCurrentContext(); |
420 if (!web_frame) | 424 if (!web_frame) |
421 return v8::Undefined(); | 425 return v8::Undefined(); |
422 | 426 |
423 WebView* web_view = web_frame->view(); | 427 WebView* web_view = web_frame->view(); |
424 if (!web_view) | 428 if (!web_view) |
425 return v8::Undefined(); | 429 return v8::Undefined(); |
426 | 430 |
427 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); | 431 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); |
428 if (!render_view_impl) | 432 if (!render_view_impl) |
429 return v8::Undefined(); | 433 return v8::Undefined(); |
430 | 434 |
431 if (!args[0]->IsFunction()) | 435 if (!args[0]->IsFunction()) |
432 return v8::Undefined(); | 436 return v8::Undefined(); |
433 | 437 |
434 v8::Local<v8::Function> callback_local = | 438 v8::Local<v8::Function> callback_local = |
435 v8::Local<v8::Function>(v8::Function::Cast(*args[0])); | 439 v8::Local<v8::Function>(v8::Function::Cast(*args[0])); |
| 440 v8::Isolate* isolate = args.GetIsolate(); |
436 v8::Persistent<v8::Function> callback = | 441 v8::Persistent<v8::Function> callback = |
437 v8::Persistent<v8::Function>::New(callback_local); | 442 v8::Persistent<v8::Function>::New(isolate, callback_local); |
438 v8::Persistent<v8::Context> context = | 443 v8::Persistent<v8::Context> context = |
439 v8::Persistent<v8::Context>::New(web_frame->mainWorldScriptContext()); | 444 v8::Persistent<v8::Context>::New(isolate, |
| 445 web_frame->mainWorldScriptContext()); |
440 | 446 |
441 render_view_impl->GetWindowSnapshot( | 447 render_view_impl->GetWindowSnapshot( |
442 base::Bind(&OnSnapshotCompleted, callback, context)); | 448 base::Bind(&OnSnapshotCompleted, callback, context)); |
443 | 449 |
444 return v8::Undefined(); | 450 return v8::Undefined(); |
445 } | 451 } |
446 }; | 452 }; |
447 | 453 |
448 v8::Extension* GpuBenchmarkingExtension::Get() { | 454 v8::Extension* GpuBenchmarkingExtension::Get() { |
449 return new GpuBenchmarkingWrapper(); | 455 return new GpuBenchmarkingWrapper(); |
450 } | 456 } |
451 | 457 |
452 } // namespace content | 458 } // namespace content |
OLD | NEW |