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

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

Issue 337035: Replace ExtensionAction with ExtensionAction2. (Closed)
Patch Set: Remove todo Created 11 years, 1 month 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 GURL url = GetResourceURL(WideToUTF8(relative)); 290 GURL url = GetResourceURL(WideToUTF8(relative));
291 ExtensionResource resource = GetResource(WideToUTF8(relative)); 291 ExtensionResource resource = GetResource(WideToUTF8(relative));
292 result->css_scripts().push_back(UserScript::File( 292 result->css_scripts().push_back(UserScript::File(
293 resource.extension_root(), resource.relative_path(), url)); 293 resource.extension_root(), resource.relative_path(), url));
294 } 294 }
295 } 295 }
296 296
297 return true; 297 return true;
298 } 298 }
299 299
300 ExtensionAction2* Extension::LoadExtensionAction2Helper( 300 ExtensionAction* Extension::LoadExtensionActionHelper(
301 const DictionaryValue* extension_action, std::string* error) { 301 const DictionaryValue* extension_action, std::string* error) {
302 scoped_ptr<ExtensionAction2> result(new ExtensionAction2()); 302 scoped_ptr<ExtensionAction> result(new ExtensionAction());
303 result->set_extension_id(id()); 303 result->set_extension_id(id());
304 304
305 // Page actions are hidden by default, and browser actions ignore 305 // Page actions are hidden by default, and browser actions ignore
306 // visibility. 306 // visibility.
307 result->SetIsVisible(ExtensionAction2::kDefaultTabId, false); 307 result->SetIsVisible(ExtensionAction::kDefaultTabId, false);
308 308
309 // TODO(EXTENSIONS_DEPRECATED): icons list is obsolete. 309 // TODO(EXTENSIONS_DEPRECATED): icons list is obsolete.
310 ListValue* icons = NULL; 310 ListValue* icons = NULL;
311 if (extension_action->HasKey(keys::kPageActionIcons) && 311 if (extension_action->HasKey(keys::kPageActionIcons) &&
312 extension_action->GetList(keys::kPageActionIcons, &icons)) { 312 extension_action->GetList(keys::kPageActionIcons, &icons)) {
313 for (ListValue::const_iterator iter = icons->begin(); 313 for (ListValue::const_iterator iter = icons->begin();
314 iter != icons->end(); ++iter) { 314 iter != icons->end(); ++iter) {
315 std::string path; 315 std::string path;
316 if (!(*iter)->GetAsString(&path) || path.empty()) { 316 if (!(*iter)->GetAsString(&path) || path.empty()) {
317 *error = errors::kInvalidPageActionIconPath; 317 *error = errors::kInvalidPageActionIconPath;
(...skipping 26 matching lines...) Expand all
344 result->set_default_icon_path(default_icon); 344 result->set_default_icon_path(default_icon);
345 } 345 }
346 346
347 // Read the page action |default_title|. 347 // Read the page action |default_title|.
348 std::string title; 348 std::string title;
349 if (!extension_action->GetString(keys::kName, &title) && 349 if (!extension_action->GetString(keys::kName, &title) &&
350 !extension_action->GetString(keys::kPageActionDefaultTitle, &title)) { 350 !extension_action->GetString(keys::kPageActionDefaultTitle, &title)) {
351 *error = errors::kInvalidPageActionDefaultTitle; 351 *error = errors::kInvalidPageActionDefaultTitle;
352 return NULL; 352 return NULL;
353 } 353 }
354 result->SetTitle(ExtensionAction2::kDefaultTabId, title); 354 result->SetTitle(ExtensionAction::kDefaultTabId, title);
355 355
356 // Read the action's |popup| (optional). 356 // Read the action's |popup| (optional).
357 DictionaryValue* popup = NULL; 357 DictionaryValue* popup = NULL;
358 std::string url_str; 358 std::string url_str;
359 if (extension_action->HasKey(keys::kPageActionPopup) && 359 if (extension_action->HasKey(keys::kPageActionPopup) &&
360 !extension_action->GetDictionary(keys::kPageActionPopup, &popup) && 360 !extension_action->GetDictionary(keys::kPageActionPopup, &popup) &&
361 !extension_action->GetString(keys::kPageActionPopup, &url_str)) { 361 !extension_action->GetString(keys::kPageActionPopup, &url_str)) {
362 *error = errors::kInvalidPageActionPopup; 362 *error = errors::kInvalidPageActionPopup;
363 return NULL; 363 return NULL;
364 } 364 }
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 return false; 939 return false;
940 } 940 }
941 941
942 DictionaryValue* page_action_value; 942 DictionaryValue* page_action_value;
943 if (!list_value->GetDictionary(0, &page_action_value)) { 943 if (!list_value->GetDictionary(0, &page_action_value)) {
944 *error = errors::kInvalidPageAction; 944 *error = errors::kInvalidPageAction;
945 return false; 945 return false;
946 } 946 }
947 947
948 page_action_.reset( 948 page_action_.reset(
949 LoadExtensionAction2Helper(page_action_value, error)); 949 LoadExtensionActionHelper(page_action_value, error));
950 if (!page_action_.get()) 950 if (!page_action_.get())
951 return false; // Failed to parse page action definition. 951 return false; // Failed to parse page action definition.
952 } else if (source.HasKey(keys::kPageAction)) { 952 } else if (source.HasKey(keys::kPageAction)) {
953 DictionaryValue* page_action_value; 953 DictionaryValue* page_action_value;
954 if (!source.GetDictionary(keys::kPageAction, &page_action_value)) { 954 if (!source.GetDictionary(keys::kPageAction, &page_action_value)) {
955 *error = errors::kInvalidPageAction; 955 *error = errors::kInvalidPageAction;
956 return false; 956 return false;
957 } 957 }
958 958
959 page_action_.reset( 959 page_action_.reset(
960 LoadExtensionAction2Helper(page_action_value, error)); 960 LoadExtensionActionHelper(page_action_value, error));
961 if (!page_action_.get()) 961 if (!page_action_.get())
962 return false; // Failed to parse page action definition. 962 return false; // Failed to parse page action definition.
963 } 963 }
964 964
965 // Initialize browser action (optional). 965 // Initialize browser action (optional).
966 if (source.HasKey(keys::kBrowserAction)) { 966 if (source.HasKey(keys::kBrowserAction)) {
967 // Restrict extensions to one UI surface. 967 // Restrict extensions to one UI surface.
968 if (source.HasKey(keys::kPageAction) || source.HasKey(keys::kPageActions)) { 968 if (source.HasKey(keys::kPageAction) || source.HasKey(keys::kPageActions)) {
969 *error = errors::kOneUISurfaceOnly; 969 *error = errors::kOneUISurfaceOnly;
970 return false; 970 return false;
971 } 971 }
972 972
973 DictionaryValue* browser_action_value; 973 DictionaryValue* browser_action_value;
974 if (!source.GetDictionary(keys::kBrowserAction, &browser_action_value)) { 974 if (!source.GetDictionary(keys::kBrowserAction, &browser_action_value)) {
975 *error = errors::kInvalidBrowserAction; 975 *error = errors::kInvalidBrowserAction;
976 return false; 976 return false;
977 } 977 }
978 978
979 browser_action_.reset( 979 browser_action_.reset(
980 LoadExtensionAction2Helper(browser_action_value, error)); 980 LoadExtensionActionHelper(browser_action_value, error));
981 if (!browser_action_.get()) 981 if (!browser_action_.get())
982 return false; // Failed to parse browser action definition. 982 return false; // Failed to parse browser action definition.
983 } 983 }
984 984
985 // Initialize the permissions (optional). 985 // Initialize the permissions (optional).
986 if (source.HasKey(keys::kPermissions)) { 986 if (source.HasKey(keys::kPermissions)) {
987 ListValue* permissions = NULL; 987 ListValue* permissions = NULL;
988 if (!source.GetList(keys::kPermissions, &permissions)) { 988 if (!source.GetList(keys::kPermissions, &permissions)) {
989 *error = ExtensionErrorUtils::FormatErrorMessage( 989 *error = ExtensionErrorUtils::FormatErrorMessage(
990 errors::kInvalidPermissions, ""); 990 errors::kInvalidPermissions, "");
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 UserScript::PatternList::const_iterator pattern = 1171 UserScript::PatternList::const_iterator pattern =
1172 content_script->url_patterns().begin(); 1172 content_script->url_patterns().begin();
1173 for (; pattern != content_script->url_patterns().end(); ++pattern) { 1173 for (; pattern != content_script->url_patterns().end(); ++pattern) {
1174 if (pattern->match_subdomains() && pattern->host().empty()) 1174 if (pattern->match_subdomains() && pattern->host().empty())
1175 return true; 1175 return true;
1176 } 1176 }
1177 } 1177 }
1178 1178
1179 return false; 1179 return false;
1180 } 1180 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_action.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698