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 "base/logging.h" | |
| 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | |
| 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | |
| 7 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 8 #include "chrome/browser/permissions/permission_request_id.h" | 11 #include "chrome/browser/permissions/permission_request_id.h" |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "components/bookmarks/browser/bookmark_model.h" | |
| 14 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
| 15 #include "components/content_settings/core/browser/website_settings_registry.h" | |
| 16 #include "content/public/browser/browser_thread.h" | |
| 9 #include "content/public/browser/child_process_security_policy.h" | 17 #include "content/public/browser/child_process_security_policy.h" |
| 18 #include "content/public/common/origin_util.h" | |
| 10 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 11 | 20 |
| 21 using bookmarks::BookmarkModel; | |
| 22 | |
| 12 DurableStoragePermissionContext::DurableStoragePermissionContext( | 23 DurableStoragePermissionContext::DurableStoragePermissionContext( |
| 13 Profile* profile) | 24 Profile* profile) |
| 14 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) { | 25 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) { |
| 15 } | 26 } |
| 16 | 27 |
| 28 void DurableStoragePermissionContext::DecidePermission( | |
| 29 content::WebContents* web_contents, | |
| 30 const PermissionRequestID& id, | |
| 31 const GURL& requesting_origin, | |
| 32 const GURL& embedding_origin, | |
| 33 bool user_gesture, | |
| 34 const BrowserPermissionCallback& callback) { | |
| 35 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 36 | |
| 37 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.
| |
| 38 std::string type_name = | |
| 39 content_settings::WebsiteSettingsRegistry::GetInstance() | |
| 40 ->Get(CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) | |
| 41 ->name(); | |
| 42 | |
| 43 DVLOG(1) << "Attempt to use " << type_name | |
| 44 << " from an invalid URL: " << requesting_origin << "," | |
| 45 << embedding_origin << " (" << type_name | |
| 46 << " is not supported in popups)"; | |
| 47 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
| 48 false /* persist */, CONTENT_SETTING_BLOCK); | |
| 49 return; | |
| 50 } | |
| 51 | |
| 52 if (IsRestrictedToSecureOrigins() && | |
| 53 !content::IsOriginSecure(requesting_origin)) { | |
| 54 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
| 55 false /* persist */, CONTENT_SETTING_BLOCK); | |
| 56 return; | |
| 57 } | |
| 58 | |
| 59 ContentSetting content_setting = | |
| 60 HostContentSettingsMapFactory::GetForProfile(profile()) | |
| 61 ->GetContentSettingAndMaybeUpdateLastUsage( | |
| 62 requesting_origin, embedding_origin, | |
| 63 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, std::string()); | |
| 64 | |
| 65 if (content_setting == CONTENT_SETTING_ALLOW) { | |
| 66 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
| 67 false /* persist */, content_setting); | |
| 68 return; | |
| 69 } | |
| 70 | |
| 71 BookmarkModel* model = BookmarkModelFactory::GetForProfileIfExists(profile()); | |
|
jsbell
2015/09/24 22:07:36
TODO for A2HS ?
dgrogan
2015/09/25 20:23:42
Done.
| |
| 72 if (model) { | |
| 73 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks; | |
| 74 model->GetBookmarks(&bookmarks); | |
| 75 if (IsOriginBookmarked(bookmarks, requesting_origin)) { | |
| 76 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
| 77 true /* persist */, CONTENT_SETTING_ALLOW); | |
| 78 return; | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
| 83 false /* persist */, CONTENT_SETTING_DEFAULT); | |
| 84 } | |
| 85 | |
| 17 bool DurableStoragePermissionContext::IsRestrictedToSecureOrigins() const { | 86 bool DurableStoragePermissionContext::IsRestrictedToSecureOrigins() const { |
| 18 return true; | 87 return true; |
| 19 } | 88 } |
| 89 | |
| 90 bool DurableStoragePermissionContext::IsOriginBookmarked( | |
| 91 const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks, | |
| 92 const GURL& origin) { | |
| 93 BookmarkModel::URLAndTitle looking_for; | |
| 94 looking_for.url = origin; | |
| 95 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.
| |
| 96 [](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
| |
| 97 const BookmarkModel::URLAndTitle& b) { | |
| 98 return a.url.GetOrigin() < b.url.GetOrigin(); | |
| 99 }); | |
| 100 } | |
| OLD | NEW |