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> |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 137 |
138 // Write the manifest. | 138 // Write the manifest. |
139 base::FilePath manifest_path = temp_dir.path().Append(kManifestFilename); | 139 base::FilePath manifest_path = temp_dir.GetPath().Append(kManifestFilename); |
140 JSONFileValueSerializer serializer(manifest_path); | 140 JSONFileValueSerializer serializer(manifest_path); |
141 if (!serializer.Serialize(*root)) { | 141 if (!serializer.Serialize(*root)) { |
142 LOG(ERROR) << "Could not serialize manifest."; | 142 LOG(ERROR) << "Could not serialize manifest."; |
143 return NULL; | 143 return NULL; |
144 } | 144 } |
145 | 145 |
146 // Write the icon files. | 146 // Write the icon files. |
147 base::FilePath icons_dir = temp_dir.path().AppendASCII(kIconsDirName); | 147 base::FilePath icons_dir = temp_dir.GetPath().AppendASCII(kIconsDirName); |
148 if (!base::CreateDirectory(icons_dir)) { | 148 if (!base::CreateDirectory(icons_dir)) { |
149 LOG(ERROR) << "Could not create icons directory."; | 149 LOG(ERROR) << "Could not create icons directory."; |
150 return NULL; | 150 return NULL; |
151 } | 151 } |
152 for (size_t i = 0; i < web_app.icons.size(); ++i) { | 152 for (size_t i = 0; i < web_app.icons.size(); ++i) { |
153 // Skip unfetched bitmaps. | 153 // Skip unfetched bitmaps. |
154 if (web_app.icons[i].data.colorType() == kUnknown_SkColorType) | 154 if (web_app.icons[i].data.colorType() == kUnknown_SkColorType) |
155 continue; | 155 continue; |
156 | 156 |
157 base::FilePath icon_file = icons_dir.AppendASCII( | 157 base::FilePath icon_file = icons_dir.AppendASCII( |
158 base::StringPrintf("%i.png", web_app.icons[i].width)); | 158 base::StringPrintf("%i.png", web_app.icons[i].width)); |
159 std::vector<unsigned char> image_data; | 159 std::vector<unsigned char> image_data; |
160 if (!gfx::PNGCodec::EncodeBGRASkBitmap(web_app.icons[i].data, | 160 if (!gfx::PNGCodec::EncodeBGRASkBitmap(web_app.icons[i].data, |
161 false, | 161 false, |
162 &image_data)) { | 162 &image_data)) { |
163 LOG(ERROR) << "Could not create icon file."; | 163 LOG(ERROR) << "Could not create icon file."; |
164 return NULL; | 164 return NULL; |
165 } | 165 } |
166 | 166 |
167 const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]); | 167 const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]); |
168 int size = base::checked_cast<int>(image_data.size()); | 168 int size = base::checked_cast<int>(image_data.size()); |
169 if (base::WriteFile(icon_file, image_data_ptr, size) != size) { | 169 if (base::WriteFile(icon_file, image_data_ptr, size) != size) { |
170 LOG(ERROR) << "Could not write icon file."; | 170 LOG(ERROR) << "Could not write icon file."; |
171 return NULL; | 171 return NULL; |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 // Finally, create the extension object to represent the unpacked directory. | 175 // Finally, create the extension object to represent the unpacked directory. |
176 std::string error; | 176 std::string error; |
177 scoped_refptr<Extension> extension = Extension::Create( | 177 scoped_refptr<Extension> extension = |
178 temp_dir.path(), | 178 Extension::Create(temp_dir.GetPath(), Manifest::INTERNAL, *root, |
179 Manifest::INTERNAL, | 179 Extension::FROM_BOOKMARK, &error); |
180 *root, | |
181 Extension::FROM_BOOKMARK, | |
182 &error); | |
183 if (!extension.get()) { | 180 if (!extension.get()) { |
184 LOG(ERROR) << error; | 181 LOG(ERROR) << error; |
185 return NULL; | 182 return NULL; |
186 } | 183 } |
187 | 184 |
188 temp_dir.Take(); // The caller takes ownership of the directory. | 185 temp_dir.Take(); // The caller takes ownership of the directory. |
189 return extension; | 186 return extension; |
190 } | 187 } |
191 | 188 |
192 } // namespace extensions | 189 } // namespace extensions |
OLD | NEW |