Commit b4f442d5 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Cleanup: audit AutomationInternalCustomBindings for std::string usage

Bug: none
Change-Id: I16fbd6b1d6a712e69628136d13884a38128d3121
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144403
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758218}
parent 44ed99f2
...@@ -803,7 +803,7 @@ void AutomationInternalCustomBindings::AddRoutes() { ...@@ -803,7 +803,7 @@ void AutomationInternalCustomBindings::AddRoutes() {
RouteNodeIDFunction( RouteNodeIDFunction(
"GetRole", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, "GetRole", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) { AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) {
std::string role_name = ui::ToString(node->data().role); const std::string& role_name = ui::ToString(node->data().role);
result.Set(v8::String::NewFromUtf8(isolate, role_name.c_str(), result.Set(v8::String::NewFromUtf8(isolate, role_name.c_str(),
v8::NewStringType::kNormal) v8::NewStringType::kNormal)
.ToLocalChecked()); .ToLocalChecked());
...@@ -936,7 +936,7 @@ void AutomationInternalCustomBindings::AddRoutes() { ...@@ -936,7 +936,7 @@ void AutomationInternalCustomBindings::AddRoutes() {
gfx::RectF local_bounds(0, 0, gfx::RectF local_bounds(0, 0,
node->data().relative_bounds.bounds.width(), node->data().relative_bounds.bounds.width(),
node->data().relative_bounds.bounds.height()); node->data().relative_bounds.bounds.height());
std::string name = const std::string& name =
node->data().GetStringAttribute(ax::mojom::StringAttribute::kName); node->data().GetStringAttribute(ax::mojom::StringAttribute::kName);
std::vector<int> character_offsets = node->data().GetIntListAttribute( std::vector<int> character_offsets = node->data().GetIntListAttribute(
ax::mojom::IntListAttribute::kCharacterOffsets); ax::mojom::IntListAttribute::kCharacterOffsets);
...@@ -1001,15 +1001,17 @@ void AutomationInternalCustomBindings::AddRoutes() { ...@@ -1001,15 +1001,17 @@ void AutomationInternalCustomBindings::AddRoutes() {
const std::string& attribute_name) { const std::string& attribute_name) {
ax::mojom::StringAttribute attribute = ax::mojom::StringAttribute attribute =
ui::ParseStringAttribute(attribute_name.c_str()); ui::ParseStringAttribute(attribute_name.c_str());
std::string attr_value; const char* attr_value;
if (attribute == ax::mojom::StringAttribute::kFontFamily || if (attribute == ax::mojom::StringAttribute::kFontFamily ||
attribute == ax::mojom::StringAttribute::kLanguage) { attribute == ax::mojom::StringAttribute::kLanguage) {
attr_value = node->GetInheritedStringAttribute(attribute); attr_value = node->GetInheritedStringAttribute(attribute).c_str();
} else if (!node->data().GetStringAttribute(attribute, &attr_value)) { } else if (!node->data().HasStringAttribute(attribute)) {
return; return;
} else {
attr_value = node->data().GetStringAttribute(attribute).c_str();
} }
result.Set(v8::String::NewFromUtf8(isolate, attr_value.c_str(), result.Set(v8::String::NewFromUtf8(isolate, attr_value,
v8::NewStringType::kNormal) v8::NewStringType::kNormal)
.ToLocalChecked()); .ToLocalChecked());
}); });
...@@ -1132,11 +1134,12 @@ void AutomationInternalCustomBindings::AddRoutes() { ...@@ -1132,11 +1134,12 @@ void AutomationInternalCustomBindings::AddRoutes() {
[](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
ui::AXTree* tree, ui::AXNode* node, ui::AXTree* tree, ui::AXNode* node,
const std::string& attribute_name) { const std::string& attribute_name) {
std::string attr_value; std::string attribute_value;
if (!node->data().GetHtmlAttribute(attribute_name.c_str(), &attr_value)) if (!node->data().GetHtmlAttribute(attribute_name.c_str(),
&attribute_value))
return; return;
result.Set(v8::String::NewFromUtf8(isolate, attr_value.c_str(), result.Set(v8::String::NewFromUtf8(isolate, attribute_value.c_str(),
v8::NewStringType::kNormal) v8::NewStringType::kNormal)
.ToLocalChecked()); .ToLocalChecked());
}); });
...@@ -1146,7 +1149,7 @@ void AutomationInternalCustomBindings::AddRoutes() { ...@@ -1146,7 +1149,7 @@ void AutomationInternalCustomBindings::AddRoutes() {
AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) { AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) {
ax::mojom::NameFrom name_from = static_cast<ax::mojom::NameFrom>( ax::mojom::NameFrom name_from = static_cast<ax::mojom::NameFrom>(
node->data().GetIntAttribute(ax::mojom::IntAttribute::kNameFrom)); node->data().GetIntAttribute(ax::mojom::IntAttribute::kNameFrom));
std::string name_from_str = ui::ToString(name_from); const std::string& name_from_str = ui::ToString(name_from);
result.Set(v8::String::NewFromUtf8(isolate, name_from_str.c_str(), result.Set(v8::String::NewFromUtf8(isolate, name_from_str.c_str(),
v8::NewStringType::kNormal) v8::NewStringType::kNormal)
.ToLocalChecked()); .ToLocalChecked());
...@@ -1188,7 +1191,7 @@ void AutomationInternalCustomBindings::AddRoutes() { ...@@ -1188,7 +1191,7 @@ void AutomationInternalCustomBindings::AddRoutes() {
"GetImageAnnotation", "GetImageAnnotation",
[this](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, [this](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) { AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) {
std::string status_string; std::string status_string = std::string();
auto status = node->data().GetImageAnnotationStatus(); auto status = node->data().GetImageAnnotationStatus();
switch (status) { switch (status) {
case ax::mojom::ImageAnnotationStatus::kNone: case ax::mojom::ImageAnnotationStatus::kNone:
...@@ -1265,7 +1268,7 @@ void AutomationInternalCustomBindings::AddRoutes() { ...@@ -1265,7 +1268,7 @@ void AutomationInternalCustomBindings::AddRoutes() {
"GetDetectedLanguage", "GetDetectedLanguage",
[](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) { AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) {
std::string detectedLanguage = node->GetLanguage(); const std::string& detectedLanguage = node->GetLanguage();
result.Set(v8::String::NewFromUtf8(isolate, detectedLanguage.c_str(), result.Set(v8::String::NewFromUtf8(isolate, detectedLanguage.c_str(),
v8::NewStringType::kNormal) v8::NewStringType::kNormal)
.ToLocalChecked()); .ToLocalChecked());
...@@ -1379,9 +1382,8 @@ void AutomationInternalCustomBindings::AddRoutes() { ...@@ -1379,9 +1382,8 @@ void AutomationInternalCustomBindings::AddRoutes() {
// Increment and decrement are available when the role is a slider or // Increment and decrement are available when the role is a slider or
// spin button. // spin button.
std::string role_string; const std::string& role_string =
node->GetStringAttribute(ax::mojom::StringAttribute::kRole, node->GetStringAttribute(ax::mojom::StringAttribute::kRole);
&role_string);
ax::mojom::Role role = ui::ParseRole(role_string.c_str()); ax::mojom::Role role = ui::ParseRole(role_string.c_str());
if (role == ax::mojom::Role::kSlider || if (role == ax::mojom::Role::kSlider ||
role == ax::mojom::Role::kSpinButton) { role == ax::mojom::Role::kSpinButton) {
...@@ -1415,7 +1417,7 @@ void AutomationInternalCustomBindings::AddRoutes() { ...@@ -1415,7 +1417,7 @@ void AutomationInternalCustomBindings::AddRoutes() {
static_cast<ax::mojom::CheckedState>(node->data().GetIntAttribute( static_cast<ax::mojom::CheckedState>(node->data().GetIntAttribute(
ax::mojom::IntAttribute::kCheckedState)); ax::mojom::IntAttribute::kCheckedState));
if (checked_state != ax::mojom::CheckedState::kNone) { if (checked_state != ax::mojom::CheckedState::kNone) {
const std::string checked_str = ui::ToString(checked_state); const std::string& checked_str = ui::ToString(checked_state);
result.Set(v8::String::NewFromUtf8(isolate, checked_str.c_str(), result.Set(v8::String::NewFromUtf8(isolate, checked_str.c_str(),
v8::NewStringType::kNormal) v8::NewStringType::kNormal)
.ToLocalChecked()); .ToLocalChecked());
...@@ -1428,7 +1430,7 @@ void AutomationInternalCustomBindings::AddRoutes() { ...@@ -1428,7 +1430,7 @@ void AutomationInternalCustomBindings::AddRoutes() {
const ax::mojom::Restriction restriction = const ax::mojom::Restriction restriction =
node->data().GetRestriction(); node->data().GetRestriction();
if (restriction != ax::mojom::Restriction::kNone) { if (restriction != ax::mojom::Restriction::kNone) {
const std::string restriction_str = ui::ToString(restriction); const std::string& restriction_str = ui::ToString(restriction);
result.Set(v8::String::NewFromUtf8(isolate, restriction_str.c_str(), result.Set(v8::String::NewFromUtf8(isolate, restriction_str.c_str(),
v8::NewStringType::kNormal) v8::NewStringType::kNormal)
.ToLocalChecked()); .ToLocalChecked());
...@@ -1442,7 +1444,8 @@ void AutomationInternalCustomBindings::AddRoutes() { ...@@ -1442,7 +1444,8 @@ void AutomationInternalCustomBindings::AddRoutes() {
static_cast<ax::mojom::DefaultActionVerb>( static_cast<ax::mojom::DefaultActionVerb>(
node->data().GetIntAttribute( node->data().GetIntAttribute(
ax::mojom::IntAttribute::kDefaultActionVerb)); ax::mojom::IntAttribute::kDefaultActionVerb));
std::string default_action_verb_str = ui::ToString(default_action_verb); const std::string& default_action_verb_str =
ui::ToString(default_action_verb);
result.Set(v8::String::NewFromUtf8(isolate, result.Set(v8::String::NewFromUtf8(isolate,
default_action_verb_str.c_str(), default_action_verb_str.c_str(),
v8::NewStringType::kNormal) v8::NewStringType::kNormal)
...@@ -1453,7 +1456,7 @@ void AutomationInternalCustomBindings::AddRoutes() { ...@@ -1453,7 +1456,7 @@ void AutomationInternalCustomBindings::AddRoutes() {
[](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) { AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) {
ax::mojom::HasPopup has_popup = node->data().GetHasPopup(); ax::mojom::HasPopup has_popup = node->data().GetHasPopup();
std::string has_popup_str = ui::ToString(has_popup); const std::string& has_popup_str = ui::ToString(has_popup);
result.Set(v8::String::NewFromUtf8(isolate, has_popup_str.c_str(), result.Set(v8::String::NewFromUtf8(isolate, has_popup_str.c_str(),
v8::NewStringType::kNormal) v8::NewStringType::kNormal)
.ToLocalChecked()); .ToLocalChecked());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment