0

PWA: migrate app_management to TypeScript

This migrates app_management components in cr_components to TypeScript
to prepare for usage in new chrome://app-settings page that will be
built using TypeScript. It also migrates mojo usage in this directory
to use modularized -webui.js files and updated needed mojo libraries to
build the modularized resources.

Change-Id: Ib55934e7b5e37a6bb0eaffceba4817753b4419a2
Bug: 1255194, 1179821
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3352843
Reviewed-by: Oksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: Tim Sergeant <tsergeant@chromium.org>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Phillis Tang <phillis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#956363}
This commit is contained in:
Phillis Tang
2022-01-07 03:20:03 +00:00
committed by Chromium LUCI CQ
parent 17ddae99e5
commit c171462ce7
42 changed files with 642 additions and 741 deletions

@ -46,6 +46,7 @@ if (optimize_webui) {
":preprocess_v3",
"../../../../../ui/webui/resources:preprocess",
"../../nearby_share/shared:preprocess_v3",
"//ui/webui/resources/cr_components/app_management:build_ts",
]
excludes = [
"chrome://resources/mojo/chromeos/services/cellular_setup/public/mojom/cellular_setup.mojom-lite.js",
@ -61,10 +62,8 @@ if (optimize_webui) {
"chrome://resources/cr_components/chromeos/cellular_setup/mojo_interface_provider.m.js",
"chrome://resources/cr_components/chromeos/network/mojo_interface_provider.m.js",
"chrome://resources/cr_components/app_management/app_management.mojom-lite.js",
"chrome://resources/cr_components/app_management/file_path.mojom-lite.js",
"chrome://resources/cr_components/app_management/image.mojom-lite.js",
"chrome://resources/cr_components/app_management/safe_base_name.mojom-lite.js",
"chrome://resources/cr_components/app_management/types.mojom-lite.js",
"chrome://resources/cr_components/app_management/app_management.mojom-webui.js",
"chrome://resources/cr_components/app_management/types.mojom-webui.js",
"chrome://resources/js/cr.m.js",
"chrome://resources/chromeos/colors/cros_styles.css",
"chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js",
@ -220,6 +219,7 @@ generate_grd("build_grd") {
":preprocess_mojo_v3",
":preprocess_v3",
"../../nearby_share/shared:build_v3_grdp",
"//ui/webui/resources/cr_components/app_management:build_ts",
]
grdp_files += [ "$root_gen_dir/chrome/browser/resources/nearby_share/shared/nearby_share_resources_v3.grdp" ]
manifest_files += [
@ -267,6 +267,7 @@ preprocess_if_expr("preprocess_v3") {
"chromeos/os_apps_page/app_management_page/store.js",
"chromeos/os_apps_page/app_management_page/store_client.js",
"chromeos/os_apps_page/app_management_page/util.js",
"chromeos/os_apps_page/app_management_page/types.js",
"chromeos/os_apps_page/app_notifications_page/mojo_interface_provider.js",
"chromeos/os_languages_page/input_method_settings.js",
"chromeos/os_languages_page/languages_browser_proxy.js",

@ -46,7 +46,6 @@ js_library("os_apps_page") {
"./app_management_page:store_client",
"./app_notifications_page:mojo_interface_provider",
"//chrome/browser/ui/webui/settings/chromeos/os_apps_page/mojom:mojom_js_library_for_compile",
"//ui/webui/resources/cr_components/app_management:constants",
"//ui/webui/resources/cr_components/chromeos/localized_link:localized_link",
"//ui/webui/resources/cr_components/chromeos/localized_link:localized_link",
"//ui/webui/resources/js:cr.m",

@ -38,6 +38,9 @@ js_type_check("closure_compile_module") {
]
}
js_library("types") {
}
js_library("actions") {
deps = [
"//ui/webui/resources/cr_components/app_management:mojo_bindings_js_library_for_compile",
@ -75,6 +78,7 @@ js_library("app_item") {
":util",
"//ui/webui/resources/js:load_time_data.m",
]
externs_list = [ "./types.js" ]
}
js_library("app_management_page") {
@ -97,8 +101,6 @@ js_library("arc_detail_view") {
":store_client",
":supported_links_item",
":util",
"//ui/webui/resources/cr_components/app_management:constants",
"//ui/webui/resources/cr_components/app_management:permission_item",
]
}
@ -133,6 +135,7 @@ js_library("fake_page_handler") {
"//ui/webui/resources/cr_components/app_management:mojo_bindings_js_library_for_compile",
"//ui/webui/resources/js:promise_resolver.m",
]
externs_list = [ "./types.js" ]
}
js_library("icons") {
@ -148,7 +151,6 @@ js_library("main_view") {
"../..:os_route.m",
"../..:route_observer_behavior",
"../../..:router",
"//ui/webui/resources/cr_components/app_management:constants",
"//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js:load_time_data.m",
]
@ -163,9 +165,7 @@ js_library("pin_to_shelf_item") {
":browser_proxy",
":util",
"../..:metrics_recorder.m",
"//ui/webui/resources/cr_components/app_management:constants",
"//ui/webui/resources/cr_components/app_management:toggle_row",
"//ui/webui/resources/cr_components/app_management:types",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/js:assert.m",
]
}
@ -178,15 +178,12 @@ js_library("pwa_detail_view") {
":store_client",
":supported_links_item",
":util",
"//ui/webui/resources/cr_components/app_management:constants",
"//ui/webui/resources/cr_components/app_management:permission_item",
]
}
js_library("reducers") {
deps = [
":util",
"//ui/webui/resources/cr_components/app_management:types",
"//ui/webui/resources/js:cr.m",
]
}
@ -195,15 +192,12 @@ js_library("resize_lock_item") {
deps = [
":browser_proxy",
":util",
"//ui/webui/resources/cr_components/app_management:constants",
"//ui/webui/resources/cr_components/app_management:toggle_row",
"//ui/webui/resources/cr_components/app_management:types",
"//ui/webui/resources/js:assert.m",
]
}
js_library("shared_style") {
deps = [ "//ui/webui/resources/cr_components/app_management:shared_style" ]
deps = []
}
js_library("store") {
@ -216,11 +210,12 @@ js_library("store") {
js_library("store_client") {
deps = [
":store",
"//ui/webui/resources/cr_components/app_management:types",
"//ui/webui/resources/cr_components/app_management:mojo_bindings_js_library_for_compile",
"//ui/webui/resources/js:cr.m",
"//ui/webui/resources/js/cr/ui:store",
"//ui/webui/resources/js/cr/ui:store_client",
]
externs_list = [ "./types.js" ]
}
js_library("supported_links_overlapping_apps_dialog") {
@ -249,7 +244,6 @@ js_library("supported_links_item") {
":supported_links_overlapping_apps_dialog",
":util",
"../..:metrics_recorder.m",
"//ui/webui/resources/cr_components/app_management:constants",
"//ui/webui/resources/cr_components/chromeos/localized_link:localized_link",
"//ui/webui/resources/cr_elements/cr_radio_button:cr_radio_button.m",
"//ui/webui/resources/cr_elements/cr_radio_group:cr_radio_group.m",

@ -54,8 +54,8 @@ Polymer({
},
/**
* @param {AppType} appType
* @return {AppManagementEntryPoint}
* @param {apps.mojom.AppType} appType
* @return {AppManagementEntryPointType}
*/
getAppManagementEntryPoint_(appType) {
switch (appType) {

@ -19,7 +19,6 @@ js_library("borealis_detail_view") {
"../:util",
"../../..:os_route.m",
"../../../..:router",
"//ui/webui/resources/cr_components/app_management:permission_item",
]
}

@ -70,7 +70,7 @@ export class FakePageHandler {
}
/**
* @param {AppType} appType
* @param {apps.mojom.AppType} appType
* @return {!Object<number, Permission>}
*/
static createPermissions(appType) {
@ -211,7 +211,7 @@ export class FakePageHandler {
/**
* @param {string} appId
* @param {OptionalBool} pinnedValue
* @param {apps.mojom.OptionalBool} pinnedValue
*/
setPinned(appId, pinnedValue) {
const app = AppManagementStore.getInstance().data.apps[appId];

@ -87,7 +87,10 @@ Polymer({
toggleSetting_() {
const newState = assert(toggleOptionalBool(this.app.isPinned));
const newStateBool = convertOptionalBoolToBool(newState);
assert(newStateBool === this.$['toggle-row'].isChecked());
assert(
newStateBool ===
(/** @type {AppManagementToggleRowElement} */ (this.$['toggle-row']))
.isChecked());
BrowserProxy.getInstance().handler.setPinned(
this.app.id,
newState,

@ -26,8 +26,7 @@ js_library("plugin_vm_detail_view") {
"../:util",
"../../..:os_route.m",
"../../../..:router",
"//ui/webui/resources/cr_components/app_management:constants",
"//ui/webui/resources/cr_components/app_management:permission_item",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js:load_time_data.m",
"//ui/webui/resources/js:web_ui_listener_behavior.m",

@ -75,7 +75,8 @@ Polymer({
* @private
*/
onPermissionChanged_: async function(e) {
this.pendingPermissionItem_ = /** @type {Element} */ (e.target);
this.pendingPermissionItem_ =
/** @type {AppManamentPermissionItemElement} */ (e.target);
switch (e.target.permissionType) {
case 'kCamera':
this.dialogText_ =

@ -0,0 +1,116 @@
// Copyright 2018 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.
/**
* @fileoverview Closure typedefs for App Management.
*/
/**
* @typedef {appManagement.mojom.App}
*/
let App;
/**
* @typedef {appManagement.mojom.ExtensionAppPermissionMessage}
*/
let ExtensionAppPermissionMessage;
/**
* @typedef {apps.mojom.Permission}
*/
let Permission;
/**
* Maps app ids to Apps.
* @typedef {!Object<string, App>}
*/
let AppMap;
/**
* @typedef {{
* apps: !AppMap,
* selectedAppId: ?string,
* }}
*/
let AppManagementPageState;
/**
* @typedef {apps.mojom.WindowMode}
*/
let WindowMode;
/**
* Must be kept in sync with
* ui/webui/resources/cr_components/app_management/constants.ts
* @enum {number}
*/
const AppManagementEntryPointType = {
AppListContextMenuAppInfoArc: 0,
AppListContextMenuAppInfoChromeApp: 1,
AppListContextMenuAppInfoWebApp: 2,
ShelfContextMenuAppInfoArc: 3,
ShelfContextMenuAppInfoChromeApp: 4,
ShelfContextMenuAppInfoWebApp: 5,
MainViewArc: 6,
MainViewChromeApp: 7,
MainViewWebApp: 8,
OsSettingsMainPage: 9,
MainViewPluginVm: 10,
DBusServicePluginVm: 11,
MainViewBorealis: 12,
};
/**
* Must be kept in sync with
* ui/webui/resources/cr_components/app_management/constants.ts
* @enum {number}
*/
const AppManagementUserAction = {
ViewOpened: 0,
NativeSettingsOpened: 1,
UninstallDialogLaunched: 2,
PinToShelfTurnedOn: 3,
PinToShelfTurnedOff: 4,
NotificationsTurnedOn: 5,
NotificationsTurnedOff: 6,
LocationTurnedOn: 7,
LocationTurnedOff: 8,
CameraTurnedOn: 9,
CameraTurnedOff: 10,
MicrophoneTurnedOn: 11,
MicrophoneTurnedOff: 12,
ContactsTurnedOn: 13,
ContactsTurnedOff: 14,
StorageTurnedOn: 15,
StorageTurnedOff: 16,
PrintingTurnedOn: 17,
PrintingTurnedOff: 18,
ResizeLockTurnedOn: 19,
ResizeLockTurnedOff: 20,
PreferredAppTurnedOn: 21,
PreferredAppTurnedOff: 22,
SupportedLinksListShown: 23,
OverlappingAppsDialogShown: 24,
};
/**
* @constructor
* @extends {HTMLElement}
*/
function AppManamentPermissionItemElement() {}
/** @type {boolean} */
AppManamentPermissionItemElement.prototype.permissionType;
AppManamentPermissionItemElement.prototype.syncPermission = function() {};
AppManamentPermissionItemElement.prototype.resetToggle = function() {};
/**
* @constructor
* @extends {HTMLElement}
*/
function AppManagementToggleRowElement() {}
/** @return {boolean} */
AppManagementToggleRowElement.prototype.isChecked = function() {};

@ -42,8 +42,6 @@ js_library("app_notification_row") {
deps = [
"../..:metrics_recorder.m",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/cr_components/app_management:permission_constants",
"//ui/webui/resources/cr_components/app_management:permission_util",
]
externs_list = [ "$externs_path/metrics_private.js" ]
}

@ -56,7 +56,9 @@ suite('<app-management-managed-apps>', () => {
function checkToggle(permissionType, policyAffected) {
const permissionToggle =
getPermissionToggleByType(appDetailView, permissionType);
expectTrue(permissionToggle.$$('cr-toggle').disabled === policyAffected);
expectTrue(
permissionToggle.shadowRoot.querySelector('cr-toggle').disabled ===
policyAffected);
expectTrue(
!!permissionToggle.root.querySelector('#policyIndicator') ===
policyAffected);
@ -71,6 +73,7 @@ suite('<app-management-managed-apps>', () => {
const pinToShelfSetting = appDetailView.$$('#pin-to-shelf-setting')
.$$('app-management-toggle-row');
expectTrue(!!pinToShelfSetting.root.querySelector('#policyIndicator'));
expectTrue(pinToShelfSetting.$$('cr-toggle').disabled);
expectTrue(
pinToShelfSetting.shadowRoot.querySelector('cr-toggle').disabled);
});
});

@ -95,7 +95,7 @@ async function navigateTo(route) {
*/
/* #export */ function getPermissionToggleByType(view, permissionType) {
return getPermissionItemByType(view, permissionType)
.$$('app-management-toggle-row');
.shadowRoot.querySelector('app-management-toggle-row');
}
/**
@ -104,7 +104,8 @@ async function navigateTo(route) {
* @return {Element}
*/
/* #export */ function getPermissionCrToggleByType(view, permissionType) {
return getPermissionToggleByType(view, permissionType).$$('cr-toggle');
return getPermissionToggleByType(view, permissionType)
.shadowRoot.querySelector('cr-toggle');
}
/**

@ -31,13 +31,13 @@ suite('<app-management-toggle-row', () => {
test('Toggle disabled by policy', async () => {
toggleRow.setToggle(false);
assertFalse(toggleRow.isChecked());
assertFalse(!!toggleRow.$$('cr-toggle').disabled);
assertFalse(!!toggleRow.$$('cr-policy-indicator'));
assertFalse(!!toggleRow.shadowRoot.querySelector('cr-toggle').disabled);
assertFalse(!!toggleRow.shadowRoot.querySelector('cr-policy-indicator'));
toggleRow.managed = true;
await test_util.flushTasks();
assertTrue(!!toggleRow.$$('cr-toggle').disabled);
assertTrue(!!toggleRow.$$('cr-policy-indicator'));
assertTrue(!!toggleRow.shadowRoot.querySelector('cr-toggle').disabled);
assertTrue(!!toggleRow.shadowRoot.querySelector('cr-policy-indicator'));
toggleRow.click();
await test_util.flushTasks();

@ -6,13 +6,13 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("types") {
sources = [ "types.mojom" ]
webui_module_path = "/"
public_deps = [
"//mojo/public/mojom/base",
"//skia/public/mojom",
"//ui/gfx/geometry/mojom",
"//ui/gfx/image/mojom",
"//ui/gfx/image/mojom",
"//ui/gfx/mojom",
"//ui/gfx/range/mojom",
"//url/mojom:url_mojom_gurl",
@ -21,6 +21,7 @@ mojom("types") {
mojom("mojom") {
sources = [ "app_service.mojom" ]
webui_module_path = "/"
public_deps = [ ":types" ]
}

@ -97,6 +97,7 @@ grit("content_resources") {
"//gpu/ipc/common:vulkan_interface_webui_js",
"//ui/base/mojom:mojom_js",
"//ui/gfx/geometry/mojom:mojom_js",
"//ui/gfx/image/mojom:mojom_js",
"//ui/gfx/range/mojom:mojom_js",
"//url/mojom:url_mojom_origin_js",
"//url/mojom:url_mojom_origin_webui_js",

@ -38,6 +38,7 @@ namespace {
const std::set<int> GetContentResourceIds() {
return std::set<int>{
IDR_GEOMETRY_MOJOM_WEBUI_JS,
IDR_IMAGE_MOJOM_WEBUI_JS,
IDR_ORIGIN_MOJO_HTML,
IDR_ORIGIN_MOJO_JS,
IDR_ORIGIN_MOJO_WEBUI_JS,

@ -25,6 +25,7 @@ Other resources that belong in this file:
<include name="IDR_DEVTOOLS_TOUCH_CURSOR_ICON" file="browser/resources/devtools/devtools_touch_cursor.png" type="BINDATA" />
<include name="IDR_DEVTOOLS_TOUCH_CURSOR_ICON_2X" file="browser/resources/devtools/devtools_touch_cursor_2x.png" type="BINDATA" />
<include name="IDR_GEOMETRY_MOJOM_WEBUI_JS" file="${root_gen_dir}/mojom-webui/ui/gfx/geometry/mojom/geometry.mojom-webui.js" resource_path="mojo/ui/gfx/geometry/mojom/geometry.mojom-webui.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_IMAGE_MOJOM_WEBUI_JS" file="${root_gen_dir}/mojom-webui/ui/gfx/image/mojom/image.mojom-webui.js" resource_path="mojo/ui/gfx/image/mojom/image.mojom-webui.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_HISTOGRAMS_INTERNALS_HTML" file="browser/resources/histograms/histograms_internals.html" type="BINDATA" />
<include name="IDR_HISTOGRAMS_INTERNALS_JS" file="browser/resources/histograms/histograms_internals.js" type="BINDATA" />
<include name="IDR_HISTOGRAMS_INTERNALS_CSS" file="browser/resources/histograms/histograms_internals.css" type="BINDATA" />

@ -65,6 +65,11 @@
use_base_dir="false"
resource_path="mojo/mojo/public/mojom/base/read_only_buffer.mojom-webui.js"
type="BINDATA" />
<include name="IDR_MOJO_SAFE_BASE_NAME_MOJOM_WEBUI_JS"
file="${root_gen_dir}/mojom-webui/mojo/public/mojom/base/safe_base_name.mojom-webui.js"
use_base_dir="false"
resource_path="mojo/mojo/public/mojom/base/safe_base_name.mojom-webui.js"
type="BINDATA" />
<include name="IDR_MOJO_STRING16_MOJOM_HTML"
file="${root_gen_dir}/mojo/public/mojom/base/string16.mojom.html"
use_base_dir="false"

@ -17,11 +17,21 @@
resource_path="mojo/skia/public/mojom/bitmap.mojom-lite.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SKIA_BITMAP_MOJOM_WEBUI_JS"
file="${root_gen_dir}/mojom-webui/skia/public/mojom/bitmap.mojom-webui.js"
resource_path="mojo/skia/public/mojom/bitmap.mojom-webui.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SKIA_IMAGE_INFO_MOJOM_LITE_JS"
file="${root_gen_dir}/skia/public/mojom/image_info.mojom-lite.js"
resource_path="mojo/skia/public/mojom/image_info.mojom-lite.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SKIA_IMAGE_INFO_MOJOM_WEBUI_JS"
file="${root_gen_dir}/mojom-webui/skia/public/mojom/image_info.mojom-webui.js"
resource_path="mojo/skia/public/mojom/image_info.mojom-webui.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SKIA_SKCOLOR_MOJOM_LITE_JS"
file="${root_gen_dir}/skia/public/mojom/skcolor.mojom-lite.js"
resource_path="mojo/skia/public/mojom/skcolor.mojom-lite.js"

@ -7,6 +7,8 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojom") {
sources = [ "image.mojom" ]
webui_module_path = "chrome://resources/mojo/ui/gfx/image/mojom"
public_deps = [ "//skia/public/mojom" ]
cpp_typemaps = [

@ -38,6 +38,7 @@ mojom("mojom") {
"//skia/public/mojom",
"//ui/gfx/geometry/mojom",
]
webui_module_path = "chrome://resources/mojo/ui/gfx/mojom"
enabled_features = []
if (ozone_platform_x11) {
@ -335,6 +336,7 @@ mojom("native_handle_types") {
}
public_deps = [ "//mojo/public/mojom/base" ]
generate_java = true
webui_module_path = "chrome://resources/mojo/ui/gfx/mojom"
shared_cpp_typemap = {
types = [

@ -49,6 +49,7 @@ generate_grd("build_grd") {
if (include_polymer) {
deps += [
"cr_components:build_grdp",
"cr_components/app_management:build_grdp",
"cr_components/customize_themes:build_grdp",
"cr_components/most_visited:build_grdp",
"cr_elements:build_grdp",
@ -60,6 +61,7 @@ generate_grd("build_grd") {
"$root_gen_dir/ui/webui/resources/cr_components/cr_components_resources.grdp",
"$root_gen_dir/ui/webui/resources/cr_components/customize_themes/resources.grdp",
"$root_gen_dir/ui/webui/resources/cr_components/most_visited/resources.grdp",
"$root_gen_dir/ui/webui/resources/cr_components/app_management/resources.grdp",
"$root_gen_dir/ui/webui/resources/cr_elements/cr_elements_resources.grdp",
"$root_gen_dir/ui/webui/resources/js/browser_command/resources.grdp",
]

@ -12,7 +12,6 @@ preprocess_folder =
"$root_gen_dir/ui/webui/resources/preprocessed/cr_components"
preprocess_gen_manifest = "preprocessed_gen_manifest.json"
preprocess_mojom_manifest = "preprocessed_mojom_manifest.json"
preprocess_external_mojo_manifest = "preprocessed_external_mojo_manifest.json"
if (is_chromeos_ash) {
preprocess_polymer2_manifest = "preprocessed_polymer2_manifest.json"
}
@ -21,10 +20,7 @@ preprocess_src_manifest = "preprocessed_src_manifest.json"
generate_grd("build_grdp") {
grd_prefix = "cr_components"
out_grd = "$target_gen_dir/${grd_prefix}_resources.grdp"
deps = [
":preprocess",
":preprocess_external_mojo",
]
deps = [ ":preprocess" ]
if (is_chromeos_ash) {
input_files_base_dir = rebase_path(".", "//")
input_files = [
@ -68,7 +64,6 @@ generate_grd("build_grdp") {
"$target_gen_dir/$preprocess_gen_manifest",
"$target_gen_dir/$preprocess_mojom_manifest",
"$target_gen_dir/$preprocess_src_manifest",
"$target_gen_dir/$preprocess_external_mojo_manifest",
]
# TODO(crbug.com/1184053): Fully remove once no longer used by CrOS.
@ -77,13 +72,6 @@ generate_grd("build_grdp") {
}
resource_path_prefix = "cr_components"
resource_path_rewrites = [
"mojo/public/mojom/base/file_path.mojom-lite.js|app_management/file_path.mojom-lite.js",
"mojo/public/mojom/base/safe_base_name.mojom-lite.js|app_management/safe_base_name.mojom-lite.js",
"ui/gfx/image/mojom/image.mojom-lite.js|app_management/image.mojom-lite.js",
"components/services/app_service/public/mojom/types.mojom-lite.js|app_management/types.mojom-lite.js",
]
}
group("preprocess") {
@ -113,12 +101,6 @@ preprocess_if_expr("preprocess_src") {
"chromeos/smb_shares/smb_browser_proxy.js",
"color_change_listener/browser_proxy.js",
"color_change_listener/colors_css_updater.js",
"app_management/permission_constants.js",
"app_management/permission_util.js",
"app_management/browser_proxy.js",
"app_management/constants.js",
"app_management/types.js",
"app_management/util.js",
]
}
@ -131,10 +113,7 @@ preprocess_if_expr("preprocess_mojom") {
}
preprocess_if_expr("preprocess_generated") {
deps = [
":polymer3_elements",
"//ui/webui/resources/cr_components/app_management:mojo_bindings_js__generator",
]
deps = [ ":polymer3_elements" ]
in_folder = target_gen_dir
out_folder = preprocess_folder
out_manifest = "$target_gen_dir/$preprocess_gen_manifest"
@ -142,11 +121,6 @@ preprocess_if_expr("preprocess_generated") {
"managed_dialog/managed_dialog.js",
"managed_footnote/managed_footnote.js",
"omnibox/cr_autocomplete_match_list.js",
"app_management/permission_item.js",
"app_management/shared_style.js",
"app_management/shared_vars.js",
"app_management/toggle_row.js",
"app_management/app_management.mojom-lite.js",
]
if (is_chromeos_ash) {
@ -418,7 +392,6 @@ if (is_chromeos_ash) {
group("closure_compile") {
deps = [
"app_management:closure_compile",
"color_change_listener:closure_compile",
"managed_dialog:closure_compile",
"managed_footnote:closure_compile",
@ -432,7 +405,6 @@ group("closure_compile") {
group("polymer3_elements") {
public_deps = [
"app_management:web_components",
"customize_themes:web_components",
"iph_bubble:web_components",
"managed_dialog:web_components",
@ -445,25 +417,3 @@ group("polymer3_elements") {
public_deps += [ "chromeos:polymer3_elements" ]
}
}
preprocess_if_expr("preprocess_external_mojo") {
deps = [
"//components/services/app_service/public/mojom:mojom_js",
"//mojo/public/js:bindings_lite",
"//mojo/public/mojom/base",
"//ui/gfx/image/mojom:mojom_js",
]
in_folder = "$root_gen_dir"
# It does not matter which preprocess folder these files are pasted into, as
# they are not used for bundling; the purpose of this build rule is to
# include them in the generated grd file.
out_folder = "$preprocess_folder"
out_manifest = "$target_gen_dir/$preprocess_external_mojo_manifest"
in_files = [
"mojo/public/mojom/base/file_path.mojom-lite.js",
"mojo/public/mojom/base/safe_base_name.mojom-lite.js",
"ui/gfx/image/mojom/image.mojom-lite.js",
"components/services/app_service/public/mojom/types.mojom-lite.js",
]
}

@ -3,95 +3,98 @@
# found in the LICENSE file.
import("//mojo/public/tools/bindings/mojom.gni")
import("//third_party/closure_compiler/compile_js.gni")
import("//tools/grit/preprocess_if_expr.gni")
import("//tools/polymer/html_to_js.gni")
import("//tools/typescript/ts_library.gni")
import("//ui/webui/resources/tools/generate_grd.gni")
js_type_check("closure_compile") {
is_polymer3 = true
deps = [
":browser_proxy",
":constants",
":permission_constants",
":permission_item",
":permission_util",
":shared_style",
":shared_vars",
":toggle_row",
":types",
":util",
]
}
preprocess_folder_tmp = "$root_gen_dir/ui/webui/resources/preprocessed/cr_components/app_management_tmp"
preprocess_folder =
"$root_gen_dir/ui/webui/resources/preprocessed/cr_components/app_management"
js_library("permission_item") {
deps = [
":browser_proxy",
":permission_constants",
":toggle_row",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
]
}
web_component_files = [
"permission_item.ts",
"shared_style.ts",
"shared_vars.ts",
"toggle_row.ts",
]
js_library("shared_style") {
deps = []
}
js_library("shared_vars") {
deps = []
}
js_library("permission_constants") {
deps = [ ":mojo_bindings_js_library_for_compile" ]
}
js_library("permission_util") {
deps = [
":permission_constants",
"//ui/webui/resources/js:assert.m",
]
}
js_library("browser_proxy") {
deps = [
":mojo_bindings_js_library_for_compile",
"//ui/webui/resources/js:cr.m",
]
}
js_library("toggle_row") {
deps = [
":types",
"//ui/webui/resources/cr_elements/cr_toggle:cr_toggle.m",
"//ui/webui/resources/cr_elements/policy:cr_policy_indicator.m",
]
}
js_library("constants") {
deps = [ ":mojo_bindings_js_library_for_compile" ]
}
js_library("types") {
deps = []
}
js_library("util") {
deps = [ ":permission_constants" ]
externs_list = [ "//third_party/closure_compiler/externs/metrics_private.js" ]
}
non_web_component_files = [
"constants.ts",
"permission_constants.ts",
"permission_util.ts",
"browser_proxy.ts",
"util.ts",
]
html_to_js("web_components") {
js_files = [
"permission_item.js",
"shared_style.js",
"shared_vars.js",
"toggle_row.js",
]
js_files = web_component_files
}
mojom("mojo_bindings") {
sources = [ "app_management.mojom" ]
webui_module_path = "/"
public_deps = [
"//components/services/app_service/public/mojom",
"//mojo/public/mojom/base",
]
}
preprocess_if_expr("preprocess_src") {
visibility = [ ":build_ts" ]
in_folder = "."
out_folder = preprocess_folder_tmp
in_files = non_web_component_files
}
preprocess_if_expr("preprocess_generated") {
visibility = [ ":build_ts" ]
deps = [ ":web_components" ]
in_folder = target_gen_dir
out_folder = preprocess_folder_tmp
in_files = web_component_files
}
copy("copy_mojo") {
deps = [
":mojo_bindings_webui_js",
"//components/services/app_service/public/mojom:types_js__generator",
]
sources = [
"$root_gen_dir/mojom-webui/components/services/app_service/public/mojom/types.mojom-webui.js",
"$root_gen_dir/mojom-webui/ui/webui/resources/cr_components/app_management/app_management.mojom-webui.js",
]
outputs = [ "$preprocess_folder_tmp/{{source_file_part}}" ]
}
ts_library("build_ts") {
root_dir = preprocess_folder_tmp
out_dir = preprocess_folder
composite = true
tsconfig_base = "tsconfig_base.json"
in_files = web_component_files + non_web_component_files + [
"app_management.mojom-webui.js",
"types.mojom-webui.js",
]
definitions = [ "//tools/typescript/definitions/metrics_private.d.ts" ]
deps = [
"//third_party/polymer/v3_0:library",
"//ui/webui/resources:library",
]
extra_deps = [
":copy_mojo",
":preprocess_generated",
":preprocess_src",
]
}
generate_grd("build_grdp") {
grd_prefix = "cr_components_app_management"
out_grd = "$target_gen_dir/resources.grdp"
deps = [ ":build_ts" ]
manifest_files = [ "$target_gen_dir/tsconfig.manifest" ]
resource_path_prefix = "cr_components/app_management"
}

@ -1,30 +0,0 @@
// Copyright 2018 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.
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import 'chrome://resources/mojo/skia/public/mojom/image_info.mojom-lite.js';
import 'chrome://resources/mojo/skia/public/mojom/bitmap.mojom-lite.js';
import 'chrome://resources/mojo/url/mojom/url.mojom-lite.js';
import './file_path.mojom-lite.js';
import './image.mojom-lite.js';
import './types.mojom-lite.js';
import './app_management.mojom-lite.js';
import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';
export class BrowserProxy {
constructor() {
/** @type {appManagement.mojom.PageCallbackRouter} */
this.callbackRouter = new appManagement.mojom.PageCallbackRouter();
/** @type {appManagement.mojom.PageHandlerRemote} */
this.handler = new appManagement.mojom.PageHandlerRemote();
const factory = appManagement.mojom.PageHandlerFactory.getRemote();
factory.createPageHandler(
this.callbackRouter.$.bindNewPipeAndPassRemote(),
this.handler.$.bindNewPipeAndPassReceiver());
}
}
addSingletonGetter(BrowserProxy);

@ -0,0 +1,31 @@
// Copyright 2018 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.
import {PageCallbackRouter, PageHandlerFactory, PageHandlerInterface, PageHandlerRemote} from './app_management.mojom-webui.js';
export class BrowserProxy {
callbackRouter: PageCallbackRouter;
handler: PageHandlerInterface;
constructor() {
this.callbackRouter = new PageCallbackRouter();
this.handler = new PageHandlerRemote();
const factory = PageHandlerFactory.getRemote();
factory.createPageHandler(
this.callbackRouter.$.bindNewPipeAndPassRemote(),
(this.handler as PageHandlerRemote).$.bindNewPipeAndPassReceiver());
}
static getInstance(): BrowserProxy {
return instance || (instance = new BrowserProxy());
}
static setInstance(obj: BrowserProxy) {
instance = obj;
}
}
let instance: BrowserProxy|null = null;

@ -1,97 +0,0 @@
// Copyright 2018 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.
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import 'chrome://resources/mojo/skia/public/mojom/image_info.mojom-lite.js';
import 'chrome://resources/mojo/skia/public/mojom/bitmap.mojom-lite.js';
import 'chrome://resources/mojo/url/mojom/url.mojom-lite.js';
import './file_path.mojom-lite.js';
import './image.mojom-lite.js';
import './safe_base_name.mojom-lite.js';
import './types.mojom-lite.js';
import './app_management.mojom-lite.js';
/**
* The number of apps displayed in app list in the main view before expanding.
* @const {number}
*/
export const NUMBER_OF_APPS_DISPLAYED_DEFAULT = 4;
/**
* Enumeration of the different subpage types within the app management page.
* @enum {number}
* @const
*/
export const PageType = {
MAIN: 0,
DETAIL: 1,
};
export const AppType = apps.mojom.AppType;
export const OptionalBool = apps.mojom.OptionalBool;
export const InstallReason = apps.mojom.InstallReason;
export const WindowMode = apps.mojom.WindowMode;
// This histogram is also declared and used at chrome/browser/ui/webui/settings/
// chromeos/app_management/app_management_uma.h.
export const AppManagementEntryPointsHistogramName =
'AppManagement.EntryPoints';
/**
* These values are persisted to logs and should not be renumbered or re-used.
* See tools/metrics/histograms/enums.xml.
* @enum {number}
*/
export const AppManagementEntryPoint = {
AppListContextMenuAppInfoArc: 0,
AppListContextMenuAppInfoChromeApp: 1,
AppListContextMenuAppInfoWebApp: 2,
ShelfContextMenuAppInfoArc: 3,
ShelfContextMenuAppInfoChromeApp: 4,
ShelfContextMenuAppInfoWebApp: 5,
MainViewArc: 6,
MainViewChromeApp: 7,
MainViewWebApp: 8,
OsSettingsMainPage: 9,
MainViewPluginVm: 10,
DBusServicePluginVm: 11,
MainViewBorealis: 12,
};
/**
* These values are persisted to logs and should not be renumbered or re-used.
* See tools/metrics/histograms/enums.xml.
* @enum {number}
*/
export const AppManagementUserAction = {
ViewOpened: 0,
NativeSettingsOpened: 1,
UninstallDialogLaunched: 2,
PinToShelfTurnedOn: 3,
PinToShelfTurnedOff: 4,
NotificationsTurnedOn: 5,
NotificationsTurnedOff: 6,
LocationTurnedOn: 7,
LocationTurnedOff: 8,
CameraTurnedOn: 9,
CameraTurnedOff: 10,
MicrophoneTurnedOn: 11,
MicrophoneTurnedOff: 12,
ContactsTurnedOn: 13,
ContactsTurnedOff: 14,
StorageTurnedOn: 15,
StorageTurnedOff: 16,
PrintingTurnedOn: 17,
PrintingTurnedOff: 18,
ResizeLockTurnedOn: 19,
ResizeLockTurnedOff: 20,
PreferredAppTurnedOn: 21,
PreferredAppTurnedOff: 22,
SupportedLinksListShown: 23,
OverlappingAppsDialogShown: 24,
};

@ -0,0 +1,73 @@
// Copyright 2018 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.
export {AppType, InstallReason, OptionalBool, WindowMode} from './types.mojom-webui.js';
/**
* The number of apps displayed in app list in the main view before expanding.
*/
export const NUMBER_OF_APPS_DISPLAYED_DEFAULT = 4;
// Enumeration of the different subpage types within the app management page.
export enum PageType {
MAIN = 0,
DETAIL = 1,
}
// This histogram is also declared and used at chrome/browser/ui/webui/settings/
// chromeos/app_management/app_management_uma.h.
export const AppManagementEntryPointsHistogramName =
'AppManagement.EntryPoints';
/**
* These values are persisted to logs and should not be renumbered or re-used.
* See tools/metrics/histograms/enums.xml.
*/
export enum AppManagementEntryPoint {
AppListContextMenuAppInfoArc = 0,
AppListContextMenuAppInfoChromeApp = 1,
AppListContextMenuAppInfoWebApp = 2,
ShelfContextMenuAppInfoArc = 3,
ShelfContextMenuAppInfoChromeApp = 4,
ShelfContextMenuAppInfoWebApp = 5,
MainViewArc = 6,
MainViewChromeApp = 7,
MainViewWebApp = 8,
OsSettingsMainPage = 9,
MainViewPluginVm = 10,
DBusServicePluginVm = 11,
MainViewBorealis = 12,
}
/**
* These values are persisted to logs and should not be renumbered or re-used.
* See tools/metrics/histograms/enums.xml.
*/
export enum AppManagementUserAction {
ViewOpened = 0,
NativeSettingsOpened = 1,
UninstallDialogLaunched = 2,
PinToShelfTurnedOn = 3,
PinToShelfTurnedOff = 4,
NotificationsTurnedOn = 5,
NotificationsTurnedOff = 6,
LocationTurnedOn = 7,
LocationTurnedOff = 8,
CameraTurnedOn = 9,
CameraTurnedOff = 10,
MicrophoneTurnedOn = 11,
MicrophoneTurnedOff = 12,
ContactsTurnedOn = 13,
ContactsTurnedOff = 14,
StorageTurnedOn = 15,
StorageTurnedOff = 16,
PrintingTurnedOn = 17,
PrintingTurnedOff = 18,
ResizeLockTurnedOn = 19,
ResizeLockTurnedOff = 20,
PreferredAppTurnedOn = 21,
PreferredAppTurnedOff = 22,
SupportedLinksListShown = 23,
OverlappingAppsDialogShown = 24,
}

@ -1,17 +0,0 @@
// Copyright 2021 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.
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import './file_path.mojom-lite.js';
import './image.mojom-lite.js';
import './safe_base_name.mojom-lite.js';
import './types.mojom-lite.js';
export const TriState = apps.mojom.TriState;
export const PermissionType = apps.mojom.PermissionType;
export const PermissionValue = apps.mojom.PermissionValue;

@ -0,0 +1,9 @@
// Copyright 2021 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.
import {PermissionType} from './types.mojom-webui.js';
export {PermissionType, PermissionValue, TriState} from './types.mojom-webui.js';
export type PermissionTypeIndex = keyof typeof PermissionType;

@ -5,85 +5,83 @@ import './shared_style.js';
import './toggle_row.js';
import {assert, assertNotReached} from '//resources/js/assert.m.js';
import {afterNextRender, flush, html, Polymer, TemplateInstanceBase, Templatizer} from '//resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {App} from './app_management.mojom-webui.js';
import {BrowserProxy} from './browser_proxy.js';
import {AppManagementUserAction} from './constants.js';
import {PermissionType, PermissionValue, TriState} from './permission_constants.js';
import {PermissionType, PermissionTypeIndex, TriState} from './permission_constants.js';
import {createBoolPermission, createTriStatePermission, getBoolPermissionValue, getTriStatePermissionValue, isBoolValue, isTriStateValue} from './permission_util.js';
import {getPermission, getPermissionValueBool, getSelectedApp, recordAppManagementUserAction} from './util.js';
import {AppManagementToggleRowElement} from './toggle_row.js';
import {Permission} from './types.mojom-webui.js';
import {getPermission, getPermissionValueBool, recordAppManagementUserAction} from './util.js';
Polymer({
_template: html`{__html_template__}`,
is: 'app-management-permission-item',
export class AppManamentPermissionItemElement extends PolymerElement {
static get is() {
return 'app-management-permission-item';
}
static get template() {
return html`{__html_template__}`;
}
static get properties() {
return {
/**
* The name of the permission, to be displayed to the user.
*/
permissionLabel: String,
/**
* A string version of the permission type. Must be a value of the
* permission type enum in apps.mojom.PermissionType.
*/
permissionType: String,
icon: String,
/**
* If set to true, toggling the permission item will not set the
* permission in the backend. Call `syncPermission()` to set the
* permission to reflect the current UI state.
*/
syncPermissionManually: Boolean,
app_: Object,
/**
* True if the permission type is available for the app.
*/
available_: {
type: Boolean,
computed: 'isAvailable_(app_, permissionType)',
reflectToAttribute: true,
},
disabled_: {
type: Boolean,
computed: 'isManaged_(app_, permissionType)',
reflectToAttribute: true,
},
};
}
private permissionLabel: string;
private permissionType: PermissionTypeIndex;
private icon: string;
private syncPermissionManually: boolean;
private app_: App;
private available_: boolean;
private disabled_: boolean;
properties: {
/**
* The name of the permission, to be displayed to the user.
* @type {string}
*/
permissionLabel: String,
ready() {
super.ready();
this.addEventListener('click', this.onClick_);
this.addEventListener('change', this.togglePermission_);
}
/**
* A string version of the permission type. Must be a value of the
* permission type enum in apps.mojom.PermissionType.
* @type {string}
*/
permissionType: String,
/**
* @type {string}
*/
icon: String,
/**
* If set to true, toggling the permission item will not set the permission
* in the backend. Call `syncPermission()` to set the permission to reflect
* the current UI state.
*
* @type {boolean}
*/
syncPermissionManually: Boolean,
/**
* @type {App}
*/
app_: Object,
/**
* True if the permission type is available for the app.
* @type {boolean}
* @private
*/
available_: {
type: Boolean,
computed: 'isAvailable_(app_, permissionType)',
reflectToAttribute: true,
},
/**
* @type {boolean}
* @private
*/
disabled_: {
type: Boolean,
computed: 'isManaged_(app_, permissionType)',
reflectToAttribute: true,
},
},
listeners: {click: 'onClick_', change: 'togglePermission_'},
/**
* Returns true if the permission type is available for the app.
*
* @param {App} app
* @param {string} permissionType
* @private
*/
isAvailable_(app, permissionType) {
private isAvailable_(app: App, permissionType: PermissionTypeIndex): boolean {
if (app === undefined || permissionType === undefined) {
return false;
}
@ -91,14 +89,9 @@ Polymer({
assert(app);
return getPermission(app, permissionType) !== undefined;
},
}
/**
* @param {App} app
* @param {string} permissionType
* @return {boolean}
*/
isManaged_(app, permissionType) {
private isManaged_(app: App, permissionType: PermissionTypeIndex): boolean {
if (app === undefined || permissionType === undefined ||
!this.isAvailable_(app, permissionType)) {
return false;
@ -109,42 +102,34 @@ Polymer({
assert(permission);
return permission.isManaged;
},
}
/**
* @param {App} app
* @param {string} permissionType
* @return {boolean}
*/
getValue_(app, permissionType) {
private getValue_(app: App, permissionType: PermissionTypeIndex): boolean {
if (app === undefined || permissionType === undefined) {
return false;
}
assert(app);
return getPermissionValueBool(app, permissionType);
},
}
resetToggle() {
const currentValue = this.getValue_(this.app_, this.permissionType);
this.$$('#toggle-row').setToggle(currentValue);
},
this.shadowRoot!
.querySelector<AppManagementToggleRowElement>('#toggle-row')!.setToggle(
currentValue);
}
/**
* @private
*/
onClick_() {
this.$$('#toggle-row').click();
},
private onClick_() {
this.shadowRoot!
.querySelector<AppManagementToggleRowElement>('#toggle-row')!.click();
}
/**
* @private
*/
togglePermission_() {
private togglePermission_() {
if (!this.syncPermissionManually) {
this.syncPermission();
}
},
}
/**
* Set the permission to match the current UI state. This only needs to be
@ -153,8 +138,7 @@ Polymer({
syncPermission() {
assert(this.app_);
/** @type {!Permission} */
let newPermission;
let newPermission: Permission|undefined = undefined;
let newBoolState = false; // to keep the closure compiler happy.
const permissionValue = getPermission(this.app_, this.permissionType).value;
@ -173,23 +157,19 @@ Polymer({
}
BrowserProxy.getInstance().handler.setPermission(
this.app_.id, newPermission);
this.app_.id, newPermission!);
recordAppManagementUserAction(
this.app_.type,
this.getUserMetricActionForPermission_(
newBoolState, this.permissionType));
},
}
/**
* Gets the permission boolean based on the toggle's UI state.
*
* @param {App} app
* @param {string} permissionType
* @return {!Permission}
* @private
*/
getUIPermissionBoolean_(app, permissionType) {
private getUIPermissionBoolean_(
app: App, permissionType: PermissionTypeIndex): Permission {
const currentPermission = getPermission(app, permissionType);
assert(isBoolValue(currentPermission.value));
@ -199,17 +179,13 @@ Polymer({
return createBoolPermission(
PermissionType[permissionType], newPermissionValue,
currentPermission.isManaged);
},
}
/**
* Gets the permission tristate based on the toggle's UI state.
*
* @param {App} app
* @param {string} permissionType
* @return {!Permission}
* @private
*/
getUIPermissionTriState_(app, permissionType) {
private getUIPermissionTriState_(
app: App, permissionType: PermissionTypeIndex): Permission {
let newPermissionValue;
const currentPermission = getPermission(app, permissionType);
@ -231,21 +207,18 @@ Polymer({
break;
default:
assertNotReached();
newPermissionValue = TriState.kBlock;
}
assert(newPermissionValue !== undefined);
return createTriStatePermission(
PermissionType[permissionType], newPermissionValue,
currentPermission.isManaged);
},
}
/**
* @param {boolean} permissionValue
* @param {string} permissionType
* @return {AppManagementUserAction}
* @private
*/
getUserMetricActionForPermission_(permissionValue, permissionType) {
private getUserMetricActionForPermission_(
permissionValue: boolean,
permissionType: PermissionTypeIndex): AppManagementUserAction {
switch (permissionType) {
case 'kNotifications':
return permissionValue ? AppManagementUserAction.NotificationsTurnedOn :
@ -277,6 +250,10 @@ Polymer({
default:
assertNotReached();
return AppManagementUserAction.NotificationsTurnedOn;
}
},
});
}
}
customElements.define(
AppManamentPermissionItemElement.is, AppManamentPermissionItemElement);

@ -1,109 +0,0 @@
// Copyright 2021 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.
import {assert, assertNotReached} from 'chrome://resources/js/assert.m.js';
import {PermissionType, PermissionValue, TriState} from './permission_constants.js';
/**
* @param {PermissionType} permissionType
* @param {PermissionValue} value
* @param {boolean} isManaged
* @return {!apps.mojom.Permission}
*/
export function createPermission(permissionType, value, isManaged) {
return {
permissionType,
value,
isManaged,
};
}
/**
* @param {TriState} value
* @returns {PermissionValue}
*/
export function createTriStatePermissionValue(value) {
return {tristateValue: value};
}
/**
* @param {PermissionValue} permissionValue
* @returns {TriState}
*/
export function getTriStatePermissionValue(permissionValue) {
assert(isTriStateValue(permissionValue));
return permissionValue['tristateValue'];
}
/**
* @param {boolean} value
* @returns {PermissionValue}
*/
export function createBoolPermissionValue(value) {
return {boolValue: value};
}
/**
* @param {PermissionValue} permissionValue
* @returns {boolean}
*/
export function getBoolPermissionValue(permissionValue) {
assert(isBoolValue(permissionValue));
return permissionValue['boolValue'];
}
/**
* @param {PermissionValue} permissionValue
* @returns {boolean}
*/
export function isTriStateValue(permissionValue) {
return permissionValue['tristateValue'] !== undefined &&
permissionValue['boolValue'] === undefined;
}
/**
* @param {PermissionValue} permissionValue
* @returns {boolean}
*/
export function isBoolValue(permissionValue) {
return permissionValue['boolValue'] !== undefined &&
permissionValue['tristateValue'] === undefined;
}
/**
* @param {PermissionType} permissionType
* @param {boolean} value
* @param {boolean} isManaged
* @return {!apps.mojom.Permission}
*/
export function createBoolPermission(permissionType, value, isManaged) {
return createPermission(
permissionType, createBoolPermissionValue(value), isManaged);
}
/**
* @param {PermissionType} permissionType
* @param {TriState} value
* @param {boolean} isManaged
* @return {!apps.mojom.Permission}
*/
export function createTriStatePermission(permissionType, value, isManaged) {
return createPermission(
permissionType, createTriStatePermissionValue(value), isManaged);
}
/**
* @param {PermissionValue} permissionValue
* @returns {boolean}
*/
export function isPermissionEnabled(permissionValue) {
if (isBoolValue(permissionValue)) {
return getBoolPermissionValue(permissionValue);
} else if (isTriStateValue(permissionValue)) {
return getTriStatePermissionValue(permissionValue) === TriState.kAllow;
} else {
assertNotReached();
}
}

@ -0,0 +1,74 @@
// Copyright 2021 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.
import {assert, assertNotReached} from 'chrome://resources/js/assert.m.js';
import {PermissionType, PermissionValue, TriState} from './permission_constants.js';
import {Permission} from './types.mojom-webui.js';
export function createPermission(
permissionType: PermissionType, value: PermissionValue,
isManaged: boolean): Permission {
return {
permissionType,
value,
isManaged,
};
}
export function createTriStatePermissionValue(value: TriState):
PermissionValue {
return {tristateValue: value} as PermissionValue;
}
export function getTriStatePermissionValue(permissionValue: PermissionValue):
TriState {
assert(isTriStateValue(permissionValue));
return permissionValue.tristateValue!;
}
export function createBoolPermissionValue(value: boolean): PermissionValue {
return {boolValue: value} as PermissionValue;
}
export function getBoolPermissionValue(permissionValue: PermissionValue):
boolean {
assert(isBoolValue(permissionValue));
return permissionValue.boolValue!;
}
export function isTriStateValue(permissionValue: PermissionValue): boolean {
return permissionValue['tristateValue'] !== undefined &&
permissionValue['boolValue'] === undefined;
}
export function isBoolValue(permissionValue: PermissionValue): boolean {
return permissionValue['boolValue'] !== undefined &&
permissionValue['tristateValue'] === undefined;
}
export function createBoolPermission(
permissionType: PermissionType, value: boolean,
isManaged: boolean): Permission {
return createPermission(
permissionType, createBoolPermissionValue(value), isManaged);
}
export function createTriStatePermission(
permissionType: PermissionType, value: TriState,
isManaged: boolean): Permission {
return createPermission(
permissionType, createTriStatePermissionValue(value), isManaged);
}
export function isPermissionEnabled(permissionValue: PermissionValue): boolean {
if (isBoolValue(permissionValue)) {
return getBoolPermissionValue(permissionValue)!;
} else if (isTriStateValue(permissionValue)) {
return getTriStatePermissionValue(permissionValue) === TriState.kAllow;
} else {
assertNotReached();
return false;
}
}

@ -1,63 +0,0 @@
// Copyright 2019 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.
import './shared_style.js';
import '//resources/cr_elements/cr_toggle/cr_toggle.m.js';
import '//resources/cr_elements/policy/cr_policy_indicator.m.js';
import {afterNextRender, flush, html, Polymer, TemplateInstanceBase, Templatizer} from '//resources/polymer/v3_0/polymer/polymer_bundled.min.js';
Polymer({
_template: html`{__html_template__}`,
is: 'app-management-toggle-row',
properties: {
/**
* @type {string}
*/
icon: String,
/**
* @type {string}
*/
label: String,
/**
* @type {boolean}
*/
managed: {type: Boolean, value: false, reflectToAttribute: true},
/**
* @type {boolean}
*/
value: {type: Boolean, value: false, reflectToAttribute: true},
/**
* @type {string}
*/
description: String,
},
listeners: {
click: 'onClick_',
},
/**
* @returns {boolean} true if the toggle is checked.
*/
isChecked() {
return this.$.toggle.checked;
},
/**
* @param {boolean} value What to set the toggle to.
*/
setToggle(value) {
this.$.toggle.checked = value;
},
/**
* @param {MouseEvent} event
* @private
*/
onClick_(event) {
event.stopPropagation();
this.$['toggle'].click();
},
});

@ -0,0 +1,54 @@
// Copyright 2019 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.
import './shared_style.js';
import '//resources/cr_elements/cr_toggle/cr_toggle.m.js';
import '//resources/cr_elements/policy/cr_policy_indicator.m.js';
import {CrToggleElement} from '//resources/cr_elements/cr_toggle/cr_toggle.m.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
export interface AppManagementToggleRowElement {
$: {toggle: CrToggleElement}
}
export class AppManagementToggleRowElement extends PolymerElement {
static get is() {
return 'app-management-toggle-row';
}
static get template() {
return html`{__html_template__}`;
}
static get properties() {
return {
icon: String,
label: String,
managed: {type: Boolean, value: false, reflectToAttribute: true},
value: {type: Boolean, value: false, reflectToAttribute: true},
description: String,
};
}
ready() {
super.ready();
this.addEventListener('click', this.onClick_);
}
isChecked(): boolean {
return this.$.toggle.checked;
}
setToggle(value: boolean) {
this.$.toggle.checked = value;
}
private onClick_(event: Event) {
event.stopPropagation();
this.$.toggle.click();
}
}
customElements.define(
AppManagementToggleRowElement.is, AppManagementToggleRowElement);

@ -0,0 +1,9 @@
{
"extends": "../../../../../tools/typescript/tsconfig_base.json",
"compilerOptions": {
"allowJs": true,
"noUncheckedIndexedAccess": false,
"noUnusedLocals": false,
"strictPropertyInitialization": false
}
}

@ -1,41 +0,0 @@
// Copyright 2018 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.
/**
* @fileoverview Closure typedefs for App Management.
*/
/**
* @typedef {appManagement.mojom.App}
*/
let App;
/**
* @typedef {appManagement.mojom.ExtensionAppPermissionMessage}
*/
let ExtensionAppPermissionMessage;
/**
* @typedef {apps.mojom.Permission}
*/
let Permission;
/**
* Maps app ids to Apps.
* @typedef {!Object<string, App>}
*/
let AppMap;
/**
* @typedef {{
* apps: !AppMap,
* selectedAppId: ?string,
* }}
*/
let AppManagementPageState;
/**
* @typedef {apps.mojom.WindowMode}
*/
let WindowMode;

@ -2,33 +2,30 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {assert} from 'chrome://resources/js/assert.m.js';
import {assertNotReached} from 'chrome://resources/js/assert.m.js';
import {assert, assertNotReached} from 'chrome://resources/js/assert.m.js';
import {App} from './app_management.mojom-webui.js';
import {AppManagementUserAction, AppType, OptionalBool} from './constants.js';
import {PermissionType} from './permission_constants.js';
import {PermissionType, PermissionTypeIndex} from './permission_constants.js';
import {isPermissionEnabled} from './permission_util.js';
/**
* @fileoverview Utility functions for the App Management page.
*/
/**
* @return {!AppManagementPageState}
*/
export function createEmptyState() {
type AppManagementPageState = {
apps: Record<string, App>,
selectedAppId: string|null,
};
export function createEmptyState(): AppManagementPageState {
return {
apps: {},
selectedAppId: null,
};
}
/**
* @param {!Array<App>} apps
* @return {!AppManagementPageState}
*/
export function createInitialState(apps) {
export function createInitialState(apps: Array<App>): AppManagementPageState {
const initialState = createEmptyState();
for (const app of apps) {
@ -38,52 +35,12 @@ export function createInitialState(apps) {
return initialState;
}
/**
* @param {App} app
* @return {string}
*/
export function getAppIcon(app) {
export function getAppIcon(app: App): string {
return `chrome://app-icon/${app.id}/64`;
}
/**
* If the given value is not in the set, returns a new set with the value
* added, otherwise returns the old set.
* @template T
* @param {!Set<T>} set
* @param {T} value
* @return {!Set<T>}
*/
export function addIfNeeded(set, value) {
if (!set.has(value)) {
set = new Set(set);
set.add(value);
}
return set;
}
/**
* If the given value is in the set, returns a new set without the value,
* otherwise returns the old set.
* @template T
* @param {!Set<T>} set
* @param {T} value
* @return {!Set<T>}
*/
export function removeIfNeeded(set, value) {
if (set.has(value)) {
set = new Set(set);
set.delete(value);
}
return set;
}
/**
* @param {App} app
* @param {string} permissionType
* @return {boolean}
*/
export function getPermissionValueBool(app, permissionType) {
export function getPermissionValueBool(
app: App, permissionType: PermissionTypeIndex): boolean {
const permission = getPermission(app, permissionType);
assert(permission);
@ -92,41 +49,27 @@ export function getPermissionValueBool(app, permissionType) {
/**
* Undefined is returned when the app does not request a permission.
*
* @param {App} app
* @param {string} permissionType
* @return {Permission|undefined}
*/
export function getPermission(app, permissionType) {
export function getPermission(app: App, permissionType: PermissionTypeIndex) {
return app.permissions[PermissionType[permissionType]];
}
/**
* @param {AppManagementPageState} state
* @return {?App}
*/
export function getSelectedApp(state) {
export function getSelectedApp(state: AppManagementPageState): App|null {
const selectedAppId = state.selectedAppId;
return selectedAppId ? state.apps[selectedAppId] : null;
}
/**
* A comparator function to sort strings alphabetically.
*
* @param {string} a
* @param {string} b
*/
export function alphabeticalSort(a, b) {
export function alphabeticalSort(a: string, b: string) {
return a.localeCompare(b);
}
/**
* Toggles an OptionalBool
*
* @param {OptionalBool} bool
* @return {OptionalBool}
*/
export function toggleOptionalBool(bool) {
export function toggleOptionalBool(bool: OptionalBool): OptionalBool {
switch (bool) {
case OptionalBool.kFalse:
return OptionalBool.kTrue;
@ -134,14 +77,11 @@ export function toggleOptionalBool(bool) {
return OptionalBool.kFalse;
default:
assertNotReached();
return OptionalBool.kFalse;
}
}
/**
* @param {OptionalBool} optionalBool
* @returns {boolean}
*/
export function convertOptionalBoolToBool(optionalBool) {
export function convertOptionalBoolToBool(optionalBool: OptionalBool): boolean {
switch (optionalBool) {
case OptionalBool.kTrue:
return true;
@ -149,15 +89,12 @@ export function convertOptionalBoolToBool(optionalBool) {
return false;
default:
assertNotReached();
return false;
}
}
/**
* @param {AppType} appType
* @return {string}
* @private
*/
export function getUserActionHistogramNameForAppType_(appType) {
export function getUserActionHistogramNameForAppType_(appType: AppType):
string {
switch (appType) {
case AppType.kArc:
return 'AppManagement.AppDetailViews.ArcApp';
@ -175,14 +112,12 @@ export function getUserActionHistogramNameForAppType_(appType) {
return 'AppManagement.AppDetailViews.BorealisApp';
default:
assertNotReached();
return '';
}
}
/**
* @param {AppType} appType
* @param {AppManagementUserAction} userAction
*/
export function recordAppManagementUserAction(appType, userAction) {
export function recordAppManagementUserAction(
appType: AppType, userAction: AppManagementUserAction) {
const histogram = getUserActionHistogramNameForAppType_(appType);
const enumLength = Object.keys(AppManagementUserAction).length;
chrome.metricsPrivate.recordEnumerationValue(

@ -21,7 +21,10 @@ ts_library("library") {
"mojo/public/mojom/base/time.mojom-webui.js",
"mojo/public/mojom/base/token.mojom-webui.js",
"skia/public/mojom/skcolor.mojom-webui.js",
"skia/public/mojom/bitmap.mojom-webui.js",
"skia/public/mojom/image_info.mojom-webui.js",
"ui/base/mojom/window_open_disposition.mojom-webui.js",
"ui/gfx/image/mojom/image.mojom-webui.js",
"url/mojom/url.mojom-webui.js",
]
@ -32,6 +35,7 @@ ts_library("library") {
"//mojo/public/mojom/base:base_js__generator",
"//skia/public/mojom:mojom_js__generator",
"//ui/base/mojom:mojom_js__generator",
"//ui/gfx/image/mojom:mojom_js__generator",
"//url/mojom:url_mojom_gurl_js__generator",
]