1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
ash / components / arc / intent_helper / arc_intent_helper_mojo_delegate.h [blame]
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_COMPONENTS_ARC_INTENT_HELPER_ARC_INTENT_HELPER_MOJO_DELEGATE_H_
#define ASH_COMPONENTS_ARC_INTENT_HELPER_ARC_INTENT_HELPER_MOJO_DELEGATE_H_
#include <optional>
#include <string>
#include <vector>
#include "ash/components/arc/intent_helper/activity_icon_loader.h"
#include "base/containers/flat_map.h"
#include "base/functional/callback.h"
#include "ui/base/resource/resource_scale_factor.h"
#include "ui/gfx/image/image_skia.h"
namespace arc {
// This class provides API to use mojo connection, which connects to ARC.
class ArcIntentHelperMojoDelegate {
public:
virtual ~ArcIntentHelperMojoDelegate() = default;
// To make ActivityName type consistent between ArcIconCacheDelegate, use
// internal::ActivityIconLoader::ActivityName.
using ActivityName = internal::ActivityIconLoader::ActivityName;
// Following structs basically refer to //ash/components/arc/mojom.
// Convert arc::mojom into general structs.
//
// Some unnecessary parameters are dropped here.
//
// TODO(crbug.com/381270283): it might make sense to remove this intermediate
// struct to avoid unnecessary copies, but it's in the scope of the bigger
// refactory.
// Describes an intent.
// See //ash/components/arc/mojom/intent_helper.mojom for more details.
struct IntentInfo {
IntentInfo(std::string action,
std::optional<std::vector<std::string>> categories,
std::optional<std::string> data,
std::optional<std::string> type,
bool ui_bypassed,
std::optional<base::flat_map<std::string, std::string>> extras);
IntentInfo(const IntentInfo& other);
IntentInfo& operator=(const IntentInfo&) = delete;
~IntentInfo();
std::string action;
std::optional<std::vector<std::string>> categories;
std::optional<std::string> data;
std::optional<std::string> type;
bool ui_bypassed;
std::optional<base::flat_map<std::string, std::string>> extras;
};
// Describes an action given by the android text selection delegate (e.g. open
// maps).
// See //ash/components/arc/mojom/intent_helper.mojom for more details.
struct TextSelectionAction {
TextSelectionAction(std::string app_id,
gfx::ImageSkia icon,
ActivityName activity,
std::string title,
IntentInfo action_intent);
TextSelectionAction(const TextSelectionAction& other);
TextSelectionAction& operator=(const TextSelectionAction&) = delete;
~TextSelectionAction();
// App ID of the package.
// Note that this parameter is not set in arc::mojom::TextSelectionAction,
// but required in this struct.
std::string app_id;
// ImageSkia icon of the package.
// Note that this parameter is not set in arc::mojom::TextSelectionAction,
// but required in this struct.
gfx::ImageSkia icon;
ActivityName activity;
std::string title;
IntentInfo action_intent;
};
// Describes a package that can handle an intent.
// See //ash/components/arc/mojom/intent_helper.mojom for more details.
struct IntentHandlerInfo {
IntentHandlerInfo(std::string name,
std::string package_name,
std::string activity_name,
bool is_preferred,
std::optional<std::string> fallback_url);
IntentHandlerInfo(const IntentHandlerInfo& other);
IntentHandlerInfo& operator=(const IntentHandlerInfo&) = default;
~IntentHandlerInfo();
// The name of the package used as a description text.
std::string name;
// The name of the package used as an ID.
std::string package_name;
// A hint for retrieving the package's icon.
std::string activity_name;
// Set to true if the package is set as a preferred package.
bool is_preferred;
// RequestUrlHandlerList may fill |fallback_url| when it is called with an
// intent: URL.
std::optional<std::string> fallback_url;
};
using RequestUrlHandlerListCallback =
base::OnceCallback<void(std::vector<IntentHandlerInfo>)>;
using RequestTextSelectionActionsCallback =
base::OnceCallback<void(std::vector<TextSelectionAction>)>;
// Returns true if ARC is available.
virtual bool IsArcAvailable() = 0;
// Returns true if RequestUrlHandlerList is available.
virtual bool IsRequestUrlHandlerListAvailable() = 0;
// Returns true if RequestTextSelectionActions is available.
virtual bool IsRequestTextSelectionActionsAvailable() = 0;
// Calls RequestUrlHandlerList mojo API.
virtual bool RequestUrlHandlerList(
const std::string& url,
RequestUrlHandlerListCallback callback) = 0;
// Calls RequestTextSelectionActions mojo API.
virtual bool RequestTextSelectionActions(
const std::string& text,
ui::ResourceScaleFactor scale_factor,
RequestTextSelectionActionsCallback callback) = 0;
// Calls HandleUrl mojo API.
virtual bool HandleUrl(const std::string& url,
const std::string& package_name) = 0;
// Calls HandleIntent mojo API.
virtual bool HandleIntent(const IntentInfo& intent,
const ActivityName& activity) = 0;
// Calls AddPreferredPackage mojo API.
virtual bool AddPreferredPackage(const std::string& package_name) = 0;
};
} // namespace arc
#endif // ASH_COMPONENTS_ARC_INTENT_HELPER_ARC_INTENT_HELPER_MOJO_DELEGATE_H_