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

Unified Diff: extensions/renderer/module_system.h

Issue 359413004: Add support for using AMD modules from extensions modules. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cross-context tests Created 6 years, 5 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: extensions/renderer/module_system.h
diff --git a/extensions/renderer/module_system.h b/extensions/renderer/module_system.h
index eec25cce5228a510eff77d9b3c6c2ec98497f535..4ab628fe0ea6c3962b23fffb709fb9d94aad2f87 100644
--- a/extensions/renderer/module_system.h
+++ b/extensions/renderer/module_system.h
@@ -15,6 +15,7 @@
#include "base/memory/scoped_ptr.h"
#include "extensions/renderer/native_handler.h"
#include "extensions/renderer/object_backed_native_handler.h"
+#include "gin/modules/module_registry_observer.h"
#include "v8/include/v8.h"
namespace extensions {
@@ -37,7 +38,8 @@ class ScriptContext;
// Note that a ModuleSystem must be used only in conjunction with a single
// v8::Context.
// TODO(koz): Rename this to JavaScriptModuleSystem.
-class ModuleSystem : public ObjectBackedNativeHandler {
+class ModuleSystem : public ObjectBackedNativeHandler,
+ public gin::ModuleRegistryObserver {
public:
class SourceMap {
public:
@@ -158,9 +160,6 @@ class ModuleSystem : public ObjectBackedNativeHandler {
// Called when an exception is thrown but not caught.
void HandleException(const v8::TryCatch& try_catch);
- // Ensure that require_ has been evaluated from require.js.
- void EnsureRequireLoaded();
-
void RequireForJs(const v8::FunctionCallbackInfo<v8::Value>& args);
v8::Local<v8::Value> RequireForJsInner(v8::Handle<v8::String> module_name);
@@ -183,15 +182,29 @@ class ModuleSystem : public ObjectBackedNativeHandler {
v8::Handle<v8::Value> RequireNativeFromString(const std::string& native_name);
void RequireNative(const v8::FunctionCallbackInfo<v8::Value>& args);
- // Wraps |source| in a (function(require, requireNative, exports) {...}).
+ // Return a promise for a requested module.
+ // |args[0]| - the name of a module.
+ void RequireAsync(const v8::FunctionCallbackInfo<v8::Value>& args);
+
+ // Wraps |source| in a (function(define, require, requireNative, ...) {...}).
v8::Handle<v8::String> WrapSource(v8::Handle<v8::String> source);
// NativeHandler implementation which returns the private area of an Object.
void Private(const v8::FunctionCallbackInfo<v8::Value>& args);
- // NativeHandler implementation which returns a function wrapper for a
- // provided function.
- void CreateFunctionWrapper(const v8::FunctionCallbackInfo<v8::Value>& args);
+ // Loads and runs a Javascript module.
+ v8::Handle<v8::Value> LoadModule(const std::string& module_name);
+
+ // Invoked when a module is loaded in response to a requireAsync call.
+ // Resolves |resolver| with |value|.
+ void OnModuleLoaded(
+ scoped_ptr<v8::UniquePersistent<v8::Promise::Resolver> > resolver,
+ v8::Handle<v8::Value> value);
+
+ // gin::ModuleRegistryObserver overrides.
+ virtual void OnDidAddPendingModule(
+ const std::string& id,
+ const std::vector<std::string>& dependencies) OVERRIDE;
ScriptContext* context_;
@@ -212,6 +225,8 @@ class ModuleSystem : public ObjectBackedNativeHandler {
std::set<std::string> overridden_native_handlers_;
+ base::WeakPtrFactory<ModuleSystem> weak_factory_;
+
DISALLOW_COPY_AND_ASSIGN(ModuleSystem);
};

Powered by Google App Engine
This is Rietveld 408576698