Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3310)

Unified Diff: chrome/browser/storage/durable_storage_permission_context.cc

Issue 2385653005: [DurableStorage] Don't grant durable if origin cannot write cookies. (Closed)
Patch Set: addressed comments, added test Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 7eac71f09f7bd38afc7452a8ef6e209229900b31..5d3c29e74d1ac0da56e045225348616f6594fa6f 100644
--- a/chrome/browser/storage/durable_storage_permission_context.cc
+++ b/chrome/browser/storage/durable_storage_permission_context.cc
@@ -8,11 +8,13 @@
#include "base/logging.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
+#include "chrome/browser/content_settings/cookie_settings_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/cookie_settings.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"
@@ -37,9 +39,30 @@ void DurableStoragePermissionContext::DecidePermission(
bool user_gesture,
const BrowserPermissionCallback& callback) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ DCHECK_NE(CONTENT_SETTING_ALLOW,
+ GetPermissionStatus(requesting_origin, embedding_origin));
+ DCHECK_NE(CONTENT_SETTING_BLOCK,
+ GetPermissionStatus(requesting_origin, embedding_origin));
- // TODO(dgrogan): Remove bookmarks check in favor of site engagement. In the
- // meantime maybe grant permission to A2HS origins as well.
+ // Durable is only allowed to be granted to the top-level origin. Embedding
+ // origin is the last committed navigation origin to the web contents.
+ if (requesting_origin != embedding_origin) {
+ NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
+ false /* persist */, CONTENT_SETTING_DEFAULT);
+ return;
+ }
+
+ // Don't grant durable if we can't write cookies.
+ scoped_refptr<content_settings::CookieSettings> cookie_settings =
+ CookieSettingsFactory::GetForProfile(profile());
+ if (!cookie_settings->IsSettingCookieAllowed(requesting_origin,
+ requesting_origin)) {
+ NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
+ false /* persist */, CONTENT_SETTING_DEFAULT);
+ return;
+ }
+
+ // TODO(dmurph): Remove bookmarks check in favor of important sites.
BookmarkModel* model =
BookmarkModelFactory::GetForBrowserContextIfExists(profile());
if (model) {

Powered by Google App Engine
This is Rietveld 408576698