blob: dc23d8d4c4882e904154919b4f53a08551cc0c93 [file] [log] [blame]
Alexey Baskakovfd3894e2018-10-16 06:09:581// Copyright 2018 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
Alexey Baskakov256a3c432019-08-15 02:56:245#include "chrome/browser/web_applications/web_app.h"
6
Alexey Baskakov4768f6232018-11-08 09:26:467#include <ios>
Alexey Baskakov393b2aa2018-10-25 06:42:318#include <ostream>
Alexey Baskakov97881e52019-09-06 05:51:039#include <tuple>
Alexey Baskakov393b2aa2018-10-25 06:42:3110
Alexey Baskakov8975f352018-12-05 02:28:2611#include "base/logging.h"
Eric Willigers234703c2019-10-04 08:08:2612#include "third_party/blink/public/common/manifest/manifest_util.h"
Alexey Baskakov4768f6232018-11-08 09:26:4613#include "ui/gfx/color_utils.h"
Alexey Baskakovfd3894e2018-10-16 06:09:5814
15namespace web_app {
16
Alexey Baskakove3804cf2019-08-14 00:16:0217WebApp::WebApp(const AppId& app_id)
Eric Willigers234703c2019-10-04 08:08:2618 : app_id_(app_id), display_mode_(blink::mojom::DisplayMode::kUndefined) {}
Alexey Baskakovfd3894e2018-10-16 06:09:5819
20WebApp::~WebApp() = default;
21
Alexey Baskakovdb72457e2019-10-11 06:55:1322WebApp::WebApp(const WebApp& web_app) = default;
23
24WebApp& WebApp::operator=(WebApp&& web_app) = default;
25
Alexey Baskakov97881e52019-09-06 05:51:0326void WebApp::AddSource(Source::Type source) {
27 sources_[source] = true;
28}
29
30void WebApp::RemoveSource(Source::Type source) {
31 sources_[source] = false;
32}
33
34bool WebApp::HasAnySources() const {
35 return sources_.any();
36}
37
Alexey Baskakov0b50ec62019-10-01 03:29:2338bool WebApp::IsSynced() const {
39 return sources_[Source::kSync];
40}
41
Alexey Baskakovfd3894e2018-10-16 06:09:5842void WebApp::SetName(const std::string& name) {
43 name_ = name;
44}
45
46void WebApp::SetDescription(const std::string& description) {
47 description_ = description;
48}
49
Alexey Baskakov79b06902018-11-08 05:30:0350void WebApp::SetLaunchUrl(const GURL& launch_url) {
51 DCHECK(!launch_url.is_empty() && launch_url.is_valid());
Alexey Baskakovfd3894e2018-10-16 06:09:5852 launch_url_ = launch_url;
53}
54
Alexey Baskakov4768f6232018-11-08 09:26:4655void WebApp::SetScope(const GURL& scope) {
56 DCHECK(scope.is_empty() || scope.is_valid());
57 scope_ = scope;
58}
59
60void WebApp::SetThemeColor(base::Optional<SkColor> theme_color) {
61 theme_color_ = theme_color;
62}
63
Eric Willigers234703c2019-10-04 08:08:2664void WebApp::SetDisplayMode(blink::mojom::DisplayMode display_mode) {
65 DCHECK_NE(blink::mojom::DisplayMode::kUndefined, display_mode);
66 display_mode_ = display_mode;
Alexey Baskakove3804cf2019-08-14 00:16:0267}
68
Alexey Baskakov256a3c432019-08-15 02:56:2469void WebApp::SetIsLocallyInstalled(bool is_locally_installed) {
70 is_locally_installed_ = is_locally_installed;
71}
72
Alexey Baskakovd702ffc2019-10-16 05:58:1073void WebApp::SetIsInSyncInstall(bool is_in_sync_install) {
74 is_in_sync_install_ = is_in_sync_install;
Alexey Baskakov8c864f182019-10-04 03:39:5675}
76
Alexey Baskakov8975f352018-12-05 02:28:2677void WebApp::SetIcons(Icons icons) {
Alexey Baskakov8975f352018-12-05 02:28:2678 icons_ = std::move(icons);
79}
80
Alexey Baskakovdb72457e2019-10-11 06:55:1381void WebApp::SetSyncData(SyncData sync_data) {
82 sync_data_ = std::move(sync_data);
Alexey Baskakov8c864f182019-10-04 03:39:5683}
84
85WebApp::SyncData::SyncData() = default;
86
87WebApp::SyncData::~SyncData() = default;
88
Alexey Baskakovdb72457e2019-10-11 06:55:1389WebApp::SyncData::SyncData(const SyncData& sync_data) = default;
90
91WebApp::SyncData& WebApp::SyncData::operator=(SyncData&& sync_data) = default;
92
Alexey Baskakov393b2aa2018-10-25 06:42:3193std::ostream& operator<<(std::ostream& out, const WebApp& app) {
Alexey Baskakov4768f6232018-11-08 09:26:4694 const std::string theme_color =
Alexey Baskakov8c864f182019-10-04 03:39:5695 app.theme_color_.has_value()
96 ? color_utils::SkColorToRgbaString(app.theme_color_.value())
97 : "none";
98 const std::string sync_theme_color =
99 app.sync_data_.theme_color.has_value()
100 ? color_utils::SkColorToRgbaString(app.sync_data_.theme_color.value())
Alexey Baskakov4768f6232018-11-08 09:26:46101 : "none";
Eric Willigers234703c2019-10-04 08:08:26102 const std::string display_mode =
103 blink::DisplayModeToString(app.display_mode_);
Alexey Baskakov8c864f182019-10-04 03:39:56104 const bool is_locally_installed = app.is_locally_installed_;
Alexey Baskakovd702ffc2019-10-16 05:58:10105 const bool is_in_sync_install = app.is_in_sync_install_;
Alexey Baskakov4768f6232018-11-08 09:26:46106
Alexey Baskakov97881e52019-09-06 05:51:03107 return out << "app_id: " << app.app_id_ << std::endl
108 << " name: " << app.name_ << std::endl
109 << " launch_url: " << app.launch_url_ << std::endl
110 << " scope: " << app.scope_ << std::endl
Alexey Baskakov4768f6232018-11-08 09:26:46111 << " theme_color: " << theme_color << std::endl
Eric Willigers234703c2019-10-04 08:08:26112 << " display_mode: " << display_mode << std::endl
Alexey Baskakov8c864f182019-10-04 03:39:56113 << " sources: " << app.sources_.to_string() << std::endl
Alexey Baskakov256a3c432019-08-15 02:56:24114 << " is_locally_installed: " << is_locally_installed << std::endl
Alexey Baskakovd702ffc2019-10-16 05:58:10115 << " is_in_sync_install: " << is_in_sync_install << std::endl
Alexey Baskakov8c864f182019-10-04 03:39:56116 << " sync_data.name: " << app.sync_data_.name << std::endl
117 << " sync_data.theme_color: " << sync_theme_color << std::endl
Alexey Baskakov97881e52019-09-06 05:51:03118 << " description: " << app.description_;
119}
120
121bool operator==(const WebApp::IconInfo& icon_info1,
122 const WebApp::IconInfo& icon_info2) {
123 return std::tie(icon_info1.url, icon_info1.size_in_px) ==
124 std::tie(icon_info2.url, icon_info2.size_in_px);
125}
126
Alexey Baskakov8c864f182019-10-04 03:39:56127bool operator==(const WebApp::SyncData& sync_data1,
128 const WebApp::SyncData& sync_data2) {
129 return std::tie(sync_data1.name, sync_data1.theme_color) ==
130 std::tie(sync_data2.name, sync_data2.theme_color);
131}
132
Alexey Baskakov97881e52019-09-06 05:51:03133bool operator==(const WebApp& app1, const WebApp& app2) {
134 return std::tie(app1.app_id_, app1.sources_, app1.name_, app1.launch_url_,
135 app1.description_, app1.scope_, app1.theme_color_,
Eric Willigers234703c2019-10-04 08:08:26136 app1.icons_, app1.display_mode_, app1.is_locally_installed_,
Alexey Baskakovd702ffc2019-10-16 05:58:10137 app1.is_in_sync_install_, app1.sync_data_) ==
Alexey Baskakov97881e52019-09-06 05:51:03138 std::tie(app2.app_id_, app2.sources_, app2.name_, app2.launch_url_,
139 app2.description_, app2.scope_, app2.theme_color_,
Eric Willigers234703c2019-10-04 08:08:26140 app2.icons_, app2.display_mode_, app2.is_locally_installed_,
Alexey Baskakovd702ffc2019-10-16 05:58:10141 app2.is_in_sync_install_, app2.sync_data_);
Alexey Baskakov97881e52019-09-06 05:51:03142}
143
144bool operator!=(const WebApp& app1, const WebApp& app2) {
145 return !(app1 == app2);
Alexey Baskakov393b2aa2018-10-25 06:42:31146}
147
Alexey Baskakovfd3894e2018-10-16 06:09:58148} // namespace web_app