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