| 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/menu_manager.h" | 5 #include "chrome/browser/extensions/menu_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/extensions/extension_tab_util.h" | 18 #include "chrome/browser/extensions/extension_tab_util.h" |
| 18 #include "chrome/browser/extensions/menu_manager_factory.h" | 19 #include "chrome/browser/extensions/menu_manager_factory.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 value->SetBoolean(kCheckedKey, checked_); | 208 value->SetBoolean(kCheckedKey, checked_); |
| 208 value->SetBoolean(kEnabledKey, enabled_); | 209 value->SetBoolean(kEnabledKey, enabled_); |
| 209 value->Set(kContextsKey, contexts_.ToValue().release()); | 210 value->Set(kContextsKey, contexts_.ToValue().release()); |
| 210 if (parent_id_) { | 211 if (parent_id_) { |
| 211 DCHECK_EQ(0, parent_id_->uid); | 212 DCHECK_EQ(0, parent_id_->uid); |
| 212 value->SetString(kParentUIDKey, parent_id_->string_uid); | 213 value->SetString(kParentUIDKey, parent_id_->string_uid); |
| 213 } | 214 } |
| 214 value->Set(kDocumentURLPatternsKey, | 215 value->Set(kDocumentURLPatternsKey, |
| 215 document_url_patterns_.ToValue().release()); | 216 document_url_patterns_.ToValue().release()); |
| 216 value->Set(kTargetURLPatternsKey, target_url_patterns_.ToValue().release()); | 217 value->Set(kTargetURLPatternsKey, target_url_patterns_.ToValue().release()); |
| 217 return value.Pass(); | 218 return value; |
| 218 } | 219 } |
| 219 | 220 |
| 220 // static | 221 // static |
| 221 MenuItem* MenuItem::Populate(const std::string& extension_id, | 222 MenuItem* MenuItem::Populate(const std::string& extension_id, |
| 222 const base::DictionaryValue& value, | 223 const base::DictionaryValue& value, |
| 223 std::string* error) { | 224 std::string* error) { |
| 224 bool incognito = false; | 225 bool incognito = false; |
| 225 if (!value.GetBoolean(kIncognitoKey, &incognito)) | 226 if (!value.GetBoolean(kIncognitoKey, &incognito)) |
| 226 return NULL; | 227 return NULL; |
| 227 Id id(incognito, MenuItem::ExtensionKey(extension_id)); | 228 Id id(incognito, MenuItem::ExtensionKey(extension_id)); |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 { | 712 { |
| 712 // Dispatch to menu item's .onclick handler (this is the legacy API, from | 713 // Dispatch to menu item's .onclick handler (this is the legacy API, from |
| 713 // before chrome.contextMenus.onClicked existed). | 714 // before chrome.contextMenus.onClicked existed). |
| 714 scoped_ptr<Event> event( | 715 scoped_ptr<Event> event( |
| 715 new Event(webview_guest ? events::WEB_VIEW_INTERNAL_CONTEXT_MENUS | 716 new Event(webview_guest ? events::WEB_VIEW_INTERNAL_CONTEXT_MENUS |
| 716 : events::CONTEXT_MENUS, | 717 : events::CONTEXT_MENUS, |
| 717 webview_guest ? kOnWebviewContextMenus : kOnContextMenus, | 718 webview_guest ? kOnWebviewContextMenus : kOnContextMenus, |
| 718 scoped_ptr<base::ListValue>(args->DeepCopy()))); | 719 scoped_ptr<base::ListValue>(args->DeepCopy()))); |
| 719 event->restrict_to_browser_context = context; | 720 event->restrict_to_browser_context = context; |
| 720 event->user_gesture = EventRouter::USER_GESTURE_ENABLED; | 721 event->user_gesture = EventRouter::USER_GESTURE_ENABLED; |
| 721 event_router->DispatchEventToExtension(item->extension_id(), event.Pass()); | 722 event_router->DispatchEventToExtension(item->extension_id(), |
| 723 std::move(event)); |
| 722 } | 724 } |
| 723 { | 725 { |
| 724 // Dispatch to .contextMenus.onClicked handler. | 726 // Dispatch to .contextMenus.onClicked handler. |
| 725 scoped_ptr<Event> event(new Event( | 727 scoped_ptr<Event> event(new Event( |
| 726 webview_guest ? events::CHROME_WEB_VIEW_INTERNAL_ON_CLICKED | 728 webview_guest ? events::CHROME_WEB_VIEW_INTERNAL_ON_CLICKED |
| 727 : events::CONTEXT_MENUS_ON_CLICKED, | 729 : events::CONTEXT_MENUS_ON_CLICKED, |
| 728 webview_guest ? api::chrome_web_view_internal::OnClicked::kEventName | 730 webview_guest ? api::chrome_web_view_internal::OnClicked::kEventName |
| 729 : api::context_menus::OnClicked::kEventName, | 731 : api::context_menus::OnClicked::kEventName, |
| 730 args.Pass())); | 732 std::move(args))); |
| 731 event->restrict_to_browser_context = context; | 733 event->restrict_to_browser_context = context; |
| 732 event->user_gesture = EventRouter::USER_GESTURE_ENABLED; | 734 event->user_gesture = EventRouter::USER_GESTURE_ENABLED; |
| 733 if (webview_guest) | 735 if (webview_guest) |
| 734 event->filter_info.SetInstanceID(webview_guest->view_instance_id()); | 736 event->filter_info.SetInstanceID(webview_guest->view_instance_id()); |
| 735 event_router->DispatchEventToExtension(item->extension_id(), event.Pass()); | 737 event_router->DispatchEventToExtension(item->extension_id(), |
| 738 std::move(event)); |
| 736 } | 739 } |
| 737 } | 740 } |
| 738 | 741 |
| 739 void MenuManager::SanitizeRadioList(const MenuItem::List& item_list) { | 742 void MenuManager::SanitizeRadioList(const MenuItem::List& item_list) { |
| 740 MenuItem::List::const_iterator i = item_list.begin(); | 743 MenuItem::List::const_iterator i = item_list.begin(); |
| 741 while (i != item_list.end()) { | 744 while (i != item_list.end()) { |
| 742 if ((*i)->type() != MenuItem::RADIO) { | 745 if ((*i)->type() != MenuItem::RADIO) { |
| 743 ++i; | 746 ++i; |
| 744 break; | 747 break; |
| 745 } | 748 } |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 bool MenuItem::Id::operator!=(const Id& other) const { | 979 bool MenuItem::Id::operator!=(const Id& other) const { |
| 977 return !(*this == other); | 980 return !(*this == other); |
| 978 } | 981 } |
| 979 | 982 |
| 980 bool MenuItem::Id::operator<(const Id& other) const { | 983 bool MenuItem::Id::operator<(const Id& other) const { |
| 981 return std::tie(incognito, extension_key, uid, string_uid) < | 984 return std::tie(incognito, extension_key, uid, string_uid) < |
| 982 std::tie(other.incognito, other.extension_key, other.uid, other.string_uid); | 985 std::tie(other.incognito, other.extension_key, other.uid, other.string_uid); |
| 983 } | 986 } |
| 984 | 987 |
| 985 } // namespace extensions | 988 } // namespace extensions |
| OLD | NEW |