• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "chrome/renderer/extensions/page_actions_custom_bindings.h"
6 
7 #include <string>
8 
9 #include "base/bind.h"
10 #include "chrome/common/extensions/api/extension_action/action_info.h"
11 #include "chrome/renderer/extensions/dispatcher.h"
12 #include "extensions/common/extension.h"
13 #include "grit/renderer_resources.h"
14 #include "v8/include/v8.h"
15 
16 namespace extensions {
17 
PageActionsCustomBindings(Dispatcher * dispatcher,ChromeV8Context * context)18 PageActionsCustomBindings::PageActionsCustomBindings(
19     Dispatcher* dispatcher, ChromeV8Context* context)
20     : ChromeV8Extension(dispatcher, context) {
21   RouteFunction("GetCurrentPageActions",
22       base::Bind(&PageActionsCustomBindings::GetCurrentPageActions,
23                  base::Unretained(this)));
24 }
25 
GetCurrentPageActions(const v8::FunctionCallbackInfo<v8::Value> & args)26 void PageActionsCustomBindings::GetCurrentPageActions(
27     const v8::FunctionCallbackInfo<v8::Value>& args) {
28   std::string extension_id = *v8::String::Utf8Value(args[0]->ToString());
29   CHECK(!extension_id.empty());
30   const Extension* extension =
31       dispatcher_->extensions()->GetByID(extension_id);
32   CHECK(extension);
33 
34   v8::Local<v8::Array> page_action_vector = v8::Array::New(args.GetIsolate());
35   if (ActionInfo::GetPageActionInfo(extension)) {
36     std::string id = ActionInfo::GetPageActionInfo(extension)->id;
37     page_action_vector->Set(v8::Integer::New(0),
38                             v8::String::NewFromUtf8(args.GetIsolate(),
39                                                     id.c_str(),
40                                                     v8::String::kNormalString,
41                                                     id.size()));
42   }
43 
44   args.GetReturnValue().Set(page_action_vector);
45 }
46 
47 }  // namespace extensions
48