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

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

Issue 1880473003: Make ModuleSystem have a const view of ResourceBundleSourceMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove double lookups Created 4 years, 8 months 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
« no previous file with comments | « no previous file | extensions/renderer/module_system.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 28 matching lines...) Expand all
39 // Note that a ModuleSystem must be used only in conjunction with a single 39 // Note that a ModuleSystem must be used only in conjunction with a single
40 // v8::Context. 40 // v8::Context.
41 // TODO(koz): Rename this to JavaScriptModuleSystem. 41 // TODO(koz): Rename this to JavaScriptModuleSystem.
42 class ModuleSystem : public ObjectBackedNativeHandler, 42 class ModuleSystem : public ObjectBackedNativeHandler,
43 public gin::ModuleRegistryObserver { 43 public gin::ModuleRegistryObserver {
44 public: 44 public:
45 class SourceMap { 45 class SourceMap {
46 public: 46 public:
47 virtual ~SourceMap() {} 47 virtual ~SourceMap() {}
48 virtual v8::Local<v8::Value> GetSource(v8::Isolate* isolate, 48 virtual v8::Local<v8::Value> GetSource(v8::Isolate* isolate,
49 const std::string& name) = 0; 49 const std::string& name) const = 0;
50 virtual bool Contains(const std::string& name) = 0; 50 virtual bool Contains(const std::string& name) const = 0;
51 }; 51 };
52 52
53 class ExceptionHandler { 53 class ExceptionHandler {
54 public: 54 public:
55 explicit ExceptionHandler(ScriptContext* context) : context_(context) {} 55 explicit ExceptionHandler(ScriptContext* context) : context_(context) {}
56 virtual ~ExceptionHandler() {} 56 virtual ~ExceptionHandler() {}
57 virtual void HandleUncaughtException(const v8::TryCatch& try_catch) = 0; 57 virtual void HandleUncaughtException(const v8::TryCatch& try_catch) = 0;
58 58
59 protected: 59 protected:
60 // Formats |try_catch| as a nice string. 60 // Formats |try_catch| as a nice string.
61 std::string CreateExceptionString(const v8::TryCatch& try_catch); 61 std::string CreateExceptionString(const v8::TryCatch& try_catch);
62 // A script context associated with this handler. Owned by the module 62 // A script context associated with this handler. Owned by the module
63 // system. 63 // system.
64 ScriptContext* context_; 64 ScriptContext* context_;
65 }; 65 };
66 66
67 // Enables native bindings for the duration of its lifetime. 67 // Enables native bindings for the duration of its lifetime.
68 class NativesEnabledScope { 68 class NativesEnabledScope {
69 public: 69 public:
70 explicit NativesEnabledScope(ModuleSystem* module_system); 70 explicit NativesEnabledScope(ModuleSystem* module_system);
71 ~NativesEnabledScope(); 71 ~NativesEnabledScope();
72 72
73 private: 73 private:
74 ModuleSystem* module_system_; 74 ModuleSystem* module_system_;
75 DISALLOW_COPY_AND_ASSIGN(NativesEnabledScope); 75 DISALLOW_COPY_AND_ASSIGN(NativesEnabledScope);
76 }; 76 };
77 77
78 // |source_map| is a weak pointer. 78 // |source_map| is a weak pointer.
79 ModuleSystem(ScriptContext* context, SourceMap* source_map); 79 ModuleSystem(ScriptContext* context, const SourceMap* source_map);
80 ~ModuleSystem() override; 80 ~ModuleSystem() override;
81 81
82 // Require the specified module. This is the equivalent of calling 82 // Require the specified module. This is the equivalent of calling
83 // require('module_name') from the loaded JS files. 83 // require('module_name') from the loaded JS files.
84 v8::MaybeLocal<v8::Object> Require(const std::string& module_name); 84 v8::MaybeLocal<v8::Object> Require(const std::string& module_name);
85 void Require(const v8::FunctionCallbackInfo<v8::Value>& args); 85 void Require(const v8::FunctionCallbackInfo<v8::Value>& args);
86 86
87 // Run |code| in the current context with the name |name| used for stack 87 // Run |code| in the current context with the name |name| used for stack
88 // traces. 88 // traces.
89 v8::Local<v8::Value> RunString(v8::Local<v8::String> code, 89 v8::Local<v8::Value> RunString(v8::Local<v8::String> code,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 const std::vector<std::string>& dependencies) override; 213 const std::vector<std::string>& dependencies) override;
214 214
215 // Marks any existing NativeHandler named |name| as clobbered. 215 // Marks any existing NativeHandler named |name| as clobbered.
216 // See |clobbered_native_handlers_|. 216 // See |clobbered_native_handlers_|.
217 void ClobberExistingNativeHandler(const std::string& name); 217 void ClobberExistingNativeHandler(const std::string& name);
218 218
219 ScriptContext* context_; 219 ScriptContext* context_;
220 220
221 // A map from module names to the JS source for that module. GetSource() 221 // A map from module names to the JS source for that module. GetSource()
222 // performs a lookup on this map. 222 // performs a lookup on this map.
223 SourceMap* source_map_; 223 const SourceMap* const source_map_;
224 224
225 // A map from native handler names to native handlers. 225 // A map from native handler names to native handlers.
226 NativeHandlerMap native_handler_map_; 226 NativeHandlerMap native_handler_map_;
227 227
228 // When 0, natives are disabled, otherwise indicates how many callers have 228 // When 0, natives are disabled, otherwise indicates how many callers have
229 // pinned natives as enabled. 229 // pinned natives as enabled.
230 int natives_enabled_; 230 int natives_enabled_;
231 231
232 // Called when an exception is thrown but not caught in JS. Overridable by 232 // Called when an exception is thrown but not caught in JS. Overridable by
233 // tests. 233 // tests.
(...skipping 10 matching lines...) Expand all
244 std::vector<scoped_ptr<NativeHandler>> clobbered_native_handlers_; 244 std::vector<scoped_ptr<NativeHandler>> clobbered_native_handlers_;
245 245
246 base::WeakPtrFactory<ModuleSystem> weak_factory_; 246 base::WeakPtrFactory<ModuleSystem> weak_factory_;
247 247
248 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); 248 DISALLOW_COPY_AND_ASSIGN(ModuleSystem);
249 }; 249 };
250 250
251 } // namespace extensions 251 } // namespace extensions
252 252
253 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ 253 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/module_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698