| 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/extensions/experimental.socket_custom_bindings.h" | 5 #include "chrome/renderer/extensions/experimental.socket_custom_bindings.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "chrome/common/extensions/extension_action.h" | 9 #include "chrome/common/extensions/extension_action.h" |
| 10 #include "chrome/renderer/extensions/extension_dispatcher.h" | 10 #include "chrome/renderer/extensions/extension_dispatcher.h" |
| 11 #include "grit/renderer_resources.h" | 11 #include "grit/renderer_resources.h" |
| 12 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace extensions { |
| 15 | 15 |
| 16 v8::Handle<v8::Value> GetNextSocketEventId(const v8::Arguments& args) { | 16 ExperimentalSocketCustomBindings::ExperimentalSocketCustomBindings( |
| 17 int dependency_count, |
| 18 const char** dependencies) |
| 19 : ChromeV8Extension( |
| 20 "extensions/experimental.socket_custom_bindings.js", |
| 21 IDR_EXPERIMENTAL_SOCKET_CUSTOM_BINDINGS_JS, |
| 22 dependency_count, |
| 23 dependencies, |
| 24 NULL) {} |
| 25 |
| 26 static v8::Handle<v8::Value> GetNextSocketEventId(const v8::Arguments& args) { |
| 17 // Note: this works because the socket API only works in the extension | 27 // Note: this works because the socket API only works in the extension |
| 18 // process, not content scripts. | 28 // process, not content scripts. |
| 19 static int next_event_id = 1; | 29 static int next_event_id = 1; |
| 20 return v8::Integer::New(next_event_id++); | 30 return v8::Integer::New(next_event_id++); |
| 21 } | 31 } |
| 22 | 32 |
| 23 } // namespace | 33 v8::Handle<v8::FunctionTemplate> |
| 34 ExperimentalSocketCustomBindings::GetNativeFunction( |
| 35 v8::Handle<v8::String> name) { |
| 36 if (name->Equals(v8::String::New("GetNextSocketEventId"))) |
| 37 return v8::FunctionTemplate::New(GetNextSocketEventId); |
| 24 | 38 |
| 25 namespace extensions { | 39 return ChromeV8Extension::GetNativeFunction(name); |
| 26 | |
| 27 ExperimentalSocketCustomBindings::ExperimentalSocketCustomBindings() | |
| 28 : ChromeV8Extension(NULL) { | |
| 29 RouteStaticFunction("GetNextSocketEventId", &GetNextSocketEventId); | |
| 30 } | 40 } |
| 31 | 41 |
| 32 } // extensions | 42 } // extensions |
| OLD | NEW |