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 #ifndef CONTENT_SHELL_RENDERER_BINDING_HELPERS_H_
6 #define CONTENT_SHELL_RENDERER_BINDING_HELPERS_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "gin/handle.h"
13 #include "gin/wrappable.h"
14 #include "third_party/WebKit/public/web/WebFrame.h"
15 #include "third_party/WebKit/public/web/WebKit.h"
19 template<class WrappedClass
>
20 void InstallAsWindowProperties(WrappedClass
* wrapped
,
21 blink::WebFrame
* frame
,
22 const std::vector
<std::string
>& names
) {
23 v8::Isolate
* isolate
= blink::mainThreadIsolate();
24 v8::HandleScope
handle_scope(isolate
);
25 v8::Handle
<v8::Context
> context
= frame
->mainWorldScriptContext();
26 if (context
.IsEmpty())
29 v8::Context::Scope
context_scope(context
);
31 gin::Handle
<WrappedClass
> bindings
= gin::CreateHandle(isolate
, wrapped
);
32 if (bindings
.IsEmpty())
34 v8::Handle
<v8::Object
> global
= context
->Global();
35 v8::Handle
<v8::Value
> v8_bindings
= bindings
.ToV8();
36 for (size_t i
= 0; i
< names
.size(); ++i
)
37 global
->Set(gin::StringToV8(isolate
, names
[i
].c_str()), v8_bindings
);
40 } // namespace content
42 #endif // CONTENT_SHELL_RENDERER_BINDING_HELPERS_H_