OLD | NEW |
---|---|
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/host_content_settings_map_factory.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
13 #include "chrome/browser/permissions/permission_request_id.h" | 14 #include "chrome/browser/permissions/permission_request_id.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "components/bookmarks/browser/bookmark_model.h" | 16 #include "components/bookmarks/browser/bookmark_model.h" |
17 #include "components/content_settings/core/browser/cookie_settings.h" | |
16 #include "components/content_settings/core/browser/host_content_settings_map.h" | 18 #include "components/content_settings/core/browser/host_content_settings_map.h" |
17 #include "components/content_settings/core/browser/website_settings_registry.h" | 19 #include "components/content_settings/core/browser/website_settings_registry.h" |
18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/child_process_security_policy.h" | 21 #include "content/public/browser/child_process_security_policy.h" |
20 #include "content/public/browser/permission_type.h" | 22 #include "content/public/browser/permission_type.h" |
21 #include "content/public/common/origin_util.h" | 23 #include "content/public/common/origin_util.h" |
22 #include "url/gurl.h" | 24 #include "url/gurl.h" |
23 | 25 |
24 using bookmarks::BookmarkModel; | 26 using bookmarks::BookmarkModel; |
25 | 27 |
26 DurableStoragePermissionContext::DurableStoragePermissionContext( | 28 DurableStoragePermissionContext::DurableStoragePermissionContext( |
27 Profile* profile) | 29 Profile* profile) |
28 : PermissionContextBase(profile, | 30 : PermissionContextBase(profile, |
29 content::PermissionType::DURABLE_STORAGE, | 31 content::PermissionType::DURABLE_STORAGE, |
30 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) {} | 32 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) {} |
31 | 33 |
32 void DurableStoragePermissionContext::DecidePermission( | 34 void DurableStoragePermissionContext::DecidePermission( |
33 content::WebContents* web_contents, | 35 content::WebContents* web_contents, |
34 const PermissionRequestID& id, | 36 const PermissionRequestID& id, |
35 const GURL& requesting_origin, | 37 const GURL& requesting_origin, |
36 const GURL& embedding_origin, | 38 const GURL& embedding_origin, |
jww
2016/10/01 04:46:20
Is embedding_origin guaranteed to be the top-level
dmurph
2016/10/04 22:00:45
Ok, so I removed this check, and we just check the
| |
37 bool user_gesture, | 39 bool user_gesture, |
38 const BrowserPermissionCallback& callback) { | 40 const BrowserPermissionCallback& callback) { |
39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 41 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
40 | 42 |
43 scoped_refptr<content_settings::CookieSettings> cookie_settings = | |
44 CookieSettingsFactory::GetForProfile(profile()); | |
45 | |
46 // Don't grant durable if we can't write cookies. | |
47 if (!cookie_settings->IsSettingCookieAllowed(requesting_origin, | |
48 embedding_origin)) { | |
michaeln
2016/09/30 22:19:03
The comment in the .h file says "or already grante
michaeln
2016/09/30 22:21:21
just read the bug... maybe use IsSettingCookiesAll
jww
2016/10/01 04:46:20
I don't know what dmurph@'s actually intent here,
dmurph
2016/10/04 22:00:45
Ok, so I'm now also blocking granting this permiss
dmurph
2016/10/04 22:00:45
This comment was wrong - we only call this if the
| |
49 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
50 false /* persist */, CONTENT_SETTING_DEFAULT); | |
51 return; | |
52 } | |
53 | |
41 // TODO(dgrogan): Remove bookmarks check in favor of site engagement. In the | 54 // TODO(dgrogan): Remove bookmarks check in favor of site engagement. In the |
42 // meantime maybe grant permission to A2HS origins as well. | 55 // meantime maybe grant permission to A2HS origins as well. |
43 BookmarkModel* model = | 56 BookmarkModel* model = |
44 BookmarkModelFactory::GetForBrowserContextIfExists(profile()); | 57 BookmarkModelFactory::GetForBrowserContextIfExists(profile()); |
45 if (model) { | 58 if (model) { |
46 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks; | 59 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks; |
47 model->GetBookmarks(&bookmarks); | 60 model->GetBookmarks(&bookmarks); |
48 if (IsOriginBookmarked(bookmarks, requesting_origin)) { | 61 if (IsOriginBookmarked(bookmarks, requesting_origin)) { |
49 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 62 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
50 true /* persist */, CONTENT_SETTING_ALLOW); | 63 true /* persist */, CONTENT_SETTING_ALLOW); |
(...skipping 28 matching lines...) Expand all Loading... | |
79 const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks, | 92 const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks, |
80 const GURL& origin) { | 93 const GURL& origin) { |
81 BookmarkModel::URLAndTitle looking_for; | 94 BookmarkModel::URLAndTitle looking_for; |
82 looking_for.url = origin; | 95 looking_for.url = origin; |
83 return std::binary_search(bookmarks.begin(), bookmarks.end(), looking_for, | 96 return std::binary_search(bookmarks.begin(), bookmarks.end(), looking_for, |
84 [](const BookmarkModel::URLAndTitle& a, | 97 [](const BookmarkModel::URLAndTitle& a, |
85 const BookmarkModel::URLAndTitle& b) { | 98 const BookmarkModel::URLAndTitle& b) { |
86 return a.url.GetOrigin() < b.url.GetOrigin(); | 99 return a.url.GetOrigin() < b.url.GetOrigin(); |
87 }); | 100 }); |
88 } | 101 } |
OLD | NEW |