| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 const std::string& field, | 135 const std::string& field, |
| 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 ModuleSystemTestEnvironment; | |
| 146 friend class ScriptContext; | 145 friend class ScriptContext; |
| 147 void Invalidate() override; | 146 void Invalidate() override; |
| 148 | 147 |
| 149 private: | 148 private: |
| 150 typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap; | 149 typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap; |
| 151 | 150 |
| 152 // Retrieves the lazily defined field specified by |property|. | 151 // Retrieves the lazily defined field specified by |property|. |
| 153 static void LazyFieldGetter(v8::Local<v8::String> property, | 152 static void LazyFieldGetter(v8::Local<v8::String> property, |
| 154 const v8::PropertyCallbackInfo<v8::Value>& info); | 153 const v8::PropertyCallbackInfo<v8::Value>& info); |
| 155 // Retrieves the lazily defined field specified by |property| on a native | 154 // Retrieves the lazily defined field specified by |property| on a native |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // 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. |
| 200 // Resolves |resolver| with |value|. | 199 // Resolves |resolver| with |value|. |
| 201 void OnModuleLoaded(scoped_ptr<v8::Global<v8::Promise::Resolver>> resolver, | 200 void OnModuleLoaded(scoped_ptr<v8::Global<v8::Promise::Resolver>> resolver, |
| 202 v8::Handle<v8::Value> value); | 201 v8::Handle<v8::Value> value); |
| 203 | 202 |
| 204 // gin::ModuleRegistryObserver overrides. | 203 // gin::ModuleRegistryObserver overrides. |
| 205 void OnDidAddPendingModule( | 204 void OnDidAddPendingModule( |
| 206 const std::string& id, | 205 const std::string& id, |
| 207 const std::vector<std::string>& dependencies) override; | 206 const std::vector<std::string>& dependencies) override; |
| 208 | 207 |
| 209 // Marks any existing NativeHandler named |name| as clobbered. | |
| 210 // See |clobbered_native_handlers_|. | |
| 211 void ClobberExistingNativeHandler(const std::string& name); | |
| 212 | |
| 213 ScriptContext* context_; | 208 ScriptContext* context_; |
| 214 | 209 |
| 215 // A map from module names to the JS source for that module. GetSource() | 210 // A map from module names to the JS source for that module. GetSource() |
| 216 // performs a lookup on this map. | 211 // performs a lookup on this map. |
| 217 SourceMap* source_map_; | 212 SourceMap* source_map_; |
| 218 | 213 |
| 219 // A map from native handler names to native handlers. | 214 // A map from native handler names to native handlers. |
| 220 NativeHandlerMap native_handler_map_; | 215 NativeHandlerMap native_handler_map_; |
| 221 | 216 |
| 222 // When 0, natives are disabled, otherwise indicates how many callers have | 217 // When 0, natives are disabled, otherwise indicates how many callers have |
| 223 // pinned natives as enabled. | 218 // pinned natives as enabled. |
| 224 int natives_enabled_; | 219 int natives_enabled_; |
| 225 | 220 |
| 226 // Called when an exception is thrown but not caught in JS. Overridable by | 221 // Called when an exception is thrown but not caught in JS. Overridable by |
| 227 // tests. | 222 // tests. |
| 228 scoped_ptr<ExceptionHandler> exception_handler_; | 223 scoped_ptr<ExceptionHandler> exception_handler_; |
| 229 | 224 |
| 230 // A set of native handlers that should actually be require()d as non-native | |
| 231 // handlers. This is used for tests to mock out native handlers in JS. | |
| 232 std::set<std::string> overridden_native_handlers_; | 225 std::set<std::string> overridden_native_handlers_; |
| 233 | 226 |
| 234 // A list of NativeHandlers that have been clobbered, either due to | |
| 235 // registering a NativeHandler when one was already registered with the same | |
| 236 // name, or due to OverrideNativeHandlerForTest. This is needed so that they | |
| 237 // can be later Invalidated. It should only happen in tests. | |
| 238 std::vector<linked_ptr<NativeHandler>> clobbered_native_handlers_; | |
| 239 | |
| 240 base::WeakPtrFactory<ModuleSystem> weak_factory_; | 227 base::WeakPtrFactory<ModuleSystem> weak_factory_; |
| 241 | 228 |
| 242 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); | 229 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); |
| 243 }; | 230 }; |
| 244 | 231 |
| 245 } // namespace extensions | 232 } // namespace extensions |
| 246 | 233 |
| 247 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ | 234 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ |
| OLD | NEW |