| 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/page_actions_custom_bindings.h" | 5 #include "chrome/renderer/extensions/page_actions_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 extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 PageActionsCustomBindings::PageActionsCustomBindings( | 16 PageActionsCustomBindings::PageActionsCustomBindings( |
| 17 int dependency_count, |
| 18 const char** dependencies, |
| 17 ExtensionDispatcher* extension_dispatcher) | 19 ExtensionDispatcher* extension_dispatcher) |
| 18 : ChromeV8Extension(extension_dispatcher) { | 20 : ChromeV8Extension( |
| 19 RouteStaticFunction("GetCurrentPageActions", &GetCurrentPageActions); | 21 "extensions/page_actions_custom_bindings.js", |
| 20 } | 22 IDR_PAGE_ACTIONS_CUSTOM_BINDINGS_JS, |
| 23 dependency_count, |
| 24 dependencies, |
| 25 extension_dispatcher) {} |
| 21 | 26 |
| 22 // static | 27 // static |
| 23 v8::Handle<v8::Value> PageActionsCustomBindings::GetCurrentPageActions( | 28 v8::Handle<v8::Value> PageActionsCustomBindings::GetCurrentPageActions( |
| 24 const v8::Arguments& args) { | 29 const v8::Arguments& args) { |
| 25 PageActionsCustomBindings* self = | 30 PageActionsCustomBindings* self = |
| 26 GetFromArguments<PageActionsCustomBindings>(args); | 31 GetFromArguments<PageActionsCustomBindings>(args); |
| 27 std::string extension_id = *v8::String::Utf8Value(args[0]->ToString()); | 32 std::string extension_id = *v8::String::Utf8Value(args[0]->ToString()); |
| 28 CHECK(!extension_id.empty()); | 33 CHECK(!extension_id.empty()); |
| 29 const ::Extension* extension = | 34 const ::Extension* extension = |
| 30 self->extension_dispatcher_->extensions()->GetByID(extension_id); | 35 self->extension_dispatcher_->extensions()->GetByID(extension_id); |
| 31 CHECK(extension); | 36 CHECK(extension); |
| 32 | 37 |
| 33 v8::Local<v8::Array> page_action_vector = v8::Array::New(); | 38 v8::Local<v8::Array> page_action_vector = v8::Array::New(); |
| 34 if (extension->page_action()) { | 39 if (extension->page_action()) { |
| 35 std::string id = extension->page_action()->id(); | 40 std::string id = extension->page_action()->id(); |
| 36 page_action_vector->Set(v8::Integer::New(0), | 41 page_action_vector->Set(v8::Integer::New(0), |
| 37 v8::String::New(id.c_str(), id.size())); | 42 v8::String::New(id.c_str(), id.size())); |
| 38 } | 43 } |
| 39 | 44 |
| 40 return page_action_vector; | 45 return page_action_vector; |
| 41 } | 46 } |
| 42 | 47 |
| 48 |
| 49 v8::Handle<v8::FunctionTemplate> PageActionsCustomBindings::GetNativeFunction( |
| 50 v8::Handle<v8::String> name) { |
| 51 if (name->Equals(v8::String::New("GetCurrentPageActions"))) { |
| 52 return v8::FunctionTemplate::New(GetCurrentPageActions, |
| 53 v8::External::New(this)); |
| 54 } |
| 55 |
| 56 return ChromeV8Extension::GetNativeFunction(name); |
| 57 } |
| 58 |
| 43 } // extensions | 59 } // extensions |
| OLD | NEW |