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 handler_functions_.push_back(function); | 31 handler_functions_.push_back(function); |
Matt Perry
2012/02/28 20:34:20
You use this pattern a few times. Do you know abou
koz (OOO until 15th September)
2012/03/01 03:41:56
I didn't know about that, thanks. I've put a TODO
| |
32 v8::Handle<v8::FunctionTemplate> function_template = | 32 v8::Handle<v8::FunctionTemplate> function_template = |
33 v8::FunctionTemplate::New(Router, | 33 v8::FunctionTemplate::New(Router, |
34 v8::External::New(function.get())); | 34 v8::External::New(function.get())); |
35 object_template_->Set(name.c_str(), function_template); | 35 object_template_->Set(name.c_str(), function_template); |
36 } | 36 } |
37 | |
38 void NativeHandler::RouteStaticFunction(const std::string& name, | |
39 const HandlerFunc handler_func) { | |
40 v8::Handle<v8::FunctionTemplate> function_template = | |
41 v8::FunctionTemplate::New(handler_func, v8::External::New(this)); | |
42 object_template_->Set(name.c_str(), function_template); | |
43 } | |
OLD | NEW |