Commit a23ca99a authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Prevent overlay in lite scripts.

Lite scripts should never show the overlay. This is achieved in two
steps:

- Auto-insert a ConfigureUiState action as the first action to run.
- Blacklist ConfigureUiState, such that scripts can't override this.

Bug: b/164506953
Change-Id: Ibce93307e2f8fd3ef15bb1aeb0b2e338b0e48457
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2362822Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Cr-Commit-Position: refs/heads/master@{#800138}
parent f201c139
......@@ -115,6 +115,15 @@ void LiteService::OnGetActions(ResponseCallback callback,
// order to map the chosen payload back to the action it originated from.
lite_service_util::AssignUniquePayloadsToPrompts(&response_proto);
// Prepend a ConfigureUi action to ensure that the overlay will not be shown.
ActionProto configure_ui;
configure_ui.mutable_configure_ui_state()->set_overlay_behavior(
ConfigureUiStateProto::HIDDEN);
*response_proto.add_actions() = configure_ui;
for (int i = response_proto.actions().size() - 1; i > 0; --i) {
response_proto.mutable_actions()->SwapElements(i, i - 1);
}
auto split_actions =
lite_service_util::SplitActionsAtLastBrowse(response_proto);
if (!split_actions.has_value()) {
......
......@@ -229,15 +229,21 @@ TEST_F(LiteServiceTest, GetActionsSplitsActionsResponseAtLastBrowse) {
// will have automatically assigned unique payloads to prompts.
ActionsResponseProto proto;
ASSERT_TRUE(proto.ParseFromString(response));
ASSERT_TRUE(proto.actions().size() == 3);
ASSERT_TRUE(proto.actions().size() == 4);
// The first action is a ConfigureUiState, which is automatically added
// by the lite_service.
EXPECT_TRUE(proto.actions(0).action_info_case() ==
ActionProto::kPrompt);
EXPECT_TRUE(proto.actions(0).prompt().browse_mode());
ActionProto::kConfigureUiState);
EXPECT_TRUE(proto.actions(0).configure_ui_state().overlay_behavior() ==
ConfigureUiStateProto::HIDDEN);
EXPECT_TRUE(proto.actions(1).action_info_case() ==
ActionProto::kWaitForDom);
ActionProto::kPrompt);
EXPECT_TRUE(proto.actions(1).prompt().browse_mode());
EXPECT_TRUE(proto.actions(2).action_info_case() ==
ActionProto::kWaitForDom);
EXPECT_TRUE(proto.actions(3).action_info_case() ==
ActionProto::kPrompt);
EXPECT_TRUE(proto.actions(2).prompt().browse_mode());
EXPECT_TRUE(proto.actions(3).prompt().browse_mode());
for (const auto& action : proto.actions()) {
processed_actions.emplace_back(ProcessedActionProto());
......@@ -245,7 +251,7 @@ TEST_F(LiteServiceTest, GetActionsSplitsActionsResponseAtLastBrowse) {
processed_actions.back().set_status(ACTION_APPLIED);
}
processed_actions.back().mutable_prompt_choice()->set_server_payload(
proto.actions(2).prompt().choices(0).server_payload());
proto.actions(3).prompt().choices(0).server_payload());
});
lite_service_->GetActions(kFakeScriptPath, GURL(kFakeUrl),
TriggerContextImpl(), "", "",
......
......@@ -29,8 +29,7 @@ const ActionProto::ActionInfoCase kAllowedActions[] = {
ActionProto::kWaitForNavigation,
ActionProto::kConfigureBottomSheet,
ActionProto::kPopupMessage,
ActionProto::kWaitForDocument,
ActionProto::kConfigureUiState};
ActionProto::kWaitForDocument};
base::Optional<std::pair<ActionsResponseProto, ActionsResponseProto>>
SplitActionsAtLastBrowse(const ActionsResponseProto& proto) {
......
......@@ -103,7 +103,6 @@ TEST(LiteServiceUtilTest, ContainsOnlySafeActions) {
safe_actions.add_actions()->mutable_configure_bottom_sheet();
safe_actions.add_actions()->mutable_popup_message();
safe_actions.add_actions()->mutable_wait_for_document();
safe_actions.add_actions()->mutable_configure_ui_state();
EXPECT_TRUE(ContainsOnlySafeActions(safe_actions));
......@@ -125,6 +124,7 @@ TEST(LiteServiceUtilTest, ContainsOnlySafeActions) {
unsafe_actions.add_actions()->mutable_generate_password_for_form_field();
unsafe_actions.add_actions()->mutable_save_generated_password();
unsafe_actions.add_actions()->mutable_presave_generated_password();
unsafe_actions.add_actions()->mutable_configure_ui_state();
for (const auto& unsafe_action : unsafe_actions.actions()) {
ActionsResponseProto test_actions = safe_actions;
*test_actions.add_actions() = unsafe_action;
......
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