Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: chrome/browser/extensions/menu_manager.cc

Issue 2740143002: Change base::Value::ListStorage to std::vector<base::Value> (Closed)
Patch Set: Comment Updates Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 properties->SetBoolean("editable", params.is_editable); 658 properties->SetBoolean("editable", params.is_editable);
659 659
660 WebViewGuest* webview_guest = WebViewGuest::FromWebContents(web_contents); 660 WebViewGuest* webview_guest = WebViewGuest::FromWebContents(web_contents);
661 if (webview_guest) { 661 if (webview_guest) {
662 // This is used in web_view_internalcustom_bindings.js. 662 // This is used in web_view_internalcustom_bindings.js.
663 // The property is not exposed to developer API. 663 // The property is not exposed to developer API.
664 properties->SetInteger("webviewInstanceId", 664 properties->SetInteger("webviewInstanceId",
665 webview_guest->view_instance_id()); 665 webview_guest->view_instance_id());
666 } 666 }
667 667
668 base::DictionaryValue* raw_properties = properties.get(); 668 size_t properties_idx = args->GetSize();
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.
672 base::DictionaryValue* raw_properties;
Devlin 2017/03/15 15:25:04 nit: initialize to nullptr
jdoerrie 2017/03/23 18:11:17 Done.
673 args->GetDictionary(properties_idx, &raw_properties);
670 674
671 // Add the tab info to the argument list. 675 // Add the tab info to the argument list.
672 // No tab info in a platform app. 676 // No tab info in a platform app.
673 if (!extension || !extension->is_platform_app()) { 677 if (!extension || !extension->is_platform_app()) {
674 // Note: web_contents are null in unit tests :( 678 // Note: web_contents are null in unit tests :(
675 if (web_contents) { 679 if (web_contents) {
676 int frame_id = ExtensionApiFrameIdMap::GetFrameId(render_frame_host); 680 int frame_id = ExtensionApiFrameIdMap::GetFrameId(render_frame_host);
677 if (frame_id != ExtensionApiFrameIdMap::kInvalidFrameId) 681 if (frame_id != ExtensionApiFrameIdMap::kInvalidFrameId)
678 raw_properties->SetInteger("frameId", frame_id); 682 raw_properties->SetInteger("frameId", frame_id);
Devlin 2017/03/15 15:25:03 Given raw_properties is only safe to use before th
679 683
680 args->Append(ExtensionTabUtil::CreateTabObject(web_contents)->ToValue()); 684 args->Append(ExtensionTabUtil::CreateTabObject(web_contents)->ToValue());
681 } else { 685 } else {
682 args->Append(base::MakeUnique<base::DictionaryValue>()); 686 args->Append(base::MakeUnique<base::DictionaryValue>());
683 } 687 }
684 } 688 }
685 689
690 // |args->Append| might have invalidated pointers, which is why |args| needs
Devlin 2017/03/15 15:25:03 Oof, that's subtle. Do we have any way of checkin
brettw 2017/03/15 22:14:14 Yes, there should be no pointers in the API when w
jdoerrie 2017/03/23 18:11:17 To answer your first question, yes, we can determi
691 // to be queried again for the pointer.
692 args->GetDictionary(properties_idx, &raw_properties);
693
686 if (item->type() == MenuItem::CHECKBOX || 694 if (item->type() == MenuItem::CHECKBOX ||
687 item->type() == MenuItem::RADIO) { 695 item->type() == MenuItem::RADIO) {
688 bool was_checked = item->checked(); 696 bool was_checked = item->checked();
689 raw_properties->SetBoolean("wasChecked", was_checked); 697 raw_properties->SetBoolean("wasChecked", was_checked);
Devlin 2017/03/15 15:25:03 Similarly here, let's only grab the dictionary if
690 698
691 // RADIO items always get set to true when you click on them, but CHECKBOX 699 // RADIO items always get set to true when you click on them, but CHECKBOX
692 // items get their state toggled. 700 // items get their state toggled.
693 bool checked = 701 bool checked =
694 (item->type() == MenuItem::RADIO) ? true : !was_checked; 702 (item->type() == MenuItem::RADIO) ? true : !was_checked;
695 703
696 item->SetChecked(checked); 704 item->SetChecked(checked);
697 raw_properties->SetBoolean("checked", item->checked()); 705 raw_properties->SetBoolean("checked", item->checked());
698 706
699 if (extension) 707 if (extension)
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 bool MenuItem::Id::operator!=(const Id& other) const { 972 bool MenuItem::Id::operator!=(const Id& other) const {
965 return !(*this == other); 973 return !(*this == other);
966 } 974 }
967 975
968 bool MenuItem::Id::operator<(const Id& other) const { 976 bool MenuItem::Id::operator<(const Id& other) const {
969 return std::tie(incognito, extension_key, uid, string_uid) < 977 return std::tie(incognito, extension_key, uid, string_uid) <
970 std::tie(other.incognito, other.extension_key, other.uid, other.string_uid); 978 std::tie(other.incognito, other.extension_key, other.uid, other.string_uid);
971 } 979 }
972 980
973 } // namespace extensions 981 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698