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