OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/renderer/extensions/document_custom_bindings.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "content/public/renderer/render_view.h" |
| 11 #include "third_party/WebKit/public/web/WebDocument.h" |
| 12 #include "third_party/WebKit/public/web/WebFrame.h" |
| 13 #include "third_party/WebKit/public/web/WebView.h" |
| 14 #include "v8/include/v8.h" |
| 15 |
| 16 namespace extensions { |
| 17 |
| 18 DocumentCustomBindings::DocumentCustomBindings( |
| 19 Dispatcher* dispatcher, ChromeV8Context* context) |
| 20 : ChromeV8Extension(dispatcher, context) { |
| 21 RouteFunction("RegisterElement", |
| 22 base::Bind(&DocumentCustomBindings::RegisterElement, |
| 23 base::Unretained(this))); |
| 24 } |
| 25 |
| 26 // Attach an event name to an object. |
| 27 void DocumentCustomBindings::RegisterElement( |
| 28 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 29 content::RenderView* render_view = GetRenderView(); |
| 30 if (!render_view) { |
| 31 return; |
| 32 } |
| 33 |
| 34 WebKit::WebView* web_view = render_view->GetWebView(); |
| 35 if (!web_view) { |
| 36 return; |
| 37 } |
| 38 |
| 39 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsObject()) { |
| 40 NOTREACHED(); |
| 41 return; |
| 42 } |
| 43 |
| 44 std::string element_name(*v8::String::AsciiValue(args[0])); |
| 45 v8::Local<v8::Object> options = args[1]->ToObject(); |
| 46 |
| 47 WebKit::WebExceptionCode ec = 0; |
| 48 WebKit::WebDocument document = web_view->mainFrame()->document(); |
| 49 v8::Handle<v8::Value> constructor = |
| 50 document.registerEmbedderCustomElement( |
| 51 WebKit::WebString::fromUTF8(element_name), options, ec); |
| 52 args.GetReturnValue().Set(constructor); |
| 53 } |
| 54 |
| 55 } // namespace extensions |
OLD | NEW |