OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/common/manifest_handlers/background_info.h" | 5 #include "extensions/common/manifest_handlers/background_info.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); | 110 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); |
111 return false; | 111 return false; |
112 } | 112 } |
113 | 113 |
114 return true; | 114 return true; |
115 } | 115 } |
116 | 116 |
117 bool BackgroundInfo::LoadBackgroundScripts(const Extension* extension, | 117 bool BackgroundInfo::LoadBackgroundScripts(const Extension* extension, |
118 const std::string& key, | 118 const std::string& key, |
119 base::string16* error) { | 119 base::string16* error) { |
120 const base::Value* background_scripts_value = NULL; | 120 const base::Value* background_scripts_value = nullptr; |
121 if (!extension->manifest()->Get(key, &background_scripts_value)) | 121 if (!extension->manifest()->Get(key, &background_scripts_value)) |
122 return true; | 122 return true; |
123 | 123 |
124 CHECK(background_scripts_value); | 124 CHECK(background_scripts_value); |
125 if (background_scripts_value->GetType() != base::Value::TYPE_LIST) { | 125 if (background_scripts_value->GetType() != base::Value::TYPE_LIST) { |
126 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts); | 126 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts); |
127 return false; | 127 return false; |
128 } | 128 } |
129 | 129 |
130 const base::ListValue* background_scripts = NULL; | 130 const base::ListValue* background_scripts = nullptr; |
131 background_scripts_value->GetAsList(&background_scripts); | 131 background_scripts_value->GetAsList(&background_scripts); |
132 for (size_t i = 0; i < background_scripts->GetSize(); ++i) { | 132 for (size_t i = 0; i < background_scripts->GetSize(); ++i) { |
133 std::string script; | 133 std::string script; |
134 if (!background_scripts->GetString(i, &script)) { | 134 if (!background_scripts->GetString(i, &script)) { |
135 *error = ErrorUtils::FormatErrorMessageUTF16( | 135 *error = ErrorUtils::FormatErrorMessageUTF16( |
136 errors::kInvalidBackgroundScript, base::IntToString(i)); | 136 errors::kInvalidBackgroundScript, base::IntToString(i)); |
137 return false; | 137 return false; |
138 } | 138 } |
139 background_scripts_.push_back(script); | 139 background_scripts_.push_back(script); |
140 } | 140 } |
141 | 141 |
142 return true; | 142 return true; |
143 } | 143 } |
144 | 144 |
145 bool BackgroundInfo::LoadBackgroundPage(const Extension* extension, | 145 bool BackgroundInfo::LoadBackgroundPage(const Extension* extension, |
146 const std::string& key, | 146 const std::string& key, |
147 base::string16* error) { | 147 base::string16* error) { |
148 const base::Value* background_page_value = NULL; | 148 const base::Value* background_page_value = nullptr; |
149 if (!extension->manifest()->Get(key, &background_page_value)) | 149 if (!extension->manifest()->Get(key, &background_page_value)) |
150 return true; | 150 return true; |
151 | 151 |
152 std::string background_str; | 152 std::string background_str; |
153 if (!background_page_value->GetAsString(&background_str)) { | 153 if (!background_page_value->GetAsString(&background_str)) { |
154 *error = ASCIIToUTF16(errors::kInvalidBackground); | 154 *error = ASCIIToUTF16(errors::kInvalidBackground); |
155 return false; | 155 return false; |
156 } | 156 } |
157 | 157 |
158 if (extension->is_hosted_app()) { | 158 if (extension->is_hosted_app()) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 return true; | 197 return true; |
198 } | 198 } |
199 | 199 |
200 bool BackgroundInfo::LoadBackgroundPersistent(const Extension* extension, | 200 bool BackgroundInfo::LoadBackgroundPersistent(const Extension* extension, |
201 base::string16* error) { | 201 base::string16* error) { |
202 if (extension->is_platform_app()) { | 202 if (extension->is_platform_app()) { |
203 is_persistent_ = false; | 203 is_persistent_ = false; |
204 return true; | 204 return true; |
205 } | 205 } |
206 | 206 |
207 const base::Value* background_persistent = NULL; | 207 const base::Value* background_persistent = nullptr; |
208 if (!extension->manifest()->Get(keys::kBackgroundPersistent, | 208 if (!extension->manifest()->Get(keys::kBackgroundPersistent, |
209 &background_persistent)) | 209 &background_persistent)) |
210 return true; | 210 return true; |
211 | 211 |
212 if (!background_persistent->GetAsBoolean(&is_persistent_)) { | 212 if (!background_persistent->GetAsBoolean(&is_persistent_)) { |
213 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistent); | 213 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistent); |
214 return false; | 214 return false; |
215 } | 215 } |
216 | 216 |
217 if (!has_background_page()) { | 217 if (!has_background_page()) { |
218 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistentNoPage); | 218 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistentNoPage); |
219 return false; | 219 return false; |
220 } | 220 } |
221 | 221 |
222 return true; | 222 return true; |
223 } | 223 } |
224 | 224 |
225 bool BackgroundInfo::LoadAllowJSAccess(const Extension* extension, | 225 bool BackgroundInfo::LoadAllowJSAccess(const Extension* extension, |
226 base::string16* error) { | 226 base::string16* error) { |
227 const base::Value* allow_js_access = NULL; | 227 const base::Value* allow_js_access = nullptr; |
228 if (!extension->manifest()->Get(keys::kBackgroundAllowJsAccess, | 228 if (!extension->manifest()->Get(keys::kBackgroundAllowJsAccess, |
229 &allow_js_access)) | 229 &allow_js_access)) |
230 return true; | 230 return true; |
231 | 231 |
232 if (!allow_js_access->IsType(base::Value::TYPE_BOOLEAN) || | 232 if (!allow_js_access->IsType(base::Value::TYPE_BOOLEAN) || |
233 !allow_js_access->GetAsBoolean(&allow_js_access_)) { | 233 !allow_js_access->GetAsBoolean(&allow_js_access_)) { |
234 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess); | 234 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess); |
235 return false; | 235 return false; |
236 } | 236 } |
237 | 237 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 const std::vector<std::string> BackgroundManifestHandler::Keys() const { | 310 const std::vector<std::string> BackgroundManifestHandler::Keys() const { |
311 static const char* keys[] = { | 311 static const char* keys[] = { |
312 keys::kBackgroundAllowJsAccess, keys::kBackgroundPage, | 312 keys::kBackgroundAllowJsAccess, keys::kBackgroundPage, |
313 keys::kBackgroundPageLegacy, keys::kBackgroundPersistent, | 313 keys::kBackgroundPageLegacy, keys::kBackgroundPersistent, |
314 keys::kBackgroundScripts, keys::kPlatformAppBackgroundPage, | 314 keys::kBackgroundScripts, keys::kPlatformAppBackgroundPage, |
315 keys::kPlatformAppBackgroundScripts}; | 315 keys::kPlatformAppBackgroundScripts}; |
316 return std::vector<std::string>(keys, keys + arraysize(keys)); | 316 return std::vector<std::string>(keys, keys + arraysize(keys)); |
317 } | 317 } |
318 | 318 |
319 } // namespace extensions | 319 } // namespace extensions |
OLD | NEW |