blob: a9fb0452fac0f8e76a15cea74b086f791e27f36c [file] [log] [blame]
[email protected]8e837ec2013-01-31 01:48:331// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/app_mode/app_mode_utils.h"
6
avie4d7b6f2015-12-26 00:59:187#include <stddef.h>
8
[email protected]8e837ec2013-01-31 01:48:339#include "base/command_line.h"
[email protected]565f32fc02013-03-05 18:51:4810#include "base/logging.h"
Toni Barzicfc4a81a2018-01-31 01:48:5911#include "base/optional.h"
Avi Drissmand251e912018-12-26 15:46:3712#include "base/stl_util.h"
[email protected]565f32fc02013-03-05 18:51:4813#include "chrome/app/chrome_command_ids.h"
[email protected]8e837ec2013-01-31 01:48:3314#include "chrome/common/chrome_switches.h"
15
16namespace chrome {
17
Toni Barzicfc4a81a2018-01-31 01:48:5918namespace {
19
20// If the device is running in forced app mode, returns the ID of the app for
21// which the device is forced in app mode. Otherwise, returns nullopt.
22base::Optional<std::string> GetForcedAppModeApp() {
23 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
24 if (!command_line->HasSwitch(switches::kForceAppMode) ||
25 !command_line->HasSwitch(switches::kAppId)) {
26 return base::nullopt;
27 }
28
29 return command_line->GetSwitchValueASCII(switches::kAppId);
30}
31
32} // namespace
33
[email protected]565f32fc02013-03-05 18:51:4834bool IsCommandAllowedInAppMode(int command_id) {
35 DCHECK(IsRunningInForcedAppMode());
36
37 const int kAllowed[] = {
toyoshim7dad4b1182016-04-01 14:28:0538 IDC_BACK,
39 IDC_FORWARD,
40 IDC_RELOAD,
Jeff Fisher6cc1ce7b2019-06-28 23:02:3841 IDC_CLOSE_FIND_OR_STOP,
toyoshim7dad4b1182016-04-01 14:28:0542 IDC_STOP,
43 IDC_RELOAD_BYPASSING_CACHE,
44 IDC_RELOAD_CLEARING_CACHE,
45 IDC_CUT,
46 IDC_COPY,
47 IDC_PASTE,
48 IDC_ZOOM_PLUS,
49 IDC_ZOOM_NORMAL,
50 IDC_ZOOM_MINUS,
[email protected]565f32fc02013-03-05 18:51:4851 };
52
Avi Drissmand251e912018-12-26 15:46:3753 for (size_t i = 0; i < base::size(kAllowed); ++i) {
[email protected]565f32fc02013-03-05 18:51:4854 if (kAllowed[i] == command_id)
55 return true;
56 }
57
58 return false;
59}
60
[email protected]8e837ec2013-01-31 01:48:3361bool IsRunningInAppMode() {
avi3ef9ec9e2014-12-22 22:50:1762 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
[email protected]8e837ec2013-01-31 01:48:3363 return command_line->HasSwitch(switches::kKioskMode) ||
poromov008f8d02016-11-17 16:34:1964 IsRunningInForcedAppMode();
[email protected]565f32fc02013-03-05 18:51:4865}
66
67bool IsRunningInForcedAppMode() {
Anatoliy Potapchukce6f8802020-01-30 09:30:3468 return base::CommandLine::ForCurrentProcess()->HasSwitch(
69 switches::kForceAppMode);
Toni Barzicfc4a81a2018-01-31 01:48:5970}
71
72bool IsRunningInForcedAppModeForApp(const std::string& app_id) {
73 DCHECK(!app_id.empty());
74
75 base::Optional<std::string> forced_app_mode_app = GetForcedAppModeApp();
76 if (!forced_app_mode_app.has_value())
77 return false;
78
79 return app_id == forced_app_mode_app.value();
[email protected]8e837ec2013-01-31 01:48:3380}
81
[email protected]15c7e8af2013-07-10 02:10:3282} // namespace chrome