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" |
(...skipping 15 matching lines...) Expand all Loading... |
26 Profile* profile) | 26 Profile* profile) |
27 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) {} | 27 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) {} |
28 | 28 |
29 void DurableStoragePermissionContext::DecidePermission( | 29 void DurableStoragePermissionContext::DecidePermission( |
30 content::WebContents* web_contents, | 30 content::WebContents* web_contents, |
31 const PermissionRequestID& id, | 31 const PermissionRequestID& id, |
32 const GURL& requesting_origin, | 32 const GURL& requesting_origin, |
33 const GURL& embedding_origin, | 33 const GURL& embedding_origin, |
34 bool user_gesture, | 34 bool user_gesture, |
35 const BrowserPermissionCallback& callback) { | 35 const BrowserPermissionCallback& callback) { |
36 // TODO(dgrogan): Reuse the base class's implementation of everything from | |
37 // here to using bookmarks. | |
38 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 36 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
39 | 37 |
40 if (!requesting_origin.is_valid() || !embedding_origin.is_valid()) { | |
41 std::string type_name = | |
42 content_settings::WebsiteSettingsRegistry::GetInstance() | |
43 ->Get(CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) | |
44 ->name(); | |
45 | |
46 DVLOG(1) << "Attempt to use " << type_name | |
47 << " from an invalid URL: " << requesting_origin << "," | |
48 << embedding_origin << " (" << type_name | |
49 << " is not supported in popups)"; | |
50 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
51 false /* persist */, CONTENT_SETTING_BLOCK); | |
52 return; | |
53 } | |
54 | |
55 if (IsRestrictedToSecureOrigins() && | |
56 !content::IsOriginSecure(requesting_origin)) { | |
57 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
58 false /* persist */, CONTENT_SETTING_BLOCK); | |
59 return; | |
60 } | |
61 | |
62 ContentSetting content_setting = | |
63 HostContentSettingsMapFactory::GetForProfile(profile()) | |
64 ->GetContentSettingAndMaybeUpdateLastUsage( | |
65 requesting_origin, embedding_origin, | |
66 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, std::string()); | |
67 | |
68 DCHECK_NE(CONTENT_SETTING_BLOCK, content_setting); | |
69 if (content_setting == CONTENT_SETTING_ALLOW) { | |
70 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
71 false /* persist */, content_setting); | |
72 return; | |
73 } | |
74 | |
75 // TODO(dgrogan): Remove bookmarks check in favor of site engagement. In the | 38 // TODO(dgrogan): Remove bookmarks check in favor of site engagement. In the |
76 // meantime maybe grant permission to A2HS origins as well. | 39 // meantime maybe grant permission to A2HS origins as well. |
77 BookmarkModel* model = BookmarkModelFactory::GetForProfileIfExists(profile()); | 40 BookmarkModel* model = BookmarkModelFactory::GetForProfileIfExists(profile()); |
78 if (model) { | 41 if (model) { |
79 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks; | 42 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks; |
80 model->GetBookmarks(&bookmarks); | 43 model->GetBookmarks(&bookmarks); |
81 if (IsOriginBookmarked(bookmarks, requesting_origin)) { | 44 if (IsOriginBookmarked(bookmarks, requesting_origin)) { |
82 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 45 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
83 true /* persist */, CONTENT_SETTING_ALLOW); | 46 true /* persist */, CONTENT_SETTING_ALLOW); |
84 return; | 47 return; |
(...skipping 27 matching lines...) Expand all Loading... |
112 const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks, | 75 const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks, |
113 const GURL& origin) { | 76 const GURL& origin) { |
114 BookmarkModel::URLAndTitle looking_for; | 77 BookmarkModel::URLAndTitle looking_for; |
115 looking_for.url = origin; | 78 looking_for.url = origin; |
116 return std::binary_search(bookmarks.begin(), bookmarks.end(), looking_for, | 79 return std::binary_search(bookmarks.begin(), bookmarks.end(), looking_for, |
117 [](const BookmarkModel::URLAndTitle& a, | 80 [](const BookmarkModel::URLAndTitle& a, |
118 const BookmarkModel::URLAndTitle& b) { | 81 const BookmarkModel::URLAndTitle& b) { |
119 return a.url.GetOrigin() < b.url.GetOrigin(); | 82 return a.url.GetOrigin() < b.url.GetOrigin(); |
120 }); | 83 }); |
121 } | 84 } |
OLD | NEW |