Add chromium_builder_lkgr_drmemory_win target for LKGR DrMemory build on ClusterFuzz
[chromium-blink-merge.git] / extensions / renderer / document_custom_bindings.cc
blobedaed987addc0ab9b2fdd8a374d84e45d35b2227
1 // Copyright 2014 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.
5 #include "extensions/renderer/document_custom_bindings.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "extensions/renderer/script_context.h"
11 #include "third_party/WebKit/public/web/WebDocument.h"
12 #include "third_party/WebKit/public/web/WebFrame.h"
13 #include "v8/include/v8.h"
15 namespace extensions {
17 DocumentCustomBindings::DocumentCustomBindings(ScriptContext* context)
18 : ObjectBackedNativeHandler(context) {
19 RouteFunction("RegisterElement",
20 base::Bind(&DocumentCustomBindings::RegisterElement,
21 base::Unretained(this)));
24 // Attach an event name to an object.
25 void DocumentCustomBindings::RegisterElement(
26 const v8::FunctionCallbackInfo<v8::Value>& args) {
27 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsObject()) {
28 NOTREACHED();
29 return;
32 std::string element_name(*v8::String::Utf8Value(args[0]));
33 v8::Local<v8::Object> options = args[1]->ToObject();
35 blink::WebExceptionCode ec = 0;
36 blink::WebDocument document = context()->web_frame()->document();
37 v8::Handle<v8::Value> constructor = document.registerEmbedderCustomElement(
38 blink::WebString::fromUTF8(element_name), options, ec);
39 args.GetReturnValue().Set(constructor);
42 } // namespace extensions