summaryrefslogtreecommitdiff
path: root/Source/WebCore/page/Location.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/page/Location.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/page/Location.cpp')
-rw-r--r--Source/WebCore/page/Location.cpp120
1 files changed, 70 insertions, 50 deletions
diff --git a/Source/WebCore/page/Location.cpp b/Source/WebCore/page/Location.cpp
index 6ae9af0bf..8eeeddae0 100644
--- a/Source/WebCore/page/Location.cpp
+++ b/Source/WebCore/page/Location.cpp
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -60,7 +60,15 @@ String Location::href() const
if (!m_frame)
return String();
- return url().string();
+ auto& url = this->url();
+
+ if (!url.hasUsername() && !url.hasPassword())
+ return url.string();
+
+ URL urlWithoutCredentials(url);
+ urlWithoutCredentials.setUser(WTF::emptyString());
+ urlWithoutCredentials.setPass(WTF::emptyString());
+ return urlWithoutCredentials.string();
}
String Location::protocol() const
@@ -68,7 +76,7 @@ String Location::protocol() const
if (!m_frame)
return String();
- return url().protocol() + ":";
+ return makeString(url().protocol(), ":");
}
String Location::host() const
@@ -78,8 +86,7 @@ String Location::host() const
// Note: this is the IE spec. The NS spec swaps the two, it says
// "The hostname property is the concatenation of the host and port properties, separated by a colon."
- const URL& url = this->url();
- return url.hasPort() ? url.host() + ":" + String::number(url.port()) : url.host();
+ return url().hostAndPort();
}
String Location::hostname() const
@@ -96,7 +103,7 @@ String Location::port() const
return String();
const URL& url = this->url();
- return url.hasPort() ? String::number(url.port()) : "";
+ return url.port() ? String::number(url.port().value()) : emptyString();
}
String Location::pathname() const
@@ -124,14 +131,14 @@ String Location::origin() const
return SecurityOrigin::create(url())->toString();
}
-PassRefPtr<DOMStringList> Location::ancestorOrigins() const
+Ref<DOMStringList> Location::ancestorOrigins() const
{
- RefPtr<DOMStringList> origins = DOMStringList::create();
+ auto origins = DOMStringList::create();
if (!m_frame)
- return origins.release();
+ return origins;
for (Frame* frame = m_frame->tree().parent(); frame; frame = frame->tree().parent())
- origins->append(frame->document()->securityOrigin()->toString());
- return origins.release();
+ origins->append(frame->document()->securityOrigin().toString());
+ return origins;
}
String Location::hash() const
@@ -143,44 +150,43 @@ String Location::hash() const
return fragmentIdentifier.isEmpty() ? emptyString() : "#" + fragmentIdentifier;
}
-void Location::setHref(const String& url, DOMWindow& activeWindow, DOMWindow& firstWindow)
+void Location::setHref(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& url)
{
if (!m_frame)
return;
- setLocation(url, activeWindow, firstWindow);
+ setLocation(activeWindow, firstWindow, url);
}
-void Location::setProtocol(const String& protocol, DOMWindow& activeWindow, DOMWindow& firstWindow, ExceptionCode& ec)
+ExceptionOr<void> Location::setProtocol(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& protocol)
{
if (!m_frame)
- return;
+ return { };
URL url = m_frame->document()->url();
- if (!url.setProtocol(protocol)) {
- ec = SYNTAX_ERR;
- return;
- }
- setLocation(url.string(), activeWindow, firstWindow);
+ if (!url.setProtocol(protocol))
+ return Exception { SYNTAX_ERR };
+ setLocation(activeWindow, firstWindow, url.string());
+ return { };
}
-void Location::setHost(const String& host, DOMWindow& activeWindow, DOMWindow& firstWindow)
+void Location::setHost(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& host)
{
if (!m_frame)
return;
URL url = m_frame->document()->url();
url.setHostAndPort(host);
- setLocation(url.string(), activeWindow, firstWindow);
+ setLocation(activeWindow, firstWindow, url.string());
}
-void Location::setHostname(const String& hostname, DOMWindow& activeWindow, DOMWindow& firstWindow)
+void Location::setHostname(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& hostname)
{
if (!m_frame)
return;
URL url = m_frame->document()->url();
url.setHost(hostname);
- setLocation(url.string(), activeWindow, firstWindow);
+ setLocation(activeWindow, firstWindow, url.string());
}
-void Location::setPort(const String& portString, DOMWindow& activeWindow, DOMWindow& firstWindow)
+void Location::setPort(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& portString)
{
if (!m_frame)
return;
@@ -190,34 +196,35 @@ void Location::setPort(const String& portString, DOMWindow& activeWindow, DOMWin
url.removePort();
else
url.setPort(port);
- setLocation(url.string(), activeWindow, firstWindow);
+ setLocation(activeWindow, firstWindow, url.string());
}
-void Location::setPathname(const String& pathname, DOMWindow& activeWindow, DOMWindow& firstWindow)
+void Location::setPathname(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& pathname)
{
if (!m_frame)
return;
URL url = m_frame->document()->url();
url.setPath(pathname);
- setLocation(url.string(), activeWindow, firstWindow);
+ setLocation(activeWindow, firstWindow, url.string());
}
-void Location::setSearch(const String& search, DOMWindow& activeWindow, DOMWindow& firstWindow)
+void Location::setSearch(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& search)
{
if (!m_frame)
return;
URL url = m_frame->document()->url();
url.setQuery(search);
- setLocation(url.string(), activeWindow, firstWindow);
+ setLocation(activeWindow, firstWindow, url.string());
}
-void Location::setHash(const String& hash, DOMWindow& activeWindow, DOMWindow& firstWindow)
+void Location::setHash(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& hash)
{
if (!m_frame)
return;
- URL url = m_frame->document()->url();
- String oldFragmentIdentifier = url.fragmentIdentifier();
- String newFragmentIdentifier = hash;
+ ASSERT(m_frame->document());
+ auto url = m_frame->document()->url();
+ auto oldFragmentIdentifier = url.fragmentIdentifier();
+ auto newFragmentIdentifier = hash;
if (hash[0] == '#')
newFragmentIdentifier = hash.substring(1);
url.setFragmentIdentifier(newFragmentIdentifier);
@@ -226,49 +233,62 @@ void Location::setHash(const String& hash, DOMWindow& activeWindow, DOMWindow& f
// cases where fragment identifiers are ignored or invalid.
if (equalIgnoringNullity(oldFragmentIdentifier, url.fragmentIdentifier()))
return;
- setLocation(url.string(), activeWindow, firstWindow);
+ setLocation(activeWindow, firstWindow, url.string());
}
-void Location::assign(const String& url, DOMWindow& activeWindow, DOMWindow& firstWindow)
+void Location::assign(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& url)
{
if (!m_frame)
return;
- setLocation(url, activeWindow, firstWindow);
+ setLocation(activeWindow, firstWindow, url);
}
-void Location::replace(const String& url, DOMWindow& activeWindow, DOMWindow& firstWindow)
+void Location::replace(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& url)
{
if (!m_frame)
return;
- // Note: We call DOMWindow::setLocation directly here because replace() always operates on the current frame.
- m_frame->document()->domWindow()->setLocation(url, activeWindow, firstWindow, LockHistoryAndBackForwardList);
+ ASSERT(m_frame->document());
+ ASSERT(m_frame->document()->domWindow());
+ // We call DOMWindow::setLocation directly here because replace() always operates on the current frame.
+ m_frame->document()->domWindow()->setLocation(activeWindow, firstWindow, url, LockHistoryAndBackForwardList);
}
void Location::reload(DOMWindow& activeWindow)
{
if (!m_frame)
return;
+
+ ASSERT(activeWindow.document());
+ ASSERT(m_frame->document());
+ ASSERT(m_frame->document()->domWindow());
+
+ auto& activeDocument = *activeWindow.document();
+ auto& targetDocument = *m_frame->document();
+
// FIXME: It's not clear this cross-origin security check is valuable.
// We allow one page to change the location of another. Why block attempts to reload?
// Other location operations simply block use of JavaScript URLs cross origin.
- DOMWindow* targetWindow = m_frame->document()->domWindow();
- if (!activeWindow.document()->securityOrigin()->canAccess(m_frame->document()->securityOrigin())) {
- targetWindow->printErrorMessage(targetWindow->crossDomainAccessErrorMessage(activeWindow));
+ if (!activeDocument.securityOrigin().canAccess(targetDocument.securityOrigin())) {
+ auto& targetWindow = *targetDocument.domWindow();
+ targetWindow.printErrorMessage(targetWindow.crossDomainAccessErrorMessage(activeWindow));
return;
}
- if (protocolIsJavaScript(m_frame->document()->url()))
+
+ if (protocolIsJavaScript(targetDocument.url()))
return;
- m_frame->navigationScheduler().scheduleRefresh();
+
+ m_frame->navigationScheduler().scheduleRefresh(activeDocument);
}
-void Location::setLocation(const String& url, DOMWindow& activeWindow, DOMWindow& firstWindow)
+void Location::setLocation(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& url)
{
ASSERT(m_frame);
- // We call findFrameForNavigation to handle the case of a seamless iframe correctly.
- Frame* frame = m_frame->loader().findFrameForNavigation(String(), activeWindow.document());
- if (!frame)
+ auto* targetFrame = m_frame->loader().findFrameForNavigation({ }, activeWindow.document());
+ if (!targetFrame)
return;
- frame->document()->domWindow()->setLocation(url, activeWindow, firstWindow);
+ ASSERT(targetFrame->document());
+ ASSERT(targetFrame->document()->domWindow());
+ targetFrame->document()->domWindow()->setLocation(activeWindow, firstWindow, url);
}
} // namespace WebCore