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

Unified Diff: third_party/WebKit/Source/core/html/forms/EmailInputType.cpp

Issue 2037963002: Make ScriptRegexp for email address a member of EmailInputType. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: explicit, simplify ensureEmailRegexp() Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/forms/EmailInputType.cpp
diff --git a/third_party/WebKit/Source/core/html/forms/EmailInputType.cpp b/third_party/WebKit/Source/core/html/forms/EmailInputType.cpp
index dbbd1ef7bb5660e450844de843ac31ea0b5da6fd..ea55a6bc744d7f58409c6cff4dd9c0c27c8504fa 100644
--- a/third_party/WebKit/Source/core/html/forms/EmailInputType.cpp
+++ b/third_party/WebKit/Source/core/html/forms/EmailInputType.cpp
@@ -30,8 +30,6 @@
#include "core/page/ChromeClient.h"
#include "platform/text/PlatformLocale.h"
#include "public/platform/Platform.h"
-#include "wtf/LeakAnnotations.h"
-#include "wtf/PassOwnPtr.h"
#include "wtf/text/StringBuilder.h"
#include <unicode/idna.h>
#include <unicode/unistr.h>
@@ -53,7 +51,12 @@ static const int32_t maximumDomainNameLength = 255;
// Use the same option as in url/url_canon_icu.cc
static const int32_t idnaConversionOption = UIDNA_CHECK_BIDI;
-String EmailInputType::convertEmailAddressToASCII(const String& address)
+std::unique_ptr<ScriptRegexp> EmailInputType::createEmailRegexp()
+{
+ return std::unique_ptr<ScriptRegexp>(new ScriptRegexp(emailPattern, TextCaseInsensitive));
+}
+
+String EmailInputType::convertEmailAddressToASCII(const ScriptRegexp& regexp, const String& address)
{
if (address.containsOnlyASCII())
return address;
@@ -82,7 +85,7 @@ String EmailInputType::convertEmailAddressToASCII(const String& address)
builder.append(address, 0, atPosition + 1);
builder.append(domainName.getBuffer(), domainName.length());
String asciiEmail = builder.toString();
- return isValidEmailAddress(asciiEmail) ? asciiEmail : address;
+ return isValidEmailAddress(regexp, asciiEmail) ? asciiEmail : address;
}
String EmailInputType::convertEmailAddressToUnicode(const String& address) const
@@ -128,21 +131,23 @@ static bool checkValidDotUsage(const String& domain)
return domain.find("..") == kNotFound;
}
-bool EmailInputType::isValidEmailAddress(const String& address)
+bool EmailInputType::isValidEmailAddress(const ScriptRegexp& regexp, const String& address)
{
int addressLength = address.length();
if (!addressLength)
return false;
- LEAK_SANITIZER_DISABLED_SCOPE;
- DEFINE_STATIC_LOCAL(const ScriptRegexp, regExp, (emailPattern, TextCaseInsensitive));
-
int matchLength;
- int matchOffset = regExp.match(address, 0, &matchLength);
+ int matchOffset = regexp.match(address, 0, &matchLength);
return !matchOffset && matchLength == addressLength;
}
+EmailInputType::EmailInputType(HTMLInputElement& element)
+ : BaseTextInputType(element)
+{
+}
+
InputType* EmailInputType::create(HTMLInputElement& element)
{
return new EmailInputType(element);
@@ -166,6 +171,13 @@ const AtomicString& EmailInputType::formControlType() const
return InputTypeNames::email;
}
+ScriptRegexp& EmailInputType::ensureEmailRegexp() const
+{
+ if (!m_emailRegexp)
+ m_emailRegexp = createEmailRegexp();
+ return *m_emailRegexp;
+}
+
// The return value is an invalid email address string if the specified string
// contains an invalid email address. Otherwise, null string is returned.
// If an empty string is returned, it means empty address is specified.
@@ -175,12 +187,12 @@ String EmailInputType::findInvalidAddress(const String& value) const
if (value.isEmpty())
return String();
if (!element().multiple())
- return isValidEmailAddress(value) ? String() : value;
+ return isValidEmailAddress(ensureEmailRegexp(), value) ? String() : value;
Vector<String> addresses;
value.split(',', true, addresses);
for (unsigned i = 0; i < addresses.size(); ++i) {
String stripped = stripLeadingAndTrailingHTMLSpaces(addresses[i]);
- if (!isValidEmailAddress(stripped))
+ if (!isValidEmailAddress(ensureEmailRegexp(), stripped))
return stripped;
}
return String();
@@ -268,7 +280,7 @@ String EmailInputType::convertFromVisibleValue(const String& visibleValue) const
{
String sanitizedValue = sanitizeValue(visibleValue);
if (!element().multiple())
- return convertEmailAddressToASCII(sanitizedValue);
+ return convertEmailAddressToASCII(ensureEmailRegexp(), sanitizedValue);
Vector<String> addresses;
sanitizedValue.split(',', true, addresses);
StringBuilder builder;
@@ -276,7 +288,7 @@ String EmailInputType::convertFromVisibleValue(const String& visibleValue) const
for (size_t i = 0; i < addresses.size(); ++i) {
if (i > 0)
builder.append(',');
- builder.append(convertEmailAddressToASCII(addresses[i]));
+ builder.append(convertEmailAddressToASCII(ensureEmailRegexp(), addresses[i]));
}
return builder.toString();
}

Powered by Google App Engine
This is Rietveld 408576698