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

Side by Side Diff: chrome/renderer/native_handler.cc

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: respond to comments 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/renderer/native_handler.h" 5 #include "chrome/renderer/native_handler.h"
6 6
7 #include "base/memory/linked_ptr.h" 7 #include "base/memory/linked_ptr.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "v8/include/v8.h" 9 #include "v8/include/v8.h"
10 10
11 NativeHandler::NativeHandler() 11 NativeHandler::NativeHandler()
12 : object_template_(v8::ObjectTemplate::New()) { 12 : object_template_(
13 v8::Persistent<v8::ObjectTemplate>::New(v8::ObjectTemplate::New())) {
13 } 14 }
14 15
15 NativeHandler::~NativeHandler() {} 16 NativeHandler::~NativeHandler() {
17 object_template_.Dispose();
18 }
16 19
17 v8::Handle<v8::Object> NativeHandler::NewInstance() { 20 v8::Handle<v8::Object> NativeHandler::NewInstance() {
18 return object_template_->NewInstance(); 21 return object_template_->NewInstance();
19 } 22 }
20 23
21 // static 24 // static
22 v8::Handle<v8::Value> NativeHandler::Router(const v8::Arguments& args) { 25 v8::Handle<v8::Value> NativeHandler::Router(const v8::Arguments& args) {
23 HandlerFunction* handler_function = static_cast<HandlerFunction*>( 26 HandlerFunction* handler_function = static_cast<HandlerFunction*>(
24 args.Data().As<v8::External>()->Value()); 27 args.Data().As<v8::External>()->Value());
25 return handler_function->Run(args); 28 return handler_function->Run(args);
(...skipping 10 matching lines...) Expand all
36 v8::External::New(function.get())); 39 v8::External::New(function.get()));
37 object_template_->Set(name.c_str(), function_template); 40 object_template_->Set(name.c_str(), function_template);
38 } 41 }
39 42
40 void NativeHandler::RouteStaticFunction(const std::string& name, 43 void NativeHandler::RouteStaticFunction(const std::string& name,
41 const HandlerFunc handler_func) { 44 const HandlerFunc handler_func) {
42 v8::Handle<v8::FunctionTemplate> function_template = 45 v8::Handle<v8::FunctionTemplate> function_template =
43 v8::FunctionTemplate::New(handler_func, v8::External::New(this)); 46 v8::FunctionTemplate::New(handler_func, v8::External::New(this));
44 object_template_->Set(name.c_str(), function_template); 47 object_template_->Set(name.c_str(), function_template);
45 } 48 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698