| 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" |
| 28 #include "base/values.h" |
| 27 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/web_application_info.h" | 30 #include "chrome/common/web_application_info.h" |
| 29 #include "crypto/sha2.h" | 31 #include "crypto/sha2.h" |
| 30 #include "extensions/common/constants.h" | 32 #include "extensions/common/constants.h" |
| 31 #include "extensions/common/extension.h" | 33 #include "extensions/common/extension.h" |
| 32 #include "extensions/common/file_util.h" | 34 #include "extensions/common/file_util.h" |
| 33 #include "extensions/common/image_util.h" | 35 #include "extensions/common/image_util.h" |
| 34 #include "extensions/common/manifest_constants.h" | 36 #include "extensions/common/manifest_constants.h" |
| 35 #include "third_party/skia/include/core/SkBitmap.h" | 37 #include "third_party/skia/include/core/SkBitmap.h" |
| 36 #include "ui/gfx/codec/png_codec.h" | 38 #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)); | 111 root->SetString(keys::kName, base::UTF16ToUTF8(web_app.title)); |
| 110 root->SetString(keys::kVersion, ConvertTimeToExtensionVersion(create_time)); | 112 root->SetString(keys::kVersion, ConvertTimeToExtensionVersion(create_time)); |
| 111 root->SetString(keys::kDescription, base::UTF16ToUTF8(web_app.description)); | 113 root->SetString(keys::kDescription, base::UTF16ToUTF8(web_app.description)); |
| 112 root->SetString(keys::kLaunchWebURL, web_app.app_url.spec()); | 114 root->SetString(keys::kLaunchWebURL, web_app.app_url.spec()); |
| 113 if (web_app.generated_icon_color != SK_ColorTRANSPARENT) { | 115 if (web_app.generated_icon_color != SK_ColorTRANSPARENT) { |
| 114 root->SetString(keys::kAppIconColor, image_util::GenerateHexColorString( | 116 root->SetString(keys::kAppIconColor, image_util::GenerateHexColorString( |
| 115 web_app.generated_icon_color)); | 117 web_app.generated_icon_color)); |
| 116 } | 118 } |
| 117 | 119 |
| 118 // Add the icons and linked icon information. | 120 // Add the icons and linked icon information. |
| 119 base::DictionaryValue* icons = new base::DictionaryValue(); | 121 auto icons = base::MakeUnique<base::DictionaryValue>(); |
| 120 root->Set(keys::kIcons, icons); | 122 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) { | 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)); |
| 137 | 139 |
| 138 // Write the manifest. | 140 // Write the manifest. |
| 139 base::FilePath manifest_path = temp_dir.GetPath().Append(kManifestFilename); | 141 base::FilePath manifest_path = temp_dir.GetPath().Append(kManifestFilename); |
| 140 JSONFileValueSerializer serializer(manifest_path); | 142 JSONFileValueSerializer serializer(manifest_path); |
| 141 if (!serializer.Serialize(*root)) { | 143 if (!serializer.Serialize(*root)) { |
| 142 LOG(ERROR) << "Could not serialize manifest."; | 144 LOG(ERROR) << "Could not serialize manifest."; |
| 143 return NULL; | 145 return NULL; |
| 144 } | 146 } |
| 145 | 147 |
| 146 // Write the icon files. | 148 // Write the icon files. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 if (!extension.get()) { | 182 if (!extension.get()) { |
| 181 LOG(ERROR) << error; | 183 LOG(ERROR) << error; |
| 182 return NULL; | 184 return NULL; |
| 183 } | 185 } |
| 184 | 186 |
| 185 temp_dir.Take(); // The caller takes ownership of the directory. | 187 temp_dir.Take(); // The caller takes ownership of the directory. |
| 186 return extension; | 188 return extension; |
| 187 } | 189 } |
| 188 | 190 |
| 189 } // namespace extensions | 191 } // namespace extensions |
| OLD | NEW |