OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/convert_web_app.h" | 5 #include "chrome/browser/extensions/convert_web_app.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
11 #include <limits> | 11 #include <limits> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/base64.h" | 17 #include "base/base64.h" |
18 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
19 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
20 #include "base/files/scoped_temp_dir.h" | 20 #include "base/files/scoped_temp_dir.h" |
21 #include "base/json/json_file_value_serializer.h" | 21 #include "base/json/json_file_value_serializer.h" |
22 #include "base/logging.h" | 22 #include "base/logging.h" |
23 #include "base/memory/ptr_util.h" | |
23 #include "base/numerics/safe_conversions.h" | 24 #include "base/numerics/safe_conversions.h" |
24 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
25 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
26 #include "base/time/time.h" | 27 #include "base/time/time.h" |
jdoerrie
2017/04/06 14:25:50
#include "base/values.h"
vabr (Chromium)
2017/04/07 20:40:40
Done.
| |
27 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/web_application_info.h" | 29 #include "chrome/common/web_application_info.h" |
29 #include "crypto/sha2.h" | 30 #include "crypto/sha2.h" |
30 #include "extensions/common/constants.h" | 31 #include "extensions/common/constants.h" |
31 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
32 #include "extensions/common/file_util.h" | 33 #include "extensions/common/file_util.h" |
33 #include "extensions/common/image_util.h" | 34 #include "extensions/common/image_util.h" |
34 #include "extensions/common/manifest_constants.h" | 35 #include "extensions/common/manifest_constants.h" |
35 #include "third_party/skia/include/core/SkBitmap.h" | 36 #include "third_party/skia/include/core/SkBitmap.h" |
36 #include "ui/gfx/codec/png_codec.h" | 37 #include "ui/gfx/codec/png_codec.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 root->SetString(keys::kName, base::UTF16ToUTF8(web_app.title)); | 110 root->SetString(keys::kName, base::UTF16ToUTF8(web_app.title)); |
110 root->SetString(keys::kVersion, ConvertTimeToExtensionVersion(create_time)); | 111 root->SetString(keys::kVersion, ConvertTimeToExtensionVersion(create_time)); |
111 root->SetString(keys::kDescription, base::UTF16ToUTF8(web_app.description)); | 112 root->SetString(keys::kDescription, base::UTF16ToUTF8(web_app.description)); |
112 root->SetString(keys::kLaunchWebURL, web_app.app_url.spec()); | 113 root->SetString(keys::kLaunchWebURL, web_app.app_url.spec()); |
113 if (web_app.generated_icon_color != SK_ColorTRANSPARENT) { | 114 if (web_app.generated_icon_color != SK_ColorTRANSPARENT) { |
114 root->SetString(keys::kAppIconColor, image_util::GenerateHexColorString( | 115 root->SetString(keys::kAppIconColor, image_util::GenerateHexColorString( |
115 web_app.generated_icon_color)); | 116 web_app.generated_icon_color)); |
116 } | 117 } |
117 | 118 |
118 // Add the icons and linked icon information. | 119 // Add the icons and linked icon information. |
119 base::DictionaryValue* icons = new base::DictionaryValue(); | 120 auto icons = base::MakeUnique<base::DictionaryValue>(); |
120 root->Set(keys::kIcons, icons); | 121 auto linked_icons = base::MakeUnique<base::ListValue>(); |
121 base::ListValue* linked_icons = new base::ListValue(); | |
122 root->Set(keys::kLinkedAppIcons, linked_icons); | |
123 for (const auto& icon : web_app.icons) { | 122 for (const auto& icon : web_app.icons) { |
124 std::string size = base::StringPrintf("%i", icon.width); | 123 std::string size = base::StringPrintf("%i", icon.width); |
125 std::string icon_path = base::StringPrintf("%s/%s.png", kIconsDirName, | 124 std::string icon_path = base::StringPrintf("%s/%s.png", kIconsDirName, |
126 size.c_str()); | 125 size.c_str()); |
127 icons->SetString(size, icon_path); | 126 icons->SetString(size, icon_path); |
128 | 127 |
129 if (icon.url.is_valid()) { | 128 if (icon.url.is_valid()) { |
130 std::unique_ptr<base::DictionaryValue> linked_icon( | 129 std::unique_ptr<base::DictionaryValue> linked_icon( |
131 new base::DictionaryValue()); | 130 new base::DictionaryValue()); |
132 linked_icon->SetString(keys::kLinkedAppIconURL, icon.url.spec()); | 131 linked_icon->SetString(keys::kLinkedAppIconURL, icon.url.spec()); |
133 linked_icon->SetInteger(keys::kLinkedAppIconSize, icon.width); | 132 linked_icon->SetInteger(keys::kLinkedAppIconSize, icon.width); |
134 linked_icons->Append(std::move(linked_icon)); | 133 linked_icons->Append(std::move(linked_icon)); |
135 } | 134 } |
136 } | 135 } |
136 root->Set(keys::kIcons, std::move(icons)); | |
137 root->Set(keys::kLinkedAppIcons, std::move(linked_icons)); | |
137 | 138 |
138 // Write the manifest. | 139 // Write the manifest. |
139 base::FilePath manifest_path = temp_dir.GetPath().Append(kManifestFilename); | 140 base::FilePath manifest_path = temp_dir.GetPath().Append(kManifestFilename); |
140 JSONFileValueSerializer serializer(manifest_path); | 141 JSONFileValueSerializer serializer(manifest_path); |
141 if (!serializer.Serialize(*root)) { | 142 if (!serializer.Serialize(*root)) { |
142 LOG(ERROR) << "Could not serialize manifest."; | 143 LOG(ERROR) << "Could not serialize manifest."; |
143 return NULL; | 144 return NULL; |
144 } | 145 } |
145 | 146 |
146 // Write the icon files. | 147 // Write the icon files. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 if (!extension.get()) { | 181 if (!extension.get()) { |
181 LOG(ERROR) << error; | 182 LOG(ERROR) << error; |
182 return NULL; | 183 return NULL; |
183 } | 184 } |
184 | 185 |
185 temp_dir.Take(); // The caller takes ownership of the directory. | 186 temp_dir.Take(); // The caller takes ownership of the directory. |
186 return extension; | 187 return extension; |
187 } | 188 } |
188 | 189 |
189 } // namespace extensions | 190 } // namespace extensions |
OLD | NEW |