| 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 313 |
| 314 // Helper method that loads a PageAction or BrowserAction object from a | 314 // Helper method that loads a PageAction or BrowserAction object from a |
| 315 // dictionary in the page_actions list or browser_action key of the manifest. | 315 // dictionary in the page_actions list or browser_action key of the manifest. |
| 316 ContextualAction* Extension::LoadContextualActionHelper( | 316 ContextualAction* Extension::LoadContextualActionHelper( |
| 317 const DictionaryValue* page_action, int definition_index, | 317 const DictionaryValue* page_action, int definition_index, |
| 318 std::string* error, ContextualAction::ContextualActionType action_type) { | 318 std::string* error, ContextualAction::ContextualActionType action_type) { |
| 319 scoped_ptr<ContextualAction> result(new ContextualAction()); | 319 scoped_ptr<ContextualAction> result(new ContextualAction()); |
| 320 result->set_extension_id(id()); | 320 result->set_extension_id(id()); |
| 321 result->set_type(action_type); | 321 result->set_type(action_type); |
| 322 | 322 |
| 323 ListValue* icons; | 323 ListValue* icons = NULL; |
| 324 // Read the page action |icons|. | 324 // Read the page action |icons|. |
| 325 if (!page_action->HasKey(keys::kPageActionIcons) || | 325 if (!page_action->HasKey(keys::kPageActionIcons) || |
| 326 !page_action->GetList(keys::kPageActionIcons, &icons) || | 326 !page_action->GetList(keys::kPageActionIcons, &icons) || |
| 327 icons->GetSize() == 0) { | 327 icons->GetSize() == 0) { |
| 328 *error = ExtensionErrorUtils::FormatErrorMessage( | 328 // Icons are only required for page actions. |
| 329 errors::kInvalidPageActionIconPaths, IntToString(definition_index)); | 329 if (action_type == ContextualAction::PAGE_ACTION) { |
| 330 return NULL; | 330 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 331 errors::kInvalidPageActionIconPaths, IntToString(definition_index)); |
| 332 return NULL; |
| 333 } |
| 331 } | 334 } |
| 332 | 335 |
| 333 int icon_count = 0; | 336 int icon_count = 0; |
| 334 for (ListValue::const_iterator iter = icons->begin(); | 337 if (icons) { |
| 335 iter != icons->end(); ++iter) { | 338 for (ListValue::const_iterator iter = icons->begin(); |
| 336 std::string path; | 339 iter != icons->end(); ++iter) { |
| 337 if (!(*iter)->GetAsString(&path) || path.empty()) { | 340 std::string path; |
| 338 *error = ExtensionErrorUtils::FormatErrorMessage( | 341 if (!(*iter)->GetAsString(&path) || path.empty()) { |
| 339 errors::kInvalidPageActionIconPath, | 342 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 340 IntToString(definition_index), IntToString(icon_count)); | 343 errors::kInvalidPageActionIconPath, |
| 341 return NULL; | 344 IntToString(definition_index), IntToString(icon_count)); |
| 345 return NULL; |
| 346 } |
| 347 |
| 348 result->AddIconPath(path); |
| 349 ++icon_count; |
| 342 } | 350 } |
| 343 | |
| 344 result->AddIconPath(path); | |
| 345 ++icon_count; | |
| 346 } | 351 } |
| 347 | 352 |
| 348 if (action_type == ContextualAction::BROWSER_ACTION) { | 353 if (action_type == ContextualAction::BROWSER_ACTION) { |
| 349 result->set_id(""); // Not needed (only 1 browser action per extension). | 354 result->set_id(""); // Not needed (only 1 browser action per extension). |
| 350 } else { | 355 } else { |
| 351 // Read the page action |id|. | 356 // Read the page action |id|. |
| 352 std::string id; | 357 std::string id; |
| 353 if (!page_action->GetString(keys::kPageActionId, &id)) { | 358 if (!page_action->GetString(keys::kPageActionId, &id)) { |
| 354 *error = ExtensionErrorUtils::FormatErrorMessage( | 359 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 355 errors::kInvalidPageActionId, IntToString(definition_index)); | 360 errors::kInvalidPageActionId, IntToString(definition_index)); |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 UserScript::PatternList::const_iterator pattern = | 1138 UserScript::PatternList::const_iterator pattern = |
| 1134 content_script->url_patterns().begin(); | 1139 content_script->url_patterns().begin(); |
| 1135 for (; pattern != content_script->url_patterns().end(); ++pattern) { | 1140 for (; pattern != content_script->url_patterns().end(); ++pattern) { |
| 1136 if (pattern->match_subdomains() && pattern->host().empty()) | 1141 if (pattern->match_subdomains() && pattern->host().empty()) |
| 1137 return true; | 1142 return true; |
| 1138 } | 1143 } |
| 1139 } | 1144 } |
| 1140 | 1145 |
| 1141 return false; | 1146 return false; |
| 1142 } | 1147 } |
| OLD | NEW |