Cleanup: WebContextMenuClient::searchWithGoogle() should parse URL using URL { URL...
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 Jun 2017 00:55:56 +0000 (00:55 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 Jun 2017 00:55:56 +0000 (00:55 +0000)
instead of URL { ParsedURLString, ... }
https://bugs.webkit.org/show_bug.cgi?id=173495
<rdar://problem/32827445>

Reviewed by Alex Christensen.

URL(ParsedURLString, ...) should only be used with a string that was the result of URL::string().
Otherwise, it will cause an assertion failure if the canonicalized URL differs from the string.
Although it is unlikely that the hardcoded string in WebContextMenuClient::searchWithGoogle()
would differ from the canonicalized URL it is best practice to use URL(URL(), ...) to
parse an arbitrary string that looks like a URL.

Also modernize the code using C++14 idioms.

Source/WebKit/win:

* WebCoreSupport/WebContextMenuClient.cpp:
(WebContextMenuClient::searchWithGoogle):

Source/WebKit2:

* WebProcess/WebCoreSupport/WebContextMenuClient.cpp:
(WebKit::WebContextMenuClient::searchWithGoogle):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@218435 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreSupport/WebContextMenuClient.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebCoreSupport/WebContextMenuClient.cpp

index ccd7e94..2fb4a99 100644 (file)
@@ -1,3 +1,23 @@
+2017-06-16  Daniel Bates  <dabates@apple.com>
+
+        Cleanup: WebContextMenuClient::searchWithGoogle() should parse URL using URL { URL { }, ... }
+        instead of URL { ParsedURLString, ... }
+        https://bugs.webkit.org/show_bug.cgi?id=173495
+        <rdar://problem/32827445>
+
+        Reviewed by Alex Christensen.
+
+        URL(ParsedURLString, ...) should only be used with a string that was the result of URL::string().
+        Otherwise, it will cause an assertion failure if the canonicalized URL differs from the string.
+        Although it is unlikely that the hardcoded string in WebContextMenuClient::searchWithGoogle()
+        would differ from the canonicalized URL it is best practice to use URL(URL(), ...) to
+        parse an arbitrary string that looks like a URL.
+
+        Also modernize the code using C++14 idioms.
+
+        * WebCoreSupport/WebContextMenuClient.cpp:
+        (WebContextMenuClient::searchWithGoogle):
+
 2017-06-15  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [Win] WebKit shouldn't include the forwarding header of WebKit itself
index 62eb159..9f1aa17 100644 (file)
@@ -61,15 +61,13 @@ void WebContextMenuClient::searchWithGoogle(const Frame* frame)
     String searchString = frame->editor().selectedText();
     searchString.stripWhiteSpace();
     String encoded = encodeWithURLEscapeSequences(searchString);
-    encoded.replace("%20", "+");
-    
-    String url("http://www.google.com/search?q=");
-    url.append(encoded);
-    url.append("&ie=UTF-8&oe=UTF-8");
+    encoded.replace(ASCIILiteral { "%20" }, ASCIILiteral { "+" });
+
+    String url = "http://www.google.com/search?q=" + encoded + "&ie=UTF-8&oe=UTF-8";
 
     if (Page* page = frame->page()) {
         UserGestureIndicator indicator(ProcessingUserGesture);
-        page->mainFrame().loader().urlSelected(URL(ParsedURLString, url), String(), 0, LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
+        page->mainFrame().loader().urlSelected(URL { URL { }, url }, { }, nullptr, LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
     }
 }
 
index 24086fd..9590dc7 100644 (file)
@@ -1,3 +1,23 @@
+2017-06-16  Daniel Bates  <dabates@apple.com>
+
+        Cleanup: WebContextMenuClient::searchWithGoogle() should parse URL using URL { URL { }, ... }
+        instead of URL { ParsedURLString, ... }
+        https://bugs.webkit.org/show_bug.cgi?id=173495
+        <rdar://problem/32827445>
+
+        Reviewed by Alex Christensen.
+
+        URL(ParsedURLString, ...) should only be used with a string that was the result of URL::string().
+        Otherwise, it will cause an assertion failure if the canonicalized URL differs from the string.
+        Although it is unlikely that the hardcoded string in WebContextMenuClient::searchWithGoogle()
+        would differ from the canonicalized URL it is best practice to use URL(URL(), ...) to
+        parse an arbitrary string that looks like a URL.
+
+        Also modernize the code using C++14 idioms.
+
+        * WebProcess/WebCoreSupport/WebContextMenuClient.cpp:
+        (WebKit::WebContextMenuClient::searchWithGoogle):
+
 2017-06-16  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iOS DnD] Upstream iOS drag and drop implementation into OpenSource WebKit
index 10d8f56..6d58e36 100644 (file)
@@ -62,13 +62,13 @@ void WebContextMenuClient::searchWithGoogle(const Frame* frame)
     String searchString = frame->editor().selectedText();
     searchString.stripWhiteSpace();
     String encoded = encodeWithURLEscapeSequences(searchString);
-    encoded.replace("%20", "+");
-    
+    encoded.replace(ASCIILiteral { "%20" }, ASCIILiteral { "+" });
+
     String url = "http://www.google.com/search?q=" + encoded + "&ie=UTF-8&oe=UTF-8";
 
     if (Page* page = frame->page()) {
         UserGestureIndicator indicator(ProcessingUserGesture);
-        page->mainFrame().loader().urlSelected(URL(ParsedURLString, url), String(), 0, LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
+        page->mainFrame().loader().urlSelected(URL { URL { }, url }, { }, nullptr, LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
     }
 }
 #endif