Commit 184fd278 authored by David Jacobo's avatar David Jacobo Committed by Commit Bot

Check for empty string in SmartSelection

TextClassifier provides methods for text classification via the ARC
container, one of these methods is classifyText(), this method expects
(among other params) a text to classify which needs to be non-empty.

This CL ensures that the provided text string is not empty before
passing it to the container, we already had a check in place but is
likely that converting the string could have messed with it.

Bug: b/119794258
Test: Build.
Change-Id: I155295c283e1f774f152483c8f5f009ded70baa3
Reviewed-on: https://chromium-review.googlesource.com/c/1344196
Commit-Queue: David Jacobo <djacobo@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610919}
parent 0395b1c0
......@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/arc/intent_helper/start_smart_selection_action_menu.h"
#include <algorithm>
#include <string>
#include <utility>
#include "base/bind.h"
......@@ -44,7 +45,8 @@ void StartSmartSelectionActionMenu::InitMenu(
if (!base::FeatureList::IsEnabled(kSmartTextSelectionFeature))
return;
if (params.selection_text.empty())
const std::string converted_text = base::UTF16ToUTF8(params.selection_text);
if (converted_text.empty())
return;
auto* arc_service_manager = ArcServiceManager::Get();
......@@ -58,8 +60,7 @@ void StartSmartSelectionActionMenu::InitMenu(
base::RecordAction(base::UserMetricsAction("Arc.SmartTextSelection.Request"));
instance->RequestTextSelectionActions(
base::UTF16ToUTF8(params.selection_text),
mojom::ScaleFactor(ui::GetSupportedScaleFactors().back()),
converted_text, mojom::ScaleFactor(ui::GetSupportedScaleFactors().back()),
base::BindOnce(&StartSmartSelectionActionMenu::HandleTextSelectionActions,
weak_ptr_factory_.GetWeakPtr()));
......
......@@ -57,32 +57,39 @@ void TouchSelectionMenuRunnerChromeOS::OpenMenu(
return;
if (base::FeatureList::IsEnabled(arc::kSmartTextSelectionFeature)) {
auto* arc_service_manager = arc::ArcServiceManager::Get();
if (arc_service_manager) {
arc::mojom::IntentHelperInstance* instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_service_manager->arc_bridge_service()->intent_helper(),
RequestTextSelectionActions);
if (instance) {
// aura::WindowTracker is used since the newly created menu may need to
// know about the parent window.
std::unique_ptr<aura::WindowTracker> tracker =
std::make_unique<aura::WindowTracker>();
tracker->Add(context);
const display::Screen* screen = display::Screen::GetScreen();
DCHECK(screen);
// Fetch actions for selected text and then show quick menu.
instance->RequestTextSelectionActions(
base::UTF16ToUTF8(client->GetSelectedText()),
arc::mojom::ScaleFactor(
screen->GetDisplayNearestWindow(context).device_scale_factor()),
base::BindOnce(&TouchSelectionMenuRunnerChromeOS::
OpenMenuWithTextSelectionAction,
weak_ptr_factory_.GetWeakPtr(), client, anchor_rect,
handle_image_size, std::move(tracker)));
return;
const std::string converted_text =
base::UTF16ToUTF8(client->GetSelectedText());
if (!converted_text.empty()) {
auto* arc_service_manager = arc::ArcServiceManager::Get();
if (arc_service_manager) {
arc::mojom::IntentHelperInstance* instance =
ARC_GET_INSTANCE_FOR_METHOD(
arc_service_manager->arc_bridge_service()->intent_helper(),
RequestTextSelectionActions);
if (instance) {
// aura::WindowTracker is used since the newly created menu may need
// to know about the parent window.
std::unique_ptr<aura::WindowTracker> tracker =
std::make_unique<aura::WindowTracker>();
tracker->Add(context);
const display::Screen* screen = display::Screen::GetScreen();
DCHECK(screen);
// Fetch actions for selected text and then show quick menu.
instance->RequestTextSelectionActions(
converted_text,
arc::mojom::ScaleFactor(screen->GetDisplayNearestWindow(context)
.device_scale_factor()),
base::BindOnce(&TouchSelectionMenuRunnerChromeOS::
OpenMenuWithTextSelectionAction,
weak_ptr_factory_.GetWeakPtr(), client,
anchor_rect, handle_image_size,
std::move(tracker)));
return;
}
}
}
}
......
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