| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 class SourceMap { | 44 class SourceMap { |
| 45 public: | 45 public: |
| 46 virtual ~SourceMap() {} | 46 virtual ~SourceMap() {} |
| 47 virtual v8::Local<v8::Value> GetSource(v8::Isolate* isolate, | 47 virtual v8::Local<v8::Value> GetSource(v8::Isolate* isolate, |
| 48 const std::string& name) = 0; | 48 const std::string& name) = 0; |
| 49 virtual bool Contains(const std::string& name) = 0; | 49 virtual bool Contains(const std::string& name) = 0; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 class ExceptionHandler { | 52 class ExceptionHandler { |
| 53 public: | 53 public: |
| 54 ExceptionHandler(ScriptContext* context) : context_(context) {} |
| 54 virtual ~ExceptionHandler() {} | 55 virtual ~ExceptionHandler() {} |
| 55 virtual void HandleUncaughtException(const v8::TryCatch& try_catch) = 0; | 56 virtual void HandleUncaughtException(const v8::TryCatch& try_catch) = 0; |
| 56 | 57 |
| 57 protected: | 58 protected: |
| 59 ScriptContext* context_; |
| 58 // Formats |try_catch| as a nice string. | 60 // Formats |try_catch| as a nice string. |
| 59 std::string CreateExceptionString(const v8::TryCatch& try_catch); | 61 std::string CreateExceptionString(const v8::TryCatch& try_catch); |
| 60 }; | 62 }; |
| 61 | 63 |
| 62 // Enables native bindings for the duration of its lifetime. | 64 // Enables native bindings for the duration of its lifetime. |
| 63 class NativesEnabledScope { | 65 class NativesEnabledScope { |
| 64 public: | 66 public: |
| 65 explicit NativesEnabledScope(ModuleSystem* module_system); | 67 explicit NativesEnabledScope(ModuleSystem* module_system); |
| 66 ~NativesEnabledScope(); | 68 ~NativesEnabledScope(); |
| 67 | 69 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // object is the only client, only that needs to implement it). | 121 // object is the only client, only that needs to implement it). |
| 120 void SetLazyField(v8::Local<v8::Object> object, | 122 void SetLazyField(v8::Local<v8::Object> object, |
| 121 const std::string& field, | 123 const std::string& field, |
| 122 const std::string& module_name, | 124 const std::string& module_name, |
| 123 const std::string& module_field); | 125 const std::string& module_field); |
| 124 | 126 |
| 125 void SetLazyField(v8::Local<v8::Object> object, | 127 void SetLazyField(v8::Local<v8::Object> object, |
| 126 const std::string& field, | 128 const std::string& field, |
| 127 const std::string& module_name, | 129 const std::string& module_name, |
| 128 const std::string& module_field, | 130 const std::string& module_field, |
| 129 v8::AccessorGetterCallback getter); | 131 v8::AccessorNameGetterCallback getter); |
| 130 | 132 |
| 131 // Make |object|.|field| lazily evaluate to the result of | 133 // Make |object|.|field| lazily evaluate to the result of |
| 132 // requireNative(|module_name|)[|module_field|]. | 134 // requireNative(|module_name|)[|module_field|]. |
| 133 // TODO(kalman): Same as above. | 135 // TODO(kalman): Same as above. |
| 134 void SetNativeLazyField(v8::Local<v8::Object> object, | 136 void SetNativeLazyField(v8::Local<v8::Object> object, |
| 135 const std::string& field, | 137 const std::string& field, |
| 136 const std::string& module_name, | 138 const std::string& module_name, |
| 137 const std::string& module_field); | 139 const std::string& module_field); |
| 138 | 140 |
| 139 // Passes exceptions to |handler| rather than console::Fatal. | 141 // Passes exceptions to |handler| rather than console::Fatal. |
| 140 void SetExceptionHandlerForTest(scoped_ptr<ExceptionHandler> handler) { | 142 void SetExceptionHandlerForTest(scoped_ptr<ExceptionHandler> handler) { |
| 141 exception_handler_ = handler.Pass(); | 143 exception_handler_ = handler.Pass(); |
| 142 } | 144 } |
| 143 | 145 |
| 144 protected: | 146 protected: |
| 145 friend class ModuleSystemTestEnvironment; | 147 friend class ModuleSystemTestEnvironment; |
| 146 friend class ScriptContext; | 148 friend class ScriptContext; |
| 147 void Invalidate() override; | 149 void Invalidate() override; |
| 148 | 150 |
| 149 private: | 151 private: |
| 150 typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap; | 152 typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap; |
| 151 | 153 |
| 152 // Retrieves the lazily defined field specified by |property|. | 154 // Retrieves the lazily defined field specified by |property|. |
| 153 static void LazyFieldGetter(v8::Local<v8::String> property, | 155 static void LazyFieldGetter(v8::Local<v8::Name> property, |
| 154 const v8::PropertyCallbackInfo<v8::Value>& info); | 156 const v8::PropertyCallbackInfo<v8::Value>& info); |
| 155 // Retrieves the lazily defined field specified by |property| on a native | 157 // Retrieves the lazily defined field specified by |property| on a native |
| 156 // object. | 158 // object. |
| 157 static void NativeLazyFieldGetter( | 159 static void NativeLazyFieldGetter( |
| 158 v8::Local<v8::String> property, | 160 v8::Local<v8::Name> property, |
| 159 const v8::PropertyCallbackInfo<v8::Value>& info); | 161 const v8::PropertyCallbackInfo<v8::Value>& info); |
| 160 | 162 |
| 161 // Called when an exception is thrown but not caught. | 163 // Called when an exception is thrown but not caught. |
| 162 void HandleException(const v8::TryCatch& try_catch); | 164 void HandleException(const v8::TryCatch& try_catch); |
| 163 | 165 |
| 164 void RequireForJs(const v8::FunctionCallbackInfo<v8::Value>& args); | 166 void RequireForJs(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 165 v8::Local<v8::Value> RequireForJsInner(v8::Local<v8::String> module_name); | 167 v8::Local<v8::Value> RequireForJsInner(v8::Local<v8::String> module_name); |
| 166 | 168 |
| 167 typedef v8::Local<v8::Value>(ModuleSystem::*RequireFunction)( | 169 typedef v8::Local<v8::Value>(ModuleSystem::*RequireFunction)( |
| 168 const std::string&); | 170 const std::string&); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 std::vector<linked_ptr<NativeHandler>> clobbered_native_handlers_; | 240 std::vector<linked_ptr<NativeHandler>> clobbered_native_handlers_; |
| 239 | 241 |
| 240 base::WeakPtrFactory<ModuleSystem> weak_factory_; | 242 base::WeakPtrFactory<ModuleSystem> weak_factory_; |
| 241 | 243 |
| 242 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); | 244 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); |
| 243 }; | 245 }; |
| 244 | 246 |
| 245 } // namespace extensions | 247 } // namespace extensions |
| 246 | 248 |
| 247 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ | 249 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ |
| OLD | NEW |