Chromium Code Reviews| 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; |
| 85 } | 48 } |
| 86 } | 49 } |
| 87 | 50 |
| 88 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 51 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 89 false /* persist */, CONTENT_SETTING_DEFAULT); | 52 false /* persist */, CONTENT_SETTING_DEFAULT); |
| 90 } | 53 } |
| 91 | 54 |
| 92 void DurableStoragePermissionContext::UpdateContentSetting( | 55 void DurableStoragePermissionContext::UpdateContentSetting( |
| 93 const GURL& requesting_origin, | 56 const GURL& requesting_origin, |
| 94 const GURL& embedding_origin_ignored, | 57 const GURL& embedding_origin_ignored, |
| 95 ContentSetting content_setting) { | 58 ContentSetting content_setting) { |
| 96 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); | 59 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); |
| 97 DCHECK_EQ(embedding_origin_ignored, embedding_origin_ignored.GetOrigin()); | 60 DCHECK_EQ(embedding_origin_ignored, embedding_origin_ignored.GetOrigin()); |
| 98 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 61 DCHECK(content_setting == CONTENT_SETTING_ALLOW); |
|
mlamouri (slow - plz ping)
2015/11/26 12:45:49
Why are you doing this change? This method was ove
johnme
2015/11/26 18:28:48
They had a `DCHECK_NE(CONTENT_SETTING_BLOCK, conte
| |
| 99 content_setting == CONTENT_SETTING_BLOCK); | |
| 100 | 62 |
| 101 HostContentSettingsMapFactory::GetForProfile(profile())->SetContentSetting( | 63 HostContentSettingsMapFactory::GetForProfile(profile())->SetContentSetting( |
| 102 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), | 64 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), |
| 103 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, | 65 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, |
| 104 std::string(), content_setting); | 66 std::string(), content_setting); |
| 105 } | 67 } |
| 106 | 68 |
| 107 bool DurableStoragePermissionContext::IsRestrictedToSecureOrigins() const { | 69 bool DurableStoragePermissionContext::IsRestrictedToSecureOrigins() const { |
| 108 return true; | 70 return true; |
| 109 } | 71 } |
| 110 | 72 |
| 111 bool DurableStoragePermissionContext::IsOriginBookmarked( | 73 bool DurableStoragePermissionContext::IsOriginBookmarked( |
| 112 const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks, | 74 const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks, |
| 113 const GURL& origin) { | 75 const GURL& origin) { |
| 114 BookmarkModel::URLAndTitle looking_for; | 76 BookmarkModel::URLAndTitle looking_for; |
| 115 looking_for.url = origin; | 77 looking_for.url = origin; |
| 116 return std::binary_search(bookmarks.begin(), bookmarks.end(), looking_for, | 78 return std::binary_search(bookmarks.begin(), bookmarks.end(), looking_for, |
| 117 [](const BookmarkModel::URLAndTitle& a, | 79 [](const BookmarkModel::URLAndTitle& a, |
| 118 const BookmarkModel::URLAndTitle& b) { | 80 const BookmarkModel::URLAndTitle& b) { |
| 119 return a.url.GetOrigin() < b.url.GetOrigin(); | 81 return a.url.GetOrigin() < b.url.GetOrigin(); |
| 120 }); | 82 }); |
| 121 } | 83 } |
| OLD | NEW |