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

Unified Diff: components/subresource_filter/core/common/first_party_origin.cc

Issue 2288023003: Cache is_third_party requests in a one-entry cache. (Closed)
Patch Set: Address more comments from engedy@ Created 4 years, 2 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: components/subresource_filter/core/common/first_party_origin.cc
diff --git a/components/subresource_filter/core/common/first_party_origin.cc b/components/subresource_filter/core/common/first_party_origin.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a622c698ba747aaa5008aa903b591a8843070b6f
--- /dev/null
+++ b/components/subresource_filter/core/common/first_party_origin.cc
@@ -0,0 +1,45 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/subresource_filter/core/common/first_party_origin.h"
+
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
+
+namespace subresource_filter {
+
+namespace {
+
+bool IsThirdPartyImpl(const GURL& url, const GURL& first_party_url) {
+ return !net::registry_controlled_domains::SameDomainOrHost(
+ url, first_party_url,
+ net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
+}
+
+} // namespace
+
+FirstPartyOrigin::FirstPartyOrigin(url::Origin document_origin)
+ : document_origin_(std::move(document_origin)) {
+ document_origin_as_gurl_ = GURL(document_origin_.Serialize());
+}
+
+bool FirstPartyOrigin::IsThirdParty(const GURL& url) const {
+ if (document_origin_.unique())
+ return true;
+ if (!last_checked_host_.empty() && url.host_piece() == last_checked_host_)
+ return last_checked_host_was_third_party_;
+
+ url.host_piece().CopyToString(&last_checked_host_);
+ last_checked_host_was_third_party_ =
+ IsThirdPartyImpl(url, document_origin_as_gurl_);
+ return last_checked_host_was_third_party_;
+}
+
+bool FirstPartyOrigin::IsThirdParty(const GURL& url,
+ const url::Origin& first_party_origin) {
+ // TODO(pkalinnikov): Avoid converting Origin to GURL.
+ return first_party_origin.unique() ||
+ IsThirdPartyImpl(url, GURL(first_party_origin.Serialize()));
+}
+
+} // namespace subresouce_filter

Powered by Google App Engine
This is Rietveld 408576698