Commit c618d824 authored by lgcheng's avatar lgcheng Committed by Commit Bot

ArcUsbPermissionDialog

Hookup permission dialog view. Add browser_test.

Bug: 776476
Change-Id: I30405949ba50591030a4645f0d7feb1f4fefc03d
Reviewed-on: https://chromium-review.googlesource.com/907691Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Commit-Queue: Long Cheng <lgcheng@google.com>
Cr-Commit-Position: refs/heads/master@{#541260}
parent 641afb48
...@@ -4661,6 +4661,15 @@ ...@@ -4661,6 +4661,15 @@
<message name="IDS_ARC_MIGRATE_ENCRYPTION_SUCCESS_MESSAGE" desc="Message of the toast shown on the first sign-in after the successfully completed migration needed for using Android apps."> <message name="IDS_ARC_MIGRATE_ENCRYPTION_SUCCESS_MESSAGE" desc="Message of the toast shown on the first sign-in after the successfully completed migration needed for using Android apps.">
You can now use Android apps. You can now use Android apps.
</message> </message>
<message name="IDS_ARC_USB_PERMISSION_TITLE" desc="Titlebar of Android app USB permissions prompt window">
Confirm USB Permission
</message>
<message name="IDS_ARC_USB_SCAN_DEVICE_LIST_PERMISSION_HEADING" desc="Heading text in the content area of the Android app scan device list permission prompt. Tells the user the app will be able to scan attached USB device list if confirmed.">
Allow "<ph name="APP_NAME">$1<ex>Gmail Checker</ex></ph>" to get the list of your attached USB devices?
</message>
<message name="IDS_ARC_USB_ACCESS_PERMISSION_HEADING" desc="Heading text in the content area of the Android app USB device access permission prompt. Tells the user the app will be able to access the usb device if confirmed.">
Allow "<ph name="APP_NAME">$1<ex>Gmail Checker</ex></ph>" to access:
</message>
<message name="IDS_VOICE_INTERACTION_VALUE_PROP_LOADING" desc="Loading message of the voice interaction value prop dialog."> <message name="IDS_VOICE_INTERACTION_VALUE_PROP_LOADING" desc="Loading message of the voice interaction value prop dialog.">
Loading Google Assistant... Loading Google Assistant...
</message> </message>
......
...@@ -14,6 +14,8 @@ class Profile; ...@@ -14,6 +14,8 @@ class Profile;
namespace arc { namespace arc {
using ArcUsbConfirmCallback = base::OnceCallback<void(bool)>;
// Shows a dialog for user to confirm uninstallation of ARC app. // Shows a dialog for user to confirm uninstallation of ARC app.
// Currently, ARC app can only be manually uninstalled from AppList. But it // Currently, ARC app can only be manually uninstalled from AppList. But it
// would be simple to enable the dialog to shown from other source. // would be simple to enable the dialog to shown from other source.
...@@ -21,6 +23,17 @@ void ShowArcAppUninstallDialog(Profile* profile, ...@@ -21,6 +23,17 @@ void ShowArcAppUninstallDialog(Profile* profile,
AppListControllerDelegate* controller, AppListControllerDelegate* controller,
const std::string& app_id); const std::string& app_id);
// Shows permission request dialog for scan USB device list.
void ShowUsbScanDeviceListPermissionDialog(Profile* profile,
const std::string& app_id,
ArcUsbConfirmCallback callback);
// Shows permission request dialog for targeting device name.
void ShowUsbAccessPermissionDialog(Profile* profile,
const std::string& app_id,
const base::string16& device_name,
ArcUsbConfirmCallback callback);
// Test purpose methods. // Test purpose methods.
bool IsArcAppDialogViewAliveForTest(); bool IsArcAppDialogViewAliveForTest();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <utility> #include <utility>
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/arc/arc_app_dialog.h"
#include "chrome/browser/ui/app_list/arc/arc_usb_host_permission_manager_factory.h" #include "chrome/browser/ui/app_list/arc/arc_usb_host_permission_manager_factory.h"
#include "components/arc/usb/usb_host_bridge.h" #include "components/arc/usb/usb_host_bridge.h"
#include "extensions/browser/api/device_permissions_manager.h" #include "extensions/browser/api/device_permissions_manager.h"
...@@ -254,7 +255,7 @@ void ArcUsbHostPermissionManager::MaybeProcessNextPermissionRequest() { ...@@ -254,7 +255,7 @@ void ArcUsbHostPermissionManager::MaybeProcessNextPermissionRequest() {
if (HasUsbScanDeviceListPermission(current_requesting_package_)) { if (HasUsbScanDeviceListPermission(current_requesting_package_)) {
OnUsbPermissionReceived(std::move(current_request), true); OnUsbPermissionReceived(std::move(current_request), true);
} else { } else {
ShowScanDeviceListPermissionDialog( ShowUsbScanDeviceListPermissionDialog(
profile_, app_id, profile_, app_id,
base::BindOnce(&ArcUsbHostPermissionManager::OnUsbPermissionReceived, base::BindOnce(&ArcUsbHostPermissionManager::OnUsbPermissionReceived,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
...@@ -265,7 +266,7 @@ void ArcUsbHostPermissionManager::MaybeProcessNextPermissionRequest() { ...@@ -265,7 +266,7 @@ void ArcUsbHostPermissionManager::MaybeProcessNextPermissionRequest() {
*current_request.usb_device_entry())) { *current_request.usb_device_entry())) {
OnUsbPermissionReceived(std::move(current_request), true); OnUsbPermissionReceived(std::move(current_request), true);
} else { } else {
ShowAccessPermissionDialog( ShowUsbAccessPermissionDialog(
profile_, app_id, current_request.usb_device_entry()->device_name, profile_, app_id, current_request.usb_device_entry()->device_name,
base::BindOnce(&ArcUsbHostPermissionManager::OnUsbPermissionReceived, base::BindOnce(&ArcUsbHostPermissionManager::OnUsbPermissionReceived,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
......
...@@ -24,8 +24,6 @@ namespace arc { ...@@ -24,8 +24,6 @@ namespace arc {
class ArcUsbHostBridge; class ArcUsbHostBridge;
using ArcUsbConfirmCallback = base::OnceCallback<void(bool)>;
class ArcUsbHostPermissionManager : public ArcAppListPrefs::Observer, class ArcUsbHostPermissionManager : public ArcAppListPrefs::Observer,
public ArcUsbHostUiDelegate, public ArcUsbHostUiDelegate,
public KeyedService { public KeyedService {
...@@ -102,18 +100,6 @@ class ArcUsbHostPermissionManager : public ArcAppListPrefs::Observer, ...@@ -102,18 +100,6 @@ class ArcUsbHostPermissionManager : public ArcAppListPrefs::Observer,
static ArcUsbHostPermissionManager* GetForBrowserContext( static ArcUsbHostPermissionManager* GetForBrowserContext(
content::BrowserContext* context); content::BrowserContext* context);
// Shows permission request dialog for scan USB device list.
static void ShowScanDeviceListPermissionDialog(
Profile* profile,
const std::string& app_id,
ArcUsbConfirmCallback callback);
// Shows permission request dialog for targeting device name.
static void ShowAccessPermissionDialog(Profile* profile,
const std::string& app_id,
const base::string16& device_name,
ArcUsbConfirmCallback callback);
// ArcUsbHostUiDelegate: // ArcUsbHostUiDelegate:
void RequestUsbScanDeviceListPermission( void RequestUsbScanDeviceListPermission(
const std::string& package_name, const std::string& package_name,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h"
#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
#include "chrome/browser/ui/app_list/arc/arc_app_utils.h" #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
#include "chrome/browser/ui/app_list/arc/arc_usb_host_permission_manager.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -38,8 +39,7 @@ const int kIconSize = 64; ...@@ -38,8 +39,7 @@ const int kIconSize = 64;
// Currenty ARC apps only support 48*48 native icon. // Currenty ARC apps only support 48*48 native icon.
const int kIconSourceSize = 48; const int kIconSourceSize = 48;
using ArcAppConfirmCallback = using ArcAppConfirmCallback = base::OnceCallback<void(bool accept)>;
base::Callback<void(const std::string& app_id, Profile* profile)>;
class ArcAppDialogView : public views::DialogDelegateView, class ArcAppDialogView : public views::DialogDelegateView,
public AppIconLoaderDelegate { public AppIconLoaderDelegate {
...@@ -67,6 +67,7 @@ class ArcAppDialogView : public views::DialogDelegateView, ...@@ -67,6 +67,7 @@ class ArcAppDialogView : public views::DialogDelegateView,
// views::DialogDelegate: // views::DialogDelegate:
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
bool Accept() override; bool Accept() override;
bool Cancel() override;
// AppIconLoaderDelegate: // AppIconLoaderDelegate:
void OnAppImageUpdated(const std::string& app_id, void OnAppImageUpdated(const std::string& app_id,
...@@ -96,7 +97,7 @@ class ArcAppDialogView : public views::DialogDelegateView, ...@@ -96,7 +97,7 @@ class ArcAppDialogView : public views::DialogDelegateView,
DISALLOW_COPY_AND_ASSIGN(ArcAppDialogView); DISALLOW_COPY_AND_ASSIGN(ArcAppDialogView);
}; };
// Browertest use only. Global pointer of ArcAppDialogView which is shown. // Browsertest use only. Global pointer of currently shown ArcAppDialogView.
ArcAppDialogView* g_current_arc_app_dialog_view = nullptr; ArcAppDialogView* g_current_arc_app_dialog_view = nullptr;
ArcAppDialogView::ArcAppDialogView(Profile* profile, ArcAppDialogView::ArcAppDialogView(Profile* profile,
...@@ -114,9 +115,7 @@ ArcAppDialogView::ArcAppDialogView(Profile* profile, ...@@ -114,9 +115,7 @@ ArcAppDialogView::ArcAppDialogView(Profile* profile,
window_title_(window_title), window_title_(window_title),
confirm_button_text_(confirm_button_text), confirm_button_text_(confirm_button_text),
cancel_button_text_(cancel_button_text), cancel_button_text_(cancel_button_text),
confirm_callback_(confirm_callback) { confirm_callback_(std::move(confirm_callback)) {
DCHECK(controller);
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>( SetLayoutManager(std::make_unique<views::BoxLayout>(
...@@ -150,7 +149,8 @@ ArcAppDialogView::ArcAppDialogView(Profile* profile, ...@@ -150,7 +149,8 @@ ArcAppDialogView::ArcAppDialogView(Profile* profile,
} }
ArcAppDialogView::~ArcAppDialogView() { ArcAppDialogView::~ArcAppDialogView() {
g_current_arc_app_dialog_view = nullptr; if (g_current_arc_app_dialog_view == this)
g_current_arc_app_dialog_view = nullptr;
} }
void ArcAppDialogView::AddMultiLineLabel(views::View* parent, void ArcAppDialogView::AddMultiLineLabel(views::View* parent,
...@@ -192,7 +192,14 @@ base::string16 ArcAppDialogView::GetDialogButtonLabel( ...@@ -192,7 +192,14 @@ base::string16 ArcAppDialogView::GetDialogButtonLabel(
} }
bool ArcAppDialogView::Accept() { bool ArcAppDialogView::Accept() {
confirm_callback_.Run(app_id_, profile_); if (confirm_callback_)
std::move(confirm_callback_).Run(true);
return true;
}
bool ArcAppDialogView::Cancel() {
if (confirm_callback_)
std::move(confirm_callback_).Run(false);
return true; return true;
} }
...@@ -213,7 +220,9 @@ void ArcAppDialogView::Show() { ...@@ -213,7 +220,9 @@ void ArcAppDialogView::Show() {
initial_setup_ = false; initial_setup_ = false;
// The parent window was killed before the icon was loaded. // The parent window was killed before the icon was loaded.
if (!AppListService::Get()->IsAppListVisible()) { // TODO(lgcheng@) : Remove this since the dialog is not parented to applist
// anymore.
if (controller_ && !AppListService::Get()->IsAppListVisible()) {
g_current_arc_app_dialog_view = nullptr; g_current_arc_app_dialog_view = nullptr;
Cancel(); Cancel();
DialogDelegateView::DeleteDelegate(); DialogDelegateView::DeleteDelegate();
...@@ -227,16 +236,26 @@ void ArcAppDialogView::Show() { ...@@ -227,16 +236,26 @@ void ArcAppDialogView::Show() {
constrained_window::CreateBrowserModalDialogViews(this, nullptr)->Show(); constrained_window::CreateBrowserModalDialogViews(this, nullptr)->Show();
} }
void HandleArcAppUninstall(base::OnceClosure closure, bool accept) {
if (accept)
std::move(closure).Run();
}
std::unique_ptr<ArcAppListPrefs::AppInfo> GetArcAppInfo(
Profile* profile,
const std::string& app_id) {
ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile);
DCHECK(arc_prefs);
return arc_prefs->GetApp(app_id);
}
} // namespace } // namespace
void ShowArcAppUninstallDialog(Profile* profile, void ShowArcAppUninstallDialog(Profile* profile,
AppListControllerDelegate* controller, AppListControllerDelegate* controller,
const std::string& app_id) { const std::string& app_id) {
ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile);
DCHECK(arc_prefs);
std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
arc_prefs->GetApp(app_id); GetArcAppInfo(profile, app_id);
if (!app_info) if (!app_info)
return; return;
...@@ -260,11 +279,67 @@ void ShowArcAppUninstallDialog(Profile* profile, ...@@ -260,11 +279,67 @@ void ShowArcAppUninstallDialog(Profile* profile,
is_shortcut ? IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON is_shortcut ? IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON
: IDS_EXTENSION_PROMPT_UNINSTALL_APP_BUTTON); : IDS_EXTENSION_PROMPT_UNINSTALL_APP_BUTTON);
base::string16 cancel_button_text = l10n_util::GetStringUTF16(IDS_CANCEL);
new ArcAppDialogView(
profile, controller, app_id, window_title, heading_text, subheading_text,
confirm_button_text, cancel_button_text,
base::BindOnce(HandleArcAppUninstall,
base::BindOnce(UninstallArcApp, app_id, profile)));
}
void ShowUsbScanDeviceListPermissionDialog(Profile* profile,
const std::string& app_id,
ArcUsbConfirmCallback callback) {
std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
GetArcAppInfo(profile, app_id);
if (!app_info) {
std::move(callback).Run(false);
return;
}
base::string16 window_title =
l10n_util::GetStringUTF16(IDS_ARC_USB_PERMISSION_TITLE);
base::string16 heading_text = l10n_util::GetStringFUTF16(
IDS_ARC_USB_SCAN_DEVICE_LIST_PERMISSION_HEADING,
base::UTF8ToUTF16(app_info->name));
base::string16 confirm_button_text = l10n_util::GetStringUTF16(IDS_OK);
base::string16 cancel_button_text = l10n_util::GetStringUTF16(IDS_CANCEL);
new ArcAppDialogView(profile, nullptr /*controller*/, app_id, window_title,
heading_text, base::string16() /*subheading_text*/,
confirm_button_text, cancel_button_text,
std::move(callback));
}
void ShowUsbAccessPermissionDialog(Profile* profile,
const std::string& app_id,
const base::string16& device_name,
ArcUsbConfirmCallback callback) {
std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
GetArcAppInfo(profile, app_id);
if (!app_info) {
std::move(callback).Run(false);
return;
}
base::string16 window_title =
l10n_util::GetStringUTF16(IDS_ARC_USB_PERMISSION_TITLE);
base::string16 heading_text = l10n_util::GetStringFUTF16(
IDS_ARC_USB_ACCESS_PERMISSION_HEADING, base::UTF8ToUTF16(app_info->name));
base::string16 subheading_text = device_name;
base::string16 confirm_button_text = l10n_util::GetStringUTF16(IDS_OK);
base::string16 cancel_button_text = l10n_util::GetStringUTF16(IDS_CANCEL); base::string16 cancel_button_text = l10n_util::GetStringUTF16(IDS_CANCEL);
new ArcAppDialogView(profile, controller, app_id, window_title, heading_text, new ArcAppDialogView(profile, nullptr /*controller*/, app_id, window_title,
subheading_text, confirm_button_text, cancel_button_text, heading_text, subheading_text, confirm_button_text,
base::Bind(UninstallArcApp)); cancel_button_text, std::move(callback));
} }
bool IsArcAppDialogViewAliveForTest() { bool IsArcAppDialogViewAliveForTest() {
......
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