Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: chrome/renderer/extensions/automation_internal_custom_bindings.cc

Issue 2873373005: Add custom action support (Closed)
Patch Set: Fix format. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/automation_internal_custom_bindings.h" 5 #include "chrome/renderer/extensions/automation_internal_custom_bindings.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 result.Set(v8::String::NewFromUtf8(isolate, attr_value.c_str())); 735 result.Set(v8::String::NewFromUtf8(isolate, attr_value.c_str()));
736 }); 736 });
737 RouteNodeIDFunction( 737 RouteNodeIDFunction(
738 "GetNameFrom", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, 738 "GetNameFrom", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
739 TreeCache* cache, ui::AXNode* node) { 739 TreeCache* cache, ui::AXNode* node) {
740 ui::AXNameFrom name_from = static_cast<ui::AXNameFrom>( 740 ui::AXNameFrom name_from = static_cast<ui::AXNameFrom>(
741 node->data().GetIntAttribute(ui::AX_ATTR_NAME_FROM)); 741 node->data().GetIntAttribute(ui::AX_ATTR_NAME_FROM));
742 std::string name_from_str = ui::ToString(name_from); 742 std::string name_from_str = ui::ToString(name_from);
743 result.Set(v8::String::NewFromUtf8(isolate, name_from_str.c_str())); 743 result.Set(v8::String::NewFromUtf8(isolate, name_from_str.c_str()));
744 }); 744 });
745 RouteNodeIDFunction("GetCustomActions", [](v8::Isolate* isolate,
746 v8::ReturnValue<v8::Value> result,
747 TreeCache* cache,
748 ui::AXNode* node) {
749 const std::vector<int32_t>& custom_action_ids =
750 node->data().GetIntListAttribute(ui::AX_ATTR_CUSTOM_ACTION_IDS);
751 if (custom_action_ids.empty()) {
752 result.SetUndefined();
753 return;
754 }
755
756 const std::vector<std::string>& custom_action_descriptions =
757 node->data().GetStringListAttribute(
758 ui::AX_ATTR_CUSTOM_ACTION_DESCRIPTIONS);
759 if (custom_action_ids.size() != custom_action_descriptions.size()) {
760 NOTREACHED();
761 return;
762 }
763
764 v8::Local<v8::Array> custom_actions(
765 v8::Array::New(isolate, custom_action_ids.size()));
766 for (size_t i = 0; i < custom_action_ids.size(); i++) {
767 v8::Local<v8::Object> custom_action(v8::Object::New(isolate));
768 SafeSetV8Property(isolate, custom_action, "id",
769 v8::Integer::New(isolate, custom_action_ids[i]));
770 SafeSetV8Property(isolate, custom_action, "description",
771 v8::String::NewFromUtf8(
772 isolate, custom_action_descriptions[i].c_str()));
773 custom_actions->Set(static_cast<uint32_t>(i), custom_action);
774 }
775 result.Set(custom_actions);
776 });
745 RouteNodeIDFunction("GetChecked", [](v8::Isolate* isolate, 777 RouteNodeIDFunction("GetChecked", [](v8::Isolate* isolate,
746 v8::ReturnValue<v8::Value> result, 778 v8::ReturnValue<v8::Value> result,
747 TreeCache* cache, ui::AXNode* node) { 779 TreeCache* cache, ui::AXNode* node) {
748 const ui::AXCheckedState checked_state = static_cast<ui::AXCheckedState>( 780 const ui::AXCheckedState checked_state = static_cast<ui::AXCheckedState>(
749 node->data().GetIntAttribute(ui::AX_ATTR_CHECKED_STATE)); 781 node->data().GetIntAttribute(ui::AX_ATTR_CHECKED_STATE));
750 if (checked_state) { 782 if (checked_state) {
751 const std::string checked_str = ui::ToString(checked_state); 783 const std::string checked_str = ui::ToString(checked_state);
752 result.Set(v8::String::NewFromUtf8(isolate, checked_str.c_str())); 784 result.Set(v8::String::NewFromUtf8(isolate, checked_str.c_str()));
753 } 785 }
754 }); 786 });
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 for (auto id : ids) 1468 for (auto id : ids)
1437 nodes->AppendInteger(id); 1469 nodes->AppendInteger(id);
1438 args.Append(std::move(nodes)); 1470 args.Append(std::move(nodes));
1439 } 1471 }
1440 1472
1441 bindings_system_->DispatchEventInContext("automationInternal.onNodesRemoved", 1473 bindings_system_->DispatchEventInContext("automationInternal.onNodesRemoved",
1442 &args, nullptr, context()); 1474 &args, nullptr, context());
1443 } 1475 }
1444 1476
1445 } // namespace extensions 1477 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698