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..b77757db272096c3c44ffa666c8df3037d497da2 100644 |
--- a/chrome/browser/storage/durable_storage_permission_context.cc |
+++ b/chrome/browser/storage/durable_storage_permission_context.cc |
@@ -4,16 +4,86 @@ |
#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/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()) { |
+ 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; |
+ } |
+ |
+ 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.
|
+ BookmarkModel* model = BookmarkModelFactory::GetForProfileIfExists(profile()); |
+ if (model) { |
+ 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, |
+ true /* persist */, CONTENT_SETTING_BLOCK); |
+} |
+ |
bool DurableStoragePermissionContext::IsRestrictedToSecureOrigins() const { |
return true; |
} |
+ |
+static bool BookmarkComparator(const BookmarkModel::URLAndTitle& a, |
+ const BookmarkModel::URLAndTitle& b) { |
+ return a.url.GetOrigin() < b.url.GetOrigin(); |
+} |
+ |
+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, |
+ BookmarkComparator); |
jsbell
2015/09/21 17:22:53
This might be more readable with a lambda.
dgrogan
2015/09/24 20:58:57
Done.
|
+} |