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

Side by Side Diff: chrome/browser/browsing_data/cookies_tree_model.cc

Issue 2005783005: Re-enable storage for Suborigins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Address msramek's nits and add comments Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/browsing_data/cookies_tree_model.h" 5 #include "chrome/browser/browsing_data/cookies_tree_model.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <functional> 10 #include <functional>
11 #include <map> 11 #include <map>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/memory/linked_ptr.h" 15 #include "base/memory/linked_ptr.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h" 18 #include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h"
19 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" 19 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
20 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h" 20 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h"
21 #include "chrome/browser/content_settings/cookie_settings_factory.h" 21 #include "chrome/browser/content_settings/cookie_settings_factory.h"
22 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
23 #include "components/content_settings/core/browser/cookie_settings.h" 23 #include "components/content_settings/core/browser/cookie_settings.h"
24 #include "content/public/common/origin_util.h"
24 #include "content/public/common/url_constants.h" 25 #include "content/public/common/url_constants.h"
25 #include "grit/theme_resources.h" 26 #include "grit/theme_resources.h"
26 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 27 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
27 #include "net/cookies/canonical_cookie.h" 28 #include "net/cookies/canonical_cookie.h"
28 #include "net/url_request/url_request_context.h" 29 #include "net/url_request/url_request_context.h"
29 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/gfx/image/image_skia.h" 32 #include "ui/gfx/image/image_skia.h"
32 #include "ui/resources/grit/ui_resources.h" 33 #include "ui/resources/grit/ui_resources.h"
33 34
(...skipping 29 matching lines...) Expand all
63 // We want to order by registry controlled domain, so we would get 64 // We want to order by registry controlled domain, so we would get
64 // google.com, ad.google.com, www.google.com, 65 // google.com, ad.google.com, www.google.com,
65 // microsoft.com, ad.microsoft.com. CanonicalizeHost transforms the origins 66 // microsoft.com, ad.microsoft.com. CanonicalizeHost transforms the origins
66 // into a form like google.com.www so that string comparisons work. 67 // into a form like google.com.www so that string comparisons work.
67 return (ltn->canonicalized_host() < 68 return (ltn->canonicalized_host() <
68 rtn->canonicalized_host()); 69 rtn->canonicalized_host());
69 } 70 }
70 }; 71 };
71 72
72 std::string CanonicalizeHost(const GURL& url) { 73 std::string CanonicalizeHost(const GURL& url) {
73 // The canonicalized representation makes the registry controlled domain 74 // The canonicalized representation makes the registry controlled domain come
74 // come first, and then adds subdomains in reverse order, e.g. 75 // first, and then adds subdomains in reverse order, e.g. 1.mail.google.com
75 // 1.mail.google.com would become google.com.mail.1, and then a standard 76 // would become google.com.mail.1, and then a standard string comparison works
76 // string comparison works to order hosts by registry controlled domain 77 // to order hosts by registry controlled domain first. Leading dots are
77 // first. Leading dots are ignored, ".google.com" is the same as 78 // ignored, ".google.com" is the same as "google.com".
78 // "google.com". 79 //
80 // Suborigins, an experimental Web platform feature defined in
81 // https://w3c.github.io/webappsec-suborigins/, are treated as part of the
82 // physical origin they are associated with. From a users perspective, they
83 // are part of and should be visualized as part of that host. For example,
84 // given a a Suborigin 'foobar' at 'https://example.com', this is serialized
85 // into the URL as 'https://foobar_example.com'. Thus, the host for this URL
86 // is canonicalized as 'example.com' to treat it as being part of that host,
87 // and thus the Suborigin is striped from the URL.
79 88
80 if (url.SchemeIsFile()) { 89 if (url.SchemeIsFile()) {
81 return std::string(url::kFileScheme) + 90 return std::string(url::kFileScheme) +
82 url::kStandardSchemeSeparator; 91 url::kStandardSchemeSeparator;
83 } 92 }
84 93
85 std::string host = url.host(); 94 std::string host = content::HostFromUrlStripSuborigin(url);
86 std::string retval = 95 std::string retval =
87 net::registry_controlled_domains::GetDomainAndRegistry( 96 net::registry_controlled_domains::GetDomainAndRegistry(
88 host, 97 host,
89 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 98 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
90 if (!retval.length()) // Is an IP address or other special origin. 99 if (!retval.length()) // Is an IP address or other special origin.
91 return host; 100 return host;
92 101
93 std::string::size_type position = host.rfind(retval); 102 std::string::size_type position = host.rfind(retval);
94 103
95 // The host may be the registry controlled domain, in which case fail fast. 104 // The host may be the registry controlled domain, in which case fail fast.
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 return DetailedInfo().Init(DetailedInfo::TYPE_ROOT); 633 return DetailedInfo().Init(DetailedInfo::TYPE_ROOT);
625 } 634 }
626 635
627 /////////////////////////////////////////////////////////////////////////////// 636 ///////////////////////////////////////////////////////////////////////////////
628 // CookieTreeHostNode, public: 637 // CookieTreeHostNode, public:
629 638
630 // static 639 // static
631 base::string16 CookieTreeHostNode::TitleForUrl(const GURL& url) { 640 base::string16 CookieTreeHostNode::TitleForUrl(const GURL& url) {
632 const std::string file_origin_node_name( 641 const std::string file_origin_node_name(
633 std::string(url::kFileScheme) + url::kStandardSchemeSeparator); 642 std::string(url::kFileScheme) + url::kStandardSchemeSeparator);
634 return base::UTF8ToUTF16(url.SchemeIsFile() ? file_origin_node_name 643 return base::UTF8ToUTF16(url.SchemeIsFile()
635 : url.host()); 644 ? file_origin_node_name
645 : content::HostFromUrlStripSuborigin(url));
636 } 646 }
637 647
638 CookieTreeHostNode::CookieTreeHostNode(const GURL& url) 648 CookieTreeHostNode::CookieTreeHostNode(const GURL& url)
639 : CookieTreeNode(TitleForUrl(url)), 649 : CookieTreeNode(TitleForUrl(url)),
640 url_(url), 650 url_(url),
641 canonicalized_host_(CanonicalizeHost(url)) {} 651 canonicalized_host_(CanonicalizeHost(url)) {}
642 652
643 CookieTreeHostNode::~CookieTreeHostNode() {} 653 CookieTreeHostNode::~CookieTreeHostNode() {}
644 654
645 std::string CookieTreeHostNode::GetHost() const { 655 std::string CookieTreeHostNode::GetHost() const {
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 void CookiesTreeModel::MaybeNotifyBatchesEnded() { 1552 void CookiesTreeModel::MaybeNotifyBatchesEnded() {
1543 // Only notify the observers if this is the outermost call to EndBatch() if 1553 // Only notify the observers if this is the outermost call to EndBatch() if
1544 // called in a nested manner. 1554 // called in a nested manner.
1545 if (batches_ended_ == batches_started_ && 1555 if (batches_ended_ == batches_started_ &&
1546 batches_seen_ == batches_expected_) { 1556 batches_seen_ == batches_expected_) {
1547 FOR_EACH_OBSERVER(Observer, 1557 FOR_EACH_OBSERVER(Observer,
1548 cookies_observer_list_, 1558 cookies_observer_list_,
1549 TreeModelEndBatch(this)); 1559 TreeModelEndBatch(this));
1550 } 1560 }
1551 } 1561 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698