Chromium Code Reviews| Index: chrome/browser/storage/durable_storage_permission_context.cc |
| diff --git a/chrome/browser/storage/durable_storage_permission_context.cc b/chrome/browser/storage/durable_storage_permission_context.cc |
| index 68b5af8a96032c2271d5b58859a691a36655ad0f..da51501887188f47619fafad5f9b5bfc2ceb6155 100644 |
| --- a/chrome/browser/storage/durable_storage_permission_context.cc |
| +++ b/chrome/browser/storage/durable_storage_permission_context.cc |
| @@ -4,16 +4,97 @@ |
| #include "chrome/browser/storage/durable_storage_permission_context.h" |
| +#include "base/logging.h" |
| +#include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| +#include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| #include "chrome/browser/permissions/permission_request_id.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "components/bookmarks/browser/bookmark_model.h" |
| +#include "components/content_settings/core/browser/host_content_settings_map.h" |
| +#include "components/content_settings/core/browser/website_settings_registry.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/child_process_security_policy.h" |
| +#include "content/public/common/origin_util.h" |
| #include "url/gurl.h" |
| +using bookmarks::BookmarkModel; |
| + |
| DurableStoragePermissionContext::DurableStoragePermissionContext( |
| Profile* profile) |
| : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) { |
| } |
| +void DurableStoragePermissionContext::DecidePermission( |
| + content::WebContents* web_contents, |
| + const PermissionRequestID& id, |
| + const GURL& requesting_origin, |
| + const GURL& embedding_origin, |
| + bool user_gesture, |
| + const BrowserPermissionCallback& callback) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + |
| + if (!requesting_origin.is_valid() || !embedding_origin.is_valid()) { |
|
jsbell
2015/09/24 22:07:36
This chunk (lines 37-70) looks like it's pretty mu
dgrogan
2015/09/25 20:23:42
Agreed. Added a TODO.
|
| + std::string type_name = |
| + content_settings::WebsiteSettingsRegistry::GetInstance() |
| + ->Get(CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) |
| + ->name(); |
| + |
| + DVLOG(1) << "Attempt to use " << type_name |
| + << " from an invalid URL: " << requesting_origin << "," |
| + << embedding_origin << " (" << type_name |
| + << " is not supported in popups)"; |
| + NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| + false /* persist */, CONTENT_SETTING_BLOCK); |
| + return; |
| + } |
| + |
| + if (IsRestrictedToSecureOrigins() && |
| + !content::IsOriginSecure(requesting_origin)) { |
| + NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| + false /* persist */, CONTENT_SETTING_BLOCK); |
| + return; |
| + } |
| + |
| + ContentSetting content_setting = |
| + HostContentSettingsMapFactory::GetForProfile(profile()) |
| + ->GetContentSettingAndMaybeUpdateLastUsage( |
| + requesting_origin, embedding_origin, |
| + CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, std::string()); |
| + |
| + if (content_setting == CONTENT_SETTING_ALLOW) { |
| + NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| + false /* persist */, content_setting); |
| + return; |
| + } |
| + |
| + BookmarkModel* model = BookmarkModelFactory::GetForProfileIfExists(profile()); |
|
jsbell
2015/09/24 22:07:36
TODO for A2HS ?
dgrogan
2015/09/25 20:23:42
Done.
|
| + if (model) { |
| + std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks; |
| + model->GetBookmarks(&bookmarks); |
| + if (IsOriginBookmarked(bookmarks, requesting_origin)) { |
| + NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| + true /* persist */, CONTENT_SETTING_ALLOW); |
| + return; |
| + } |
| + } |
| + |
| + NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| + false /* persist */, CONTENT_SETTING_DEFAULT); |
| +} |
| + |
| bool DurableStoragePermissionContext::IsRestrictedToSecureOrigins() const { |
| return true; |
| } |
| + |
| +bool DurableStoragePermissionContext::IsOriginBookmarked( |
| + const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks, |
| + const GURL& origin) { |
| + BookmarkModel::URLAndTitle looking_for; |
| + looking_for.url = origin; |
| + return std::binary_search(bookmarks.begin(), bookmarks.end(), looking_for, |
|
jsbell
2015/09/24 22:07:36
#include <algorithm>
dgrogan
2015/09/25 20:23:43
Done.
|
| + [](const BookmarkModel::URLAndTitle& a, |
|
jsbell
2015/09/24 22:07:36
I wonder if you could get away with auto here, but
dgrogan
2015/09/25 20:23:43
I fall on the "less readable" side. Further, the c
|
| + const BookmarkModel::URLAndTitle& b) { |
| + return a.url.GetOrigin() < b.url.GetOrigin(); |
| + }); |
| +} |