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

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

Issue 1181263007: WebView context menu cleanup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 items_to_remove.insert(iter->first); 876 items_to_remove.insert(iter->first);
877 } 877 }
878 878
879 std::set<MenuItem::Id>::iterator remove_iter; 879 std::set<MenuItem::Id>::iterator remove_iter;
880 for (remove_iter = items_to_remove.begin(); 880 for (remove_iter = items_to_remove.begin();
881 remove_iter != items_to_remove.end(); 881 remove_iter != items_to_remove.end();
882 ++remove_iter) 882 ++remove_iter)
883 RemoveContextMenuItem(*remove_iter); 883 RemoveContextMenuItem(*remove_iter);
884 } 884 }
885 885
886 MenuItem::ExtensionKey::ExtensionKey() : webview_instance_id(0) {} 886 MenuItem::ExtensionKey::ExtensionKey()
887 : webview_embedder_process_id(0), webview_instance_id(0) {}
888
889 MenuItem::ExtensionKey::ExtensionKey(const std::string& extension_id)
890 : extension_id(extension_id),
891 webview_embedder_process_id(0),
892 webview_instance_id(0) {
893 DCHECK(!extension_id.empty());
894 }
895
896 MenuItem::ExtensionKey::ExtensionKey(int webview_embedder_process_id,
897 int webview_instance_id)
898 : ExtensionKey("", webview_embedder_process_id, webview_instance_id) {}
887 899
888 MenuItem::ExtensionKey::ExtensionKey(const std::string& extension_id, 900 MenuItem::ExtensionKey::ExtensionKey(const std::string& extension_id,
901 int webview_embedder_process_id,
889 int webview_instance_id) 902 int webview_instance_id)
890 : extension_id(extension_id), webview_instance_id(webview_instance_id) {} 903 : extension_id(extension_id),
891 904 webview_embedder_process_id(webview_embedder_process_id),
892 MenuItem::ExtensionKey::ExtensionKey(const std::string& extension_id) 905 webview_instance_id(webview_instance_id) {
893 : extension_id(extension_id), webview_instance_id(0) {} 906 DCHECK(webview_embedder_process_id && webview_instance_id);
907 }
894 908
895 bool MenuItem::ExtensionKey::operator==(const ExtensionKey& other) const { 909 bool MenuItem::ExtensionKey::operator==(const ExtensionKey& other) const {
896 return extension_id == other.extension_id && 910 bool webview_ids_match = webview_instance_id == other.webview_instance_id &&
897 webview_instance_id == other.webview_instance_id; 911 webview_embedder_process_id == other.webview_embedder_process_id;
912
913 // If either extension ID is empty, then these ExtensionKeys will be matched
914 // only based on the other IDs.
915 if (extension_id.empty() || other.extension_id.empty())
916 return webview_ids_match;
917
918 return extension_id == other.extension_id && webview_ids_match;
898 } 919 }
899 920
900 bool MenuItem::ExtensionKey::operator<(const ExtensionKey& other) const { 921 bool MenuItem::ExtensionKey::operator<(const ExtensionKey& other) const {
901 if (extension_id != other.extension_id) 922 if (webview_embedder_process_id != other.webview_embedder_process_id)
902 return extension_id < other.extension_id; 923 return webview_embedder_process_id < other.webview_embedder_process_id;
903 924
904 return webview_instance_id < other.webview_instance_id; 925 if (webview_instance_id != other.webview_instance_id)
926 return webview_instance_id < other.webview_instance_id;
927
928 // If either extension ID is empty, then these ExtensionKeys will be compared
929 // only based on the other IDs.
930 if (extension_id.empty() || other.extension_id.empty())
931 return false;
932
933 return extension_id < other.extension_id;
905 } 934 }
906 935
907 bool MenuItem::ExtensionKey::operator!=(const ExtensionKey& other) const { 936 bool MenuItem::ExtensionKey::operator!=(const ExtensionKey& other) const {
908 return !(*this == other); 937 return !(*this == other);
909 } 938 }
910 939
911 bool MenuItem::ExtensionKey::empty() const { 940 bool MenuItem::ExtensionKey::empty() const {
912 return extension_id.empty() && !webview_instance_id; 941 return extension_id.empty() && !webview_embedder_process_id &&
942 !webview_instance_id;
913 } 943 }
914 944
915 MenuItem::Id::Id() : incognito(false), uid(0) {} 945 MenuItem::Id::Id() : incognito(false), uid(0) {}
916 946
917 MenuItem::Id::Id(bool incognito, const MenuItem::ExtensionKey& extension_key) 947 MenuItem::Id::Id(bool incognito, const MenuItem::ExtensionKey& extension_key)
918 : incognito(incognito), extension_key(extension_key), uid(0) {} 948 : incognito(incognito), extension_key(extension_key), uid(0) {}
919 949
920 MenuItem::Id::~Id() { 950 MenuItem::Id::~Id() {
921 } 951 }
922 952
(...skipping 17 matching lines...) Expand all
940 if (uid < other.uid) 970 if (uid < other.uid)
941 return true; 971 return true;
942 if (uid == other.uid) 972 if (uid == other.uid)
943 return string_uid < other.string_uid; 973 return string_uid < other.string_uid;
944 } 974 }
945 } 975 }
946 return false; 976 return false;
947 } 977 }
948 978
949 } // namespace extensions 979 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698