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

Unified Diff: content/browser/push_messaging/push_messaging_manager.cc

Issue 2706243007: Don't assume that the permission manager exists. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/push_messaging/push_messaging_manager.cc
diff --git a/content/browser/push_messaging/push_messaging_manager.cc b/content/browser/push_messaging/push_messaging_manager.cc
index f9cacdd4efc5165416f0b698245deaa94e2c7e6b..9f4c2623f206ecab40607ab1895923185000829e 100644
--- a/content/browser/push_messaging/push_messaging_manager.cc
+++ b/content/browser/push_messaging/push_messaging_manager.cc
@@ -422,18 +422,31 @@ void PushMessagingManager::Core::RegisterOnUI(
if (web_contents) {
web_contents->GetMainFrame()->AddMessageToConsole(
CONSOLE_MESSAGE_LEVEL_ERROR, kIncognitoPushUnsupportedMessage);
+
+ BrowserContext* browser_context = web_contents->GetBrowserContext();
+
+ // It's valid for embedders to return a null permission manager.
+ // Immediately reject the permission request when this happens.
+ if (!browser_context->GetPermissionManager()) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(
+ &PushMessagingManager::SendSubscriptionError, io_parent_,
+ callback, data,
+ PUSH_REGISTRATION_STATUS_INCOGNITO_PERMISSION_DENIED));
+
+ return;
+ }
+
// Request push messaging permission (which will fail, since
// notifications aren't supported in incognito), so the website can't
// detect whether incognito is active.
- web_contents->GetBrowserContext()
- ->GetPermissionManager()
- ->RequestPermission(
- PermissionType::PUSH_MESSAGING, render_frame_host,
- data.requesting_origin, false /* user_gesture */,
- base::Bind(&PushMessagingManager::Core::
- DidRequestPermissionInIncognito,
- weak_factory_ui_to_ui_.GetWeakPtr(), callback,
- data));
+ browser_context->GetPermissionManager()->RequestPermission(
+ PermissionType::PUSH_MESSAGING, render_frame_host,
+ data.requesting_origin, false /* user_gesture */,
+ base::Bind(
+ &PushMessagingManager::Core::DidRequestPermissionInIncognito,
+ weak_factory_ui_to_ui_.GetWeakPtr(), callback, data));
}
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698