Skip to content

Commit

Permalink
[Extensions refactor] Use DialogModel in ExtensionInstallBlockedByPar…
Browse files Browse the repository at this point in the history
…entDialog

Bug: 1330637
Change-Id: Ie3116c6e00a67e77581644c099820c91d3fec78c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3816900
Commit-Queue: Emilia Paz <emiliapaz@chromium.org>
Reviewed-by: Caroline Rising <corising@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1035121}
  • Loading branch information
emilia-paz authored and Chromium LUCI CQ committed Aug 15, 2022
1 parent 91bed74 commit ea8d0b4
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 216 deletions.
3 changes: 1 addition & 2 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1901,8 +1901,7 @@ static_library("ui") {
assert(is_chromeos)
sources += [
"supervised_user/parent_permission_dialog.h",
"views/supervised_user/extension_install_blocked_by_parent_dialog_view.cc",
"views/supervised_user/extension_install_blocked_by_parent_dialog_view.h",
"views/supervised_user/extension_install_blocked_by_parent_dialog.cc",
"views/supervised_user/parent_permission_dialog_view.cc",
"views/supervised_user/parent_permission_dialog_view.h",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string>
#include <utility>

#include "chrome/browser/ui/extensions/extensions_dialogs.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/ui/vector_icons/vector_icons.h"
#include "components/constrained_window/constrained_window_views.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "extensions/common/extension.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/dialog_model.h"
#include "ui/base/models/image_model.h"
#include "ui/gfx/paint_vector_icon.h"

namespace {

std::u16string GetExtensionType(const extensions::Extension* extension) {
return l10n_util::GetStringUTF16(
extension->is_app()
? IDS_PARENT_PERMISSION_PROMPT_EXTENSION_TYPE_APP
: IDS_PARENT_PERMISSION_PROMPT_EXTENSION_TYPE_EXTENSION);
}

std::u16string GetTitle(
extensions::ExtensionInstalledBlockedByParentDialogAction action,
std::u16string extension_type) {
int title_id =
action == extensions::ExtensionInstalledBlockedByParentDialogAction::kAdd
? IDS_EXTENSION_INSTALL_BLOCKED_BY_PARENT_PROMPT_TITLE
: IDS_EXTENSION_ENABLE_BLOCKED_BY_PARENT_PROMPT_TITLE;
return l10n_util::GetStringFUTF16(title_id, extension_type);
}

std::u16string GetBodyText(
extensions::ExtensionInstalledBlockedByParentDialogAction action,
std::u16string extension_type) {
int body_id =
action == extensions::ExtensionInstalledBlockedByParentDialogAction::kAdd
? IDS_EXTENSION_INSTALL_BLOCKED_BY_PARENT_PROMPT_MESSAGE
: IDS_EXTENSION_ENABLE_BLOCKED_BY_PARENT_PROMPT_MESSAGE;
return l10n_util::GetStringFUTF16(body_id, extension_type);
}

} // namespace

namespace extensions {

void ShowExtensionInstallBlockedByParentDialog(
ExtensionInstalledBlockedByParentDialogAction action,
const extensions::Extension* extension,
content::WebContents* web_contents,
base::OnceClosure done_callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
std::u16string extension_type = GetExtensionType(extension);

auto dialog_model =
ui::DialogModel::Builder()
.SetTitle(GetTitle(action, extension_type))
.SetIcon(ui::ImageModel::FromImageSkia(gfx::CreateVectorIcon(
chromeos::kNotificationSupervisedUserIcon, ui::kColorIcon)))
.AddBodyText(
ui::DialogModelLabel(GetBodyText(action, extension_type)))
.AddOkButton(base::DoNothing(), l10n_util::GetStringUTF16(IDS_OK))
.SetDialogDestroyingCallback(std::move(done_callback))
.Build();

gfx::NativeWindow parent_window =
web_contents ? web_contents->GetTopLevelNativeWindow() : nullptr;
constrained_window::ShowBrowserModal(std::move(dialog_model), parent_window);
}

} // namespace extensions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3499,7 +3499,7 @@ if (!is_android) {
if (enable_extensions) {
sources += [
"../browser/supervised_user/supervised_user_extension_browsertest.cc",
"../browser/ui/views/supervised_user/extension_install_blocked_by_parent_dialog_view_browsertest.cc",
"../browser/ui/views/supervised_user/extension_install_blocked_by_parent_dialog_browsertest.cc",
"../browser/ui/views/supervised_user/parent_permission_dialog_view_browsertest.cc",
]
}
Expand Down

0 comments on commit ea8d0b4

Please sign in to comment.