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

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

Issue 545068: Allow extensions to add, remove, or change their page action popup. (Closed)
Patch Set: Rebase, to run trybots with test data in place. Created 10 years, 11 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
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/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 } 429 }
430 } else if (extension_action->HasKey(keys::kName)) { 430 } else if (extension_action->HasKey(keys::kName)) {
431 if (!extension_action->GetString(keys::kName, &title)) { 431 if (!extension_action->GetString(keys::kName, &title)) {
432 *error = errors::kInvalidPageActionName; 432 *error = errors::kInvalidPageActionName;
433 return NULL; 433 return NULL;
434 } 434 }
435 } 435 }
436 result->SetTitle(ExtensionAction::kDefaultTabId, title); 436 result->SetTitle(ExtensionAction::kDefaultTabId, title);
437 437
438 // Read the action's |popup| (optional). 438 // Read the action's |popup| (optional).
439 DictionaryValue* popup = NULL; 439 const wchar_t* popup_key = NULL;
440 std::string url_str; 440 if (extension_action->HasKey(keys::kPageActionDefaultPopup))
441 if (extension_action->HasKey(keys::kPageActionPopup) && 441 popup_key = keys::kPageActionDefaultPopup;
442 !extension_action->GetDictionary(keys::kPageActionPopup, &popup) && 442
443 !extension_action->GetString(keys::kPageActionPopup, &url_str)) { 443 // For backward compatibility, alias old key "popup" to new
444 *error = errors::kInvalidPageActionPopup; 444 // key "default_popup".
445 return NULL; 445 if (extension_action->HasKey(keys::kPageActionPopup)) {
446 } 446 if (popup_key) {
447 if (popup) {
448 // TODO(EXTENSIONS_DEPRECATED): popup is a string only
449 if (!popup->GetString(keys::kPageActionPopupPath, &url_str)) {
450 *error = ExtensionErrorUtils::FormatErrorMessage( 447 *error = ExtensionErrorUtils::FormatErrorMessage(
451 errors::kInvalidPageActionPopupPath, "<missing>"); 448 errors::kInvalidPageActionOldAndNewKeys,
449 WideToASCII(keys::kPageActionDefaultPopup),
450 WideToASCII(keys::kPageActionPopup));
452 return NULL; 451 return NULL;
453 } 452 }
454 GURL url = GetResourceURL(url_str); 453 popup_key = keys::kPageActionPopup;
455 if (!url.is_valid()) { 454 }
456 *error = ExtensionErrorUtils::FormatErrorMessage( 455
457 errors::kInvalidPageActionPopupPath, url_str); 456 if (popup_key) {
457 DictionaryValue* popup = NULL;
458 std::string url_str;
459
460 if (extension_action->GetString(popup_key, &url_str)) {
461 // On success, |url_str| is set. Nothing else to do.
462 } else if (extension_action->GetDictionary(popup_key, &popup)) {
463 // TODO(EXTENSIONS_DEPRECATED): popup is now a string only.
464 // Support the old dictionary format for backward compatibility.
465 if (!popup->GetString(keys::kPageActionPopupPath, &url_str)) {
466 *error = ExtensionErrorUtils::FormatErrorMessage(
467 errors::kInvalidPageActionPopupPath, "<missing>");
468 return NULL;
469 }
470 } else {
471 *error = errors::kInvalidPageActionPopup;
458 return NULL; 472 return NULL;
459 } 473 }
460 result->SetPopupUrl(ExtensionAction::kDefaultTabId, url); 474
461 } else if (!url_str.empty()) { 475 if (!url_str.empty()) {
462 GURL url = GetResourceURL(url_str); 476 // An empty string is treated as having no popup.
463 if (!url.is_valid()) { 477 GURL url = GetResourceURL(url_str);
464 *error = ExtensionErrorUtils::FormatErrorMessage( 478 if (!url.is_valid()) {
465 errors::kInvalidPageActionPopupPath, url_str); 479 *error = ExtensionErrorUtils::FormatErrorMessage(
466 return NULL; 480 errors::kInvalidPageActionPopupPath, url_str);
481 return NULL;
482 }
483 result->SetPopupUrl(ExtensionAction::kDefaultTabId, url);
484 } else {
485 DCHECK(!result->HasPopup(ExtensionAction::kDefaultTabId))
486 << "Shouldn't be posible for the popup to be set.";
467 } 487 }
468 result->SetPopupUrl(ExtensionAction::kDefaultTabId, url);
469 } 488 }
470 489
471 return result.release(); 490 return result.release();
472 } 491 }
473 492
474 bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) { 493 bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) {
475 // Generate a map of allowable keys 494 // Generate a map of allowable keys
476 static std::map<std::wstring, bool> theme_keys; 495 static std::map<std::wstring, bool> theme_keys;
477 static bool theme_key_mapped = false; 496 static bool theme_key_mapped = false;
478 if (!theme_key_mapped) { 497 if (!theme_key_mapped) {
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 UserScript::PatternList::const_iterator pattern = 1396 UserScript::PatternList::const_iterator pattern =
1378 content_script->url_patterns().begin(); 1397 content_script->url_patterns().begin();
1379 for (; pattern != content_script->url_patterns().end(); ++pattern) { 1398 for (; pattern != content_script->url_patterns().end(); ++pattern) {
1380 if (pattern->match_subdomains() && pattern->host().empty()) 1399 if (pattern->match_subdomains() && pattern->host().empty())
1381 return true; 1400 return true;
1382 } 1401 }
1383 } 1402 }
1384 1403
1385 return false; 1404 return false;
1386 } 1405 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/static/pageAction.html ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698