OLD | NEW |
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 |
(...skipping 10 matching lines...) Expand all Loading... |
21 // static | 21 // static |
22 v8::Handle<v8::Value> NativeHandler::Router(const v8::Arguments& args) { | 22 v8::Handle<v8::Value> NativeHandler::Router(const v8::Arguments& args) { |
23 HandlerFunction* handler_function = static_cast<HandlerFunction*>( | 23 HandlerFunction* handler_function = static_cast<HandlerFunction*>( |
24 args.Data().As<v8::External>()->Value()); | 24 args.Data().As<v8::External>()->Value()); |
25 return handler_function->Run(args); | 25 return handler_function->Run(args); |
26 } | 26 } |
27 | 27 |
28 void NativeHandler::RouteFunction(const std::string& name, | 28 void NativeHandler::RouteFunction(const std::string& name, |
29 const HandlerFunction& handler_function) { | 29 const HandlerFunction& handler_function) { |
30 linked_ptr<HandlerFunction> function(new HandlerFunction(handler_function)); | 30 linked_ptr<HandlerFunction> function(new HandlerFunction(handler_function)); |
| 31 // TODO(koz): Investigate using v8's MakeWeak() function instead of holding |
| 32 // on to these pointers here. |
31 handler_functions_.push_back(function); | 33 handler_functions_.push_back(function); |
32 v8::Handle<v8::FunctionTemplate> function_template = | 34 v8::Handle<v8::FunctionTemplate> function_template = |
33 v8::FunctionTemplate::New(Router, | 35 v8::FunctionTemplate::New(Router, |
34 v8::External::New(function.get())); | 36 v8::External::New(function.get())); |
35 object_template_->Set(name.c_str(), function_template); | 37 object_template_->Set(name.c_str(), function_template); |
36 } | 38 } |
| 39 |
| 40 void NativeHandler::RouteStaticFunction(const std::string& name, |
| 41 const HandlerFunc handler_func) { |
| 42 v8::Handle<v8::FunctionTemplate> function_template = |
| 43 v8::FunctionTemplate::New(handler_func, v8::External::New(this)); |
| 44 object_template_->Set(name.c_str(), function_template); |
| 45 } |
OLD | NEW |