[ios] Use base::Contains() instead of std::find() in //ios part #2
1. Use base::Contains() instead of std::find() where appropriate in //ios. 2. Two other small improvements related to code readability. Bug: 561800 Change-Id: I702b9912e2f04069a8deb98e9acba376a0130050 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4792710 Reviewed-by: David Roger <droger@chromium.org> Reviewed-by: Sylvain Defresne <sdefresne@chromium.org> Commit-Queue: Ho Cheung <uioptt24@gmail.com> Cr-Commit-Position: refs/heads/main@{#1187142}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
8caf421895
commit
98006d51f1
ios
chrome
browser
ui
location_bar
omnibox
overlays
popup_menu
settings
tab_switcher
tab_grid
tabs
toolbar
webui
update_client
web_state_list
test
earl_grey
components
security_interstitials
net
web
content
js_messaging
find_in_page
js_messaging
navigation
public
test
web_state
web_view
internal
@ -542,8 +542,8 @@ const NSString* kScribbleOmniboxElementId = @"omnibox";
|
||||
if (clipboard_content_types.has_value()) {
|
||||
std::set<ClipboardContentType> clipboard_content_types_values =
|
||||
clipboard_content_types.value();
|
||||
if (clipboard_content_types_values.find(ClipboardContentType::Image) !=
|
||||
clipboard_content_types_values.end()) {
|
||||
if (base::Contains(clipboard_content_types_values,
|
||||
ClipboardContentType::Image)) {
|
||||
// Either add an option to search the copied image with Lens, or via the
|
||||
// default search engine's reverse image search functionality.
|
||||
if (self.shouldUseLensInLongPressMenu) {
|
||||
@ -569,8 +569,8 @@ const NSString* kScribbleOmniboxElementId = @"omnibox";
|
||||
handler:searchCopiedImageHandler];
|
||||
[menuElements addObject:searchCopiedImageAction];
|
||||
}
|
||||
} else if (clipboard_content_types_values.find(ClipboardContentType::URL) !=
|
||||
clipboard_content_types_values.end()) {
|
||||
} else if (base::Contains(clipboard_content_types_values,
|
||||
ClipboardContentType::URL)) {
|
||||
id visitCopiedLinkHandler = ^(UIAction* action) {
|
||||
[self visitCopiedLink:nil];
|
||||
};
|
||||
@ -580,9 +580,8 @@ const NSString* kScribbleOmniboxElementId = @"omnibox";
|
||||
identifier:nil
|
||||
handler:visitCopiedLinkHandler];
|
||||
[menuElements addObject:visitCopiedLinkAction];
|
||||
} else if (clipboard_content_types_values.find(
|
||||
ClipboardContentType::Text) !=
|
||||
clipboard_content_types_values.end()) {
|
||||
} else if (base::Contains(clipboard_content_types_values,
|
||||
ClipboardContentType::Text)) {
|
||||
id searchCopiedTextHandler = ^(UIAction* action) {
|
||||
[self searchCopiedText:nil];
|
||||
};
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "ios/chrome/browser/ui/omnibox/fake_suggestions_database.h"
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/json/json_reader.h"
|
||||
@ -64,7 +65,7 @@ void FakeSuggestionsDatabase::LoadSuggestionsFromFile(
|
||||
|
||||
bool FakeSuggestionsDatabase::HasFakeSuggestions(const GURL& url) const {
|
||||
std::u16string search_terms = ExtractSearchTerms(url);
|
||||
return data_.find(search_terms) != data_.end();
|
||||
return base::Contains(data_, search_terms);
|
||||
}
|
||||
|
||||
std::string FakeSuggestionsDatabase::GetFakeSuggestions(const GURL& url) const {
|
||||
|
@ -5,6 +5,7 @@
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "base/apple/foundation_util.h"
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/functional/bind.h"
|
||||
#import "base/ios/ios_util.h"
|
||||
#import "base/strings/sys_string_conversions.h"
|
||||
@ -83,7 +84,7 @@ std::unique_ptr<net::test_server::HttpResponse> StandardResponse(
|
||||
|
||||
if (request.relative_url == kHeaderPageURL) {
|
||||
std::string result = kHeaderPageFailure;
|
||||
if (request.headers.find("X-Client-Data") != request.headers.end()) {
|
||||
if (base::Contains(request.headers, "X-Client-Data")) {
|
||||
result = kHeaderPageSuccess;
|
||||
}
|
||||
http_response->set_content("<html><body>" + result + "</body></html>");
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/functional/bind.h"
|
||||
#import "base/functional/callback.h"
|
||||
#import "base/memory/ptr_util.h"
|
||||
@ -289,8 +290,9 @@ UIViewController* OverlayPresentationContextImpl::GetBaseViewController(
|
||||
|
||||
OverlayRequestUIState* OverlayPresentationContextImpl::GetRequestUIState(
|
||||
OverlayRequest* request) const {
|
||||
if (!request || states_.find(request) == states_.end())
|
||||
if (!request || !base::Contains(states_, request)) {
|
||||
return nullptr;
|
||||
}
|
||||
return states_.at(request).get();
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "ios/chrome/browser/ui/overlays/test/fake_overlay_request_coordinator_delegate.h"
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
|
||||
FakeOverlayRequestCoordinatorDelegate::FakeOverlayRequestCoordinatorDelegate() =
|
||||
default;
|
||||
FakeOverlayRequestCoordinatorDelegate::
|
||||
@ -11,13 +13,13 @@ FakeOverlayRequestCoordinatorDelegate::
|
||||
|
||||
bool FakeOverlayRequestCoordinatorDelegate::HasUIBeenPresented(
|
||||
OverlayRequest* request) const {
|
||||
return states_.find(request) != states_.end() &&
|
||||
return base::Contains(states_, request) &&
|
||||
states_.at(request) == PresentationState::kPresented;
|
||||
}
|
||||
|
||||
bool FakeOverlayRequestCoordinatorDelegate::HasUIBeenDismissed(
|
||||
OverlayRequest* request) const {
|
||||
return states_.find(request) != states_.end() &&
|
||||
return base::Contains(states_, request) &&
|
||||
states_.at(request) == PresentationState::kDismissed;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#import "ios/chrome/browser/ui/popup_menu/overflow_menu/overflow_menu_orderer.h"
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/strings/sys_string_conversions.h"
|
||||
#import "components/prefs/pref_service.h"
|
||||
#import "components/prefs/scoped_user_pref_update.h"
|
||||
@ -286,7 +287,7 @@ base::Value::Dict DictFromBadgeData(const BadgeData badgeData) {
|
||||
- (void)recordClickForDestination:(overflow_menu::Destination)destination {
|
||||
_untappedDestinations.erase(destination);
|
||||
|
||||
if (_destinationBadgeData.find(destination) != _destinationBadgeData.end() &&
|
||||
if (base::Contains(_destinationBadgeData, destination) &&
|
||||
!_destinationBadgeData[destination].isFeatureDrivenBadge) {
|
||||
_destinationBadgeData.erase(destination);
|
||||
}
|
||||
@ -787,8 +788,7 @@ base::Value::Dict DictFromBadgeData(const BadgeData badgeData) {
|
||||
|
||||
// If item is badged with impressions remaining, it should be reordered to
|
||||
// a specific position and will be added later.
|
||||
if (_destinationBadgeData.find(destination) !=
|
||||
_destinationBadgeData.end() &&
|
||||
if (base::Contains(_destinationBadgeData, destination) &&
|
||||
_destinationBadgeData[destination].impressionsRemaining > 0) {
|
||||
continue;
|
||||
}
|
||||
@ -1005,8 +1005,7 @@ base::Value::Dict DictFromBadgeData(const BadgeData badgeData) {
|
||||
for (overflow_menu::Destination newDestination : newDestinations) {
|
||||
_untappedDestinations.insert(newDestination);
|
||||
|
||||
if (_destinationBadgeData.find(newDestination) ==
|
||||
_destinationBadgeData.end()) {
|
||||
if (!base::Contains(_destinationBadgeData, newDestination)) {
|
||||
_destinationBadgeData[newDestination].badgeType = BadgeTypeNew;
|
||||
_destinationBadgeData[newDestination].impressionsRemaining = 3;
|
||||
}
|
||||
@ -1040,8 +1039,7 @@ base::Value::Dict DictFromBadgeData(const BadgeData badgeData) {
|
||||
// If this is a new badge, the current badge is not feature driven, or the
|
||||
// badge from the provider is different than the current, then update the
|
||||
// data. Otherwise, the badge is already known about.
|
||||
if (_destinationBadgeData.find(destination) ==
|
||||
_destinationBadgeData.end() ||
|
||||
if (!base::Contains(_destinationBadgeData, destination) ||
|
||||
!_destinationBadgeData[destination].isFeatureDrivenBadge ||
|
||||
badgeType != _destinationBadgeData[destination].badgeType) {
|
||||
_destinationBadgeData[destination].badgeType = badgeType;
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/strings/sys_string_conversions.h"
|
||||
#import "base/test/ios/wait_util.h"
|
||||
#import "base/time/time.h"
|
||||
@ -99,7 +100,7 @@ class UserAgentResponseProvider : public web::DataResponseProvider {
|
||||
}
|
||||
|
||||
std::string purge_additions = "";
|
||||
if (request.url.path().find(kPurgeURL) != std::string::npos) {
|
||||
if (base::Contains(request.url.path(), kPurgeURL)) {
|
||||
purge_additions = kJavaScriptReload;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#import <memory>
|
||||
|
||||
#import "base/apple/foundation_util.h"
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/strings/sys_string_conversions.h"
|
||||
#import "base/test/ios/wait_util.h"
|
||||
#import "components/content_settings/core/browser/host_content_settings_map.h"
|
||||
@ -218,11 +219,11 @@ TEST_F(BlockPopupsTableViewControllerTest, TestMultipleAllowedItemsDeleted) {
|
||||
|
||||
std::vector<std::string> blocked_urls;
|
||||
std::vector<std::string> allowed_urls;
|
||||
for (std::pair<std::string, std::string> element : patterns_to_url) {
|
||||
if (deleted_patterns.find(element.first) != deleted_patterns.end()) {
|
||||
blocked_urls.push_back(element.second);
|
||||
for (const auto& [pattern, url] : patterns_to_url) {
|
||||
if (base::Contains(deleted_patterns, pattern)) {
|
||||
blocked_urls.push_back(url);
|
||||
} else {
|
||||
allowed_urls.push_back(element.second);
|
||||
allowed_urls.push_back(url);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#import "ios/chrome/browser/ui/settings/password/password_details/add_password_mediator.h"
|
||||
|
||||
#import "base/check.h"
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/containers/flat_set.h"
|
||||
#import "base/functional/bind.h"
|
||||
#import "base/memory/raw_ptr.h"
|
||||
@ -204,7 +205,7 @@ bool CheckForDuplicates(
|
||||
|
||||
- (BOOL)isTLDMissing {
|
||||
std::string hostname = self.URL.host();
|
||||
return hostname.find('.') == std::string::npos;
|
||||
return !base::Contains(hostname, '.');
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -7,6 +7,7 @@
|
||||
#import <memory>
|
||||
|
||||
#import "base/apple/foundation_util.h"
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/ios/ios_util.h"
|
||||
#import "base/strings/utf_string_conversions.h"
|
||||
#import "base/test/metrics/histogram_tester.h"
|
||||
@ -622,8 +623,8 @@ TEST_F(PasswordDetailsTableViewControllerTest, TestChangePasswordOnWebsite) {
|
||||
// called with a URL argument which matches the initial URL passed to
|
||||
// the password form above. Information may have been appended to the
|
||||
// URL argument, so we only make sure it includes the initial URL.
|
||||
return (((OpenNewTabCommand*)value).URL.spec().find(kExampleCom) !=
|
||||
std::string::npos);
|
||||
return base::Contains(((OpenNewTabCommand*)value).URL.spec(),
|
||||
kExampleCom);
|
||||
}]]);
|
||||
[password_details tableView:password_details.tableView
|
||||
didSelectRowAtIndexPath:indexPath];
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/ios/ios_util.h"
|
||||
#import "base/strings/sys_string_conversions.h"
|
||||
#import "base/test/ios/wait_util.h"
|
||||
@ -41,9 +42,9 @@ std::unique_ptr<net::test_server::HttpResponse> SearchResponse(
|
||||
std::unique_ptr<net::test_server::BasicHttpResponse> http_response =
|
||||
std::make_unique<net::test_server::BasicHttpResponse>();
|
||||
http_response->set_code(net::HTTP_OK);
|
||||
if (request.GetURL().path().find(kGoogleURL) != std::string::npos) {
|
||||
if (base::Contains(request.GetURL().path(), kGoogleURL)) {
|
||||
http_response->set_content("<body>" + std::string(kGoogleURL) + "</body>");
|
||||
} else if (request.GetURL().path().find(kYahooURL) != std::string::npos) {
|
||||
} else if (base::Contains(request.GetURL().path(), kYahooURL)) {
|
||||
http_response->set_content("<body>" + std::string(kYahooURL) + "</body>");
|
||||
}
|
||||
return std::move(http_response);
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#import "ios/chrome/browser/ui/settings/settings_app_interface.h"
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/strings/sys_string_conversions.h"
|
||||
#import "components/browsing_data/core/pref_names.h"
|
||||
#import "components/metrics/metrics_pref_names.h"
|
||||
@ -34,10 +35,9 @@ std::string portForRewrite;
|
||||
|
||||
bool HostToLocalHostRewrite(GURL* url, web::BrowserState* browser_state) {
|
||||
DCHECK(url);
|
||||
for (std::string host : listHosts) {
|
||||
if (url->host().find(host) != std::string::npos) {
|
||||
*url =
|
||||
GURL(std::string("http://127.0.0.1:") + portForRewrite + "/" + host);
|
||||
for (const std::string& host : listHosts) {
|
||||
if (base::Contains(url->host(), host)) {
|
||||
*url = GURL("http://127.0.0.1:" + portForRewrite + "/" + host);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/format_macros.h"
|
||||
#import "base/i18n/message_formatter.h"
|
||||
#import "base/ios/ios_util.h"
|
||||
@ -267,7 +268,7 @@ class EchoURLDefaultSearchEngineResponseProvider
|
||||
|
||||
bool EchoURLDefaultSearchEngineResponseProvider::CanHandleRequest(
|
||||
const Request& request) {
|
||||
return request.url.spec().find(kSearchEngineHost) != std::string::npos;
|
||||
return base::Contains(request.url.spec(), kSearchEngineHost);
|
||||
}
|
||||
|
||||
void EchoURLDefaultSearchEngineResponseProvider::GetResponseHeadersAndBody(
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#import "ios/chrome/browser/ui/tabs/target_frame_cache.h"
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
|
||||
TargetFrameCache::TargetFrameCache() {}
|
||||
|
||||
TargetFrameCache::~TargetFrameCache() {}
|
||||
@ -25,5 +27,5 @@ CGRect TargetFrameCache::GetFrame(UIView* view) {
|
||||
}
|
||||
|
||||
bool TargetFrameCache::HasFrame(UIView* view) {
|
||||
return targetFrames_.find(view) != targetFrames_.end();
|
||||
return base::Contains(targetFrames_, view);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#import "ios/chrome/browser/ui/toolbar/adaptive_toolbar_mediator.h"
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/memory/ptr_util.h"
|
||||
#import "base/metrics/user_metrics.h"
|
||||
#import "base/metrics/user_metrics_action.h"
|
||||
@ -475,14 +476,14 @@
|
||||
clipboardContentType.value();
|
||||
|
||||
if (search_engines::SupportsSearchByImage(self.templateURLService) &&
|
||||
clipboardContentTypeValues.find(ClipboardContentType::Image) !=
|
||||
clipboardContentTypeValues.end()) {
|
||||
base::Contains(clipboardContentTypeValues,
|
||||
ClipboardContentType::Image)) {
|
||||
return [self.actionFactory actionToSearchCopiedImage];
|
||||
} else if (clipboardContentTypeValues.find(ClipboardContentType::URL) !=
|
||||
clipboardContentTypeValues.end()) {
|
||||
} else if (base::Contains(clipboardContentTypeValues,
|
||||
ClipboardContentType::URL)) {
|
||||
return [self.actionFactory actionToSearchCopiedURL];
|
||||
} else if (clipboardContentTypeValues.find(ClipboardContentType::Text) !=
|
||||
clipboardContentTypeValues.end()) {
|
||||
} else if (base::Contains(clipboardContentTypeValues,
|
||||
ClipboardContentType::Text)) {
|
||||
return [self.actionFactory actionToSearchCopiedText];
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/format_macros.h"
|
||||
#include "base/i18n/number_formatting.h"
|
||||
#include "base/memory/ref_counted_memory.h"
|
||||
@ -136,7 +137,7 @@ void AboutUIHTMLSource::StartDataRequest(
|
||||
for (base::HistogramBase* histogram : base::StatisticsRecorder::Sort(
|
||||
base::StatisticsRecorder::GetHistograms())) {
|
||||
std::string histogram_name = histogram->histogram_name();
|
||||
if (histogram_name.find(path) == std::string::npos) {
|
||||
if (!base::Contains(histogram_name, path)) {
|
||||
continue;
|
||||
}
|
||||
base::Value::Dict histogram_dict = histogram->ToGraphDict();
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/functional/callback_helpers.h"
|
||||
#include "base/strings/strcat.h"
|
||||
@ -15,33 +16,25 @@
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "testing/platform_test.h"
|
||||
|
||||
namespace {
|
||||
|
||||
bool Contains(const std::string& source, const std::string& target) {
|
||||
return source.find(target) != std::string::npos;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void TestParams(update_client::UpdateQueryParams::ProdId prod_id) {
|
||||
std::string params = update_client::UpdateQueryParams::Get(prod_id);
|
||||
|
||||
EXPECT_TRUE(Contains(
|
||||
EXPECT_TRUE(base::Contains(
|
||||
params,
|
||||
base::StrCat({"os=", update_client::UpdateQueryParams::GetOS()})));
|
||||
EXPECT_TRUE(Contains(
|
||||
EXPECT_TRUE(base::Contains(
|
||||
params,
|
||||
base::StrCat({"arch=", update_client::UpdateQueryParams::GetArch()})));
|
||||
EXPECT_TRUE(Contains(
|
||||
EXPECT_TRUE(base::Contains(
|
||||
params,
|
||||
base::StrCat({"prod=", update_client::UpdateQueryParams::GetProdIdString(
|
||||
prod_id)})));
|
||||
EXPECT_TRUE(
|
||||
Contains(params, base::StrCat({"prodchannel=", GetChannelString()})));
|
||||
EXPECT_TRUE(Contains(
|
||||
EXPECT_TRUE(base::Contains(
|
||||
params, base::StrCat({"prodchannel=", GetChannelString()})));
|
||||
EXPECT_TRUE(base::Contains(
|
||||
params,
|
||||
base::StrCat({"prodversion=", version_info::GetVersionNumber()})));
|
||||
EXPECT_TRUE(Contains(
|
||||
EXPECT_TRUE(base::Contains(
|
||||
params,
|
||||
base::StrCat({"lang=", IOSChromeUpdateQueryParamsDelegate::GetLang()})));
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#import <set>
|
||||
|
||||
#import "base/check_op.h"
|
||||
#import "base/containers/contains.h"
|
||||
#import "ios/chrome/browser/shared/model/web_state_list/web_state_list.h"
|
||||
#import "ios/chrome/browser/shared/model/web_state_list/web_state_opener.h"
|
||||
#import "ios/chrome/browser/web_state_list/web_state_list_removing_indexes.h"
|
||||
@ -33,7 +34,7 @@ int FindIndexOfNextNonRemovedWebStateOpenedBy(
|
||||
}
|
||||
|
||||
// All children are going to be removed, fallback to the next heuristic.
|
||||
if (children.find(child_index) != children.end()) {
|
||||
if (base::Contains(children, child_index)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#import "base/command_line.h"
|
||||
#import "base/ios/ios_util.h"
|
||||
#import "base/path_service.h"
|
||||
#import "base/strings/string_util.h"
|
||||
#import "base/strings/sys_string_conversions.h"
|
||||
#import "base/test/ios/wait_util.h"
|
||||
#import "ios/chrome/browser/policy/policy_earl_grey_utils.h"
|
||||
@ -370,7 +371,7 @@ void ResetAuthentication() {
|
||||
NSMutableArray* flakyTestNames = [NSMutableArray array];
|
||||
for (unsigned int i = 0; i < count; i++) {
|
||||
SEL selector = method_getName(methods[i]);
|
||||
if (std::string(sel_getName(selector)).find(kFlakyTestPrefix) == 0) {
|
||||
if (base::StartsWith(sel_getName(selector), kFlakyTestPrefix)) {
|
||||
NSMethodSignature* methodSignature =
|
||||
[self instanceMethodSignatureForSelector:selector];
|
||||
NSInvocation* invocation =
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#import "ios/components/security_interstitials/lookalikes/lookalike_url_tab_allow_list.h"
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "ios/web/public/web_state.h"
|
||||
|
||||
WEB_STATE_USER_DATA_KEY_IMPL(LookalikeUrlTabAllowList)
|
||||
@ -19,7 +20,7 @@ LookalikeUrlTabAllowList& LookalikeUrlTabAllowList::operator=(
|
||||
LookalikeUrlTabAllowList::~LookalikeUrlTabAllowList() = default;
|
||||
|
||||
bool LookalikeUrlTabAllowList::IsDomainAllowed(const std::string& domain) {
|
||||
return allowed_domains_.find(domain) != allowed_domains_.end();
|
||||
return base::Contains(allowed_domains_, domain);
|
||||
}
|
||||
|
||||
void LookalikeUrlTabAllowList::AllowDomain(const std::string& domain) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#import "ios/components/security_interstitials/safe_browsing/pending_unsafe_resource_storage.h"
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/functional/callback_helpers.h"
|
||||
#import "base/memory/ptr_util.h"
|
||||
#import "ios/components/security_interstitials/safe_browsing/unsafe_resource_util.h"
|
||||
@ -20,8 +21,7 @@ bool IsUnsafeResourcePending(const UnsafeResource& resource) {
|
||||
return allow_list &&
|
||||
allow_list->IsUnsafeNavigationDecisionPending(decision_url,
|
||||
&pending_threat_types) &&
|
||||
pending_threat_types.find(resource.threat_type) !=
|
||||
pending_threat_types.end();
|
||||
base::Contains(pending_threat_types, resource.threat_type);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -119,7 +119,7 @@ void PendingUnsafeResourceStorage::ResourcePolicyObserver::
|
||||
const UnsafeResource* resource = storage_->resource();
|
||||
if (policy == SafeBrowsingUrlAllowList::Policy::kPending ||
|
||||
url != resource->navigation_url ||
|
||||
threat_types.find(resource->threat_type) == threat_types.end()) {
|
||||
!base::Contains(threat_types, resource->threat_type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/feature_list.h"
|
||||
#import "base/functional/bind.h"
|
||||
#import "base/metrics/histogram_functions.h"
|
||||
@ -155,8 +156,7 @@ bool SafeBrowsingTabHelper::PolicyDecider::IsQueryStale(
|
||||
web_state()->GetNavigationManager()->GetLastCommittedItem();
|
||||
return !last_committed_item ||
|
||||
last_committed_item->GetUniqueID() != query.main_frame_item_id ||
|
||||
pending_sub_frame_queries_.find(url) ==
|
||||
pending_sub_frame_queries_.end();
|
||||
!base::Contains(pending_sub_frame_queries_, url);
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,12 +209,12 @@ void SafeBrowsingTabHelper::PolicyDecider::ShouldAllowRequest(
|
||||
// Track all pending URL queries.
|
||||
bool is_main_frame = request_info.target_frame_is_main;
|
||||
if (is_main_frame) {
|
||||
if (pending_main_frame_query_)
|
||||
if (pending_main_frame_query_) {
|
||||
previous_main_frame_query_ = std::move(pending_main_frame_query_);
|
||||
}
|
||||
|
||||
pending_main_frame_query_ = MainFrameUrlQuery(request_url);
|
||||
} else if (pending_sub_frame_queries_.find(request_url) ==
|
||||
pending_sub_frame_queries_.end()) {
|
||||
} else if (!base::Contains(pending_sub_frame_queries_, request_url)) {
|
||||
pending_sub_frame_queries_.insert({request_url, SubFrameUrlQuery()});
|
||||
}
|
||||
|
||||
@ -435,8 +435,7 @@ void SafeBrowsingTabHelper::PolicyDecider::OnSubFrameUrlQueryDecided(
|
||||
navigation_manager->GetLastCommittedItem();
|
||||
|
||||
// The URL check is expected to have been registered for the sub frame.
|
||||
DCHECK(pending_sub_frame_queries_.find(url) !=
|
||||
pending_sub_frame_queries_.end());
|
||||
DCHECK(base::Contains(pending_sub_frame_queries_, url));
|
||||
|
||||
// Store the decision for `url` and run all the response callbacks that have
|
||||
// been received before the URL check completion.
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#import "ios/components/security_interstitials/safe_browsing/url_checker_delegate_impl.h"
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "components/safe_browsing/core/browser/db/database_manager.h"
|
||||
#import "components/safe_browsing/core/browser/db/v4_protocol_manager_util.h"
|
||||
#import "components/safe_browsing/ios/browser/safe_browsing_url_allow_list.h"
|
||||
@ -48,7 +49,7 @@ void HandleBlockingPageRequestOnUIThread(
|
||||
SafeBrowsingUrlAllowList* allow_list =
|
||||
SafeBrowsingUrlAllowList::FromWebState(web_state);
|
||||
if (allow_list->AreUnsafeNavigationsAllowed(url, &allowed_threats)) {
|
||||
if (allowed_threats.find(threat_type) != allowed_threats.end()) {
|
||||
if (base::Contains(allowed_threats, threat_type)) {
|
||||
RunUnsafeResourceCallback(resource, /*proceed=*/true,
|
||||
/*showed_interstitial=*/false);
|
||||
return;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include "base/check_op.h"
|
||||
#import "base/containers/contains.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/time/time.h"
|
||||
#include "ios/net/ios_net_buildflags.h"
|
||||
@ -61,7 +62,7 @@ void CookieCreationTimeManager::SetCreationTime(
|
||||
NSHTTPCookie* cookie,
|
||||
const base::Time& creation_time) {
|
||||
DCHECK(thread_checker_.CalledOnValidThread());
|
||||
DCHECK(unique_times_.find(creation_time) == unique_times_.end());
|
||||
DCHECK(!base::Contains(unique_times_, creation_time));
|
||||
|
||||
// If the cookie overrides an existing cookie, remove its creation time.
|
||||
auto it = creation_times_.find(GetCookieUniqueID(cookie));
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#import "base/apple/foundation_util.h"
|
||||
#import "base/check_op.h"
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/files/file_path.h"
|
||||
#import "base/files/file_util.h"
|
||||
#import "base/functional/bind.h"
|
||||
@ -559,7 +560,7 @@ std::unique_ptr<CookieChangeSubscription> CookieStoreIOS::AddCallbackForCookie(
|
||||
hook_map_[key] = std::make_unique<CookieChangeCallbackList>();
|
||||
}
|
||||
|
||||
DCHECK(hook_map_.find(key) != hook_map_.end());
|
||||
DCHECK(base::Contains(hook_map_, key));
|
||||
auto subscription =
|
||||
std::make_unique<Subscription>(hook_map_[key]->Add(std::move(callback)));
|
||||
all_subscriptions_.Append(subscription.get());
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#import "ios/web/content/js_messaging/content_java_script_feature_manager.h"
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/ios/ios_util.h"
|
||||
#import "base/strings/string_util.h"
|
||||
#import "base/strings/sys_string_conversions.h"
|
||||
@ -51,7 +52,7 @@ void ContentJavaScriptFeatureManager::InjectDocumentEndScripts(
|
||||
|
||||
bool ContentJavaScriptFeatureManager::HasFeature(
|
||||
const JavaScriptFeature* feature) const {
|
||||
return features_.find(feature) != features_.end();
|
||||
return base::Contains(features_, feature);
|
||||
}
|
||||
|
||||
void ContentJavaScriptFeatureManager::AddFeature(
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "ios/web/public/js_messaging/web_frame.h"
|
||||
|
||||
namespace web {
|
||||
@ -119,7 +120,7 @@ bool JavaScriptFindInPageRequest::GoToPreviousMatch() {
|
||||
|
||||
int JavaScriptFindInPageRequest::GetMatchCountForFrame(
|
||||
const std::string& frame_id) {
|
||||
if (frame_match_count_.find(frame_id) == frame_match_count_.end()) {
|
||||
if (!base::Contains(frame_match_count_, frame_id)) {
|
||||
return -1;
|
||||
}
|
||||
return frame_match_count_[frame_id];
|
||||
|
@ -5,6 +5,7 @@
|
||||
#import "ios/web/js_messaging/java_script_content_world.h"
|
||||
|
||||
#import "base/check_op.h"
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/notreached.h"
|
||||
#import "base/strings/sys_string_conversions.h"
|
||||
#import "ios/web/js_messaging/web_view_js_utils.h"
|
||||
@ -66,7 +67,7 @@ WKContentWorld* JavaScriptContentWorld::GetWKContentWorld() {
|
||||
JavaScriptContentWorld::~JavaScriptContentWorld() {}
|
||||
|
||||
bool JavaScriptContentWorld::HasFeature(const JavaScriptFeature* feature) {
|
||||
return features_.find(feature) != features_.end();
|
||||
return base::Contains(features_, feature);
|
||||
}
|
||||
|
||||
void JavaScriptContentWorld::AddFeature(const JavaScriptFeature* feature) {
|
||||
|
@ -149,8 +149,8 @@ bool ExtractTargetURL(const GURL& restore_session_url, GURL* target_url) {
|
||||
<< restore_session_url.possibly_invalid_spec()
|
||||
<< " is not a restore session URL";
|
||||
std::string target_url_spec;
|
||||
bool success =
|
||||
restore_session_url.ref().find(kRestoreSessionTargetUrlHashPrefix) == 0;
|
||||
bool success = base::StartsWith(restore_session_url.ref(),
|
||||
kRestoreSessionTargetUrlHashPrefix);
|
||||
if (success) {
|
||||
std::string encoded_target_url = restore_session_url.ref().substr(
|
||||
strlen(kRestoreSessionTargetUrlHashPrefix));
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#import "ios/web/public/test/fakes/fake_web_state_delegate.h"
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
|
||||
namespace web {
|
||||
|
||||
FakeOpenURLRequest::FakeOpenURLRequest()
|
||||
@ -43,8 +45,7 @@ WebState* FakeWebStateDelegate::CreateNewWebState(WebState* source,
|
||||
last_create_new_web_state_request_->opener_url = opener_url;
|
||||
last_create_new_web_state_request_->initiated_by_user = initiated_by_user;
|
||||
|
||||
if (!initiated_by_user &&
|
||||
allowed_popups_.find(opener_url) == allowed_popups_.end()) {
|
||||
if (!initiated_by_user && !base::Contains(allowed_popups_, opener_url)) {
|
||||
popups_.push_back(FakePopup(url, opener_url));
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#import "ios/web/public/test/http_server/html_response_provider_impl.h"
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "ios/web/public/test/http_server/response_provider.h"
|
||||
#import "net/http/http_response_headers.h"
|
||||
#import "net/http/http_status_code.h"
|
||||
@ -87,7 +88,7 @@ HtmlResponseProviderImpl::~HtmlResponseProviderImpl() {}
|
||||
|
||||
bool HtmlResponseProviderImpl::CanHandleRequest(
|
||||
const web::ResponseProvider::Request& request) {
|
||||
return responses_.find(request.url) != responses_.end();
|
||||
return base::Contains(responses_, request.url);
|
||||
}
|
||||
|
||||
void HtmlResponseProviderImpl::GetResponseHeadersAndBody(
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#import "ios/web/public/test/test_redirect_observer.h"
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "ios/web/public/navigation/navigation_context.h"
|
||||
#import "ios/web/public/navigation/navigation_item.h"
|
||||
#import "ios/web/public/navigation/navigation_manager.h"
|
||||
@ -39,11 +40,11 @@ void TestRedirectObserver::DidStartNavigation(web::WebState* web_state,
|
||||
GURL url = context->GetUrl();
|
||||
NavigationItem* item = web_state->GetNavigationManager()->GetVisibleItem();
|
||||
DCHECK(item);
|
||||
if (redirect_chains_.find(item) != redirect_chains_.end()) {
|
||||
if (base::Contains(redirect_chains_, item)) {
|
||||
// If the redirect chain for the pending NavigationItem is already being
|
||||
// tracked, add the new URL to the end of the chain.
|
||||
redirect_chains_[item].final_url = url;
|
||||
} else if (expected_urls_.find(url) != expected_urls_.end()) {
|
||||
} else if (base::Contains(expected_urls_, url)) {
|
||||
// If a load has begun for an expected URL, begin observing the redirect
|
||||
// chain for that NavigationItem.
|
||||
expected_urls_.erase(url);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/functional/bind.h"
|
||||
#import "base/run_loop.h"
|
||||
#import "base/strings/stringprintf.h"
|
||||
@ -103,7 +104,7 @@ bool IsWebViewContainingText(web::WebState* web_state,
|
||||
web::test::ExecuteJavaScript(web_state, kGetDocumentBodyJavaScript);
|
||||
std::string body;
|
||||
if (value && value->is_string()) {
|
||||
return value->GetString().find(text) != std::string::npos;
|
||||
return base::Contains(value->GetString(), text);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#import <WebKit/WebKit.h>
|
||||
|
||||
#import "base/apple/foundation_util.h"
|
||||
#import "base/containers/contains.h"
|
||||
#import "base/functional/bind.h"
|
||||
#import "base/ios/block_types.h"
|
||||
#import "base/ios/ios_util.h"
|
||||
@ -1816,8 +1817,8 @@ CrFullscreenState CrFullscreenStateFromWKFullscreenState(
|
||||
if (_documentURL.DeprecatedGetOriginAsURL() !=
|
||||
newURL.DeprecatedGetOriginAsURL()) {
|
||||
if (!_documentURL.host().empty() &&
|
||||
(newURL.username().find(_documentURL.host()) != std::string::npos ||
|
||||
newURL.password().find(_documentURL.host()) != std::string::npos)) {
|
||||
(base::Contains(newURL.username(), _documentURL.host()) ||
|
||||
base::Contains(newURL.password(), _documentURL.host()))) {
|
||||
CHECK(false);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#import "ios/web/public/web_state_delegate.h"
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
|
||||
namespace web {
|
||||
|
||||
WebStateDelegate::WebStateDelegate() {}
|
||||
@ -61,12 +63,12 @@ UIView* WebStateDelegate::GetWebViewContainer(WebState* source) {
|
||||
}
|
||||
|
||||
void WebStateDelegate::Attach(WebState* source) {
|
||||
DCHECK(attached_states_.find(source) == attached_states_.end());
|
||||
DCHECK(!base::Contains(attached_states_, source));
|
||||
attached_states_.insert(source);
|
||||
}
|
||||
|
||||
void WebStateDelegate::Detach(WebState* source) {
|
||||
DCHECK(attached_states_.find(source) != attached_states_.end());
|
||||
DCHECK(base::Contains(attached_states_, source));
|
||||
attached_states_.erase(source);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
#import "base/containers/contains.h"
|
||||
#include "base/test/task_environment.h"
|
||||
#include "components/flags_ui/pref_service_flags_storage.h"
|
||||
#include "components/prefs/in_memory_pref_store.h"
|
||||
@ -43,15 +44,13 @@ class CWVFlagsTest : public PlatformTest {
|
||||
TEST_F(CWVFlagsTest, SetUsesSyncAndWalletSandbox) {
|
||||
flags_.usesSyncAndWalletSandbox = YES;
|
||||
std::set<std::string> stored_flags = flags_storage_->GetFlags();
|
||||
EXPECT_NE(stored_flags.end(), stored_flags.find(kUseSyncSandboxFlagName));
|
||||
EXPECT_NE(stored_flags.end(),
|
||||
stored_flags.find(kUseWalletSandboxFlagNameEnabled));
|
||||
EXPECT_TRUE(base::Contains(stored_flags, kUseSyncSandboxFlagName));
|
||||
EXPECT_TRUE(base::Contains(stored_flags, kUseWalletSandboxFlagNameEnabled));
|
||||
|
||||
flags_.usesSyncAndWalletSandbox = NO;
|
||||
stored_flags = flags_storage_->GetFlags();
|
||||
EXPECT_EQ(stored_flags.end(), stored_flags.find(kUseSyncSandboxFlagName));
|
||||
EXPECT_EQ(stored_flags.end(),
|
||||
stored_flags.find(kUseWalletSandboxFlagNameEnabled));
|
||||
EXPECT_FALSE(base::Contains(stored_flags, kUseSyncSandboxFlagName));
|
||||
EXPECT_FALSE(base::Contains(stored_flags, kUseWalletSandboxFlagNameEnabled));
|
||||
}
|
||||
|
||||
// Tests CWVFlag's usesSyncAndWalletSandbox getter.
|
||||
|
Reference in New Issue
Block a user