OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/event_bindings.h" | 5 #include "chrome/renderer/extensions/event_bindings.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 class ExtensionImpl : public ChromeV8Extension { | 56 class ExtensionImpl : public ChromeV8Extension { |
57 public: | 57 public: |
58 explicit ExtensionImpl(ExtensionDispatcher* dispatcher) | 58 explicit ExtensionImpl(ExtensionDispatcher* dispatcher) |
59 : ChromeV8Extension("extensions/event.js", | 59 : ChromeV8Extension("extensions/event.js", |
60 IDR_EVENT_BINDINGS_JS, | 60 IDR_EVENT_BINDINGS_JS, |
61 dispatcher) { | 61 dispatcher) { |
62 } | 62 } |
63 ~ExtensionImpl() {} | 63 ~ExtensionImpl() {} |
64 | 64 |
65 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 65 void SetNativeFunctions(v8::Handle<v8::Object> object) { |
66 v8::Handle<v8::String> name) { | 66 RouteFunctionToStatic("AttachEvent", AttachEvent, object); |
67 if (name->Equals(v8::String::New("AttachEvent"))) { | 67 RouteFunctionToStatic("DetachEvent", DetachEvent, object); |
68 return v8::FunctionTemplate::New(AttachEvent, v8::External::New(this)); | |
69 } else if (name->Equals(v8::String::New("DetachEvent"))) { | |
70 return v8::FunctionTemplate::New(DetachEvent, v8::External::New(this)); | |
71 } | |
72 return ChromeV8Extension::GetNativeFunction(name); | |
73 } | 68 } |
74 | 69 |
75 // Attach an event name to an object. | 70 // Attach an event name to an object. |
76 static v8::Handle<v8::Value> AttachEvent(const v8::Arguments& args) { | 71 static v8::Handle<v8::Value> AttachEvent(const v8::Arguments& args) { |
77 DCHECK(args.Length() == 1); | 72 DCHECK(args.Length() == 1); |
78 // TODO(erikkay) should enforce that event name is a string in the bindings | 73 // TODO(erikkay) should enforce that event name is a string in the bindings |
79 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); | 74 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); |
80 | 75 |
81 if (args[0]->IsString()) { | 76 if (args[0]->IsString()) { |
82 ExtensionImpl* v8_extension = GetFromArguments<ExtensionImpl>(args); | 77 ExtensionImpl* v8_extension = GetFromArguments<ExtensionImpl>(args); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 event_name)); | 118 event_name)); |
124 } | 119 } |
125 } | 120 } |
126 | 121 |
127 return v8::Undefined(); | 122 return v8::Undefined(); |
128 } | 123 } |
129 }; | 124 }; |
130 | 125 |
131 } // namespace | 126 } // namespace |
132 | 127 |
133 v8::Extension* EventBindings::Get(ExtensionDispatcher* dispatcher) { | 128 ChromeV8Extension* EventBindings::Get(ExtensionDispatcher* dispatcher) { |
134 static v8::Extension* extension = new ExtensionImpl(dispatcher); | 129 return new ExtensionImpl(dispatcher); |
135 return extension; | |
136 } | 130 } |
OLD | NEW |