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

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

Issue 2873373005: Add custom action support (Closed)
Patch Set: Rebase. Created 3 years, 7 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 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 result.Set(v8::String::NewFromUtf8(isolate, attr_value.c_str())); 732 result.Set(v8::String::NewFromUtf8(isolate, attr_value.c_str()));
733 }); 733 });
734 RouteNodeIDFunction( 734 RouteNodeIDFunction(
735 "GetNameFrom", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, 735 "GetNameFrom", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
736 TreeCache* cache, ui::AXNode* node) { 736 TreeCache* cache, ui::AXNode* node) {
737 ui::AXNameFrom name_from = static_cast<ui::AXNameFrom>( 737 ui::AXNameFrom name_from = static_cast<ui::AXNameFrom>(
738 node->data().GetIntAttribute(ui::AX_ATTR_NAME_FROM)); 738 node->data().GetIntAttribute(ui::AX_ATTR_NAME_FROM));
739 std::string name_from_str = ui::ToString(name_from); 739 std::string name_from_str = ui::ToString(name_from);
740 result.Set(v8::String::NewFromUtf8(isolate, name_from_str.c_str())); 740 result.Set(v8::String::NewFromUtf8(isolate, name_from_str.c_str()));
741 }); 741 });
742 RouteNodeIDFunction("GetCustomActions", [](v8::Isolate* isolate,
743 v8::ReturnValue<v8::Value> result,
744 TreeCache* cache,
745 ui::AXNode* node) {
746 const std::vector<int32_t>& custom_action_ids =
747 node->data().GetIntListAttribute(ui::AX_ATTR_CUSTOM_ACTION_IDS);
748 if (custom_action_ids.empty()) {
749 result.SetUndefined();
750 return;
751 }
752
753 const std::vector<std::string>& custom_action_descriptions =
754 node->data().GetStringListAttribute(
755 ui::AX_ATTR_CUSTOM_ACTION_DESCRIPTIONS);
756 if (custom_action_ids.size() != custom_action_descriptions.size()) {
757 result.SetUndefined();
David Tseng 2017/05/16 22:33:23 I would actually NOTREACHED here.
yawano 2017/06/02 09:02:38 Done.
758 return;
759 }
760
761 v8::Local<v8::Array> custom_actions(
762 v8::Array::New(isolate, custom_action_ids.size()));
763 for (size_t i = 0; i < custom_action_ids.size(); i++) {
764 v8::Local<v8::Object> custom_action(v8::Object::New(isolate));
765 SafeSetV8Property(isolate, custom_action, "id",
766 v8::Integer::New(isolate, custom_action_ids[i]));
767 SafeSetV8Property(isolate, custom_action, "description",
768 v8::String::NewFromUtf8(
769 isolate, custom_action_descriptions[i].c_str()));
770 custom_actions->Set(static_cast<uint32_t>(i), custom_action);
771 }
772 result.Set(custom_actions);
773 });
742 RouteNodeIDFunction("GetChecked", [](v8::Isolate* isolate, 774 RouteNodeIDFunction("GetChecked", [](v8::Isolate* isolate,
743 v8::ReturnValue<v8::Value> result, 775 v8::ReturnValue<v8::Value> result,
744 TreeCache* cache, ui::AXNode* node) { 776 TreeCache* cache, ui::AXNode* node) {
745 const ui::AXCheckedState checked_state = static_cast<ui::AXCheckedState>( 777 const ui::AXCheckedState checked_state = static_cast<ui::AXCheckedState>(
746 node->data().GetIntAttribute(ui::AX_ATTR_CHECKED_STATE)); 778 node->data().GetIntAttribute(ui::AX_ATTR_CHECKED_STATE));
747 if (checked_state) { 779 if (checked_state) {
748 const std::string checked_str = ui::ToString(checked_state); 780 const std::string checked_str = ui::ToString(checked_state);
749 result.Set(v8::String::NewFromUtf8(isolate, checked_str.c_str())); 781 result.Set(v8::String::NewFromUtf8(isolate, checked_str.c_str()));
750 } 782 }
751 }); 783 });
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 for (auto id : ids) 1461 for (auto id : ids)
1430 nodes->AppendInteger(id); 1462 nodes->AppendInteger(id);
1431 args.Append(std::move(nodes)); 1463 args.Append(std::move(nodes));
1432 } 1464 }
1433 1465
1434 bindings_system_->DispatchEventInContext("automationInternal.onNodesRemoved", 1466 bindings_system_->DispatchEventInContext("automationInternal.onNodesRemoved",
1435 &args, nullptr, context()); 1467 &args, nullptr, context());
1436 } 1468 }
1437 1469
1438 } // namespace extensions 1470 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698