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

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

Issue 149046: PageActions can now specify multiple icons and switch between them... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/page_action.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 int Extension::id_counter_ = 0; 49 int Extension::id_counter_ = 0;
50 50
51 const char Extension::kManifestFilename[] = "manifest.json"; 51 const char Extension::kManifestFilename[] = "manifest.json";
52 52
53 const wchar_t* Extension::kBackgroundKey = L"background_page"; 53 const wchar_t* Extension::kBackgroundKey = L"background_page";
54 const wchar_t* Extension::kContentScriptsKey = L"content_scripts"; 54 const wchar_t* Extension::kContentScriptsKey = L"content_scripts";
55 const wchar_t* Extension::kCssKey = L"css"; 55 const wchar_t* Extension::kCssKey = L"css";
56 const wchar_t* Extension::kDescriptionKey = L"description"; 56 const wchar_t* Extension::kDescriptionKey = L"description";
57 const wchar_t* Extension::kIconPathKey = L"icon"; 57 const wchar_t* Extension::kIconPathKey = L"icon";
58 const wchar_t* Extension::kIconPathsKey = L"icons";
58 const wchar_t* Extension::kJsKey = L"js"; 59 const wchar_t* Extension::kJsKey = L"js";
59 const wchar_t* Extension::kMatchesKey = L"matches"; 60 const wchar_t* Extension::kMatchesKey = L"matches";
60 const wchar_t* Extension::kNameKey = L"name"; 61 const wchar_t* Extension::kNameKey = L"name";
61 const wchar_t* Extension::kPageActionIdKey = L"id"; 62 const wchar_t* Extension::kPageActionIdKey = L"id";
62 const wchar_t* Extension::kPageActionsKey = L"page_actions"; 63 const wchar_t* Extension::kPageActionsKey = L"page_actions";
63 const wchar_t* Extension::kPermissionsKey = L"permissions"; 64 const wchar_t* Extension::kPermissionsKey = L"permissions";
64 const wchar_t* Extension::kPluginsKey = L"plugins"; 65 const wchar_t* Extension::kPluginsKey = L"plugins";
65 const wchar_t* Extension::kPluginsPathKey = L"path"; 66 const wchar_t* Extension::kPluginsPathKey = L"path";
66 const wchar_t* Extension::kPluginsPublicKey = L"public"; 67 const wchar_t* Extension::kPluginsPublicKey = L"public";
67 const wchar_t* Extension::kPublicKeyKey = L"key"; 68 const wchar_t* Extension::kPublicKeyKey = L"key";
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 "Invalid value for 'content_scripts[*].matches. There must be at least one " 120 "Invalid value for 'content_scripts[*].matches. There must be at least one "
120 "match specified."; 121 "match specified.";
121 const char* Extension::kInvalidMatchError = 122 const char* Extension::kInvalidMatchError =
122 "Invalid value for 'content_scripts[*].matches[*]'."; 123 "Invalid value for 'content_scripts[*].matches[*]'.";
123 const char* Extension::kInvalidMatchesError = 124 const char* Extension::kInvalidMatchesError =
124 "Required value 'content_scripts[*].matches' is missing or invalid."; 125 "Required value 'content_scripts[*].matches' is missing or invalid.";
125 const char* Extension::kInvalidNameError = 126 const char* Extension::kInvalidNameError =
126 "Required value 'name' is missing or invalid."; 127 "Required value 'name' is missing or invalid.";
127 const char* Extension::kInvalidPageActionError = 128 const char* Extension::kInvalidPageActionError =
128 "Invalid value for 'page_actions[*]'."; 129 "Invalid value for 'page_actions[*]'.";
130 const char* Extension::kInvalidPageActionIconPathError =
131 "Invalid value for 'page_actions[*].icons[*]'.";
129 const char* Extension::kInvalidPageActionsListError = 132 const char* Extension::kInvalidPageActionsListError =
130 "Invalid value for 'page_actions'."; 133 "Invalid value for 'page_actions'.";
131 const char* Extension::kInvalidPageActionIconPathError = 134 const char* Extension::kInvalidPageActionIconPathsError =
132 "Invalid value for 'page_actions[*].icon'."; 135 "Required value 'page_actions[*].icons' is missing or invalid.";
133 const char* Extension::kInvalidPageActionIdError = 136 const char* Extension::kInvalidPageActionIdError =
134 "Required value 'id' is missing or invalid."; 137 "Required value 'id' is missing or invalid.";
135 const char* Extension::kInvalidPageActionTypeValueError = 138 const char* Extension::kInvalidPageActionTypeValueError =
136 "Invalid value for 'page_actions[*].type', expected 'tab' or 'permanent'."; 139 "Invalid value for 'page_actions[*].type', expected 'tab' or 'permanent'.";
137 const char* Extension::kInvalidPermissionsError = 140 const char* Extension::kInvalidPermissionsError =
138 "Required value 'permissions' is missing or invalid."; 141 "Required value 'permissions' is missing or invalid.";
139 const char* Extension::kInvalidPermissionCountWarning = 142 const char* Extension::kInvalidPermissionCountWarning =
140 "Warning, 'permissions' key found, but array is empty."; 143 "Warning, 'permissions' key found, but array is empty.";
141 const char* Extension::kInvalidPermissionError = 144 const char* Extension::kInvalidPermissionError =
142 "Invalid value for 'permissions[*]'."; 145 "Invalid value for 'permissions[*]'.";
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 394 }
392 395
393 // Helper method that loads a PageAction object from a dictionary in the 396 // Helper method that loads a PageAction object from a dictionary in the
394 // page_action list of the manifest. 397 // page_action list of the manifest.
395 PageAction* Extension::LoadPageActionHelper( 398 PageAction* Extension::LoadPageActionHelper(
396 const DictionaryValue* page_action, int definition_index, 399 const DictionaryValue* page_action, int definition_index,
397 std::string* error) { 400 std::string* error) {
398 scoped_ptr<PageAction> result(new PageAction()); 401 scoped_ptr<PageAction> result(new PageAction());
399 result->set_extension_id(id()); 402 result->set_extension_id(id());
400 403
401 // Read the page action |icon|. 404 ListValue* icons;
402 std::string icon; 405 // Read the page action |icons|.
403 if (!page_action->GetString(kIconPathKey, &icon)) { 406 if (!page_action->HasKey(kIconPathsKey) ||
407 !page_action->GetList(kIconPathsKey, &icons) ||
408 icons->GetSize() == 0) {
404 *error = ExtensionErrorUtils::FormatErrorMessage( 409 *error = ExtensionErrorUtils::FormatErrorMessage(
405 kInvalidPageActionIconPathError, IntToString(definition_index)); 410 kInvalidPageActionIconPathsError, IntToString(definition_index));
406 return NULL; 411 return NULL;
407 } 412 }
408 FilePath icon_path = path_.AppendASCII(icon); 413
409 result->set_icon_path(icon_path); 414 int icon_count = 0;
415 for (ListValue::const_iterator iter = icons->begin();
416 iter != icons->end(); ++iter) {
417 FilePath::StringType path;
418 if (!(*iter)->GetAsString(&path) || path.empty()) {
419 *error = ExtensionErrorUtils::FormatErrorMessage(
420 kInvalidPageActionIconPathError,
421 IntToString(definition_index), IntToString(icon_count));
422 return NULL;
423 }
424
425 FilePath icon_path = path_.Append(path);
426 result->AddIconPath(icon_path);
427 ++icon_count;
428 }
410 429
411 // Read the page action |id|. 430 // Read the page action |id|.
412 std::string id; 431 std::string id;
413 if (!page_action->GetString(kPageActionIdKey, &id)) { 432 if (!page_action->GetString(kPageActionIdKey, &id)) {
414 *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidPageActionIdError, 433 *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidPageActionIdError,
415 IntToString(definition_index)); 434 IntToString(definition_index));
416 return NULL; 435 return NULL;
417 } 436 }
418 result->set_id(id); 437 result->set_id(id);
419 438
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 return FilePath(); 516 return FilePath();
498 517
499 // Double-check that the path we ended up with is actually inside the 518 // Double-check that the path we ended up with is actually inside the
500 // extension root. 519 // extension root.
501 if (!extension_path.IsParent(ret_val)) 520 if (!extension_path.IsParent(ret_val))
502 return FilePath(); 521 return FilePath();
503 522
504 return ret_val; 523 return ret_val;
505 } 524 }
506 525
507 Extension::Extension(const FilePath& path) { 526 Extension::Extension(const FilePath& path) : is_theme_(false) {
508 DCHECK(path.IsAbsolute()); 527 DCHECK(path.IsAbsolute());
509 location_ = INVALID; 528 location_ = INVALID;
510 529
511 #if defined(OS_WIN) 530 #if defined(OS_WIN)
512 // Normalize any drive letter to upper-case. We do this for consistency with 531 // Normalize any drive letter to upper-case. We do this for consistency with
513 // net_utils::FilePathToFileURL(), which does the same thing, to make string 532 // net_utils::FilePathToFileURL(), which does the same thing, to make string
514 // comparisons simpler. 533 // comparisons simpler.
515 std::wstring path_str = path.value(); 534 std::wstring path_str = path.value();
516 if (path_str.size() >= 2 && path_str[0] >= L'a' && path_str[0] <= L'z' && 535 if (path_str.size() >= 2 && path_str[0] >= L'a' && path_str[0] <= L'z' &&
517 path_str[1] == ':') 536 path_str[1] == ':')
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 it != theme_images->end_keys(); ++it) { 951 it != theme_images->end_keys(); ++it) {
933 std::wstring val; 952 std::wstring val;
934 if (theme_images->GetString(*it, &val)) { 953 if (theme_images->GetString(*it, &val)) {
935 image_paths.insert(FilePath::FromWStringHack(val)); 954 image_paths.insert(FilePath::FromWStringHack(val));
936 } 955 }
937 } 956 }
938 } 957 }
939 958
940 for (PageActionMap::const_iterator it = page_actions().begin(); 959 for (PageActionMap::const_iterator it = page_actions().begin();
941 it != page_actions().end(); ++it) { 960 it != page_actions().end(); ++it) {
942 image_paths.insert(it->second->icon_path()); 961 const std::vector<FilePath>& icon_paths = it->second->icon_paths();
962 for (std::vector<FilePath>::const_iterator iter = icon_paths.begin();
963 iter != icon_paths.end(); ++iter) {
964 image_paths.insert(*iter);
965 }
943 } 966 }
944 967
945 return image_paths; 968 return image_paths;
946 } 969 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/page_action.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698