OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 *error = ExtensionErrorUtils::FormatErrorMessage( | 378 *error = ExtensionErrorUtils::FormatErrorMessage( |
379 errors::kInvalidPageActionPopupPath, url_str); | 379 errors::kInvalidPageActionPopupPath, url_str); |
380 return NULL; | 380 return NULL; |
381 } | 381 } |
382 result->set_popup_url(url); | 382 result->set_popup_url(url); |
383 } | 383 } |
384 | 384 |
385 return result.release(); | 385 return result.release(); |
386 } | 386 } |
387 | 387 |
| 388 ExtensionAction2* Extension::LoadExtensionAction2Helper( |
| 389 const DictionaryValue* extension_action, std::string* error) { |
| 390 scoped_ptr<ExtensionAction2> result(new ExtensionAction2()); |
| 391 result->set_extension_id(id()); |
| 392 |
| 393 // TODO(EXTENSIONS_DEPRECATED): icons list is obsolete. |
| 394 ListValue* icons = NULL; |
| 395 if (extension_action->HasKey(keys::kPageActionIcons) && |
| 396 extension_action->GetList(keys::kPageActionIcons, &icons)) { |
| 397 for (ListValue::const_iterator iter = icons->begin(); |
| 398 iter != icons->end(); ++iter) { |
| 399 std::string path; |
| 400 if (!(*iter)->GetAsString(&path) || path.empty()) { |
| 401 *error = errors::kInvalidPageActionIconPath; |
| 402 return NULL; |
| 403 } |
| 404 |
| 405 result->icon_paths()->push_back(path); |
| 406 result->SetDefaultIcon(path); |
| 407 } |
| 408 } |
| 409 |
| 410 // TODO(EXTENSIONS_DEPRECATED): Read the page action |id| (optional). |
| 411 std::string id; |
| 412 if (extension_action->HasKey(keys::kPageActionId)) { |
| 413 if (!extension_action->GetString(keys::kPageActionId, &id)) { |
| 414 *error = errors::kInvalidPageActionId; |
| 415 return NULL; |
| 416 } |
| 417 result->set_id(id); |
| 418 } |
| 419 |
| 420 std::string default_icon; |
| 421 // Read the page action |default_icon| (optional). |
| 422 if (extension_action->HasKey(keys::kPageActionDefaultIcon)) { |
| 423 if (!extension_action->GetString(keys::kPageActionDefaultIcon, |
| 424 &default_icon) || |
| 425 default_icon.empty()) { |
| 426 *error = errors::kInvalidPageActionIconPath; |
| 427 return NULL; |
| 428 } |
| 429 result->SetDefaultIcon(default_icon); |
| 430 } |
| 431 |
| 432 // Read the page action |default_title|. |
| 433 std::string title; |
| 434 if (!extension_action->GetString(keys::kName, &title) && |
| 435 !extension_action->GetString(keys::kPageActionDefaultTitle, &title)) { |
| 436 *error = errors::kInvalidPageActionDefaultTitle; |
| 437 return NULL; |
| 438 } |
| 439 result->SetTitle(ExtensionAction2::kDefaultTabId, title); |
| 440 |
| 441 // Read the action's |popup| (optional). |
| 442 DictionaryValue* popup = NULL; |
| 443 std::string url_str; |
| 444 if (extension_action->HasKey(keys::kPageActionPopup) && |
| 445 !extension_action->GetDictionary(keys::kPageActionPopup, &popup) && |
| 446 !extension_action->GetString(keys::kPageActionPopup, &url_str)) { |
| 447 *error = errors::kInvalidPageActionPopup; |
| 448 return NULL; |
| 449 } |
| 450 if (popup) { |
| 451 // TODO(EXTENSIONS_DEPRECATED): popup is a string only |
| 452 if (!popup->GetString(keys::kPageActionPopupPath, &url_str)) { |
| 453 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 454 errors::kInvalidPageActionPopupPath, "<missing>"); |
| 455 return NULL; |
| 456 } |
| 457 GURL url = GetResourceURL(url_str); |
| 458 if (!url.is_valid()) { |
| 459 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 460 errors::kInvalidPageActionPopupPath, url_str); |
| 461 return NULL; |
| 462 } |
| 463 result->set_popup_url(url); |
| 464 } else if (!url_str.empty()) { |
| 465 GURL url = GetResourceURL(url_str); |
| 466 if (!url.is_valid()) { |
| 467 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 468 errors::kInvalidPageActionPopupPath, url_str); |
| 469 return NULL; |
| 470 } |
| 471 result->set_popup_url(url); |
| 472 } |
| 473 |
| 474 return result.release(); |
| 475 } |
| 476 |
388 bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) { | 477 bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) { |
389 // Generate a map of allowable keys | 478 // Generate a map of allowable keys |
390 static std::map<std::wstring, bool> theme_keys; | 479 static std::map<std::wstring, bool> theme_keys; |
391 static bool theme_key_mapped = false; | 480 static bool theme_key_mapped = false; |
392 if (!theme_key_mapped) { | 481 if (!theme_key_mapped) { |
393 for (size_t i = 0; i < arraysize(kValidThemeKeys); ++i) { | 482 for (size_t i = 0; i < arraysize(kValidThemeKeys); ++i) { |
394 theme_keys[kValidThemeKeys[i]] = true; | 483 theme_keys[kValidThemeKeys[i]] = true; |
395 } | 484 } |
396 theme_key_mapped = true; | 485 theme_key_mapped = true; |
397 } | 486 } |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 return false; | 1057 return false; |
969 } | 1058 } |
970 | 1059 |
971 DictionaryValue* browser_action_value; | 1060 DictionaryValue* browser_action_value; |
972 if (!source.GetDictionary(keys::kBrowserAction, &browser_action_value)) { | 1061 if (!source.GetDictionary(keys::kBrowserAction, &browser_action_value)) { |
973 *error = errors::kInvalidBrowserAction; | 1062 *error = errors::kInvalidBrowserAction; |
974 return false; | 1063 return false; |
975 } | 1064 } |
976 | 1065 |
977 browser_action_.reset( | 1066 browser_action_.reset( |
978 LoadExtensionActionHelper(browser_action_value, error, | 1067 LoadExtensionAction2Helper(browser_action_value, error)); |
979 ExtensionAction::BROWSER_ACTION)); | |
980 if (!browser_action_.get()) | 1068 if (!browser_action_.get()) |
981 return false; // Failed to parse browser action definition. | 1069 return false; // Failed to parse browser action definition. |
982 | |
983 browser_action_state_.reset( | |
984 new ExtensionActionState(browser_action_->title(), 0)); | |
985 } | 1070 } |
986 | 1071 |
987 // Initialize the permissions (optional). | 1072 // Initialize the permissions (optional). |
988 if (source.HasKey(keys::kPermissions)) { | 1073 if (source.HasKey(keys::kPermissions)) { |
989 ListValue* permissions = NULL; | 1074 ListValue* permissions = NULL; |
990 if (!source.GetList(keys::kPermissions, &permissions)) { | 1075 if (!source.GetList(keys::kPermissions, &permissions)) { |
991 *error = ExtensionErrorUtils::FormatErrorMessage( | 1076 *error = ExtensionErrorUtils::FormatErrorMessage( |
992 errors::kInvalidPermissions, ""); | 1077 errors::kInvalidPermissions, ""); |
993 return false; | 1078 return false; |
994 } | 1079 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 if (page_action_.get()) { | 1181 if (page_action_.get()) { |
1097 const std::vector<std::string>& icon_paths = page_action_->icon_paths(); | 1182 const std::vector<std::string>& icon_paths = page_action_->icon_paths(); |
1098 for (std::vector<std::string>::const_iterator iter = icon_paths.begin(); | 1183 for (std::vector<std::string>::const_iterator iter = icon_paths.begin(); |
1099 iter != icon_paths.end(); ++iter) { | 1184 iter != icon_paths.end(); ++iter) { |
1100 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(*iter))); | 1185 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(*iter))); |
1101 } | 1186 } |
1102 } | 1187 } |
1103 | 1188 |
1104 // browser action icons | 1189 // browser action icons |
1105 if (browser_action_.get()) { | 1190 if (browser_action_.get()) { |
1106 const std::vector<std::string>& icon_paths = browser_action_->icon_paths(); | 1191 std::vector<std::string>* icon_paths = browser_action_->icon_paths(); |
1107 for (std::vector<std::string>::const_iterator iter = icon_paths.begin(); | 1192 for (std::vector<std::string>::iterator iter = icon_paths->begin(); |
1108 iter != icon_paths.end(); ++iter) { | 1193 iter != icon_paths->end(); ++iter) { |
1109 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(*iter))); | 1194 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(*iter))); |
1110 } | 1195 } |
1111 } | 1196 } |
1112 | 1197 |
1113 return image_paths; | 1198 return image_paths; |
1114 } | 1199 } |
1115 | 1200 |
1116 bool Extension::GetBackgroundPageReady() { | 1201 bool Extension::GetBackgroundPageReady() { |
1117 return background_page_ready_ || background_url().is_empty(); | 1202 return background_page_ready_ || background_url().is_empty(); |
1118 } | 1203 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 UserScript::PatternList::const_iterator pattern = | 1258 UserScript::PatternList::const_iterator pattern = |
1174 content_script->url_patterns().begin(); | 1259 content_script->url_patterns().begin(); |
1175 for (; pattern != content_script->url_patterns().end(); ++pattern) { | 1260 for (; pattern != content_script->url_patterns().end(); ++pattern) { |
1176 if (pattern->match_subdomains() && pattern->host().empty()) | 1261 if (pattern->match_subdomains() && pattern->host().empty()) |
1177 return true; | 1262 return true; |
1178 } | 1263 } |
1179 } | 1264 } |
1180 | 1265 |
1181 return false; | 1266 return false; |
1182 } | 1267 } |
OLD | NEW |