| 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 "chrome/renderer/extensions/page_capture_custom_bindings.h" | 5 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/common/extensions/extension_messages.h" | 8 #include "chrome/common/extensions/extension_messages.h" |
| 9 #include "content/public/renderer/render_view.h" | 9 #include "content/public/renderer/render_view.h" |
| 10 #include "grit/renderer_resources.h" | 10 #include "grit/renderer_resources.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlob.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlob.h" |
| 12 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 PageCaptureCustomBindings::PageCaptureCustomBindings() | 16 PageCaptureCustomBindings::PageCaptureCustomBindings( |
| 17 : ChromeV8Extension(NULL) { | 17 Dispatcher* dispatcher, |
| 18 v8::Handle<v8::Context> context) |
| 19 : ChromeV8Extension(dispatcher, context) { |
| 18 RouteStaticFunction("CreateBlob", &CreateBlob); | 20 RouteStaticFunction("CreateBlob", &CreateBlob); |
| 19 RouteStaticFunction("SendResponseAck", &SendResponseAck); | 21 RouteStaticFunction("SendResponseAck", &SendResponseAck); |
| 20 } | 22 } |
| 21 | 23 |
| 22 // static | 24 // static |
| 23 v8::Handle<v8::Value> PageCaptureCustomBindings::CreateBlob( | 25 v8::Handle<v8::Value> PageCaptureCustomBindings::CreateBlob( |
| 24 const v8::Arguments& args) { | 26 const v8::Arguments& args) { |
| 25 CHECK(args.Length() == 2); | 27 CHECK(args.Length() == 2); |
| 26 CHECK(args[0]->IsString()); | 28 CHECK(args[0]->IsString()); |
| 27 CHECK(args[1]->IsInt32()); | 29 CHECK(args[1]->IsInt32()); |
| 28 WebKit::WebString path(UTF8ToUTF16(*v8::String::Utf8Value(args[0]))); | 30 WebKit::WebString path(UTF8ToUTF16(*v8::String::Utf8Value(args[0]))); |
| 29 WebKit::WebBlob blob = | 31 WebKit::WebBlob blob = |
| 30 WebKit::WebBlob::createFromFile(path, args[1]->Int32Value()); | 32 WebKit::WebBlob::createFromFile(path, args[1]->Int32Value()); |
| 31 return blob.toV8Value(); | 33 return blob.toV8Value(); |
| 32 } | 34 } |
| 33 | 35 |
| 34 // static | 36 // static |
| 35 v8::Handle<v8::Value> PageCaptureCustomBindings::SendResponseAck( | 37 v8::Handle<v8::Value> PageCaptureCustomBindings::SendResponseAck( |
| 36 const v8::Arguments& args) { | 38 const v8::Arguments& args) { |
| 37 CHECK(args.Length() == 1); | 39 CHECK(args.Length() == 1); |
| 38 CHECK(args[0]->IsInt32()); | 40 CHECK(args[0]->IsInt32()); |
| 39 | 41 |
| 40 content::RenderView* render_view = GetCurrentRenderView(); | 42 PageCaptureCustomBindings* self = |
| 43 GetFromArguments<PageCaptureCustomBindings>(args); |
| 44 content::RenderView* render_view = self->GetRenderView(); |
| 41 if (render_view) { | 45 if (render_view) { |
| 42 render_view->Send(new ExtensionHostMsg_ResponseAck( | 46 render_view->Send(new ExtensionHostMsg_ResponseAck( |
| 43 render_view->GetRoutingID(), args[0]->Int32Value())); | 47 render_view->GetRoutingID(), args[0]->Int32Value())); |
| 44 } | 48 } |
| 45 return v8::Undefined(); | 49 return v8::Undefined(); |
| 46 } | 50 } |
| 47 | 51 |
| 48 } // namespace extensions | 52 } // namespace extensions |
| OLD | NEW |