Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Alan Cutter | eb525cd0 | 2020-06-20 03:12:42 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_PROTO_UTILS_H_ |
| 6 | #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_PROTO_UTILS_H_ |
| 7 | |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 8 | #include <optional> |
Alan Cutter | eb525cd0 | 2020-06-20 03:12:42 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Carlos Frias | 514cf67 | 2020-08-13 23:53:43 | [diff] [blame] | 11 | #include "chrome/browser/web_applications/proto/web_app.pb.h" |
Louise Brett | 2cc8f48 | 2023-05-16 15:15:29 | [diff] [blame] | 12 | #include "chrome/browser/web_applications/proto/web_app_tab_strip.pb.h" |
| 13 | #include "chrome/browser/web_applications/proto/web_app_url_pattern.pb.h" |
Alan Cutter | eb525cd0 | 2020-06-20 03:12:42 | [diff] [blame] | 14 | #include "chrome/browser/web_applications/web_app.h" |
| 15 | #include "components/sync/protocol/web_app_specifics.pb.h" |
Kasie Wang | ba02612 | 2023-01-19 21:58:59 | [diff] [blame] | 16 | #include "content/browser/background_fetch/background_fetch.pb.h" |
Yoshisato Yanagisawa | 51abed9c | 2023-06-28 23:30:17 | [diff] [blame] | 17 | #include "third_party/blink/public/common/safe_url_pattern.h" |
Alan Cutter | eb525cd0 | 2020-06-20 03:12:42 | [diff] [blame] | 18 | |
Evan Stade | fbe5ca5 | 2021-08-19 00:51:43 | [diff] [blame] | 19 | namespace apps { |
| 20 | struct IconInfo; |
| 21 | } |
| 22 | |
Alan Cutter | eb525cd0 | 2020-06-20 03:12:42 | [diff] [blame] | 23 | namespace web_app { |
| 24 | |
Carlos Frias | 514cf67 | 2020-08-13 23:53:43 | [diff] [blame] | 25 | enum class RunOnOsLoginMode; |
| 26 | |
Alan Cutter | eb525cd0 | 2020-06-20 03:12:42 | [diff] [blame] | 27 | using RepeatedIconInfosProto = |
| 28 | const ::google::protobuf::RepeatedPtrField<::sync_pb::WebAppIconInfo>; |
| 29 | |
Kasie Wang | ba02612 | 2023-01-19 21:58:59 | [diff] [blame] | 30 | using RepeatedImageResourceProto = |
| 31 | const ::google::protobuf::RepeatedPtrField<content::proto::ImageResource>; |
| 32 | |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 33 | std::optional<std::vector<apps::IconInfo>> ParseAppIconInfos( |
Evan Stade | fbe5ca5 | 2021-08-19 00:51:43 | [diff] [blame] | 34 | const char* container_name_for_logging, |
Eric Willigers | 197ff88 | 2022-03-02 07:15:45 | [diff] [blame] | 35 | const RepeatedIconInfosProto& manifest_icons_proto); |
Evan Stade | fbe5ca5 | 2021-08-19 00:51:43 | [diff] [blame] | 36 | |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 37 | std::optional<std::vector<blink::Manifest::ImageResource>> |
Kasie Wang | ba02612 | 2023-01-19 21:58:59 | [diff] [blame] | 38 | ParseAppImageResource(const char* container_name_for_logging, |
| 39 | const RepeatedImageResourceProto& manifest_icons_proto); |
| 40 | |
Glen Robertson | 2585e8a9 | 2020-07-29 08:33:08 | [diff] [blame] | 41 | // Use the given |icon_info| to populate a |WebAppIconInfo| sync proto. |
Evan Stade | fbe5ca5 | 2021-08-19 00:51:43 | [diff] [blame] | 42 | sync_pb::WebAppIconInfo AppIconInfoToSyncProto(const apps::IconInfo& icon_info); |
| 43 | |
Kasie Wang | ba02612 | 2023-01-19 21:58:59 | [diff] [blame] | 44 | // Use the given |image_resource| to populate a |ImageResource| proto. |
| 45 | content::proto::ImageResource AppImageResourceToProto( |
| 46 | const blink::Manifest::ImageResource& image_resource); |
| 47 | |
Daniel Murphy | adf55306 | 2025-03-10 16:46:35 | [diff] [blame] | 48 | RunOnOsLoginMode ToRunOnOsLoginMode(proto::WebApp::RunOnOsLoginMode mode); |
Carlos Frias | 514cf67 | 2020-08-13 23:53:43 | [diff] [blame] | 49 | |
Daniel Murphy | adf55306 | 2025-03-10 16:46:35 | [diff] [blame] | 50 | proto::WebApp::RunOnOsLoginMode ToWebAppProtoRunOnOsLoginMode( |
Carlos Frias | 514cf67 | 2020-08-13 23:53:43 | [diff] [blame] | 51 | RunOnOsLoginMode mode); |
| 52 | |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 53 | std::optional<blink::SafeUrlPattern> ToUrlPattern( |
Louise Brett | 2cc8f48 | 2023-05-16 15:15:29 | [diff] [blame] | 54 | const proto::UrlPattern& proto_url_pattern); |
| 55 | |
Yoshisato Yanagisawa | 51abed9c | 2023-06-28 23:30:17 | [diff] [blame] | 56 | proto::UrlPattern ToUrlPatternProto(const blink::SafeUrlPattern& url_pattern); |
Louise Brett | 2cc8f48 | 2023-05-16 15:15:29 | [diff] [blame] | 57 | |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 58 | std::optional<TabStrip> ProtoToTabStrip(proto::TabStrip tab_strip_proto); |
Louise Brett | 2cc8f48 | 2023-05-16 15:15:29 | [diff] [blame] | 59 | |
Glen Robertson | f429224d | 2024-05-03 02:44:32 | [diff] [blame] | 60 | // Compute the relative manifest ID path as used in the sync proto. |
| 61 | std::string RelativeManifestIdPath(webapps::ManifestId manifest_id); |
| 62 | |
Alan Cutter | eb525cd0 | 2020-06-20 03:12:42 | [diff] [blame] | 63 | } // namespace web_app |
| 64 | |
| 65 | #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_PROTO_UTILS_H_ |