| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/extensions/extension_toolbar_model.h" | 5 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/browser_event_router.h" | 7 #include "chrome/browser/extensions/browser_event_router.h" |
| 8 #include "chrome/browser/extensions/extension_prefs.h" | 8 #include "chrome/browser/extensions/extension_prefs.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
| 11 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_tabstrip.h" | 15 #include "chrome/browser/ui/browser_tabstrip.h" |
| 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
| 19 #include "chrome/common/extensions/extension_switch_utils.h" |
| 19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 20 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 21 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
| 22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 23 | 24 |
| 24 using extensions::Extension; | 25 using extensions::Extension; |
| 25 using extensions::ExtensionList; | 26 using extensions::ExtensionList; |
| 26 | 27 |
| 28 namespace { |
| 29 |
| 30 // Returns true if an |extension| is in an |extension_list|. |
| 31 bool IsInExtensionList(const Extension* extension, |
| 32 const extensions::ExtensionList& extension_list) { |
| 33 for (size_t i = 0; i < extension_list.size(); i++) { |
| 34 if (extension_list[i].get() == extension) |
| 35 return true; |
| 36 } |
| 37 return false; |
| 38 } |
| 39 |
| 40 } // namespace |
| 41 |
| 27 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service) | 42 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service) |
| 28 : service_(service), | 43 : service_(service), |
| 29 prefs_(service->profile()->GetPrefs()), | 44 prefs_(service->profile()->GetPrefs()), |
| 30 extensions_initialized_(false) { | 45 extensions_initialized_(false) { |
| 31 DCHECK(service_); | 46 DCHECK(service_); |
| 32 | 47 |
| 33 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 48 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 34 content::Source<Profile>(service_->profile())); | 49 content::Source<Profile>(service_->profile())); |
| 35 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 50 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 36 content::Source<Profile>(service_->profile())); | 51 content::Source<Profile>(service_->profile())); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 49 void ExtensionToolbarModel::AddObserver(Observer* observer) { | 64 void ExtensionToolbarModel::AddObserver(Observer* observer) { |
| 50 observers_.AddObserver(observer); | 65 observers_.AddObserver(observer); |
| 51 } | 66 } |
| 52 | 67 |
| 53 void ExtensionToolbarModel::RemoveObserver(Observer* observer) { | 68 void ExtensionToolbarModel::RemoveObserver(Observer* observer) { |
| 54 observers_.RemoveObserver(observer); | 69 observers_.RemoveObserver(observer); |
| 55 } | 70 } |
| 56 | 71 |
| 57 void ExtensionToolbarModel::MoveBrowserAction(const Extension* extension, | 72 void ExtensionToolbarModel::MoveBrowserAction(const Extension* extension, |
| 58 int index) { | 73 int index) { |
| 59 ExtensionList::iterator pos = std::find(begin(), end(), extension); | 74 ExtensionList::iterator pos = std::find(toolbar_items_.begin(), |
| 60 if (pos == end()) { | 75 toolbar_items_.end(), extension); |
| 76 if (pos == toolbar_items_.end()) { |
| 61 NOTREACHED(); | 77 NOTREACHED(); |
| 62 return; | 78 return; |
| 63 } | 79 } |
| 64 toolitems_.erase(pos); | 80 toolbar_items_.erase(pos); |
| 65 | 81 |
| 66 int i = 0; | 82 int i = 0; |
| 67 bool inserted = false; | 83 bool inserted = false; |
| 68 for (ExtensionList::iterator iter = begin(); iter != end(); ++iter, ++i) { | 84 for (ExtensionList::iterator iter = toolbar_items_.begin(); |
| 85 iter != toolbar_items_.end(); |
| 86 ++iter, ++i) { |
| 69 if (i == index) { | 87 if (i == index) { |
| 70 toolitems_.insert(iter, make_scoped_refptr(extension)); | 88 toolbar_items_.insert(iter, make_scoped_refptr(extension)); |
| 71 inserted = true; | 89 inserted = true; |
| 72 break; | 90 break; |
| 73 } | 91 } |
| 74 } | 92 } |
| 75 | 93 |
| 76 if (!inserted) { | 94 if (!inserted) { |
| 77 DCHECK_EQ(index, static_cast<int>(toolitems_.size())); | 95 DCHECK_EQ(index, static_cast<int>(toolbar_items_.size())); |
| 78 index = toolitems_.size(); | 96 index = toolbar_items_.size(); |
| 79 | 97 |
| 80 toolitems_.push_back(make_scoped_refptr(extension)); | 98 toolbar_items_.push_back(make_scoped_refptr(extension)); |
| 81 } | 99 } |
| 82 | 100 |
| 83 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); | 101 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); |
| 84 | 102 |
| 85 UpdatePrefs(); | 103 UpdatePrefs(); |
| 86 } | 104 } |
| 87 | 105 |
| 88 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( | 106 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( |
| 89 const Extension* extension, | 107 const Extension* extension, |
| 90 Browser* browser, | 108 Browser* browser, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 111 *popup_url_out = browser_action->GetPopupUrl(tab_id); | 129 *popup_url_out = browser_action->GetPopupUrl(tab_id); |
| 112 return ACTION_SHOW_POPUP; | 130 return ACTION_SHOW_POPUP; |
| 113 } | 131 } |
| 114 | 132 |
| 115 service_->browser_event_router()->BrowserActionExecuted( | 133 service_->browser_event_router()->BrowserActionExecuted( |
| 116 *browser_action, browser); | 134 *browser_action, browser); |
| 117 return ACTION_NONE; | 135 return ACTION_NONE; |
| 118 } | 136 } |
| 119 | 137 |
| 120 void ExtensionToolbarModel::SetVisibleIconCount(int count) { | 138 void ExtensionToolbarModel::SetVisibleIconCount(int count) { |
| 121 visible_icon_count_ = count == static_cast<int>(size()) ? -1 : count; | 139 visible_icon_count_ = |
| 140 count == static_cast<int>(toolbar_items_.size()) ? -1 : count; |
| 122 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); | 141 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); |
| 123 } | 142 } |
| 124 | 143 |
| 125 void ExtensionToolbarModel::Observe( | 144 void ExtensionToolbarModel::Observe( |
| 126 int type, | 145 int type, |
| 127 const content::NotificationSource& source, | 146 const content::NotificationSource& source, |
| 128 const content::NotificationDetails& details) { | 147 const content::NotificationDetails& details) { |
| 129 if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { | 148 if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { |
| 130 InitializeExtensionList(); | 149 InitializeExtensionLists(); |
| 131 return; | 150 return; |
| 132 } | 151 } |
| 133 | 152 |
| 134 if (!service_->is_ready()) | 153 if (!service_->is_ready()) |
| 135 return; | 154 return; |
| 136 | 155 |
| 137 const Extension* extension = NULL; | 156 const Extension* extension = NULL; |
| 138 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { | 157 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { |
| 139 extension = content::Details<extensions::UnloadedExtensionInfo>( | 158 extension = content::Details<extensions::UnloadedExtensionInfo>( |
| 140 details)->extension; | 159 details)->extension; |
| 141 } else { | 160 } else { |
| 142 extension = content::Details<const Extension>(details).ptr(); | 161 extension = content::Details<const Extension>(details).ptr(); |
| 143 } | 162 } |
| 163 ExtensionList* list_with_extension = FindListWithExtension(extension); |
| 144 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { | 164 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { |
| 145 // We don't want to add the same extension twice. It may have already been | 165 // We don't want to add the same extension twice. It may have already been |
| 146 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user | 166 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user |
| 147 // hides the browser action and then disables and enables the extension. | 167 // hides the browser action and then disables and enables the extension. |
| 148 for (size_t i = 0; i < toolitems_.size(); i++) { | 168 if (list_with_extension) |
| 149 if (toolitems_[i].get() == extension) | 169 return; |
| 150 return; // Already exists. | 170 if (extensions::switch_utils::IsActionBoxEnabled()) |
| 171 AddExtension(extension, &action_box_menu_items_); |
| 172 else if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) |
| 173 AddExtension(extension, &toolbar_items_); |
| 174 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { |
| 175 if (list_with_extension) |
| 176 RemoveExtension(extension, list_with_extension); |
| 177 } else if (type == |
| 178 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { |
| 179 if (extensions::switch_utils::IsActionBoxEnabled()) { |
| 180 // TODO(yefim): Implement this when implementing drag & drop |
| 181 // for action box menu. |
| 182 } else if ( |
| 183 service_->extension_prefs()->GetBrowserActionVisibility(extension)) { |
| 184 AddExtension(extension, &toolbar_items_); |
| 185 } else { |
| 186 RemoveExtension(extension, &toolbar_items_); |
| 151 } | 187 } |
| 152 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) | |
| 153 AddExtension(extension); | |
| 154 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { | |
| 155 RemoveExtension(extension); | |
| 156 } else if ( | |
| 157 type == | |
| 158 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { | |
| 159 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) | |
| 160 AddExtension(extension); | |
| 161 else | |
| 162 RemoveExtension(extension); | |
| 163 } else { | 188 } else { |
| 164 NOTREACHED() << "Received unexpected notification"; | 189 NOTREACHED() << "Received unexpected notification"; |
| 165 } | 190 } |
| 166 } | 191 } |
| 167 | 192 |
| 168 void ExtensionToolbarModel::AddExtension(const Extension* extension) { | 193 void ExtensionToolbarModel::AddExtension(const Extension* extension, |
| 194 ExtensionList* list) { |
| 169 // We only care about extensions with browser actions. | 195 // We only care about extensions with browser actions. |
| 170 if (!extension->browser_action()) | 196 if (!extension->browser_action()) |
| 171 return; | 197 return; |
| 172 | 198 |
| 173 if (extension->id() == last_extension_removed_ && | 199 if (extension->id() == last_extension_removed_ && |
| 174 last_extension_removed_index_ < toolitems_.size()) { | 200 last_extension_removed_index_ < list->size()) { |
| 175 toolitems_.insert(begin() + last_extension_removed_index_, | 201 list->insert(list->begin() + last_extension_removed_index_, |
| 176 make_scoped_refptr(extension)); | 202 make_scoped_refptr(extension)); |
| 177 FOR_EACH_OBSERVER(Observer, observers_, | 203 FOR_EACH_OBSERVER(Observer, observers_, |
| 178 BrowserActionAdded(extension, last_extension_removed_index_)); | 204 BrowserActionAdded(extension, last_extension_removed_index_)); |
| 179 } else { | 205 } else { |
| 180 toolitems_.push_back(make_scoped_refptr(extension)); | 206 list->push_back(make_scoped_refptr(extension)); |
| 181 FOR_EACH_OBSERVER(Observer, observers_, | 207 FOR_EACH_OBSERVER(Observer, observers_, |
| 182 BrowserActionAdded(extension, toolitems_.size() - 1)); | 208 BrowserActionAdded(extension, list->size() - 1)); |
| 183 } | 209 } |
| 184 | 210 |
| 185 last_extension_removed_ = ""; | 211 last_extension_removed_ = ""; |
| 186 last_extension_removed_index_ = -1; | 212 last_extension_removed_index_ = -1; |
| 187 | 213 |
| 188 UpdatePrefs(); | 214 UpdatePrefs(); |
| 189 } | 215 } |
| 190 | 216 |
| 191 void ExtensionToolbarModel::RemoveExtension(const Extension* extension) { | 217 void ExtensionToolbarModel::RemoveExtension(const Extension* extension, |
| 192 ExtensionList::iterator pos = std::find(begin(), end(), extension); | 218 ExtensionList* list) { |
| 193 if (pos == end()) { | 219 ExtensionList::iterator pos = |
| 220 std::find(list->begin(), list->end(), extension); |
| 221 if (pos == list->end()) |
| 194 return; | 222 return; |
| 195 } | |
| 196 | 223 |
| 197 last_extension_removed_ = extension->id(); | 224 last_extension_removed_ = extension->id(); |
| 198 last_extension_removed_index_ = pos - begin(); | 225 last_extension_removed_index_ = pos - list->begin(); |
| 199 | 226 |
| 200 toolitems_.erase(pos); | 227 list->erase(pos); |
| 201 FOR_EACH_OBSERVER(Observer, observers_, | 228 FOR_EACH_OBSERVER(Observer, observers_, |
| 202 BrowserActionRemoved(extension)); | 229 BrowserActionRemoved(extension)); |
| 203 | 230 |
| 204 UpdatePrefs(); | 231 UpdatePrefs(); |
| 205 } | 232 } |
| 206 | 233 |
| 234 extensions::ExtensionList* ExtensionToolbarModel::FindListWithExtension( |
| 235 const Extension* extension) { |
| 236 if (IsInExtensionList(extension, toolbar_items_)) |
| 237 return &toolbar_items_; |
| 238 return IsInExtensionList(extension, action_box_menu_items_) ? |
| 239 &action_box_menu_items_ : NULL; |
| 240 } |
| 241 |
| 242 |
| 207 // Combine the currently enabled extensions that have browser actions (which | 243 // Combine the currently enabled extensions that have browser actions (which |
| 208 // we get from the ExtensionService) with the ordering we get from the | 244 // we get from the ExtensionService) with the ordering we get from the |
| 209 // pref service. For robustness we use a somewhat inefficient process: | 245 // pref service. For robustness we use a somewhat inefficient process: |
| 210 // 1. Create a vector of extensions sorted by their pref values. This vector may | 246 // 1. Create a vector of extensions sorted by their pref values. This vector may |
| 211 // have holes. | 247 // have holes. |
| 212 // 2. Create a vector of extensions that did not have a pref value. | 248 // 2. Create a vector of extensions that did not have a pref value. |
| 213 // 3. Remove holes from the sorted vector and append the unsorted vector. | 249 // 3. Remove holes from the sorted vector and append the unsorted vector. |
| 214 void ExtensionToolbarModel::InitializeExtensionList() { | 250 void ExtensionToolbarModel::InitializeExtensionLists() { |
| 215 DCHECK(service_->is_ready()); | 251 DCHECK(service_->is_ready()); |
| 216 | 252 |
| 217 std::vector<std::string> pref_order = service_->extension_prefs()-> | 253 if (extensions::switch_utils::IsActionBoxEnabled()) |
| 218 GetToolbarOrder(); | 254 PopulateForActionBoxMode(); |
| 255 else |
| 256 PopulateForNonActionBoxMode(); |
| 257 |
| 258 UpdatePrefs(); |
| 259 |
| 260 extensions_initialized_ = true; |
| 261 FOR_EACH_OBSERVER(Observer, observers_, ModelLoaded()); |
| 262 } |
| 263 |
| 264 void ExtensionToolbarModel::PopulateForActionBoxMode() { |
| 265 const extensions::ExtensionPrefs::ExtensionIdSet toolbar_order = |
| 266 service_->extension_prefs()->GetToolbarOrder(); |
| 267 extensions::ExtensionPrefs::ExtensionIdSet action_box_order = |
| 268 service_->extension_prefs()->GetActionBoxOrder(); |
| 269 |
| 270 // Add all browser actions not already in the toolbar or action box |
| 271 // to the action box (the prefs list may omit some extensions). |
| 272 for (ExtensionSet::const_iterator iter = service_->extensions()->begin(); |
| 273 iter != service_->extensions()->end(); ++iter) { |
| 274 const Extension* extension = *iter; |
| 275 if (!extension->browser_action()) |
| 276 continue; |
| 277 |
| 278 if (std::find(toolbar_order.begin(), toolbar_order.end(), |
| 279 extension->id()) != toolbar_order.end()) |
| 280 continue; |
| 281 |
| 282 if (std::find(action_box_order.begin(), action_box_order.end(), |
| 283 extension->id()) != action_box_order.end()) |
| 284 continue; |
| 285 |
| 286 action_box_order.push_back(extension->id()); |
| 287 } |
| 288 |
| 289 FillExtensionList(action_box_order, &action_box_menu_items_); |
| 290 FillExtensionList(toolbar_order, &toolbar_items_); |
| 291 } |
| 292 |
| 293 void ExtensionToolbarModel::PopulateForNonActionBoxMode() { |
| 294 const extensions::ExtensionPrefs::ExtensionIdSet pref_order = |
| 295 service_->extension_prefs()->GetToolbarOrder(); |
| 219 // Items that have a pref for their position. | 296 // Items that have a pref for their position. |
| 220 ExtensionList sorted; | 297 ExtensionList sorted; |
| 221 sorted.resize(pref_order.size(), NULL); | 298 sorted.resize(pref_order.size(), NULL); |
| 222 // The items that don't have a pref for their position. | 299 // The items that don't have a pref for their position. |
| 223 ExtensionList unsorted; | 300 ExtensionList unsorted; |
| 224 | 301 |
| 225 // Create the lists. | 302 // Create the lists. |
| 226 for (ExtensionSet::const_iterator it = service_->extensions()->begin(); | 303 for (ExtensionSet::const_iterator it = service_->extensions()->begin(); |
| 227 it != service_->extensions()->end(); ++it) { | 304 it != service_->extensions()->end(); ++it) { |
| 228 const Extension* extension = *it; | 305 const Extension* extension = *it; |
| 229 if (!extension->browser_action()) | 306 if (!extension->browser_action()) |
| 230 continue; | 307 continue; |
| 231 if (!service_->extension_prefs()->GetBrowserActionVisibility(extension)) | 308 if (!service_->extension_prefs()->GetBrowserActionVisibility(extension)) |
| 232 continue; | 309 continue; |
| 233 | 310 |
| 234 std::vector<std::string>::iterator pos = | 311 extensions::ExtensionPrefs::ExtensionIdSet::const_iterator pos = |
| 235 std::find(pref_order.begin(), pref_order.end(), extension->id()); | 312 std::find(pref_order.begin(), pref_order.end(), extension->id()); |
| 236 if (pos != pref_order.end()) { | 313 if (pos != pref_order.end()) |
| 237 int index = std::distance(pref_order.begin(), pos); | 314 sorted[pos - pref_order.begin()] = extension; |
| 238 sorted[index] = extension; | 315 else |
| 239 } else { | |
| 240 unsorted.push_back(make_scoped_refptr(extension)); | 316 unsorted.push_back(make_scoped_refptr(extension)); |
| 241 } | |
| 242 } | 317 } |
| 243 | 318 |
| 244 // Merge the lists. | 319 // Merge the lists. |
| 245 toolitems_.reserve(sorted.size() + unsorted.size()); | 320 toolbar_items_.clear(); |
| 246 for (ExtensionList::iterator iter = sorted.begin(); | 321 toolbar_items_.reserve(sorted.size() + unsorted.size()); |
| 322 for (ExtensionList::const_iterator iter = sorted.begin(); |
| 247 iter != sorted.end(); ++iter) { | 323 iter != sorted.end(); ++iter) { |
| 324 // It's possible for the extension order to contain items that aren't |
| 325 // actually loaded on this machine. For example, when extension sync is on, |
| 326 // we sync the extension order as-is but double-check with the user before |
| 327 // syncing NPAPI-containing extensions, so if one of those is not actually |
| 328 // synced, we'll get a NULL in the list. This sort of case can also happen |
| 329 // if some error prevents an extension from loading. |
| 248 if (*iter != NULL) | 330 if (*iter != NULL) |
| 249 toolitems_.push_back(*iter); | 331 toolbar_items_.push_back(*iter); |
| 250 } | 332 } |
| 251 toolitems_.insert(toolitems_.end(), unsorted.begin(), unsorted.end()); | 333 toolbar_items_.insert(toolbar_items_.end(), unsorted.begin(), |
| 334 unsorted.end()); |
| 252 | 335 |
| 253 // Inform observers. | 336 // Inform observers. |
| 254 for (size_t i = 0; i < toolitems_.size(); i++) { | 337 for (size_t i = 0; i < toolbar_items_.size(); i++) { |
| 255 FOR_EACH_OBSERVER(Observer, observers_, | 338 FOR_EACH_OBSERVER(Observer, observers_, |
| 256 BrowserActionAdded(toolitems_[i], i)); | 339 BrowserActionAdded(toolbar_items_[i], i)); |
| 257 } | 340 } |
| 341 } |
| 258 | 342 |
| 259 UpdatePrefs(); | 343 void ExtensionToolbarModel::FillExtensionList( |
| 260 | 344 const extensions::ExtensionPrefs::ExtensionIdSet& order, |
| 261 extensions_initialized_ = true; | 345 ExtensionList* list) { |
| 262 FOR_EACH_OBSERVER(Observer, observers_, ModelLoaded()); | 346 list->clear(); |
| 347 list->reserve(order.size()); |
| 348 for (size_t i = 0; i < order.size(); ++i) { |
| 349 const extensions::Extension* extension = |
| 350 service_->GetExtensionById(order[i], false); |
| 351 if (extension) |
| 352 AddExtension(extension, list); |
| 353 } |
| 263 } | 354 } |
| 264 | 355 |
| 265 void ExtensionToolbarModel::UpdatePrefs() { | 356 void ExtensionToolbarModel::UpdatePrefs() { |
| 266 if (!service_->extension_prefs()) | 357 if (!service_->extension_prefs()) |
| 267 return; | 358 return; |
| 268 | 359 |
| 269 std::vector<std::string> ids; | 360 extensions::ExtensionPrefs::ExtensionIdSet toolbar_ids; |
| 270 ids.reserve(toolitems_.size()); | 361 toolbar_ids.reserve(toolbar_items_.size()); |
| 271 for (ExtensionList::iterator iter = begin(); iter != end(); ++iter) | 362 for (size_t i = 0; i < toolbar_items_.size(); ++i) |
| 272 ids.push_back((*iter)->id()); | 363 toolbar_ids.push_back(toolbar_items_[i]->id()); |
| 273 service_->extension_prefs()->SetToolbarOrder(ids); | 364 service_->extension_prefs()->SetToolbarOrder(toolbar_ids); |
| 274 } | |
| 275 | 365 |
| 276 const Extension* ExtensionToolbarModel::GetExtensionByIndex(int index) const { | 366 extensions::ExtensionPrefs::ExtensionIdSet action_box_ids; |
| 277 return toolitems_[index]; | 367 action_box_ids.reserve(action_box_menu_items_.size()); |
| 368 for (size_t i = 0; i < action_box_menu_items_.size(); ++i) |
| 369 action_box_ids.push_back(action_box_menu_items_[i]->id()); |
| 370 service_->extension_prefs()->SetActionBoxOrder(action_box_ids); |
| 278 } | 371 } |
| 279 | 372 |
| 280 int ExtensionToolbarModel::IncognitoIndexToOriginal(int incognito_index) { | 373 int ExtensionToolbarModel::IncognitoIndexToOriginal(int incognito_index) { |
| 281 int original_index = 0, i = 0; | 374 int original_index = 0, i = 0; |
| 282 for (ExtensionList::iterator iter = begin(); iter != end(); | 375 for (ExtensionList::iterator iter = toolbar_items_.begin(); |
| 376 iter != toolbar_items_.end(); |
| 283 ++iter, ++original_index) { | 377 ++iter, ++original_index) { |
| 284 if (service_->IsIncognitoEnabled((*iter)->id())) { | 378 if (service_->IsIncognitoEnabled((*iter)->id())) { |
| 285 if (incognito_index == i) | 379 if (incognito_index == i) |
| 286 break; | 380 break; |
| 287 ++i; | 381 ++i; |
| 288 } | 382 } |
| 289 } | 383 } |
| 290 return original_index; | 384 return original_index; |
| 291 } | 385 } |
| 292 | 386 |
| 293 int ExtensionToolbarModel::OriginalIndexToIncognito(int original_index) { | 387 int ExtensionToolbarModel::OriginalIndexToIncognito(int original_index) { |
| 294 int incognito_index = 0, i = 0; | 388 int incognito_index = 0, i = 0; |
| 295 for (ExtensionList::iterator iter = begin(); iter != end(); | 389 for (ExtensionList::iterator iter = toolbar_items_.begin(); |
| 390 iter != toolbar_items_.end(); |
| 296 ++iter, ++i) { | 391 ++iter, ++i) { |
| 297 if (original_index == i) | 392 if (original_index == i) |
| 298 break; | 393 break; |
| 299 if (service_->IsIncognitoEnabled((*iter)->id())) | 394 if (service_->IsIncognitoEnabled((*iter)->id())) |
| 300 ++incognito_index; | 395 ++incognito_index; |
| 301 } | 396 } |
| 302 return incognito_index; | 397 return incognito_index; |
| 303 } | 398 } |
| OLD | NEW |