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

Unified Diff: chrome/renderer/extensions/module_system.h

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more progress Created 7 years, 11 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/extensions/module_system.h
diff --git a/chrome/renderer/extensions/module_system.h b/chrome/renderer/extensions/module_system.h
index 4f790842aec9f0a5095e355b90c10a2d991a837b..11e84e74bc135be61abc3be7c732822bbbdf2495 100644
--- a/chrome/renderer/extensions/module_system.h
+++ b/chrome/renderer/extensions/module_system.h
@@ -8,7 +8,7 @@
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/renderer/extensions/native_handler.h"
+#include "chrome/renderer/extensions/object_backed_native_handler.h"
#include "v8/include/v8.h"
#include <map>
@@ -33,7 +33,7 @@ namespace extensions {
// Note that a ModuleSystem must be used only in conjunction with a single
// v8::Context.
// TODO(koz): Rename this to JavaScriptModuleSystem.
-class ModuleSystem : public NativeHandler {
+class ModuleSystem : public ObjectBackedNativeHandler {
public:
class SourceMap {
public:
@@ -71,7 +71,7 @@ class ModuleSystem : public NativeHandler {
// Require the specified module. This is the equivalent of calling
// require('module_name') from the loaded JS files.
- void Require(const std::string& module_name);
+ v8::Handle<v8::Value> Require(const std::string& module_name);
v8::Handle<v8::Value> Require(const v8::Arguments& args);
v8::Handle<v8::Value> RequireForJs(const v8::Arguments& args);
v8::Handle<v8::Value> RequireForJsInner(v8::Handle<v8::String> module_name);
@@ -81,11 +81,17 @@ class ModuleSystem : public NativeHandler {
void CallModuleMethod(const std::string& module_name,
const std::string& method_name);
+ // Call |value| with arguments |argv| and return the result.
+ v8::Handle<v8::Value> CallModuleMethod(v8::Local<v8::Value> value,
not at google - send to devlin 2013/01/24 21:10:12 would prefer this to be a v8::Function but if it a
cduvall 2013/01/24 22:15:15 Added TODO.
+ int argc,
+ v8::Handle<v8::Value> argv[]);
+
// Register |native_handler| as a potential target for requireNative(), so
// 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);
+ bool HasNativeHandler(const std::string& name);
not at google - send to devlin 2013/01/24 21:10:12 docs on all these methods
cduvall 2013/01/24 22:15:15 Done.
// Causes requireNative(|name|) to look for its module in |source_map_|
// instead of using a registered native handler. This can be used in unit
@@ -98,6 +104,21 @@ class ModuleSystem : public NativeHandler {
// Retrieves the lazily defined field specified by |property|.
static v8::Handle<v8::Value> LazyFieldGetter(v8::Local<v8::String> property,
const v8::AccessorInfo& info);
+ static v8::Handle<v8::Value> NativeLazyFieldGetter(
+ v8::Local<v8::String> property,
+ const v8::AccessorInfo& info);
+
+ typedef v8::Handle<v8::Object> (*GetModuleFunc)(ModuleSystem*,
+ v8::Handle<v8::Object>);
+ static v8::Handle<v8::Value> BaseLazyFieldGetter(
+ v8::Local<v8::String> property,
+ const v8::AccessorInfo& info,
+ GetModuleFunc get_module);
+ static v8::Handle<v8::Object> GetModule(ModuleSystem* module_system,
+ v8::Handle<v8::Object> parameters);
+ static v8::Handle<v8::Object> GetNativeModule(
+ ModuleSystem* module_system,
+ v8::Handle<v8::Object> parameters);
not at google - send to devlin 2013/01/24 21:10:12 why are these static?
cduvall 2013/01/24 22:15:15 Because... who knows. They aren't anymore.
// Make |object|.|field| lazily evaluate to the result of
// require(|module_name|)[|module_field|].
@@ -106,6 +127,13 @@ class ModuleSystem : public NativeHandler {
const std::string& module_name,
const std::string& module_field);
+ // Make |object|.|field| lazily evaluate to the result of
+ // requireNative(|module_name|)[|module_field|].
+ void SetNativeLazyField(v8::Handle<v8::Object> object,
+ const std::string& field,
+ const std::string& module_name,
+ const std::string& module_field);
+
void set_exception_handler(scoped_ptr<ExceptionHandler> handler) {
exception_handler_ = handler.Pass();
}
@@ -124,6 +152,12 @@ class ModuleSystem : public NativeHandler {
v8::Handle<v8::Value> RunString(v8::Handle<v8::String> code,
v8::Handle<v8::String> name);
+ void SetLazyField(v8::Handle<v8::Object> object,
+ const std::string& field,
+ const std::string& module_name,
+ const std::string& module_field,
+ v8::AccessorGetter getter);
+
// Return the named source file stored in the source map.
// |args[0]| - the name of a source file in source_map_.
v8::Handle<v8::Value> GetSource(v8::Handle<v8::String> source_name);
@@ -131,6 +165,7 @@ class ModuleSystem : public NativeHandler {
// Return an object that contains the native methods defined by the named
// NativeHandler.
// |args[0]| - the name of a native handler object.
+ v8::Handle<v8::Value> GetNativeFromString(const std::string& native_name);
v8::Handle<v8::Value> GetNative(const v8::Arguments& args);
// Wraps |source| in a (function(require, requireNative, exports) {...}).

Powered by Google App Engine
This is Rietveld 408576698