OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
17 #include "base/sha2.h" | 17 #include "base/sha2.h" |
18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
19 #include "base/time.h" | 19 #include "base/time.h" |
20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
24 #include "chrome/common/json_value_serializer.h" | 24 #include "chrome/common/json_value_serializer.h" |
25 #include "chrome/common/web_apps.h" | |
25 #include "gfx/codec/png_codec.h" | 26 #include "gfx/codec/png_codec.h" |
26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
27 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
28 #include "webkit/glue/dom_operations.h" | |
29 | 29 |
30 namespace keys = extension_manifest_keys; | 30 namespace keys = extension_manifest_keys; |
31 | 31 |
32 using base::Time; | 32 using base::Time; |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 const char kIconsDirName[] = "_icons"; | 36 const char kIconsDirName[] = "_icons"; |
37 | 37 |
38 // Create the public key for the converted web app. | 38 // Create the public key for the converted web app. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 LOG(ERROR) << "stamp: " << stamp; | 74 LOG(ERROR) << "stamp: " << stamp; |
75 | 75 |
76 return base::StringPrintf("%i.%i.%i.%i", | 76 return base::StringPrintf("%i.%i.%i.%i", |
77 create_time_exploded.year, | 77 create_time_exploded.year, |
78 create_time_exploded.month, | 78 create_time_exploded.month, |
79 create_time_exploded.day_of_month, | 79 create_time_exploded.day_of_month, |
80 static_cast<uint16>(stamp)); | 80 static_cast<uint16>(stamp)); |
81 } | 81 } |
82 | 82 |
83 scoped_refptr<Extension> ConvertWebAppToExtension( | 83 scoped_refptr<Extension> ConvertWebAppToExtension( |
84 const webkit_glue::WebApplicationInfo& web_app, | 84 const WebApplicationInfo& web_app, |
85 const Time& create_time) { | 85 const base::Time& create_time) { |
86 FilePath user_data_temp_dir; | 86 FilePath user_data_temp_dir; |
87 CHECK(PathService::Get(chrome::DIR_USER_DATA_TEMP, &user_data_temp_dir)); | 87 CHECK(PathService::Get(chrome::DIR_USER_DATA_TEMP, &user_data_temp_dir)); |
88 | 88 |
89 ScopedTempDir temp_dir; | 89 ScopedTempDir temp_dir; |
90 if (!temp_dir.CreateUniqueTempDirUnderPath(user_data_temp_dir)) { | 90 if (!temp_dir.CreateUniqueTempDirUnderPath(user_data_temp_dir)) { |
91 LOG(ERROR) << "Could not create temporary directory."; | 91 LOG(ERROR) << "Could not create temporary directory."; |
92 return NULL; | 92 return NULL; |
93 } | 93 } |
94 | 94 |
95 // Create the manifest | 95 // Create the manifest |
96 scoped_ptr<DictionaryValue> root(new DictionaryValue); | 96 scoped_ptr<DictionaryValue> root(new DictionaryValue); |
97 root->SetString(keys::kPublicKey, GenerateKey(web_app.manifest_url)); | 97 root->SetString(keys::kPublicKey, GenerateKey(web_app.manifest_url)); |
98 root->SetString(keys::kName, UTF16ToUTF8(web_app.title)); | 98 root->SetString(keys::kName, UTF16ToUTF8(web_app.title)); |
99 root->SetString(keys::kVersion, ConvertTimeToExtensionVersion(create_time)); | 99 root->SetString(keys::kVersion, ConvertTimeToExtensionVersion(create_time)); |
100 root->SetString(keys::kDescription, UTF16ToUTF8(web_app.description)); | 100 root->SetString(keys::kDescription, UTF16ToUTF8(web_app.description)); |
101 root->SetString(keys::kLaunchWebURL, web_app.app_url.spec()); | 101 root->SetString(keys::kLaunchWebURL, web_app.app_url.spec()); |
102 | 102 |
103 if (web_app.launch_container == "panel") { | |
104 root->SetString(keys::kLaunchContainer, | |
105 extension_manifest_values::kLaunchContainerPanel); | |
106 } | |
107 | |
108 // TODO(aa): kConvertedFromWebApp? | |
109 | |
103 // Add the icons. | 110 // Add the icons. |
104 DictionaryValue* icons = new DictionaryValue(); | 111 DictionaryValue* icons = new DictionaryValue(); |
105 root->Set(keys::kIcons, icons); | 112 root->Set(keys::kIcons, icons); |
106 for (size_t i = 0; i < web_app.icons.size(); ++i) { | 113 for (size_t i = 0; i < web_app.icons.size(); ++i) { |
107 std::string size = StringPrintf("%i", web_app.icons[i].width); | 114 std::string size = StringPrintf("%i", web_app.icons[i].width); |
108 std::string icon_path = StringPrintf("%s/%s.png", kIconsDirName, | 115 std::string icon_path = StringPrintf("%s/%s.png", kIconsDirName, |
109 size.c_str()); | 116 size.c_str()); |
110 icons->SetString(size, icon_path); | 117 icons->SetString(size, icon_path); |
111 } | 118 } |
112 | 119 |
113 // Add the permissions. | 120 // Add the permissions. In web apps, these are called 'privileges'. |
Erik does not do reviews
2010/11/15 19:45:36
I'm not sure we want to make this change just yet.
Aaron Boodman
2010/11/16 03:44:45
I decided to land these changes in a different ord
| |
114 ListValue* permissions = new ListValue(); | 121 ListValue* permissions = new ListValue(); |
115 root->Set(keys::kPermissions, permissions); | 122 root->Set(keys::kPermissions, permissions); |
116 for (size_t i = 0; i < web_app.permissions.size(); ++i) { | 123 for (size_t i = 0; i < web_app.privileges.size(); ++i) { |
117 permissions->Append(Value::CreateStringValue(web_app.permissions[i])); | 124 permissions->Append(Value::CreateStringValue(web_app.privileges[i])); |
118 } | 125 } |
119 | 126 |
120 // Add the URLs. | 127 // Add the URLs. |
121 ListValue* urls = new ListValue(); | 128 ListValue* urls = new ListValue(); |
122 root->Set(keys::kWebURLs, urls); | 129 root->Set(keys::kWebURLs, urls); |
123 for (size_t i = 0; i < web_app.urls.size(); ++i) { | 130 for (size_t i = 0; i < web_app.urls.size(); ++i) { |
124 urls->Append(Value::CreateStringValue(web_app.urls[i].spec())); | 131 urls->Append(Value::CreateStringValue(web_app.urls[i].spec())); |
125 } | 132 } |
126 | 133 |
127 // Write the manifest. | 134 // Write the manifest. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 scoped_refptr<Extension> extension = Extension::Create( | 169 scoped_refptr<Extension> extension = Extension::Create( |
163 temp_dir.path(), Extension::INTERNAL, *root, false, &error); | 170 temp_dir.path(), Extension::INTERNAL, *root, false, &error); |
164 if (!extension) { | 171 if (!extension) { |
165 LOG(ERROR) << error; | 172 LOG(ERROR) << error; |
166 return NULL; | 173 return NULL; |
167 } | 174 } |
168 | 175 |
169 temp_dir.Take(); // The caller takes ownership of the directory. | 176 temp_dir.Take(); // The caller takes ownership of the directory. |
170 return extension; | 177 return extension; |
171 } | 178 } |
OLD | NEW |