-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
privacy-hub: Setup browser and frontend communication
- Setup communication between the browser process and front end to display the list of applications in the Privacy controls sensor subpages - Display the list of applications in the microphone subpage with a dummy UI Bug: b:305006304 Change-Id: I28d63429364e6dde9e299224f14e4b758093d4bd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4935211 Reviewed-by: Wes Okuhara <wesokuhara@google.com> Reviewed-by: Tim Sergeant <tsergeant@chromium.org> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Commit-Queue: Md Shahadat Hossain Shahin <shahinmd@google.com> Cr-Commit-Position: refs/heads/main@{#1212177}
- Loading branch information
Md Shahadat Hossain Shahin
authored and
Chromium LUCI CQ
committed
Oct 19, 2023
1 parent
e699805
commit 5db996b
Showing
19 changed files
with
636 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
chrome/browser/ui/webui/ash/settings/pages/privacy/app_permission_handler.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/webui/ash/settings/pages/privacy/app_permission_handler.h" | ||
|
||
#include "base/ranges/algorithm.h" | ||
#include "chrome/browser/apps/app_service/app_service_proxy.h" | ||
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h" | ||
#include "components/services/app_service/public/cpp/permission.h" | ||
#include "components/services/app_service/public/cpp/types_util.h" | ||
|
||
namespace ash::settings { | ||
|
||
namespace { | ||
|
||
// Returns true if `permission` is one of {apps::PermissionType::kCamera, | ||
// apps::PermissionType::kLocation, apps::PermissionType::kMicrophone}. | ||
bool IsPermissionTypeRelevant(const apps::PermissionPtr& permission) { | ||
return (permission->permission_type == apps::PermissionType::kCamera || | ||
permission->permission_type == apps::PermissionType::kLocation || | ||
permission->permission_type == apps::PermissionType::kMicrophone); | ||
} | ||
|
||
bool HasRelevantPermission(const apps::AppUpdate& update) { | ||
return base::ranges::any_of(update.Permissions(), &IsPermissionTypeRelevant); | ||
} | ||
|
||
app_permission::mojom::AppPtr CreateAppPtr(const apps::AppUpdate& update) { | ||
auto app = app_permission::mojom::App::New(); | ||
app->id = update.AppId(); | ||
app->name = update.Name(); | ||
|
||
for (const auto& permission : update.Permissions()) { | ||
if (IsPermissionTypeRelevant(permission)) { | ||
app->permissions[permission->permission_type] = permission->Clone(); | ||
} | ||
} | ||
return app; | ||
} | ||
|
||
} // namespace | ||
|
||
using app_permission::mojom::AppPermissionsHandler; | ||
using app_permission::mojom::AppPermissionsObserver; | ||
|
||
AppPermissionHandler::AppPermissionHandler( | ||
apps::AppServiceProxy* app_service_proxy) | ||
: app_service_proxy_(app_service_proxy) { | ||
app_registry_cache_observer_.Observe(&app_service_proxy_->AppRegistryCache()); | ||
} | ||
|
||
AppPermissionHandler::~AppPermissionHandler() {} | ||
|
||
void AppPermissionHandler::AddObserver( | ||
mojo::PendingRemote<app_permission::mojom::AppPermissionsObserver> | ||
observer) { | ||
observer_list_.Add(std::move(observer)); | ||
} | ||
|
||
void AppPermissionHandler::BindInterface( | ||
mojo::PendingReceiver<app_permission::mojom::AppPermissionsHandler> | ||
receiver) { | ||
if (receiver_.is_bound()) { | ||
receiver_.reset(); | ||
} | ||
receiver_.Bind(std::move(receiver)); | ||
} | ||
|
||
void AppPermissionHandler::GetApps( | ||
base::OnceCallback<void(std::vector<app_permission::mojom::AppPtr>)> | ||
callback) { | ||
std::move(callback).Run(GetAppList()); | ||
} | ||
|
||
void AppPermissionHandler::OnAppUpdate(const apps::AppUpdate& update) { | ||
if (!HasRelevantPermission(update)) { | ||
// This app is irrelevant for the Privacy controls sensor subpages. | ||
return; | ||
} | ||
|
||
if (!apps_util::IsInstalled(update.Readiness()) || | ||
!update.ShowInManagement().value_or(true)) { | ||
for (const auto& observer : observer_list_) { | ||
observer->OnAppRemoved(update.AppId()); | ||
} | ||
} else { | ||
for (const auto& observer : observer_list_) { | ||
observer->OnAppUpdated(CreateAppPtr(update)); | ||
} | ||
} | ||
} | ||
|
||
std::vector<app_permission::mojom::AppPtr> AppPermissionHandler::GetAppList() { | ||
std::vector<app_permission::mojom::AppPtr> apps; | ||
app_service_proxy_->AppRegistryCache().ForEachApp( | ||
[&apps](const apps::AppUpdate& update) { | ||
if (update.ShowInManagement().value_or(false) && | ||
apps_util::IsInstalled(update.Readiness()) && | ||
HasRelevantPermission(update)) { | ||
apps.push_back(CreateAppPtr(update)); | ||
} | ||
}); | ||
return apps; | ||
} | ||
|
||
void AppPermissionHandler::OnAppRegistryCacheWillBeDestroyed( | ||
apps::AppRegistryCache* cache) { | ||
app_registry_cache_observer_.Reset(); | ||
} | ||
|
||
} // namespace ash::settings |
Oops, something went wrong.