| 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 <cmath> | 7 #include <cmath> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/base64.h" | 12 #include "base/base64.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
| 16 #include "base/json/json_file_value_serializer.h" | 16 #include "base/json/json_file_value_serializer.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/web_application_info.h" | 23 #include "chrome/common/web_application_info.h" |
| 24 #include "crypto/sha2.h" | 24 #include "crypto/sha2.h" |
| 25 #include "extensions/common/constants.h" | 25 #include "extensions/common/constants.h" |
| 26 #include "extensions/common/extension.h" | 26 #include "extensions/common/extension.h" |
| 27 #include "extensions/common/file_util.h" | 27 #include "extensions/common/file_util.h" |
| 28 #include "extensions/common/image_util.h" |
| 28 #include "extensions/common/manifest_constants.h" | 29 #include "extensions/common/manifest_constants.h" |
| 29 #include "third_party/skia/include/core/SkBitmap.h" | 30 #include "third_party/skia/include/core/SkBitmap.h" |
| 30 #include "ui/gfx/codec/png_codec.h" | 31 #include "ui/gfx/codec/png_codec.h" |
| 31 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 32 | 33 |
| 33 namespace extensions { | 34 namespace extensions { |
| 34 | 35 |
| 35 namespace keys = manifest_keys; | 36 namespace keys = manifest_keys; |
| 36 | 37 |
| 37 using base::Time; | 38 using base::Time; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 return NULL; | 100 return NULL; |
| 100 } | 101 } |
| 101 | 102 |
| 102 // Create the manifest | 103 // Create the manifest |
| 103 scoped_ptr<base::DictionaryValue> root(new base::DictionaryValue); | 104 scoped_ptr<base::DictionaryValue> root(new base::DictionaryValue); |
| 104 root->SetString(keys::kPublicKey, GenerateKey(web_app.app_url)); | 105 root->SetString(keys::kPublicKey, GenerateKey(web_app.app_url)); |
| 105 root->SetString(keys::kName, base::UTF16ToUTF8(web_app.title)); | 106 root->SetString(keys::kName, base::UTF16ToUTF8(web_app.title)); |
| 106 root->SetString(keys::kVersion, ConvertTimeToExtensionVersion(create_time)); | 107 root->SetString(keys::kVersion, ConvertTimeToExtensionVersion(create_time)); |
| 107 root->SetString(keys::kDescription, base::UTF16ToUTF8(web_app.description)); | 108 root->SetString(keys::kDescription, base::UTF16ToUTF8(web_app.description)); |
| 108 root->SetString(keys::kLaunchWebURL, web_app.app_url.spec()); | 109 root->SetString(keys::kLaunchWebURL, web_app.app_url.spec()); |
| 110 if (web_app.generated_icon_color != SK_ColorTRANSPARENT) { |
| 111 root->SetString( |
| 112 keys::kAppIconColor, |
| 113 image_util::GenerateCSSColorString(web_app.generated_icon_color)); |
| 114 } |
| 109 | 115 |
| 110 // Add the icons. | 116 // Add the icons. |
| 111 base::DictionaryValue* icons = new base::DictionaryValue(); | 117 base::DictionaryValue* icons = new base::DictionaryValue(); |
| 112 root->Set(keys::kIcons, icons); | 118 root->Set(keys::kIcons, icons); |
| 113 for (size_t i = 0; i < web_app.icons.size(); ++i) { | 119 for (size_t i = 0; i < web_app.icons.size(); ++i) { |
| 114 std::string size = base::StringPrintf("%i", web_app.icons[i].width); | 120 std::string size = base::StringPrintf("%i", web_app.icons[i].width); |
| 115 std::string icon_path = base::StringPrintf("%s/%s.png", kIconsDirName, | 121 std::string icon_path = base::StringPrintf("%s/%s.png", kIconsDirName, |
| 116 size.c_str()); | 122 size.c_str()); |
| 117 icons->SetString(size, icon_path); | 123 icons->SetString(size, icon_path); |
| 118 } | 124 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 if (!extension.get()) { | 171 if (!extension.get()) { |
| 166 LOG(ERROR) << error; | 172 LOG(ERROR) << error; |
| 167 return NULL; | 173 return NULL; |
| 168 } | 174 } |
| 169 | 175 |
| 170 temp_dir.Take(); // The caller takes ownership of the directory. | 176 temp_dir.Take(); // The caller takes ownership of the directory. |
| 171 return extension; | 177 return extension; |
| 172 } | 178 } |
| 173 | 179 |
| 174 } // namespace extensions | 180 } // namespace extensions |
| OLD | NEW |