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

Unified Diff: chrome/renderer/module_system.h

Issue 9386001: Implement a module system for the extension bindings JS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile errors Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/module_system.h
diff --git a/chrome/renderer/module_system.h b/chrome/renderer/module_system.h
index b29d8d644b4d4758b77e3d4d3f3fce49257f8a1c..920a4867680f8906bc0b985aef2af45b0cc0ba78 100644
--- a/chrome/renderer/module_system.h
+++ b/chrome/renderer/module_system.h
@@ -9,12 +9,15 @@
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
+#include "base/string_piece.h"
#include "chrome/renderer/native_handler.h"
#include "v8/include/v8.h"
#include <map>
#include <string>
+class SourceMap;
+
// A module system for JS similar to node.js' require() function.
// Each module has three variables in the global scope:
// - exports, an object returned to dependencies who require() this
@@ -27,10 +30,11 @@
//
// Each module in a ModuleSystem is executed at most once and its exports
// object cached.
Matt Perry 2012/03/01 23:23:06 Could you add a quick comment that explains this i
koz (OOO until 15th September) 2012/03/02 01:13:58 Done.
+// TODO(koz): Rename this to JavaScriptModuleSystem.
class ModuleSystem : public NativeHandler {
public:
// |source_map| is a weak pointer.
- explicit ModuleSystem(const std::map<std::string, std::string>* source_map);
+ explicit ModuleSystem(SourceMap* source_map);
virtual ~ModuleSystem();
// Require the specified module. This is the equivalent of calling
@@ -41,14 +45,21 @@ class ModuleSystem : public NativeHandler {
// calls to requireNative(|name|) from JS will return a new object created by
// |native_handler|.
void RegisterNativeHandler(const std::string& name,
- scoped_ptr<NativeHandler> native_handler);
+ scoped_ptr<NativeHandler> native_handler);
+
+ // Prevents any new JS code from being injected by causing GetSource(), Run()
+ // and GetNative() to throw exceptions.
+ void DisableInjection();
Aaron Boodman 2012/03/01 07:24:26 It's only GetNative() that needs to be disabled; t
koz (OOO until 15th September) 2012/03/02 01:13:58 Done.
private:
+ typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap;
Aaron Boodman 2012/03/01 07:24:26 .append("\n");
koz (OOO until 15th September) 2012/03/02 01:13:58 Done.
// Ensure that require_ has been evaluated from require.js.
void EnsureRequireLoaded();
- // Run |code| in the current context.
- v8::Handle<v8::Value> RunString(v8::Handle<v8::String> code);
+ // Run |code| in the current context with the name |name| used for stack
+ // traces.
+ v8::Handle<v8::Value> RunString(v8::Handle<v8::String> code,
+ v8::Handle<v8::String> name);
// Run the given code in the current context.
// |args[0]| - the code to execute.
@@ -63,12 +74,17 @@ class ModuleSystem : public NativeHandler {
// |args[0]| - the name of a native handler object.
v8::Handle<v8::Value> GetNative(const v8::Arguments& args);
+ base::StringPiece GetResource(int resource_id);
+
+ // Throws an exception in the calling JS context.
+ v8::Handle<v8::Value> ThrowException(const std::string& message);
+
// A map from module names to the JS source for that module. GetSource()
// performs a lookup on this map.
- const std::map<std::string, std::string>* source_map_;
- typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap;
+ SourceMap* source_map_;
NativeHandlerMap native_handler_map_;
v8::Handle<v8::Function> require_;
+ bool injection_enabled_;
};
#endif // CHROME_RENDERER_MODULE_SYSTEM_H_

Powered by Google App Engine
This is Rietveld 408576698