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" | |
24 #include "base/numerics/safe_conversions.h" | 23 #include "base/numerics/safe_conversions.h" |
25 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
26 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
27 #include "base/time/time.h" | 26 #include "base/time/time.h" |
28 #include "base/values.h" | |
29 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
30 #include "chrome/common/web_application_info.h" | 28 #include "chrome/common/web_application_info.h" |
31 #include "crypto/sha2.h" | 29 #include "crypto/sha2.h" |
32 #include "extensions/common/constants.h" | 30 #include "extensions/common/constants.h" |
33 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
34 #include "extensions/common/file_util.h" | 32 #include "extensions/common/file_util.h" |
35 #include "extensions/common/image_util.h" | 33 #include "extensions/common/image_util.h" |
36 #include "extensions/common/manifest_constants.h" | 34 #include "extensions/common/manifest_constants.h" |
37 #include "third_party/skia/include/core/SkBitmap.h" | 35 #include "third_party/skia/include/core/SkBitmap.h" |
38 #include "ui/gfx/codec/png_codec.h" | 36 #include "ui/gfx/codec/png_codec.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 root->SetString(keys::kName, base::UTF16ToUTF8(web_app.title)); | 109 root->SetString(keys::kName, base::UTF16ToUTF8(web_app.title)); |
112 root->SetString(keys::kVersion, ConvertTimeToExtensionVersion(create_time)); | 110 root->SetString(keys::kVersion, ConvertTimeToExtensionVersion(create_time)); |
113 root->SetString(keys::kDescription, base::UTF16ToUTF8(web_app.description)); | 111 root->SetString(keys::kDescription, base::UTF16ToUTF8(web_app.description)); |
114 root->SetString(keys::kLaunchWebURL, web_app.app_url.spec()); | 112 root->SetString(keys::kLaunchWebURL, web_app.app_url.spec()); |
115 if (web_app.generated_icon_color != SK_ColorTRANSPARENT) { | 113 if (web_app.generated_icon_color != SK_ColorTRANSPARENT) { |
116 root->SetString(keys::kAppIconColor, image_util::GenerateHexColorString( | 114 root->SetString(keys::kAppIconColor, image_util::GenerateHexColorString( |
117 web_app.generated_icon_color)); | 115 web_app.generated_icon_color)); |
118 } | 116 } |
119 | 117 |
120 // Add the icons and linked icon information. | 118 // Add the icons and linked icon information. |
121 auto icons = base::MakeUnique<base::DictionaryValue>(); | 119 base::DictionaryValue* icons = new base::DictionaryValue(); |
122 auto linked_icons = base::MakeUnique<base::ListValue>(); | 120 root->Set(keys::kIcons, icons); |
| 121 base::ListValue* linked_icons = new base::ListValue(); |
| 122 root->Set(keys::kLinkedAppIcons, linked_icons); |
123 for (const auto& icon : web_app.icons) { | 123 for (const auto& icon : web_app.icons) { |
124 std::string size = base::StringPrintf("%i", icon.width); | 124 std::string size = base::StringPrintf("%i", icon.width); |
125 std::string icon_path = base::StringPrintf("%s/%s.png", kIconsDirName, | 125 std::string icon_path = base::StringPrintf("%s/%s.png", kIconsDirName, |
126 size.c_str()); | 126 size.c_str()); |
127 icons->SetString(size, icon_path); | 127 icons->SetString(size, icon_path); |
128 | 128 |
129 if (icon.url.is_valid()) { | 129 if (icon.url.is_valid()) { |
130 std::unique_ptr<base::DictionaryValue> linked_icon( | 130 std::unique_ptr<base::DictionaryValue> linked_icon( |
131 new base::DictionaryValue()); | 131 new base::DictionaryValue()); |
132 linked_icon->SetString(keys::kLinkedAppIconURL, icon.url.spec()); | 132 linked_icon->SetString(keys::kLinkedAppIconURL, icon.url.spec()); |
133 linked_icon->SetInteger(keys::kLinkedAppIconSize, icon.width); | 133 linked_icon->SetInteger(keys::kLinkedAppIconSize, icon.width); |
134 linked_icons->Append(std::move(linked_icon)); | 134 linked_icons->Append(std::move(linked_icon)); |
135 } | 135 } |
136 } | 136 } |
137 root->Set(keys::kIcons, std::move(icons)); | |
138 root->Set(keys::kLinkedAppIcons, std::move(linked_icons)); | |
139 | 137 |
140 // Write the manifest. | 138 // Write the manifest. |
141 base::FilePath manifest_path = temp_dir.GetPath().Append(kManifestFilename); | 139 base::FilePath manifest_path = temp_dir.GetPath().Append(kManifestFilename); |
142 JSONFileValueSerializer serializer(manifest_path); | 140 JSONFileValueSerializer serializer(manifest_path); |
143 if (!serializer.Serialize(*root)) { | 141 if (!serializer.Serialize(*root)) { |
144 LOG(ERROR) << "Could not serialize manifest."; | 142 LOG(ERROR) << "Could not serialize manifest."; |
145 return NULL; | 143 return NULL; |
146 } | 144 } |
147 | 145 |
148 // Write the icon files. | 146 // Write the icon files. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 if (!extension.get()) { | 180 if (!extension.get()) { |
183 LOG(ERROR) << error; | 181 LOG(ERROR) << error; |
184 return NULL; | 182 return NULL; |
185 } | 183 } |
186 | 184 |
187 temp_dir.Take(); // The caller takes ownership of the directory. | 185 temp_dir.Take(); // The caller takes ownership of the directory. |
188 return extension; | 186 return extension; |
189 } | 187 } |
190 | 188 |
191 } // namespace extensions | 189 } // namespace extensions |
OLD | NEW |