| Index: mojo/services/network/network_service_impl.cc
|
| diff --git a/mojo/services/network/network_service_impl.cc b/mojo/services/network/network_service_impl.cc
|
| index 661f7e0cf6f910523c69c04cf840e0633c2e89a6..1dd57100c8e10aef4e1104aa4bc0e9d40a4ffa9a 100644
|
| --- a/mojo/services/network/network_service_impl.cc
|
| +++ b/mojo/services/network/network_service_impl.cc
|
| @@ -12,6 +12,7 @@
|
| #include "mojo/services/network/udp_socket_impl.h"
|
| #include "mojo/services/network/url_loader_impl.h"
|
| #include "mojo/services/network/web_socket_impl.h"
|
| +#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
|
|
|
| namespace mojo {
|
|
|
| @@ -33,6 +34,48 @@ void NetworkServiceImpl::GetCookieStore(InterfaceRequest<CookieStore> store) {
|
| new CookieStoreImpl(context_, origin_, app_refcount_->Clone(), store.Pass());
|
| }
|
|
|
| +void NetworkServiceImpl::GetSiteForURL(const String& url,
|
| + const GetSiteForURLCallback& callback) {
|
| + GURL gurl(url);
|
| + // If the url has a host, then determine the site.
|
| + if (gurl.has_host()) {
|
| + // Only keep the scheme and registered domain as given by GetOrigin. This
|
| + // may also include a port, which we need to drop.
|
| + GURL site = gurl.GetOrigin();
|
| +
|
| + // Remove port, if any.
|
| + if (site.has_port()) {
|
| + GURL::Replacements rep;
|
| + rep.ClearPort();
|
| + site = site.ReplaceComponents(rep);
|
| + }
|
| +
|
| + // If this URL has a registered domain, we only want to remember that part.
|
| + std::string domain =
|
| + net::registry_controlled_domains::GetDomainAndRegistry(
|
| + url,
|
| + net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
|
| + if (!domain.empty()) {
|
| + GURL::Replacements rep;
|
| + rep.SetHostStr(domain);
|
| + site = site.ReplaceComponents(rep);
|
| + }
|
| + callback.Run(String::From(site.spec()));
|
| + return;
|
| + }
|
| +
|
| + // If there is no host but there is a scheme, return the scheme.
|
| + // This is useful for cases like file URLs.
|
| + if (gurl.has_scheme()) {
|
| + callback.Run(String::From(GURL(gurl.scheme() + ":").spec()));
|
| + return;
|
| + }
|
| +
|
| + // Otherwise the URL should be invalid; return an empty site.
|
| + DCHECK(!gurl.is_valid());
|
| + callback.Run(String());
|
| +}
|
| +
|
| void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) {
|
| new WebSocketImpl(context_, app_refcount_->Clone(), socket.Pass());
|
| }
|
|
|