| Index: chrome/browser/extensions/extension_menu_manager.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/extension_menu_manager.cc (revision 117097)
|
| +++ chrome/browser/extensions/extension_menu_manager.cc (working copy)
|
| @@ -139,8 +139,12 @@
|
| context_items_[extension_id].push_back(item);
|
| items_by_id_[item->id()] = item;
|
|
|
| - if (item->type() == ExtensionMenuItem::RADIO && item->checked())
|
| - RadioItemSelected(item);
|
| + if (item->type() == ExtensionMenuItem::RADIO) {
|
| + if (item->checked())
|
| + RadioItemSelected(item);
|
| + else
|
| + SanitizeRadioList(context_items_[extension_id]);
|
| + }
|
|
|
| // If this is the first item for this extension, start loading its icon.
|
| if (first_item)
|
| @@ -158,6 +162,10 @@
|
| return false;
|
| parent->AddChild(child);
|
| items_by_id_[child->id()] = child;
|
| +
|
| + if (child->type() == ExtensionMenuItem::RADIO)
|
| + SanitizeRadioList(parent->children());
|
| +
|
| return true;
|
| }
|
|
|
| @@ -201,6 +209,7 @@
|
| ExtensionMenuItem* taken =
|
| old_parent->ReleaseChild(child_id, false /* non-recursive search*/);
|
| DCHECK(taken == child);
|
| + SanitizeRadioList(old_parent->children());
|
| } else {
|
| // This is a top-level item, so we need to pull it out of our list of
|
| // top-level items.
|
| @@ -217,13 +226,16 @@
|
| return false;
|
| }
|
| list.erase(j);
|
| + SanitizeRadioList(list);
|
| }
|
|
|
| if (new_parent) {
|
| new_parent->AddChild(child);
|
| + SanitizeRadioList(new_parent->children());
|
| } else {
|
| context_items_[child->extension_id()].push_back(child);
|
| child->parent_id_.reset(NULL);
|
| + SanitizeRadioList(context_items_[child->extension_id()]);
|
| }
|
| return true;
|
| }
|
| @@ -254,6 +266,7 @@
|
| delete *j;
|
| list.erase(j);
|
| result = true;
|
| + SanitizeRadioList(list);
|
| break;
|
| } else {
|
| // See if the item to remove was found as a descendant of the current
|
| @@ -262,6 +275,7 @@
|
| if (child) {
|
| items_removed = child->RemoveAllDescendants();
|
| items_removed.insert(id);
|
| + SanitizeRadioList(GetItemById(*child->parent_id())->children());
|
| delete child;
|
| result = true;
|
| break;
|
| @@ -449,6 +463,63 @@
|
| item->extension_id(), event_name, json_args, profile, GURL());
|
| }
|
|
|
| +void ExtensionMenuManager::SanitizeRadioList(
|
| + const ExtensionMenuItem::List& item_list) {
|
| + ExtensionMenuItem::List::const_iterator i = item_list.begin();
|
| + while (i != item_list.end()) {
|
| + if ((*i)->type() != ExtensionMenuItem::RADIO) {
|
| + ++i;
|
| + break;
|
| + }
|
| +
|
| + // Uncheck any checked radio items in the run, and at the end reset
|
| + // the appropriate one to checked. If no check radio items were found,
|
| + // then check the first radio item in the run.
|
| + ExtensionMenuItem::List::const_iterator last_checked = item_list.end();
|
| + ExtensionMenuItem::List::const_iterator radio_run_iter;
|
| + for (radio_run_iter = i; radio_run_iter != item_list.end();
|
| + ++radio_run_iter) {
|
| + if ((*radio_run_iter)->type() != ExtensionMenuItem::RADIO) {
|
| + break;
|
| + }
|
| +
|
| + if ((*radio_run_iter)->checked()) {
|
| + last_checked = radio_run_iter;
|
| + (*radio_run_iter)->SetChecked(false);
|
| + }
|
| + }
|
| +
|
| + if (last_checked != item_list.end())
|
| + (*last_checked)->SetChecked(true);
|
| + else
|
| + (*i)->SetChecked(true);
|
| +
|
| + i = radio_run_iter;
|
| + }
|
| +}
|
| +
|
| +bool ExtensionMenuManager::ItemUpdated(const ExtensionMenuItem::Id& id) {
|
| + if (!ContainsKey(items_by_id_, id))
|
| + return false;
|
| +
|
| + ExtensionMenuItem* menu_item = GetItemById(id);
|
| + DCHECK(menu_item);
|
| +
|
| + if (menu_item->parent_id()) {
|
| + SanitizeRadioList(GetItemById(*menu_item->parent_id())->children());
|
| + } else {
|
| + std::string extension_id = menu_item->extension_id();
|
| + MenuItemMap::iterator i = context_items_.find(extension_id);
|
| + if (i == context_items_.end()) {
|
| + NOTREACHED();
|
| + return false;
|
| + }
|
| + SanitizeRadioList(i->second);
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| void ExtensionMenuManager::Observe(
|
| int type,
|
| const content::NotificationSource& source,
|
|
|