Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: chrome/renderer/extensions/module_system.h

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_ 5 #ifndef CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_
6 #define CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_ 6 #define CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/linked_ptr.h" 9 #include "base/memory/linked_ptr.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 virtual ~ModuleSystem(); 64 virtual ~ModuleSystem();
65 65
66 // Returns true if the current context has a ModuleSystem installed in it. 66 // Returns true if the current context has a ModuleSystem installed in it.
67 static bool IsPresentInCurrentContext(); 67 static bool IsPresentInCurrentContext();
68 68
69 // Dumps the debug info from |try_catch| to LOG(ERROR). 69 // Dumps the debug info from |try_catch| to LOG(ERROR).
70 static void DumpException(const v8::TryCatch& try_catch); 70 static void DumpException(const v8::TryCatch& try_catch);
71 71
72 // Require the specified module. This is the equivalent of calling 72 // Require the specified module. This is the equivalent of calling
73 // require('module_name') from the loaded JS files. 73 // require('module_name') from the loaded JS files.
74 void Require(const std::string& module_name); 74 v8::Handle<v8::Value> Require(const std::string& module_name);
75 v8::Handle<v8::Value> Require(const v8::Arguments& args); 75 v8::Handle<v8::Value> Require(const v8::Arguments& args);
76 v8::Handle<v8::Value> RequireForJs(const v8::Arguments& args); 76 v8::Handle<v8::Value> RequireForJs(const v8::Arguments& args);
77 v8::Handle<v8::Value> RequireForJsInner(v8::Handle<v8::String> module_name); 77 v8::Handle<v8::Value> RequireForJsInner(v8::Handle<v8::String> module_name);
78 78
79 // Calls the specified method exported by the specified module. This is 79 // Calls the specified method exported by the specified module. This is
80 // equivalent to calling require('module_name').method_name() from JS. 80 // equivalent to calling require('module_name').method_name() from JS.
81 void CallModuleMethod(const std::string& module_name, 81 void CallModuleMethod(const std::string& module_name,
82 const std::string& method_name); 82 const std::string& method_name);
83 83
84 // Call |value| with arguments |argv| and return the result.
85 v8::Handle<v8::Value> CallModuleMethod(v8::Local<v8::Value> value,
86 int argc,
87 v8::Handle<v8::Value> argv[]);
88
84 // Register |native_handler| as a potential target for requireNative(), so 89 // Register |native_handler| as a potential target for requireNative(), so
85 // calls to requireNative(|name|) from JS will return a new object created by 90 // calls to requireNative(|name|) from JS will return a new object created by
86 // |native_handler|. 91 // |native_handler|.
87 void RegisterNativeHandler(const std::string& name, 92 void RegisterNativeHandler(const std::string& name,
88 scoped_ptr<NativeHandler> native_handler); 93 scoped_ptr<NativeHandler> native_handler);
94 bool HasNativeHandler(const std::string& name);
89 95
90 // Causes requireNative(|name|) to look for its module in |source_map_| 96 // Causes requireNative(|name|) to look for its module in |source_map_|
91 // instead of using a registered native handler. This can be used in unit 97 // instead of using a registered native handler. This can be used in unit
92 // tests to mock out native modules. 98 // tests to mock out native modules.
93 void OverrideNativeHandler(const std::string& name); 99 void OverrideNativeHandler(const std::string& name);
94 100
95 // Executes |code| in the current context with |name| as the filename. 101 // Executes |code| in the current context with |name| as the filename.
96 void RunString(const std::string& code, const std::string& name); 102 void RunString(const std::string& code, const std::string& name);
97 103
98 // Retrieves the lazily defined field specified by |property|. 104 // Retrieves the lazily defined field specified by |property|.
99 static v8::Handle<v8::Value> LazyFieldGetter(v8::Local<v8::String> property, 105 static v8::Handle<v8::Value> LazyFieldGetter(v8::Local<v8::String> property,
100 const v8::AccessorInfo& info); 106 const v8::AccessorInfo& info);
101 107
102 // Make |object|.|field| lazily evaluate to the result of 108 // Make |object|.|field| lazily evaluate to the result of
109 // require(|module_name|)[|module_field|](|arg|).
110 void SetLazyField(v8::Handle<v8::Object> object,
111 const std::string& field,
112 const std::string& module_name,
113 const std::string& module_field,
114 const std::string& arg);
115
116 // Make |object|.|field| lazily evaluate to the result of
103 // require(|module_name|)[|module_field|]. 117 // require(|module_name|)[|module_field|].
104 void SetLazyField(v8::Handle<v8::Object> object, 118 void SetLazyField(v8::Handle<v8::Object> object,
105 const std::string& field, 119 const std::string& field,
106 const std::string& module_name, 120 const std::string& module_name,
107 const std::string& module_field); 121 const std::string& module_field);
108 122
109 void set_exception_handler(scoped_ptr<ExceptionHandler> handler) { 123 void set_exception_handler(scoped_ptr<ExceptionHandler> handler) {
110 exception_handler_ = handler.Pass(); 124 exception_handler_ = handler.Pass();
111 } 125 }
112 126
113 private: 127 private:
114 typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap; 128 typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap;
115 129
116 // Called when an exception is thrown but not caught. 130 // Called when an exception is thrown but not caught.
117 void HandleException(const v8::TryCatch& try_catch); 131 void HandleException(const v8::TryCatch& try_catch);
118 132
119 // Ensure that require_ has been evaluated from require.js. 133 // Ensure that require_ has been evaluated from require.js.
120 void EnsureRequireLoaded(); 134 void EnsureRequireLoaded();
121 135
122 // Run |code| in the current context with the name |name| used for stack 136 // Run |code| in the current context with the name |name| used for stack
123 // traces. 137 // traces.
124 v8::Handle<v8::Value> RunString(v8::Handle<v8::String> code, 138 v8::Handle<v8::Value> RunString(v8::Handle<v8::String> code,
125 v8::Handle<v8::String> name); 139 v8::Handle<v8::String> name);
126 140
141
127 // Return the named source file stored in the source map. 142 // Return the named source file stored in the source map.
128 // |args[0]| - the name of a source file in source_map_. 143 // |args[0]| - the name of a source file in source_map_.
129 v8::Handle<v8::Value> GetSource(v8::Handle<v8::String> source_name); 144 v8::Handle<v8::Value> GetSource(v8::Handle<v8::String> source_name);
130 145
131 // Return an object that contains the native methods defined by the named 146 // Return an object that contains the native methods defined by the named
132 // NativeHandler. 147 // NativeHandler.
133 // |args[0]| - the name of a native handler object. 148 // |args[0]| - the name of a native handler object.
134 v8::Handle<v8::Value> GetNative(const v8::Arguments& args); 149 v8::Handle<v8::Value> GetNative(const v8::Arguments& args);
135 150
136 // Wraps |source| in a (function(require, requireNative, exports) {...}). 151 // Wraps |source| in a (function(require, requireNative, exports) {...}).
(...skipping 20 matching lines...) Expand all
157 scoped_ptr<ExceptionHandler> exception_handler_; 172 scoped_ptr<ExceptionHandler> exception_handler_;
158 173
159 std::set<std::string> overridden_native_handlers_; 174 std::set<std::string> overridden_native_handlers_;
160 175
161 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); 176 DISALLOW_COPY_AND_ASSIGN(ModuleSystem);
162 }; 177 };
163 178
164 } // extensions 179 } // extensions
165 180
166 #endif // CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_ 181 #endif // CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698