| 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 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 DurableStoragePermissionContext::DurableStoragePermissionContext( | 26 DurableStoragePermissionContext::DurableStoragePermissionContext( |
| 27 Profile* profile) | 27 Profile* profile) |
| 28 : PermissionContextBase(profile, | 28 : PermissionContextBase(profile, |
| 29 content::PermissionType::DURABLE_STORAGE, | 29 content::PermissionType::DURABLE_STORAGE, |
| 30 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) {} | 30 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) {} |
| 31 | 31 |
| 32 void DurableStoragePermissionContext::DecidePermission( | 32 void DurableStoragePermissionContext::DecidePermission( |
| 33 content::WebContents* web_contents, | 33 content::WebContents* web_contents, |
| 34 const PermissionRequestID& id, | 34 const PermissionRequestID& id, |
| 35 const GURL& requesting_origin, | 35 const url::Origin& requesting_origin, |
| 36 const GURL& embedding_origin, | 36 const url::Origin& embedding_origin, |
| 37 const BrowserPermissionCallback& callback) { | 37 const BrowserPermissionCallback& callback) { |
| 38 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 38 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 39 | 39 |
| 40 // TODO(dgrogan): Remove bookmarks check in favor of site engagement. In the | 40 // TODO(dgrogan): Remove bookmarks check in favor of site engagement. In the |
| 41 // meantime maybe grant permission to A2HS origins as well. | 41 // meantime maybe grant permission to A2HS origins as well. |
| 42 BookmarkModel* model = BookmarkModelFactory::GetForProfileIfExists(profile()); | 42 BookmarkModel* model = BookmarkModelFactory::GetForProfileIfExists(profile()); |
| 43 if (model) { | 43 if (model) { |
| 44 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks; | 44 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks; |
| 45 model->GetBookmarks(&bookmarks); | 45 model->GetBookmarks(&bookmarks); |
| 46 if (IsOriginBookmarked(bookmarks, requesting_origin)) { | 46 if (IsOriginBookmarked(bookmarks, GURL(requesting_origin.Serialize()))) { |
| 47 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 47 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 48 true /* persist */, CONTENT_SETTING_ALLOW); | 48 true /* persist */, CONTENT_SETTING_ALLOW); |
| 49 return; | 49 return; |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 53 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 54 false /* persist */, CONTENT_SETTING_DEFAULT); | 54 false /* persist */, CONTENT_SETTING_DEFAULT); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void DurableStoragePermissionContext::UpdateContentSetting( | 57 void DurableStoragePermissionContext::UpdateContentSetting( |
| 58 const GURL& requesting_origin, | 58 const url::Origin& requesting_origin, |
| 59 const GURL& embedding_origin_ignored, | 59 const url::Origin& embedding_origin_ignored, |
| 60 ContentSetting content_setting) { | 60 ContentSetting content_setting) { |
| 61 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); | 61 const GURL requesting_url(requesting_origin.Serialize()); |
| 62 DCHECK_EQ(embedding_origin_ignored, embedding_origin_ignored.GetOrigin()); | 62 const GURL embedding_url(embedding_origin_ignored.Serialize()); |
| 63 DCHECK_EQ(requesting_origin, url::Origin(requesting_url)); |
| 64 DCHECK_EQ(embedding_origin_ignored, url::Origin(embedding_url)); |
| 63 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 65 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
| 64 content_setting == CONTENT_SETTING_BLOCK); | 66 content_setting == CONTENT_SETTING_BLOCK); |
| 65 | 67 |
| 66 HostContentSettingsMapFactory::GetForProfile(profile()) | 68 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 67 ->SetContentSettingDefaultScope(requesting_origin, GURL(), | 69 ->SetContentSettingDefaultScope(requesting_url, GURL(), |
| 68 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, | 70 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, |
| 69 std::string(), content_setting); | 71 std::string(), content_setting); |
| 70 } | 72 } |
| 71 | 73 |
| 72 bool DurableStoragePermissionContext::IsRestrictedToSecureOrigins() const { | 74 bool DurableStoragePermissionContext::IsRestrictedToSecureOrigins() const { |
| 73 return true; | 75 return true; |
| 74 } | 76 } |
| 75 | 77 |
| 76 bool DurableStoragePermissionContext::IsOriginBookmarked( | 78 bool DurableStoragePermissionContext::IsOriginBookmarked( |
| 77 const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks, | 79 const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks, |
| 78 const GURL& origin) { | 80 const GURL& origin) { |
| 79 BookmarkModel::URLAndTitle looking_for; | 81 BookmarkModel::URLAndTitle looking_for; |
| 80 looking_for.url = origin; | 82 looking_for.url = origin; |
| 81 return std::binary_search(bookmarks.begin(), bookmarks.end(), looking_for, | 83 return std::binary_search(bookmarks.begin(), bookmarks.end(), looking_for, |
| 82 [](const BookmarkModel::URLAndTitle& a, | 84 [](const BookmarkModel::URLAndTitle& a, |
| 83 const BookmarkModel::URLAndTitle& b) { | 85 const BookmarkModel::URLAndTitle& b) { |
| 84 return a.url.GetOrigin() < b.url.GetOrigin(); | 86 return a.url.GetOrigin() < b.url.GetOrigin(); |
| 85 }); | 87 }); |
| 86 } | 88 } |
| OLD | NEW |