OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ | 5 #ifndef EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ |
6 #define EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ | 6 #define EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 explicit NativesEnabledScope(ModuleSystem* module_system); | 65 explicit NativesEnabledScope(ModuleSystem* module_system); |
66 ~NativesEnabledScope(); | 66 ~NativesEnabledScope(); |
67 | 67 |
68 private: | 68 private: |
69 ModuleSystem* module_system_; | 69 ModuleSystem* module_system_; |
70 DISALLOW_COPY_AND_ASSIGN(NativesEnabledScope); | 70 DISALLOW_COPY_AND_ASSIGN(NativesEnabledScope); |
71 }; | 71 }; |
72 | 72 |
73 // |source_map| is a weak pointer. | 73 // |source_map| is a weak pointer. |
74 ModuleSystem(ScriptContext* context, SourceMap* source_map); | 74 ModuleSystem(ScriptContext* context, SourceMap* source_map); |
75 virtual ~ModuleSystem(); | 75 ~ModuleSystem() override; |
76 | 76 |
77 // Require the specified module. This is the equivalent of calling | 77 // Require the specified module. This is the equivalent of calling |
78 // require('module_name') from the loaded JS files. | 78 // require('module_name') from the loaded JS files. |
79 v8::Handle<v8::Value> Require(const std::string& module_name); | 79 v8::Handle<v8::Value> Require(const std::string& module_name); |
80 void Require(const v8::FunctionCallbackInfo<v8::Value>& args); | 80 void Require(const v8::FunctionCallbackInfo<v8::Value>& args); |
81 | 81 |
82 // Run |code| in the current context with the name |name| used for stack | 82 // Run |code| in the current context with the name |name| used for stack |
83 // traces. | 83 // traces. |
84 v8::Handle<v8::Value> RunString(v8::Handle<v8::String> code, | 84 v8::Handle<v8::Value> RunString(v8::Handle<v8::String> code, |
85 v8::Handle<v8::String> name); | 85 v8::Handle<v8::String> name); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 const std::string& module_name, | 136 const std::string& module_name, |
137 const std::string& module_field); | 137 const std::string& module_field); |
138 | 138 |
139 // Passes exceptions to |handler| rather than console::Fatal. | 139 // Passes exceptions to |handler| rather than console::Fatal. |
140 void SetExceptionHandlerForTest(scoped_ptr<ExceptionHandler> handler) { | 140 void SetExceptionHandlerForTest(scoped_ptr<ExceptionHandler> handler) { |
141 exception_handler_ = handler.Pass(); | 141 exception_handler_ = handler.Pass(); |
142 } | 142 } |
143 | 143 |
144 protected: | 144 protected: |
145 friend class ScriptContext; | 145 friend class ScriptContext; |
146 virtual void Invalidate() override; | 146 void Invalidate() override; |
147 | 147 |
148 private: | 148 private: |
149 typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap; | 149 typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap; |
150 | 150 |
151 // Retrieves the lazily defined field specified by |property|. | 151 // Retrieves the lazily defined field specified by |property|. |
152 static void LazyFieldGetter(v8::Local<v8::String> property, | 152 static void LazyFieldGetter(v8::Local<v8::String> property, |
153 const v8::PropertyCallbackInfo<v8::Value>& info); | 153 const v8::PropertyCallbackInfo<v8::Value>& info); |
154 // Retrieves the lazily defined field specified by |property| on a native | 154 // Retrieves the lazily defined field specified by |property| on a native |
155 // object. | 155 // object. |
156 static void NativeLazyFieldGetter( | 156 static void NativeLazyFieldGetter( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // Loads and runs a Javascript module. | 195 // Loads and runs a Javascript module. |
196 v8::Handle<v8::Value> LoadModule(const std::string& module_name); | 196 v8::Handle<v8::Value> LoadModule(const std::string& module_name); |
197 | 197 |
198 // Invoked when a module is loaded in response to a requireAsync call. | 198 // Invoked when a module is loaded in response to a requireAsync call. |
199 // Resolves |resolver| with |value|. | 199 // Resolves |resolver| with |value|. |
200 void OnModuleLoaded( | 200 void OnModuleLoaded( |
201 scoped_ptr<v8::UniquePersistent<v8::Promise::Resolver> > resolver, | 201 scoped_ptr<v8::UniquePersistent<v8::Promise::Resolver> > resolver, |
202 v8::Handle<v8::Value> value); | 202 v8::Handle<v8::Value> value); |
203 | 203 |
204 // gin::ModuleRegistryObserver overrides. | 204 // gin::ModuleRegistryObserver overrides. |
205 virtual void OnDidAddPendingModule( | 205 void OnDidAddPendingModule( |
206 const std::string& id, | 206 const std::string& id, |
207 const std::vector<std::string>& dependencies) override; | 207 const std::vector<std::string>& dependencies) override; |
208 | 208 |
209 ScriptContext* context_; | 209 ScriptContext* context_; |
210 | 210 |
211 // A map from module names to the JS source for that module. GetSource() | 211 // A map from module names to the JS source for that module. GetSource() |
212 // performs a lookup on this map. | 212 // performs a lookup on this map. |
213 SourceMap* source_map_; | 213 SourceMap* source_map_; |
214 | 214 |
215 // A map from native handler names to native handlers. | 215 // A map from native handler names to native handlers. |
(...skipping 10 matching lines...) Expand all Loading... |
226 std::set<std::string> overridden_native_handlers_; | 226 std::set<std::string> overridden_native_handlers_; |
227 | 227 |
228 base::WeakPtrFactory<ModuleSystem> weak_factory_; | 228 base::WeakPtrFactory<ModuleSystem> weak_factory_; |
229 | 229 |
230 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); | 230 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); |
231 }; | 231 }; |
232 | 232 |
233 } // namespace extensions | 233 } // namespace extensions |
234 | 234 |
235 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ | 235 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ |
OLD | NEW |