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

Unified Diff: chrome/renderer/module_system.h

Issue 9835039: Make app_custom_bindings.js lazily evaluated so it doesn't execute on every page load. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 9 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
« no previous file with comments | « chrome/renderer/extensions/extension_dispatcher.cc ('k') | chrome/renderer/module_system.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/module_system.h
diff --git a/chrome/renderer/module_system.h b/chrome/renderer/module_system.h
index 4a50938650894c068e835bf915288ef6c0127b15..7b65c69fe9390383926dccedd8b7c4105d910031 100644
--- a/chrome/renderer/module_system.h
+++ b/chrome/renderer/module_system.h
@@ -39,6 +39,17 @@ class ModuleSystem : public NativeHandler {
virtual bool Contains(const std::string& name) = 0;
};
+ // Enables native bindings for the duration of its lifetime.
+ class NativesEnabledScope {
+ public:
+ explicit NativesEnabledScope(ModuleSystem* module_system);
+ ~NativesEnabledScope();
+
+ private:
+ ModuleSystem* module_system_;
+ DISALLOW_COPY_AND_ASSIGN(NativesEnabledScope);
+ };
+
// |source_map| is a weak pointer.
explicit ModuleSystem(SourceMap* source_map);
virtual ~ModuleSystem();
@@ -59,14 +70,9 @@ class ModuleSystem : public NativeHandler {
// Executes |code| in the current context with |name| as the filename.
void RunString(const std::string& code, const std::string& name);
- // When false |natives_enabled_| causes calls to GetNative() (the basis of
- // requireNative() in JS) to throw an exception.
- void set_natives_enabled(bool natives_enabled) {
- natives_enabled_ = natives_enabled;
- }
-
- static v8::Handle<v8::Value> GetterRouter(v8::Local<v8::String> property,
- const v8::AccessorInfo& info);
+ // Retrieves the lazily defined field specified by |property|.
+ static v8::Handle<v8::Value> LazyFieldGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo& info);
// Make |object|.|field| lazily evaluate to the result of
// require(|module_name|)[|module_field|].
@@ -105,7 +111,11 @@ class ModuleSystem : public NativeHandler {
// performs a lookup on this map.
SourceMap* source_map_;
NativeHandlerMap native_handler_map_;
- bool natives_enabled_;
+ // When 0, natives are disabled, otherwise indicates how many callers have
+ // pinned natives as enabled.
+ int natives_enabled_;
+
+ DISALLOW_COPY_AND_ASSIGN(ModuleSystem);
};
#endif // CHROME_RENDERER_MODULE_SYSTEM_H_
« no previous file with comments | « chrome/renderer/extensions/extension_dispatcher.cc ('k') | chrome/renderer/module_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698