Chromium Code Reviews| 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 NOTREACHED(); | |
| 32 return; | |
| 33 } | |
| 34 | |
| 35 WebKit::WebView* web_view = render_view->GetWebView(); | |
| 36 if (!web_view) { | |
| 37 NOTREACHED(); | |
|
Matt Perry
2013/08/20 23:10:24
I think both render_view and web_view can legitima
Fady Samuel
2013/08/21 11:47:24
Done.
| |
| 38 return; | |
| 39 } | |
| 40 | |
| 41 WebKit::WebDocument document = web_view->mainFrame()->document(); | |
| 42 if (args.Length() != 2) { | |
| 43 NOTREACHED(); | |
| 44 return; | |
| 45 } | |
| 46 | |
| 47 if (!args[0]->IsString() || !args[1]->IsObject()) { | |
|
Matt Perry
2013/08/20 23:10:24
nit: combine this with the previous if
Fady Samuel
2013/08/21 11:47:24
Done.
| |
| 48 NOTREACHED(); | |
| 49 return; | |
| 50 } | |
| 51 | |
| 52 std::string element_name(*v8::String::AsciiValue(args[0])); | |
| 53 v8::Local<v8::Object> options = args[1]->ToObject(); | |
| 54 | |
| 55 WebKit::WebExceptionCode ec = 0; | |
| 56 v8::Handle<v8::Value> constructor = | |
| 57 document.registerEmbedderCustomElement( | |
| 58 WebKit::WebString::fromUTF8(element_name), options, ec); | |
| 59 args.GetReturnValue().Set(constructor); | |
| 60 } | |
| 61 | |
| 62 } // namespace extensions | |
| OLD | NEW |