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

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: 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
30 namespace {} // namespace
raymes 2016/10/05 23:04:27 nit: is this still needed?
dmurph 2016/10/06 01:02:00 Done.
31
28 DurableStoragePermissionContext::DurableStoragePermissionContext( 32 DurableStoragePermissionContext::DurableStoragePermissionContext(
29 Profile* profile) 33 Profile* profile)
30 : PermissionContextBase(profile, 34 : PermissionContextBase(profile,
31 content::PermissionType::DURABLE_STORAGE, 35 content::PermissionType::DURABLE_STORAGE,
32 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) {} 36 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) {}
33 37
34 void DurableStoragePermissionContext::DecidePermission( 38 void DurableStoragePermissionContext::DecidePermission(
35 content::WebContents* web_contents, 39 content::WebContents* web_contents,
36 const PermissionRequestID& id, 40 const PermissionRequestID& id,
37 const GURL& requesting_origin, 41 const GURL& requesting_origin,
(...skipping 17 matching lines...) Expand all
55 // Don't grant durable if we can't write cookies. 59 // Don't grant durable if we can't write cookies.
56 scoped_refptr<content_settings::CookieSettings> cookie_settings = 60 scoped_refptr<content_settings::CookieSettings> cookie_settings =
57 CookieSettingsFactory::GetForProfile(profile()); 61 CookieSettingsFactory::GetForProfile(profile());
58 if (!cookie_settings->IsSettingCookieAllowed(requesting_origin, 62 if (!cookie_settings->IsSettingCookieAllowed(requesting_origin,
59 requesting_origin)) { 63 requesting_origin)) {
60 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 64 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
61 false /* persist */, CONTENT_SETTING_DEFAULT); 65 false /* persist */, CONTENT_SETTING_DEFAULT);
62 return; 66 return;
63 } 67 }
64 68
65 // TODO(dmurph): Remove bookmarks check in favor of important sites. 69 static const size_t kMaxImportantResults = 10;
michaeln 2016/10/05 23:27:45 why static? i dont see the need for static here an
dmurph 2016/10/06 01:02:00 We discussed this on the bug, we are limiting the
66 BookmarkModel* model = 70 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites =
67 BookmarkModelFactory::GetForBrowserContextIfExists(profile()); 71 ImportantSitesUtil::GetImportantRegisterableDomains(profile(),
68 if (model) { 72 kMaxImportantResults);
69 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks; 73
70 model->GetBookmarks(&bookmarks); 74 std::string registerable_domain =
71 if (IsOriginBookmarked(bookmarks, requesting_origin)) { 75 net::registry_controlled_domains::GetDomainAndRegistry(
76 requesting_origin,
77 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
78 if (registerable_domain.empty() && requesting_origin.HostIsIPAddress())
79 registerable_domain = requesting_origin.host();
80
81 for (const auto& important_site : important_sites) {
82 if (important_site.registerable_domain == registerable_domain) {
michaeln 2016/10/05 23:27:45 maybe not for this cl, but nice utlits could be Im
dmurph 2016/10/06 01:02:00 SGTM, I'll make that in another CL.
72 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 83 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
73 true /* persist */, CONTENT_SETTING_ALLOW); 84 true /* persist */, CONTENT_SETTING_ALLOW);
74 return; 85 return;
75 } 86 }
76 } 87 }
77 88
78 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 89 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
79 false /* persist */, CONTENT_SETTING_DEFAULT); 90 false /* persist */, CONTENT_SETTING_DEFAULT);
80 } 91 }
81 92
82 void DurableStoragePermissionContext::UpdateContentSetting( 93 void DurableStoragePermissionContext::UpdateContentSetting(
83 const GURL& requesting_origin, 94 const GURL& requesting_origin,
84 const GURL& embedding_origin_ignored, 95 const GURL& embedding_origin_ignored,
85 ContentSetting content_setting) { 96 ContentSetting content_setting) {
86 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); 97 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin());
87 DCHECK_EQ(embedding_origin_ignored, embedding_origin_ignored.GetOrigin()); 98 DCHECK_EQ(embedding_origin_ignored, embedding_origin_ignored.GetOrigin());
88 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 99 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
89 content_setting == CONTENT_SETTING_BLOCK); 100 content_setting == CONTENT_SETTING_BLOCK);
90 101
91 HostContentSettingsMapFactory::GetForProfile(profile()) 102 HostContentSettingsMapFactory::GetForProfile(profile())
92 ->SetContentSettingDefaultScope(requesting_origin, GURL(), 103 ->SetContentSettingDefaultScope(requesting_origin, GURL(),
93 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, 104 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE,
94 std::string(), content_setting); 105 std::string(), content_setting);
95 } 106 }
96 107
97 bool DurableStoragePermissionContext::IsRestrictedToSecureOrigins() const { 108 bool DurableStoragePermissionContext::IsRestrictedToSecureOrigins() const {
98 return true; 109 return true;
99 } 110 }
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