Commit c57fe765 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Avoid needless parsing constants URLs.

There is a global comparison operator allowing to check whether
a GURL is equal to a constant URL. This avoid needlessly parsing
the constant to a GURL everytime the comparison is done.

Bug: 655467
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I9c876b542f09235042c36026b32977d88c2f0d0b
Reviewed-on: https://chromium-review.googlesource.com/886421
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532373}
parent 5983e37f
......@@ -111,7 +111,7 @@ class SyncSessionsClientImpl : public sync_sessions::SyncSessionsClient {
}
bool ShouldSyncURL(const GURL& url) const override {
if (url == GURL(kChromeUIHistoryURL)) {
if (url == kChromeUIHistoryURL) {
// The history page is treated specially as we want it to trigger syncable
// events for UI purposes.
return true;
......
......@@ -783,7 +783,7 @@ void RecordMainFrameNavigationMetric(web::WebState* web_state) {
webState->GetNavigationManager()->GetVisibleItem();
if (!(visible_item &&
visible_item->GetVirtualURL() == GURL(kChromeUINewTabURL))) {
visible_item->GetVirtualURL() == kChromeUINewTabURL)) {
PagePlaceholderTabHelper::FromWebState(webState)
->AddPlaceholderForNextNavigation();
}
......
......@@ -782,7 +782,7 @@ std::vector<GURL> GetUrlsToOpen(const std::vector<const BookmarkNode*>& nodes) {
}
- (void)loadURL:(const GURL&)url {
if (url == GURL() || url.SchemeIs(url::kJavaScriptScheme))
if (url.is_empty() || url.SchemeIs(url::kJavaScriptScheme))
return;
new_tab_page_uma::RecordAction(self.browserState,
......
......@@ -2339,7 +2339,7 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
BOOL hideToolbar = NO;
if (item) {
GURL url = item->GetURL();
BOOL isNTP = url.GetOrigin() == GURL(kChromeUINewTabURL);
BOOL isNTP = url.GetOrigin() == kChromeUINewTabURL;
hideToolbar = isNTP && !_isOffTheRecord &&
![self.primaryToolbarCoordinator isOmniboxFirstResponder] &&
![self.primaryToolbarCoordinator showingOmniboxPopup];
......
......@@ -70,6 +70,11 @@ NSString* const kAppLogoImageName = @"launchscreen_app_logo";
NSString* const kCheckBoxImageName = @"checkbox";
NSString* const kCheckBoxCheckedImageName = @"checkbox_checked";
// Constants for the Terms of Service and Privacy Notice URLs in the
// first run experience.
const char kTermsOfServiceUrl[] = "internal://terms-of-service";
const char kPrivacyNoticeUrl[] = "internal://privacy-notice";
} // namespace
@interface WelcomeToChromeView () {
......@@ -392,9 +397,9 @@ NSString* const kCheckBoxCheckedImageName = @"checkbox_checked";
WelcomeToChromeView* strongSelf = weakSelf;
if (!strongSelf)
return;
if (url == GURL("internal://terms-of-service")) {
if (url == kTermsOfServiceUrl) {
[[strongSelf delegate] welcomeToChromeViewDidTapTOSLink];
} else if (url == GURL("internal://privacy-notice")) {
} else if (url == kPrivacyNoticeUrl) {
[[strongSelf delegate] welcomeToChromeViewDidTapPrivacyLink];
} else {
NOTREACHED();
......@@ -403,11 +408,10 @@ NSString* const kCheckBoxCheckedImageName = @"checkbox_checked";
_TOSLabelLinkController =
[[LabelLinkController alloc] initWithLabel:_TOSLabel action:action];
[_TOSLabelLinkController
addLinkWithRange:tosLinkTextRange
url:GURL("internal://terms-of-service")];
[_TOSLabelLinkController addLinkWithRange:tosLinkTextRange
url:GURL(kTermsOfServiceUrl)];
[_TOSLabelLinkController addLinkWithRange:privacyLinkTextRange
url:GURL("internal://privacy-notice")];
url:GURL(kPrivacyNoticeUrl)];
[_TOSLabelLinkController setLinkColor:UIColorFromRGB(kLinkColorRGB)];
CGSize TOSLabelSize = [self.TOSLabel sizeThatFits:containerSize];
......
......@@ -78,7 +78,7 @@ bool ChromeOmniboxClientIOS::IsInstantNTP() const {
// because if they're not using Google the Google landing page is not shown
// (crbug/315563).
GURL currentURL = controller_->GetWebState()->GetVisibleURL();
return currentURL == GURL(kChromeUINewTabURL);
return currentURL == kChromeUINewTabURL;
}
bool ChromeOmniboxClientIOS::IsSearchResultsPage() const {
......
......@@ -655,7 +655,7 @@ using ios::material::TimingFunction;
- (void)updateToolbarForSideSwipeSnapshot:(Tab*)tab {
web::WebState* webState = tab.webState;
BOOL isCurrentTab = webState == [self.delegate currentWebState];
BOOL isNTP = webState->GetVisibleURL() == GURL(kChromeUINewTabURL);
BOOL isNTP = webState->GetVisibleURL() == kChromeUINewTabURL;
// Don't do anything for a live non-ntp tab.
if (isCurrentTab && !isNTP) {
......@@ -1012,7 +1012,7 @@ using ios::material::TimingFunction;
DCHECK(!IsIPadIdiom());
// Hide the toolbar if the NTP is currently displayed.
web::WebState* webState = [self.delegate currentWebState];
if (webState && (webState->GetVisibleURL() == GURL(kChromeUINewTabURL))) {
if (webState && (webState->GetVisibleURL() == kChromeUINewTabURL)) {
[self.view setHidden:YES];
}
}
......@@ -1590,7 +1590,7 @@ using ios::material::TimingFunction;
// If app is on the regular New Tab Page, make this animation occur instantly
// since this page has a fakebox to omnibox transition.
web::WebState* webState = [self.delegate currentWebState];
if (webState && webState->GetVisibleURL() == GURL(kChromeUINewTabURL) &&
if (webState && webState->GetVisibleURL() == kChromeUINewTabURL &&
!_incognito) {
duration = 0.0;
}
......
......@@ -105,7 +105,7 @@ GURL GetTestUrl() {
block:^BOOL {
const GURL& currentURL =
chrome_test_util::GetCurrentWebState()->GetVisibleURL();
return currentURL == GURL(url::kAboutBlankURL);
return currentURL == url::kAboutBlankURL;
}] waitWithTimeout:kConditionTimeout];
[ChromeEarlGrey waitForMainTabCount:1];
}
......
......@@ -23,30 +23,30 @@ namespace {
NSString* const kPageTemplate = @"<html><head>%@</head></html>";
// URL for BuildSimplePage.
const char* kSimplePageUrl("http://simplepage");
const char kSimplePageUrl[] = "http://simplepage/";
// URL for BuildPageWithJSSubresource.
const char* kJsPageUrl("http://javascriptpage");
const char kJsPageUrl[] = "http://javascriptpage/";
// URL for BuildPageWithCSSSubresource.
const char* kCssPageUrl("http://csspage");
const char kCssPageUrl[] = "http://csspage/";
// URL for BuildPageWithMultipleSubresources.
const char* kMultipleResourcesPageUrl("http://multipleresourcespage");
const char kMultipleResourcesPageUrl[] = "http://multipleresourcespage/";
// URL for BuildPageWithCSSNestedSubresources.
const char* kCssImportPageUrl("http://csspagewithimport");
const char kCssImportPageUrl[] = "http://csspagewithimport/";
// URL for BuildPageWithRelativeSubresource.
const char* kCssRelativePageUrl("http://css/csspage.html");
const char kCssRelativePageUrl[] = "http://css/csspage.html";
// URL for BuildPageWithWebUIJS.
const char* kCoreJsPageUrl("http://corejs");
const char kCoreJsPageUrl[] = "http://corejs/";
// URL for JS resource.
const char* kJsResourceUrl("http://javascriptpage/resources/javascript.js");
const char kJsResourceUrl[] = "http://javascriptpage/resources/javascript.js";
// URL for CSS resource.
const char* kCssResourceUrl("http://csspage/resources/stylesheet.css");
const char kCssResourceUrl[] = "http://csspage/resources/stylesheet.css";
// URL for CSS resource with import.
const char* kCssImportResourceUrl("http://csspage/resources/import.css");
const char kCssImportResourceUrl[] = "http://csspage/resources/import.css";
// Chrome URL for messaging JavaScript.
const char* kCoreJsResourceUrl("chrome://resources/js/ios/web_ui.js");
const char kCoreJsResourceUrl[] = "chrome://resources/js/ios/web_ui.js";
// String for relative resource URL.
const char* kRelativeCssString("myresource.css");
const char kRelativeCssString[] = "myresource.css";
// Template for JS tag with URL.
NSString* const kJsTagTemplate = @"<script src=\"%@\"></script>";
......@@ -107,20 +107,20 @@ NSString* PageForTagTemplateAndContent(NSString* tag_template,
- (NSString*)resourceForURL:(const GURL&)resourceURL {
// Resource for BuildSimplePage.
if (resourceURL == GURL(kSimplePageUrl))
if (resourceURL == kSimplePageUrl)
return [NSString stringWithFormat:kPageTemplate, @""];
// Resources for BuildPageWithJSSubresource.
if (resourceURL == GURL(kJsPageUrl))
if (resourceURL == kJsPageUrl)
return [self pageWithTagTemplate:kJsTagTemplate URL:kJsResourceUrl];
if (resourceURL == GURL(kJsResourceUrl))
if (resourceURL == kJsResourceUrl)
return kJsContent;
// Resources for BuildPageWithCSSSubresource.
if (resourceURL == GURL(kCssPageUrl))
if (resourceURL == kCssPageUrl)
return [self pageWithTagTemplate:kCssTagTemplate URL:kCssResourceUrl];
if (resourceURL == GURL(kCssResourceUrl))
if (resourceURL == kCssResourceUrl)
return kCssContent;
// Resource for BuildPageWithMultipleSubresources.
if (resourceURL == GURL(kMultipleResourcesPageUrl)) {
if (resourceURL == kMultipleResourcesPageUrl) {
NSString* JSTag =
[NSString stringWithFormat:kJsTagTemplate,
base::SysUTF8ToNSString(kJsResourceUrl)];
......@@ -135,10 +135,10 @@ NSString* PageForTagTemplateAndContent(NSString* tag_template,
return [NSString stringWithFormat:kPageTemplate, tags];
}
// Resources for BuildPageWithCSSNestedSubresource.
if (resourceURL == GURL(kCssImportPageUrl)) {
if (resourceURL == kCssImportPageUrl) {
return [self pageWithTagTemplate:kCssTagTemplate URL:kCssImportResourceUrl];
}
if (resourceURL == GURL(kCssImportResourceUrl)) {
if (resourceURL == kCssImportResourceUrl) {
return [NSString stringWithFormat:kCssImportTemplate,
base::SysUTF8ToNSString(kCssResourceUrl)];
}
......@@ -151,7 +151,7 @@ NSString* PageForTagTemplateAndContent(NSString* tag_template,
if (resourceURL == cssRelativeResourceURL)
return kRelativeCssContent;
// Resource for BuildPageWithWebUIJS.
if (resourceURL == GURL(kCoreJsPageUrl))
if (resourceURL == kCoreJsPageUrl)
return [self pageWithTagTemplate:kJsTagTemplate URL:kCoreJsResourceUrl];
NOTREACHED();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment