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

Side by Side Diff: chrome/browser/services/gcm/permission_context_base.cc

Issue 343743004: Implement a permission check for push. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add content settings html sections Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/services/gcm/permission_context_base.h"
6
7 #include "base/logging.h"
8 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "chrome/browser/content_settings/permission_queue_controller.h"
10 #include "chrome/browser/content_settings/permission_request_id.h"
11 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/web_contents.h"
15
16 namespace gcm {
17
18 PermissionContextBase::PermissionContextBase(
19 Profile* profile,
20 const ContentSettingsType permission_type)
21 : profile_(profile),
22 permission_type_(permission_type),
23 weak_factory_(this) {
24 permission_queue_controller_.reset(
25 new PermissionQueueController(profile_, permission_type_));
26 }
27
28 PermissionContextBase::~PermissionContextBase() {
29 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
30 }
31
32 void PermissionContextBase::RequestPermission(
33 content::WebContents* web_contents,
34 const PermissionRequestID& id,
35 const GURL& requesting_frame,
36 bool user_gesture,
37 const BrowserPermissionCallback& callback) {
38 // TODO(miguelg): Add UMA instrumentation.
39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
40
41 DecidePermission(web_contents,
42 id,
43 requesting_frame,
44 requesting_frame,
45 user_gesture,
46 callback);
47 }
48
49 void PermissionContextBase::DecidePermission(
50 content::WebContents* web_contents,
51 const PermissionRequestID& id,
52 const GURL& requesting_frame,
53 const GURL& embedder,
54 bool user_gesture,
55 const BrowserPermissionCallback& callback) {
56 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
57
58 ContentSetting content_setting =
59 profile_->GetHostContentSettingsMap()->GetContentSetting(
60 requesting_frame, embedder, permission_type_, std::string());
61 switch (content_setting) {
62 case CONTENT_SETTING_BLOCK:
63 PermissionDecided(id, requesting_frame, embedder, callback, false);
64 break;
65 case CONTENT_SETTING_ALLOW:
66 PermissionDecided(id, requesting_frame, embedder, callback, true);
67 break;
68 default:
69 // TODO(miguelg): implement bubble support.
70
71 // TODO(gbillock): Delete this and the infobar delegate when
72 // we're using only bubbles. crbug.com/337458
73 GetQueueController()->CreateInfoBarRequest(
74 id,
75 requesting_frame,
76 embedder,
77 std::string(),
78 base::Bind(&PermissionContextBase::NotifyPermissionSet,
79 weak_factory_.GetWeakPtr(),
80 id,
81 requesting_frame,
82 callback));
83 }
84 }
85
86 void PermissionContextBase::PermissionDecided(
87 const PermissionRequestID& id,
88 const GURL& requesting_frame,
89 const GURL& embedder,
90 const BrowserPermissionCallback& callback,
91 bool allowed) {
92 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
93 NotifyPermissionSet(id, requesting_frame, callback, allowed);
94 }
95
96 PermissionQueueController* PermissionContextBase::GetQueueController() {
97 return permission_queue_controller_.get();
98 }
99
100 void PermissionContextBase::NotifyPermissionSet(
101 const PermissionRequestID& id,
102 const GURL& requesting_frame,
103 const BrowserPermissionCallback& callback,
104 bool allowed) {
105 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
106 UpdateTabContext(id, requesting_frame, allowed);
107
108 callback.Run(allowed);
109 }
110
111 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/permission_context_base.h ('k') | chrome/browser/services/gcm/permission_infobar_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698