| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/renderer_context_menu/render_view_context_menu_base.h" | 5 #include "components/renderer_context_menu/render_view_context_menu_base.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 AddCustomItemsToMenu(params_.custom_items, 0, &total_items, &custom_submenus_, | 254 AddCustomItemsToMenu(params_.custom_items, 0, &total_items, &custom_submenus_, |
| 255 this, &menu_model_); | 255 this, &menu_model_); |
| 256 return total_items > 0; | 256 return total_items > 0; |
| 257 } | 257 } |
| 258 | 258 |
| 259 bool RenderViewContextMenuBase::IsCommandIdKnown( | 259 bool RenderViewContextMenuBase::IsCommandIdKnown( |
| 260 int id, | 260 int id, |
| 261 bool* enabled) const { | 261 bool* enabled) const { |
| 262 // If this command is added by one of our observers, we dispatch | 262 // If this command is added by one of our observers, we dispatch |
| 263 // it to the observer. | 263 // it to the observer. |
| 264 base::ObserverListBase<RenderViewContextMenuObserver>::Iterator it( | 264 for (auto& observer : observers_) { |
| 265 &observers_); | 265 if (observer.IsCommandIdSupported(id)) { |
| 266 RenderViewContextMenuObserver* observer; | 266 *enabled = observer.IsCommandIdEnabled(id); |
| 267 while ((observer = it.GetNext()) != NULL) { | |
| 268 if (observer->IsCommandIdSupported(id)) { | |
| 269 *enabled = observer->IsCommandIdEnabled(id); | |
| 270 return true; | 267 return true; |
| 271 } | 268 } |
| 272 } | 269 } |
| 273 | 270 |
| 274 // Custom items. | 271 // Custom items. |
| 275 if (IsContentCustomCommandId(id)) { | 272 if (IsContentCustomCommandId(id)) { |
| 276 *enabled = IsCustomItemEnabled(id); | 273 *enabled = IsCustomItemEnabled(id); |
| 277 return true; | 274 return true; |
| 278 } | 275 } |
| 279 | 276 |
| 280 return false; | 277 return false; |
| 281 } | 278 } |
| 282 | 279 |
| 283 // Menu delegate functions ----------------------------------------------------- | 280 // Menu delegate functions ----------------------------------------------------- |
| 284 | 281 |
| 285 bool RenderViewContextMenuBase::IsCommandIdChecked(int id) const { | 282 bool RenderViewContextMenuBase::IsCommandIdChecked(int id) const { |
| 286 // If this command is is added by one of our observers, we dispatch it to the | 283 // If this command is is added by one of our observers, we dispatch it to the |
| 287 // observer. | 284 // observer. |
| 288 base::ObserverListBase<RenderViewContextMenuObserver>::Iterator it( | 285 for (auto& observer : observers_) { |
| 289 &observers_); | 286 if (observer.IsCommandIdSupported(id)) |
| 290 RenderViewContextMenuObserver* observer; | 287 return observer.IsCommandIdChecked(id); |
| 291 while ((observer = it.GetNext()) != NULL) { | |
| 292 if (observer->IsCommandIdSupported(id)) | |
| 293 return observer->IsCommandIdChecked(id); | |
| 294 } | 288 } |
| 295 | 289 |
| 296 // Custom items. | 290 // Custom items. |
| 297 if (IsContentCustomCommandId(id)) | 291 if (IsContentCustomCommandId(id)) |
| 298 return IsCustomItemChecked(id); | 292 return IsCustomItemChecked(id); |
| 299 | 293 |
| 300 return false; | 294 return false; |
| 301 } | 295 } |
| 302 | 296 |
| 303 void RenderViewContextMenuBase::ExecuteCommand(int id, int event_flags) { | 297 void RenderViewContextMenuBase::ExecuteCommand(int id, int event_flags) { |
| 304 command_executed_ = true; | 298 command_executed_ = true; |
| 305 RecordUsedItem(id); | 299 RecordUsedItem(id); |
| 306 | 300 |
| 307 // If this command is is added by one of our observers, we dispatch | 301 // If this command is is added by one of our observers, we dispatch |
| 308 // it to the observer. | 302 // it to the observer. |
| 309 base::ObserverListBase<RenderViewContextMenuObserver>::Iterator it( | 303 for (auto& observer : observers_) { |
| 310 &observers_); | 304 if (observer.IsCommandIdSupported(id)) |
| 311 RenderViewContextMenuObserver* observer; | 305 return observer.ExecuteCommand(id); |
| 312 while ((observer = it.GetNext()) != NULL) { | |
| 313 if (observer->IsCommandIdSupported(id)) | |
| 314 return observer->ExecuteCommand(id); | |
| 315 } | 306 } |
| 316 | 307 |
| 317 // Process custom actions range. | 308 // Process custom actions range. |
| 318 if (IsContentCustomCommandId(id)) { | 309 if (IsContentCustomCommandId(id)) { |
| 319 unsigned action = id - content_context_custom_first; | 310 unsigned action = id - content_context_custom_first; |
| 320 const content::CustomContextMenuContext& context = params_.custom_context; | 311 const content::CustomContextMenuContext& context = params_.custom_context; |
| 321 #if defined(ENABLE_PLUGINS) | 312 #if defined(ENABLE_PLUGINS) |
| 322 if (context.request_id && !context.is_pepper_menu) | 313 if (context.request_id && !context.is_pepper_menu) |
| 323 HandleAuthorizeAllPlugins(); | 314 HandleAuthorizeAllPlugins(); |
| 324 #endif | 315 #endif |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 NotifyURLOpened(url, new_contents); | 399 NotifyURLOpened(url, new_contents); |
| 409 } | 400 } |
| 410 | 401 |
| 411 bool RenderViewContextMenuBase::IsCustomItemChecked(int id) const { | 402 bool RenderViewContextMenuBase::IsCustomItemChecked(int id) const { |
| 412 return IsCustomItemCheckedInternal(params_.custom_items, id); | 403 return IsCustomItemCheckedInternal(params_.custom_items, id); |
| 413 } | 404 } |
| 414 | 405 |
| 415 bool RenderViewContextMenuBase::IsCustomItemEnabled(int id) const { | 406 bool RenderViewContextMenuBase::IsCustomItemEnabled(int id) const { |
| 416 return IsCustomItemEnabledInternal(params_.custom_items, id); | 407 return IsCustomItemEnabledInternal(params_.custom_items, id); |
| 417 } | 408 } |
| OLD | NEW |