| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_RENDERER_MODULE_SYSTEM_H_ | 5 #ifndef CHROME_RENDERER_MODULE_SYSTEM_H_ |
| 6 #define CHROME_RENDERER_MODULE_SYSTEM_H_ | 6 #define CHROME_RENDERER_MODULE_SYSTEM_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // v8::Context. | 32 // v8::Context. |
| 33 // TODO(koz): Rename this to JavaScriptModuleSystem. | 33 // TODO(koz): Rename this to JavaScriptModuleSystem. |
| 34 class ModuleSystem : public NativeHandler { | 34 class ModuleSystem : public NativeHandler { |
| 35 public: | 35 public: |
| 36 class SourceMap { | 36 class SourceMap { |
| 37 public: | 37 public: |
| 38 virtual v8::Handle<v8::Value> GetSource(const std::string& name) = 0; | 38 virtual v8::Handle<v8::Value> GetSource(const std::string& name) = 0; |
| 39 virtual bool Contains(const std::string& name) = 0; | 39 virtual bool Contains(const std::string& name) = 0; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // Enables native bindings for the duration of its lifetime. |
| 43 class NativesEnabledScope { |
| 44 public: |
| 45 explicit NativesEnabledScope(ModuleSystem* module_system); |
| 46 ~NativesEnabledScope(); |
| 47 |
| 48 private: |
| 49 ModuleSystem* module_system_; |
| 50 }; |
| 51 |
| 42 // |source_map| is a weak pointer. | 52 // |source_map| is a weak pointer. |
| 43 explicit ModuleSystem(SourceMap* source_map); | 53 explicit ModuleSystem(SourceMap* source_map); |
| 44 virtual ~ModuleSystem(); | 54 virtual ~ModuleSystem(); |
| 45 | 55 |
| 46 // Require the specified module. This is the equivalent of calling | 56 // Require the specified module. This is the equivalent of calling |
| 47 // require('module_name') from the loaded JS files. | 57 // require('module_name') from the loaded JS files. |
| 48 void Require(const std::string& module_name); | 58 void Require(const std::string& module_name); |
| 49 v8::Handle<v8::Value> Require(const v8::Arguments& args); | 59 v8::Handle<v8::Value> Require(const v8::Arguments& args); |
| 50 v8::Handle<v8::Value> RequireForJs(const v8::Arguments& args); | 60 v8::Handle<v8::Value> RequireForJs(const v8::Arguments& args); |
| 51 v8::Handle<v8::Value> RequireForJsInner(v8::Handle<v8::String> module_name); | 61 v8::Handle<v8::Value> RequireForJsInner(v8::Handle<v8::String> module_name); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 v8::Handle<v8::Value> ThrowException(const std::string& message); | 112 v8::Handle<v8::Value> ThrowException(const std::string& message); |
| 103 | 113 |
| 104 // A map from module names to the JS source for that module. GetSource() | 114 // A map from module names to the JS source for that module. GetSource() |
| 105 // performs a lookup on this map. | 115 // performs a lookup on this map. |
| 106 SourceMap* source_map_; | 116 SourceMap* source_map_; |
| 107 NativeHandlerMap native_handler_map_; | 117 NativeHandlerMap native_handler_map_; |
| 108 bool natives_enabled_; | 118 bool natives_enabled_; |
| 109 }; | 119 }; |
| 110 | 120 |
| 111 #endif // CHROME_RENDERER_MODULE_SYSTEM_H_ | 121 #endif // CHROME_RENDERER_MODULE_SYSTEM_H_ |
| OLD | NEW |