| 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 <memory> | 8 #include <memory> |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 properties->SetBoolean("editable", params.is_editable); | 656 properties->SetBoolean("editable", params.is_editable); |
| 657 | 657 |
| 658 WebViewGuest* webview_guest = WebViewGuest::FromWebContents(web_contents); | 658 WebViewGuest* webview_guest = WebViewGuest::FromWebContents(web_contents); |
| 659 if (webview_guest) { | 659 if (webview_guest) { |
| 660 // This is used in web_view_internalcustom_bindings.js. | 660 // This is used in web_view_internalcustom_bindings.js. |
| 661 // The property is not exposed to developer API. | 661 // The property is not exposed to developer API. |
| 662 properties->SetInteger("webviewInstanceId", | 662 properties->SetInteger("webviewInstanceId", |
| 663 webview_guest->view_instance_id()); | 663 webview_guest->view_instance_id()); |
| 664 } | 664 } |
| 665 | 665 |
| 666 auto args = base::MakeUnique<base::ListValue>(); | 666 auto args = base::MakeUnique<base::Value>(); |
| 667 args->Reserve(2); | 667 args->GetList().reserve(2); |
| 668 args->Append(std::move(properties)); | 668 args->GetList().push_back(std::move(*properties)); |
| 669 // |properties| is invalidated at this time, which is why |args| needs to be | 669 // |properties| is invalidated at this time, which is why |args| needs to be |
| 670 // queried for the pointer. The obtained pointer is guaranteed to stay valid | 670 // queried for the pointer. The obtained pointer is guaranteed to stay valid |
| 671 // even after further Appends, because enough storage was reserved above. | 671 // even after further Appends, because enough storage was reserved above. |
| 672 base::DictionaryValue* raw_properties = nullptr; | 672 base::DictionaryValue* raw_properties = |
| 673 args->GetDictionary(0, &raw_properties); | 673 static_cast<base::DictionaryValue*>(&args->GetList()[0]); |
| 674 | 674 |
| 675 // Add the tab info to the argument list. | 675 // Add the tab info to the argument list. |
| 676 // No tab info in a platform app. | 676 // No tab info in a platform app. |
| 677 if (!extension || !extension->is_platform_app()) { | 677 if (!extension || !extension->is_platform_app()) { |
| 678 // Note: web_contents are null in unit tests :( | 678 // Note: web_contents are null in unit tests :( |
| 679 if (web_contents) { | 679 if (web_contents) { |
| 680 int frame_id = ExtensionApiFrameIdMap::GetFrameId(render_frame_host); | 680 int frame_id = ExtensionApiFrameIdMap::GetFrameId(render_frame_host); |
| 681 if (frame_id != ExtensionApiFrameIdMap::kInvalidFrameId) | 681 if (frame_id != ExtensionApiFrameIdMap::kInvalidFrameId) |
| 682 raw_properties->SetInteger("frameId", frame_id); | 682 raw_properties->SetInteger("frameId", frame_id); |
| 683 | 683 |
| 684 args->Append(ExtensionTabUtil::CreateTabObject(web_contents)->ToValue()); | 684 args->GetList().push_back( |
| 685 *ExtensionTabUtil::CreateTabObject(web_contents)->ToValue()); |
| 685 } else { | 686 } else { |
| 686 args->Append(base::MakeUnique<base::DictionaryValue>()); | 687 args->GetList().push_back(base::DictionaryValue()); |
| 687 } | 688 } |
| 688 } | 689 } |
| 689 | 690 |
| 690 if (item->type() == MenuItem::CHECKBOX || | 691 if (item->type() == MenuItem::CHECKBOX || |
| 691 item->type() == MenuItem::RADIO) { | 692 item->type() == MenuItem::RADIO) { |
| 692 bool was_checked = item->checked(); | 693 bool was_checked = item->checked(); |
| 693 raw_properties->SetBoolean("wasChecked", was_checked); | 694 raw_properties->SetBoolean("wasChecked", was_checked); |
| 694 | 695 |
| 695 // RADIO items always get set to true when you click on them, but CHECKBOX | 696 // RADIO items always get set to true when you click on them, but CHECKBOX |
| 696 // items get their state toggled. | 697 // items get their state toggled. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 711 ->GrantIfRequested(extension); | 712 ->GrantIfRequested(extension); |
| 712 } | 713 } |
| 713 | 714 |
| 714 { | 715 { |
| 715 // Dispatch to menu item's .onclick handler (this is the legacy API, from | 716 // Dispatch to menu item's .onclick handler (this is the legacy API, from |
| 716 // before chrome.contextMenus.onClicked existed). | 717 // before chrome.contextMenus.onClicked existed). |
| 717 std::unique_ptr<Event> event( | 718 std::unique_ptr<Event> event( |
| 718 new Event(webview_guest ? events::WEB_VIEW_INTERNAL_CONTEXT_MENUS | 719 new Event(webview_guest ? events::WEB_VIEW_INTERNAL_CONTEXT_MENUS |
| 719 : events::CONTEXT_MENUS, | 720 : events::CONTEXT_MENUS, |
| 720 webview_guest ? kOnWebviewContextMenus : kOnContextMenus, | 721 webview_guest ? kOnWebviewContextMenus : kOnContextMenus, |
| 721 std::unique_ptr<base::ListValue>(args->DeepCopy()))); | 722 base::ListValue::From(args->CreateDeepCopy()))); |
| 722 event->restrict_to_browser_context = context; | 723 event->restrict_to_browser_context = context; |
| 723 event->user_gesture = EventRouter::USER_GESTURE_ENABLED; | 724 event->user_gesture = EventRouter::USER_GESTURE_ENABLED; |
| 724 event_router->DispatchEventToExtension(item->extension_id(), | 725 event_router->DispatchEventToExtension(item->extension_id(), |
| 725 std::move(event)); | 726 std::move(event)); |
| 726 } | 727 } |
| 727 { | 728 { |
| 728 // Dispatch to .contextMenus.onClicked handler. | 729 // Dispatch to .contextMenus.onClicked handler. |
| 729 std::unique_ptr<Event> event(new Event( | 730 std::unique_ptr<Event> event(new Event( |
| 730 webview_guest ? events::CHROME_WEB_VIEW_INTERNAL_ON_CLICKED | 731 webview_guest ? events::CHROME_WEB_VIEW_INTERNAL_ON_CLICKED |
| 731 : events::CONTEXT_MENUS_ON_CLICKED, | 732 : events::CONTEXT_MENUS_ON_CLICKED, |
| 732 webview_guest ? api::chrome_web_view_internal::OnClicked::kEventName | 733 webview_guest ? api::chrome_web_view_internal::OnClicked::kEventName |
| 733 : api::context_menus::OnClicked::kEventName, | 734 : api::context_menus::OnClicked::kEventName, |
| 734 std::move(args))); | 735 base::ListValue::From(std::move(args)))); |
| 735 event->restrict_to_browser_context = context; | 736 event->restrict_to_browser_context = context; |
| 736 event->user_gesture = EventRouter::USER_GESTURE_ENABLED; | 737 event->user_gesture = EventRouter::USER_GESTURE_ENABLED; |
| 737 if (webview_guest) | 738 if (webview_guest) |
| 738 event->filter_info.SetInstanceID(webview_guest->view_instance_id()); | 739 event->filter_info.SetInstanceID(webview_guest->view_instance_id()); |
| 739 event_router->DispatchEventToExtension(item->extension_id(), | 740 event_router->DispatchEventToExtension(item->extension_id(), |
| 740 std::move(event)); | 741 std::move(event)); |
| 741 } | 742 } |
| 742 } | 743 } |
| 743 | 744 |
| 744 void MenuManager::SanitizeRadioList(const MenuItem::OwnedList& item_list) { | 745 void MenuManager::SanitizeRadioList(const MenuItem::OwnedList& item_list) { |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 bool MenuItem::Id::operator!=(const Id& other) const { | 969 bool MenuItem::Id::operator!=(const Id& other) const { |
| 969 return !(*this == other); | 970 return !(*this == other); |
| 970 } | 971 } |
| 971 | 972 |
| 972 bool MenuItem::Id::operator<(const Id& other) const { | 973 bool MenuItem::Id::operator<(const Id& other) const { |
| 973 return std::tie(incognito, extension_key, uid, string_uid) < | 974 return std::tie(incognito, extension_key, uid, string_uid) < |
| 974 std::tie(other.incognito, other.extension_key, other.uid, other.string_uid); | 975 std::tie(other.incognito, other.extension_key, other.uid, other.string_uid); |
| 975 } | 976 } |
| 976 | 977 |
| 977 } // namespace extensions | 978 } // namespace extensions |
| OLD | NEW |