Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 7917006: Extension loading extracts intents from Manifest data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/i18n/rtl.h" 14 #include "base/i18n/rtl.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/string16.h" 18 #include "base/string16.h"
19 #include "base/string_number_conversions.h" 19 #include "base/string_number_conversions.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "base/values.h" 22 #include "base/values.h"
23 #include "base/version.h" 23 #include "base/version.h"
24 #include "crypto/sha2.h" 24 #include "crypto/sha2.h"
25 #include "chrome/browser/intents/web_intent_data.h"
25 #include "chrome/common/chrome_constants.h" 26 #include "chrome/common/chrome_constants.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/chrome_version_info.h" 28 #include "chrome/common/chrome_version_info.h"
28 #include "chrome/common/extensions/extension_action.h" 29 #include "chrome/common/extensions/extension_action.h"
29 #include "chrome/common/extensions/extension_constants.h" 30 #include "chrome/common/extensions/extension_constants.h"
30 #include "chrome/common/extensions/extension_error_utils.h" 31 #include "chrome/common/extensions/extension_error_utils.h"
31 #include "chrome/common/extensions/extension_l10n_util.h" 32 #include "chrome/common/extensions/extension_l10n_util.h"
32 #include "chrome/common/extensions/extension_resource.h" 33 #include "chrome/common/extensions/extension_resource.h"
33 #include "chrome/common/extensions/extension_sidebar_defaults.h" 34 #include "chrome/common/extensions/extension_sidebar_defaults.h"
34 #include "chrome/common/extensions/extension_sidebar_utils.h" 35 #include "chrome/common/extensions/extension_sidebar_utils.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 break; 168 break;
168 169
169 default: 170 default:
170 NOTREACHED() << "Need to add new extension locaton " << location; 171 NOTREACHED() << "Need to add new extension locaton " << location;
171 } 172 }
172 173
173 CHECK(rank != kInvalidRank); 174 CHECK(rank != kInvalidRank);
174 return rank; 175 return rank;
175 } 176 }
176 177
178 bool InitializeWebIntents(const DictionaryValue& source,
179 std::vector<WebIntentData>* intents,
180 std::string* error) {
181 DCHECK(intents);
Greg Billock 2011/09/16 15:43:17 Add the flag check.
groby-ooo-7-16 2011/09/16 17:40:37 Which flag check?
Greg Billock 2011/09/16 18:45:51 if (!CommandLine::ForCurrentProcess()->HasSwitch(s
groby-ooo-7-16 2011/09/17 01:14:42 Done.
182 DCHECK(error);
183 if (!source.HasKey(keys::kIntents))
184 return true;
185
186 DictionaryValue* all_intents = NULL;
187 if (!source.GetDictionary(keys::kIntents, &all_intents)) {
188 *error = errors::kInvalidIntents;
189 return false;
190 }
191
192 std::string value;
193 DictionaryValue::key_iterator iter(all_intents->begin_keys());
194 for (; iter != all_intents->end_keys(); ++iter) {
195 WebIntentData intent;
196
197 intent.service_url = GURL(*iter);
198 DictionaryValue* one_intent = NULL;
199 if (!all_intents->GetDictionaryWithoutPathExpansion(*iter, &one_intent)) {
200 *error = errors::kInvalidIntent;
201 return false;
202 }
203
204 // TODO(groby): Support an array of types
205 if (one_intent->HasKey(keys::kIntentType)) {
206 if (!one_intent->GetString(
207 keys::kIntentType, &intent.type)) {
208 *error = errors::kInvalidIntentType;
209 return false;
210 }
211 }
212
213 if (!one_intent->GetString(
214 keys::kIntentAction, &intent.action)) {
215 *error = errors::kInvalidIntentAction;
216 return false;
217 }
218
219 if (one_intent->HasKey(keys::kIntentTitle)) {
220 if (!one_intent->GetString(
221 keys::kIntentTitle, &intent.title)) {
222 *error = errors::kInvalidIntentTitle;
223 return false;
224 }
225 }
226
227 if (one_intent->HasKey(keys::kIntentDisposition)) {
228 if (!one_intent->GetString(keys::kIntentDisposition, &value) ||
229 (value != values::kIntentDispositionWindow &&
230 value != values::kIntentDispositionInline)) {
231 *error = errors::kInvalidIntentDisposition;
232 return false;
233 }
234 if (value == values::kIntentDispositionInline)
235 intent.disposition = WebIntentData::DISPOSITION_INLINE;
236 else
237 intent.disposition = WebIntentData::DISPOSITION_WINDOW;
238 }
239
240 intents->push_back(intent);
241 }
242 return true;
243 }
177 } // namespace 244 } // namespace
178 245
179 const FilePath::CharType Extension::kManifestFilename[] = 246 const FilePath::CharType Extension::kManifestFilename[] =
180 FILE_PATH_LITERAL("manifest.json"); 247 FILE_PATH_LITERAL("manifest.json");
181 const FilePath::CharType Extension::kLocaleFolder[] = 248 const FilePath::CharType Extension::kLocaleFolder[] =
182 FILE_PATH_LITERAL("_locales"); 249 FILE_PATH_LITERAL("_locales");
183 const FilePath::CharType Extension::kMessagesFilename[] = 250 const FilePath::CharType Extension::kMessagesFilename[] =
184 FILE_PATH_LITERAL("messages.json"); 251 FILE_PATH_LITERAL("messages.json");
185 252
186 #if defined(OS_WIN) 253 #if defined(OS_WIN)
(...skipping 2078 matching lines...) Expand 10 before | Expand all | Expand 10 after
2265 } 2332 }
2266 voice_data.event_types.insert(event_type); 2333 voice_data.event_types.insert(event_type);
2267 } 2334 }
2268 } 2335 }
2269 2336
2270 tts_voices_.push_back(voice_data); 2337 tts_voices_.push_back(voice_data);
2271 } 2338 }
2272 } 2339 }
2273 } 2340 }
2274 2341
2342 // Initialize web intents (optional).
2343 if (!InitializeWebIntents(source, &intents_, error))
2344 return false;
2345
2275 // Initialize incognito behavior. Apps default to split mode, extensions 2346 // Initialize incognito behavior. Apps default to split mode, extensions
2276 // default to spanning. 2347 // default to spanning.
2277 incognito_split_mode_ = is_app(); 2348 incognito_split_mode_ = is_app();
2278 if (source.HasKey(keys::kIncognito)) { 2349 if (source.HasKey(keys::kIncognito)) {
2279 std::string value; 2350 std::string value;
2280 if (!source.GetString(keys::kIncognito, &value)) { 2351 if (!source.GetString(keys::kIncognito, &value)) {
2281 *error = errors::kInvalidIncognitoBehavior; 2352 *error = errors::kInvalidIncognitoBehavior;
2282 return false; 2353 return false;
2283 } 2354 }
2284 if (value == values::kIncognitoSpanning) { 2355 if (value == values::kIncognitoSpanning) {
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
2897 already_disabled(false), 2968 already_disabled(false),
2898 extension(extension) {} 2969 extension(extension) {}
2899 2970
2900 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 2971 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
2901 const Extension* extension, 2972 const Extension* extension,
2902 const ExtensionPermissionSet* permissions, 2973 const ExtensionPermissionSet* permissions,
2903 Reason reason) 2974 Reason reason)
2904 : reason(reason), 2975 : reason(reason),
2905 extension(extension), 2976 extension(extension),
2906 permissions(permissions) {} 2977 permissions(permissions) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698