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

Unified Diff: mojo/services/network/url_loader_impl.cc

Issue 1229903003: Mandoline: Implement basic "process per site" support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nit Created 5 years, 5 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
« no previous file with comments | « mojo/services/network/public/interfaces/url_loader.mojom ('k') | mojo/shell/application_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/network/url_loader_impl.cc
diff --git a/mojo/services/network/url_loader_impl.cc b/mojo/services/network/url_loader_impl.cc
index e2e88a1b43b1cd1ebbd77fa06747ddd5ec6175f0..f9590f148937fabff3989e952c9cfb6b442cf8c4 100644
--- a/mojo/services/network/url_loader_impl.cc
+++ b/mojo/services/network/url_loader_impl.cc
@@ -13,6 +13,7 @@
#include "net/base/elements_upload_data_stream.h"
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/base/upload_bytes_element_reader.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/redirect_info.h"
@@ -21,10 +22,46 @@
namespace mojo {
namespace {
+GURL GetSiteForURL(const GURL& url) {
+ // If the url has a host, then determine the site.
+ if (url.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 = url.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);
+ }
+ return site;
+ }
+
+ // If there is no host but there is a scheme, return the scheme.
+ // This is useful for cases like file URLs.
+ if (url.has_scheme())
+ return GURL(url.scheme() + ":");
+
+ // Otherwise the URL should be invalid; return an empty site.
+ DCHECK(!url.is_valid());
+ return GURL();
+}
+
// Generates an URLResponsePtr from the response state of a net::URLRequest.
URLResponsePtr MakeURLResponse(const net::URLRequest* url_request) {
URLResponsePtr response(URLResponse::New());
response->url = String::From(url_request->url());
+ response->site = GetSiteForURL(url_request->url()).spec();
const net::HttpResponseHeaders* headers = url_request->response_headers();
if (headers) {
« no previous file with comments | « mojo/services/network/public/interfaces/url_loader.mojom ('k') | mojo/shell/application_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698