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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 if (!item) | 619 if (!item) |
620 return; | 620 return; |
621 | 621 |
622 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_); | 622 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_); |
623 const Extension* extension = | 623 const Extension* extension = |
624 registry->enabled_extensions().GetByID(item->extension_id()); | 624 registry->enabled_extensions().GetByID(item->extension_id()); |
625 | 625 |
626 if (item->type() == MenuItem::RADIO) | 626 if (item->type() == MenuItem::RADIO) |
627 RadioItemSelected(item); | 627 RadioItemSelected(item); |
628 | 628 |
629 std::unique_ptr<base::ListValue> args(new base::ListValue()); | |
630 | 629 |
631 std::unique_ptr<base::DictionaryValue> properties( | 630 std::unique_ptr<base::DictionaryValue> properties( |
632 new base::DictionaryValue()); | 631 new base::DictionaryValue()); |
633 SetIdKeyValue(properties.get(), "menuItemId", item->id()); | 632 SetIdKeyValue(properties.get(), "menuItemId", item->id()); |
634 if (item->parent_id()) | 633 if (item->parent_id()) |
635 SetIdKeyValue(properties.get(), "parentMenuItemId", *item->parent_id()); | 634 SetIdKeyValue(properties.get(), "parentMenuItemId", *item->parent_id()); |
636 | 635 |
637 switch (params.media_type) { | 636 switch (params.media_type) { |
638 case blink::WebContextMenuData::MediaTypeImage: | 637 case blink::WebContextMenuData::MediaTypeImage: |
639 properties->SetString("mediaType", "image"); | 638 properties->SetString("mediaType", "image"); |
(...skipping 18 matching lines...) Expand all Loading... | |
658 properties->SetBoolean("editable", params.is_editable); | 657 properties->SetBoolean("editable", params.is_editable); |
659 | 658 |
660 WebViewGuest* webview_guest = WebViewGuest::FromWebContents(web_contents); | 659 WebViewGuest* webview_guest = WebViewGuest::FromWebContents(web_contents); |
661 if (webview_guest) { | 660 if (webview_guest) { |
662 // This is used in web_view_internalcustom_bindings.js. | 661 // This is used in web_view_internalcustom_bindings.js. |
663 // The property is not exposed to developer API. | 662 // The property is not exposed to developer API. |
664 properties->SetInteger("webviewInstanceId", | 663 properties->SetInteger("webviewInstanceId", |
665 webview_guest->view_instance_id()); | 664 webview_guest->view_instance_id()); |
666 } | 665 } |
667 | 666 |
668 base::DictionaryValue* raw_properties = properties.get(); | 667 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
Devlin
2017/03/30 22:44:59
nit: prefer base::MakeUnique<>.
jdoerrie
2017/04/07 13:56:17
Done.
| |
668 args->Reserve(2); | |
669 args->Append(std::move(properties)); | 669 args->Append(std::move(properties)); |
670 // |properties| is invalidated at this time, which is why |args| needs to be | |
671 // queried for the pointer. The obtained pointer is guaranteed to stay valid | |
672 // even after further Appends, because enough storage was reserved above. | |
673 base::DictionaryValue* raw_properties = nullptr; | |
674 args->GetDictionary(0, &raw_properties); | |
670 | 675 |
671 // Add the tab info to the argument list. | 676 // Add the tab info to the argument list. |
672 // No tab info in a platform app. | 677 // No tab info in a platform app. |
673 if (!extension || !extension->is_platform_app()) { | 678 if (!extension || !extension->is_platform_app()) { |
674 // Note: web_contents are null in unit tests :( | 679 // Note: web_contents are null in unit tests :( |
675 if (web_contents) { | 680 if (web_contents) { |
676 int frame_id = ExtensionApiFrameIdMap::GetFrameId(render_frame_host); | 681 int frame_id = ExtensionApiFrameIdMap::GetFrameId(render_frame_host); |
677 if (frame_id != ExtensionApiFrameIdMap::kInvalidFrameId) | 682 if (frame_id != ExtensionApiFrameIdMap::kInvalidFrameId) |
678 raw_properties->SetInteger("frameId", frame_id); | 683 raw_properties->SetInteger("frameId", frame_id); |
679 | 684 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
964 bool MenuItem::Id::operator!=(const Id& other) const { | 969 bool MenuItem::Id::operator!=(const Id& other) const { |
965 return !(*this == other); | 970 return !(*this == other); |
966 } | 971 } |
967 | 972 |
968 bool MenuItem::Id::operator<(const Id& other) const { | 973 bool MenuItem::Id::operator<(const Id& other) const { |
969 return std::tie(incognito, extension_key, uid, string_uid) < | 974 return std::tie(incognito, extension_key, uid, string_uid) < |
970 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); |
971 } | 976 } |
972 | 977 |
973 } // namespace extensions | 978 } // namespace extensions |
OLD | NEW |