Fix a couple bugs in the settings_page_header wrt breadcrumbs.
[chromium-blink-merge.git] / content / renderer / notification_permission_dispatcher.cc
blob90eef27cf7787f650bbbe87a4e7910ba8acad42a
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/notification_permission_dispatcher.h"
7 #include "base/bind.h"
8 #include "content/public/common/service_registry.h"
9 #include "content/public/renderer/render_frame.h"
10 #include "third_party/WebKit/public/platform/WebString.h"
11 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
12 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
13 #include "third_party/WebKit/public/web/modules/notifications/WebNotificationPermissionCallback.h"
15 namespace content {
17 NotificationPermissionDispatcher::NotificationPermissionDispatcher(
18 RenderFrame* render_frame) : RenderFrameObserver(render_frame) {
21 NotificationPermissionDispatcher::~NotificationPermissionDispatcher() {
24 void NotificationPermissionDispatcher::RequestPermission(
25 const blink::WebSecurityOrigin& origin,
26 blink::WebNotificationPermissionCallback* callback) {
27 if (!permission_service_.get()) {
28 render_frame()->GetServiceRegistry()->ConnectToRemoteService(
29 mojo::GetProxy(&permission_service_));
32 int request_id = pending_requests_.Add(callback);
34 permission_service_->RequestPermission(
35 PERMISSION_NAME_NOTIFICATIONS,
36 origin.toString().utf8(),
37 blink::WebUserGestureIndicator::isProcessingUserGesture(),
38 base::Bind(&NotificationPermissionDispatcher::OnPermissionRequestComplete,
39 base::Unretained(this),
40 request_id));
43 void NotificationPermissionDispatcher::OnPermissionRequestComplete(
44 int request_id, PermissionStatus status) {
45 blink::WebNotificationPermissionCallback* callback =
46 pending_requests_.Lookup(request_id);
47 DCHECK(callback);
49 blink::WebNotificationPermission permission =
50 blink::WebNotificationPermissionDefault;
51 switch (status) {
52 case PERMISSION_STATUS_GRANTED:
53 permission = blink::WebNotificationPermissionAllowed;
54 break;
55 case PERMISSION_STATUS_DENIED:
56 permission = blink::WebNotificationPermissionDenied;
57 break;
58 case PERMISSION_STATUS_ASK:
59 permission = blink::WebNotificationPermissionDefault;
60 break;
63 callback->permissionRequestComplete(permission);
64 pending_requests_.Remove(request_id);
67 } // namespace content