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

Side by Side Diff: chrome/browser/storage/durable_storage_permission_context.cc

Issue 2393103002: [Durable] Updated Durable heuristic to use 'important sites' (Closed)
Patch Set: windows test fix 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/storage/durable_storage_permission_context.h" 5 #include "chrome/browser/storage/durable_storage_permission_context.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
11 #include "chrome/browser/content_settings/cookie_settings_factory.h" 11 #include "chrome/browser/content_settings/cookie_settings_factory.h"
12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
14 #include "chrome/browser/engagement/important_sites_util.h"
14 #include "chrome/browser/permissions/permission_request_id.h" 15 #include "chrome/browser/permissions/permission_request_id.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "components/bookmarks/browser/bookmark_model.h" 17 #include "components/bookmarks/browser/bookmark_model.h"
17 #include "components/content_settings/core/browser/cookie_settings.h" 18 #include "components/content_settings/core/browser/cookie_settings.h"
18 #include "components/content_settings/core/browser/host_content_settings_map.h" 19 #include "components/content_settings/core/browser/host_content_settings_map.h"
19 #include "components/content_settings/core/browser/website_settings_registry.h" 20 #include "components/content_settings/core/browser/website_settings_registry.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/child_process_security_policy.h" 22 #include "content/public/browser/child_process_security_policy.h"
22 #include "content/public/browser/permission_type.h" 23 #include "content/public/browser/permission_type.h"
23 #include "content/public/common/origin_util.h" 24 #include "content/public/common/origin_util.h"
25 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
24 #include "url/gurl.h" 26 #include "url/gurl.h"
25 27
26 using bookmarks::BookmarkModel; 28 using bookmarks::BookmarkModel;
27 29
28 DurableStoragePermissionContext::DurableStoragePermissionContext( 30 DurableStoragePermissionContext::DurableStoragePermissionContext(
29 Profile* profile) 31 Profile* profile)
30 : PermissionContextBase(profile, 32 : PermissionContextBase(profile,
31 content::PermissionType::DURABLE_STORAGE, 33 content::PermissionType::DURABLE_STORAGE,
32 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) {} 34 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) {}
33 35
(...skipping 21 matching lines...) Expand all
55 // Don't grant durable if we can't write cookies. 57 // Don't grant durable if we can't write cookies.
56 scoped_refptr<content_settings::CookieSettings> cookie_settings = 58 scoped_refptr<content_settings::CookieSettings> cookie_settings =
57 CookieSettingsFactory::GetForProfile(profile()); 59 CookieSettingsFactory::GetForProfile(profile());
58 if (!cookie_settings->IsSettingCookieAllowed(requesting_origin, 60 if (!cookie_settings->IsSettingCookieAllowed(requesting_origin,
59 requesting_origin)) { 61 requesting_origin)) {
60 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 62 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
61 false /* persist */, CONTENT_SETTING_DEFAULT); 63 false /* persist */, CONTENT_SETTING_DEFAULT);
62 return; 64 return;
63 } 65 }
64 66
65 // TODO(dmurph): Remove bookmarks check in favor of important sites. 67 const size_t kMaxImportantResults = 10;
66 BookmarkModel* model = 68 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites =
67 BookmarkModelFactory::GetForBrowserContextIfExists(profile()); 69 ImportantSitesUtil::GetImportantRegisterableDomains(profile(),
68 if (model) { 70 kMaxImportantResults);
69 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks; 71
70 model->GetBookmarks(&bookmarks); 72 std::string registerable_domain =
71 if (IsOriginBookmarked(bookmarks, requesting_origin)) { 73 net::registry_controlled_domains::GetDomainAndRegistry(
74 requesting_origin,
75 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
76 if (registerable_domain.empty() && requesting_origin.HostIsIPAddress())
77 registerable_domain = requesting_origin.host();
78
79 for (const auto& important_site : important_sites) {
80 if (important_site.registerable_domain == registerable_domain) {
72 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 81 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
73 true /* persist */, CONTENT_SETTING_ALLOW); 82 true /* persist */, CONTENT_SETTING_ALLOW);
74 return; 83 return;
75 } 84 }
76 } 85 }
77 86
78 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 87 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
79 false /* persist */, CONTENT_SETTING_DEFAULT); 88 false /* persist */, CONTENT_SETTING_DEFAULT);
80 } 89 }
81 90
82 void DurableStoragePermissionContext::UpdateContentSetting( 91 void DurableStoragePermissionContext::UpdateContentSetting(
83 const GURL& requesting_origin, 92 const GURL& requesting_origin,
84 const GURL& embedding_origin_ignored, 93 const GURL& embedding_origin_ignored,
85 ContentSetting content_setting) { 94 ContentSetting content_setting) {
86 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); 95 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin());
87 DCHECK_EQ(embedding_origin_ignored, embedding_origin_ignored.GetOrigin()); 96 DCHECK_EQ(embedding_origin_ignored, embedding_origin_ignored.GetOrigin());
88 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 97 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
89 content_setting == CONTENT_SETTING_BLOCK); 98 content_setting == CONTENT_SETTING_BLOCK);
90 99
91 HostContentSettingsMapFactory::GetForProfile(profile()) 100 HostContentSettingsMapFactory::GetForProfile(profile())
92 ->SetContentSettingDefaultScope(requesting_origin, GURL(), 101 ->SetContentSettingDefaultScope(requesting_origin, GURL(),
93 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, 102 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE,
94 std::string(), content_setting); 103 std::string(), content_setting);
95 } 104 }
96 105
97 bool DurableStoragePermissionContext::IsRestrictedToSecureOrigins() const { 106 bool DurableStoragePermissionContext::IsRestrictedToSecureOrigins() const {
98 return true; 107 return true;
99 } 108 }
100
101 bool DurableStoragePermissionContext::IsOriginBookmarked(
102 const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks,
103 const GURL& origin) {
104 BookmarkModel::URLAndTitle looking_for;
105 looking_for.url = origin;
106 return std::binary_search(bookmarks.begin(), bookmarks.end(), looking_for,
107 [](const BookmarkModel::URLAndTitle& a,
108 const BookmarkModel::URLAndTitle& b) {
109 return a.url.GetOrigin() < b.url.GetOrigin();
110 });
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698