9dec6dcd929efcd1f18e8e661d1ff275a6aba4c2
[platform/framework/web/crosswalk.git] / src / xwalk / extensions / renderer / xwalk_js_module.h
1 // Copyright (c) 2013 Intel Corporation. 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 #ifndef XWALK_EXTENSIONS_RENDERER_XWALK_JS_MODULE_H_
6 #define XWALK_EXTENSIONS_RENDERER_XWALK_JS_MODULE_H_
7
8 #include <string>
9 #include "xwalk/extensions/renderer/xwalk_module_system.h"
10
11 namespace xwalk {
12 namespace extensions {
13
14 scoped_ptr<XWalkNativeModule> CreateJSModuleFromResource(int resource_id);
15
16 // Provides a module for the Module System based on a JavaScript code. This is
17 // useful for providing JS helpers and small libraries to extensions creators.
18 //
19 // The JS code of a native module is executed with an object "exports" that
20 // should be filled with functions and properties that the module will export.
21 class XWalkJSModule : public XWalkNativeModule {
22  public:
23   explicit XWalkJSModule(const std::string& js_code);
24   virtual ~XWalkJSModule();
25
26  private:
27   // XWalkNativeModule implementation.
28   v8::Handle<v8::Object> NewInstance() override;
29
30   bool Compile(v8::Isolate* isolate, std::string* error);
31
32   std::string js_code_;
33   v8::Persistent<v8::Script> compiled_script_;
34 };
35
36 }  // namespace extensions
37 }  // namespace xwalk
38
39 #endif  // XWALK_EXTENSIONS_RENDERER_XWALK_JS_MODULE_H_