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

Side by Side Diff: chrome/browser/content_settings/permission_context_base.cc

Issue 365123003: Implement midi permissions on top of the new common permission classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/services/gcm/permission_context_base.h" 5 #include "chrome/browser/content_settings/permission_context_base.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/content_settings/host_content_settings_map.h" 9 #include "chrome/browser/content_settings/host_content_settings_map.h"
10 #include "chrome/browser/content_settings/permission_bubble_request_impl.h"
10 #include "chrome/browser/content_settings/permission_queue_controller.h" 11 #include "chrome/browser/content_settings/permission_queue_controller.h"
11 #include "chrome/browser/content_settings/permission_request_id.h" 12 #include "chrome/browser/content_settings/permission_request_id.h"
12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/services/gcm/permission_bubble_request_impl.h"
15 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 15 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
20 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
21 21
22 namespace gcm {
23 22
24 PermissionContextBase::PermissionContextBase( 23 PermissionContextBase::PermissionContextBase(
25 Profile* profile, 24 Profile* profile,
26 const ContentSettingsType permission_type) 25 const ContentSettingsType permission_type)
27 : profile_(profile), 26 : profile_(profile),
28 permission_type_(permission_type), 27 permission_type_(permission_type),
29 weak_factory_(this) { 28 weak_factory_(this) {
30 permission_queue_controller_.reset( 29 permission_queue_controller_.reset(
31 new PermissionQueueController(profile_, permission_type_)); 30 new PermissionQueueController(profile_, permission_type_));
32 } 31 }
33 32
34 PermissionContextBase::~PermissionContextBase() { 33 PermissionContextBase::~PermissionContextBase() {
35 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
36 } 35 }
37 36
38 void PermissionContextBase::RequestPermission( 37 void PermissionContextBase::RequestPermission(
39 content::WebContents* web_contents, 38 content::WebContents* web_contents,
40 const PermissionRequestID& id, 39 const PermissionRequestID& id,
41 const GURL& requesting_frame, 40 const GURL& requesting_frame,
42 bool user_gesture, 41 bool user_gesture,
43 const BrowserPermissionCallback& callback) { 42 const BrowserPermissionCallback& callback) {
44 // TODO(miguelg): Add UMA instrumentation. 43 // TODO(miguelg): Add UMA instrumentation.
45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 44 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
46 45
47 DecidePermission(web_contents, 46 DecidePermission(web_contents,
48 id, 47 id,
49 requesting_frame, 48 requesting_frame.GetOrigin(),
50 requesting_frame, 49 web_contents->GetURL().GetOrigin(),
Michael van Ouwerkerk 2014/07/04 10:34:32 Use GetLastCommittedURL as GetURL is deprecated an
Miguel Garcia 2014/07/04 12:09:52 True, you pointed this out before, thanks for spot
51 user_gesture, 50 user_gesture,
52 callback); 51 callback);
53 } 52 }
54 53
55 void PermissionContextBase::DecidePermission( 54 void PermissionContextBase::DecidePermission(
56 content::WebContents* web_contents, 55 content::WebContents* web_contents,
57 const PermissionRequestID& id, 56 const PermissionRequestID& id,
58 const GURL& requesting_frame, 57 const GURL& requesting_origin,
59 const GURL& embedder, 58 const GURL& embedder_origin,
60 bool user_gesture, 59 bool user_gesture,
61 const BrowserPermissionCallback& callback) { 60 const BrowserPermissionCallback& callback) {
62 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
63 62
64 ContentSetting content_setting = 63 ContentSetting content_setting =
65 profile_->GetHostContentSettingsMap()->GetContentSetting( 64 profile_->GetHostContentSettingsMap()->GetContentSetting(
66 requesting_frame, embedder, permission_type_, std::string()); 65 requesting_origin, embedder_origin, permission_type_, std::string());
67 switch (content_setting) { 66 switch (content_setting) {
68 case CONTENT_SETTING_BLOCK: 67 case CONTENT_SETTING_BLOCK:
69 PermissionDecided(id, requesting_frame, embedder, callback, false); 68 PermissionDecided(
69 id, requesting_origin, embedder_origin, callback, false);
70 break; 70 break;
Bernhard Bauer 2014/07/04 10:24:13 Could you return here, so we can move the ASK case
Miguel Garcia 2014/07/04 12:09:52 Done.
71 case CONTENT_SETTING_ALLOW: 71 case CONTENT_SETTING_ALLOW:
72 PermissionDecided(id, requesting_frame, embedder, callback, true); 72 PermissionDecided(id, requesting_origin, embedder_origin, callback, true);
73 break; 73 break;
74 default: 74 default:
75 if (PermissionBubbleManager::Enabled()) { 75 if (PermissionBubbleManager::Enabled()) {
76 PermissionBubbleManager* bubble_manager = 76 PermissionBubbleManager* bubble_manager =
77 PermissionBubbleManager::FromWebContents(web_contents); 77 PermissionBubbleManager::FromWebContents(web_contents);
78 DCHECK(bubble_manager); 78 DCHECK(bubble_manager);
79 scoped_ptr<PermissionBubbleRequest> request_ptr( 79 scoped_ptr<PermissionBubbleRequest> request_ptr(
80 new PermissionBubbleRequestImpl( 80 new PermissionBubbleRequestImpl(
81 requesting_frame, 81 requesting_origin,
82 user_gesture, 82 user_gesture,
83 permission_type_, 83 permission_type_,
84 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), 84 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
85 base::Bind(&PermissionContextBase::NotifyPermissionSet, 85 base::Bind(&PermissionContextBase::NotifyPermissionSet,
86 weak_factory_.GetWeakPtr(), 86 weak_factory_.GetWeakPtr(),
87 id, 87 id,
88 requesting_frame, 88 requesting_origin,
89 embedder, 89 embedder_origin,
90 callback), 90 callback),
91 base::Bind(&PermissionContextBase::CleanUpBubble, 91 base::Bind(&PermissionContextBase::CleanUpBubble,
Bernhard Bauer 2014/07/04 10:24:13 This should be aligned with the previous base::Bin
Miguel Garcia 2014/07/04 12:09:52 Done.
92 weak_factory_.GetWeakPtr(), id))); 92 weak_factory_.GetWeakPtr(), id)));
93 PermissionBubbleRequest* request = request_ptr.get(); 93 PermissionBubbleRequest* request = request_ptr.get();
94 94
95 bool inserted = pending_bubbles_.add( 95 bool inserted = pending_bubbles_.add(
96 id.ToString(), request_ptr.Pass()).second; 96 id.ToString(), request_ptr.Pass()).second;
97 DCHECK(inserted) << "Duplicate id " << id.ToString(); 97 DCHECK(inserted) << "Duplicate id " << id.ToString();
98 bubble_manager->AddRequest(request); 98 bubble_manager->AddRequest(request);
99 return; 99 return;
100 } 100 }
101 101
102 // TODO(gbillock): Delete this and the infobar delegate when 102 // TODO(gbillock): Delete this and the infobar delegate when
103 // we're using only bubbles. crbug.com/337458 103 // we're using only bubbles. crbug.com/337458
104 GetQueueController()->CreateInfoBarRequest( 104 GetQueueController()->CreateInfoBarRequest(
105 id, 105 id,
106 requesting_frame, 106 requesting_origin,
107 embedder, 107 embedder_origin,
108 std::string(), 108 std::string(),
109 base::Bind(&PermissionContextBase::NotifyPermissionSet, 109 base::Bind(&PermissionContextBase::NotifyPermissionSet,
110 weak_factory_.GetWeakPtr(), 110 weak_factory_.GetWeakPtr(),
111 id, 111 id,
112 requesting_frame, 112 requesting_origin,
113 embedder, 113 embedder_origin,
114 callback, 114 callback,
115 // the queue controller takes care of persisting the 115 // the queue controller takes care of persisting the
116 // permission 116 // permission
117 false)); 117 false));
118 } 118 }
119 } 119 }
120 120
121 void PermissionContextBase::PermissionDecided( 121 void PermissionContextBase::PermissionDecided(
122 const PermissionRequestID& id, 122 const PermissionRequestID& id,
123 const GURL& requesting_frame, 123 const GURL& requesting_origin,
124 const GURL& embedder, 124 const GURL& embedder_origin,
125 const BrowserPermissionCallback& callback, 125 const BrowserPermissionCallback& callback,
126 bool allowed) { 126 bool allowed) {
127 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 127 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
128 NotifyPermissionSet(id, requesting_frame, embedder, callback, false, allowed); 128 NotifyPermissionSet(
129 id, requesting_origin, embedder_origin, callback, false, allowed);
129 } 130 }
130 131
131 PermissionQueueController* PermissionContextBase::GetQueueController() { 132 PermissionQueueController* PermissionContextBase::GetQueueController() {
132 return permission_queue_controller_.get(); 133 return permission_queue_controller_.get();
133 } 134 }
134 135
135 void PermissionContextBase::NotifyPermissionSet( 136 void PermissionContextBase::NotifyPermissionSet(
136 const PermissionRequestID& id, 137 const PermissionRequestID& id,
137 const GURL& requesting_frame, 138 const GURL& requesting_origin,
138 const GURL& embedder, 139 const GURL& embedder_origin,
139 const BrowserPermissionCallback& callback, 140 const BrowserPermissionCallback& callback,
140 bool persist, 141 bool persist,
141 bool allowed) { 142 bool allowed) {
142 if (persist) { 143 if (persist) {
143 UpdateContentSetting(requesting_frame, embedder, allowed); 144 UpdateContentSetting(requesting_origin, embedder_origin, allowed);
Bernhard Bauer 2014/07/04 10:24:13 Nit: braces are unnecessary for single-line bodies
Miguel Garcia 2014/07/04 12:09:52 Done.
144 } 145 }
145 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 146 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
146 UpdateTabContext(id, requesting_frame, allowed); 147 UpdateTabContext(id, requesting_origin, allowed);
147
148 callback.Run(allowed); 148 callback.Run(allowed);
149 } 149 }
150 150
151 void PermissionContextBase::CleanUpBubble(const PermissionRequestID& id) { 151 void PermissionContextBase::CleanUpBubble(const PermissionRequestID& id) {
152 base::ScopedPtrHashMap<std::string, PermissionBubbleRequest>::iterator it; 152 base::ScopedPtrHashMap<std::string, PermissionBubbleRequest>::iterator it;
Bernhard Bauer 2014/07/04 10:24:13 I would probably simplify this to: bool success
Miguel Garcia 2014/07/04 12:09:52 Good idea, done.
153 it = pending_bubbles_.find(id.ToString()); 153 it = pending_bubbles_.find(id.ToString());
154 if (it != pending_bubbles_.end()) { 154 if (it != pending_bubbles_.end()) {
155 pending_bubbles_.take_and_erase(it); 155 pending_bubbles_.take_and_erase(it);
156 return; 156 return;
157 } 157 }
158 158
159 NOTREACHED() << "Missing request"; 159 NOTREACHED() << "Missing request";
160 } 160 }
161 161
162 void PermissionContextBase::UpdateContentSetting( 162 void PermissionContextBase::UpdateContentSetting(
163 const GURL& requesting_frame, 163 const GURL& requesting_origin,
164 const GURL& embedder, 164 const GURL& embedder_origin,
165 bool allowed) { 165 bool allowed) {
166 ContentSetting content_setting = 166 ContentSetting content_setting =
167 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 167 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
168 profile_->GetHostContentSettingsMap()->SetContentSetting( 168 profile_->GetHostContentSettingsMap()->SetContentSetting(
169 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), 169 ContentSettingsPattern::FromURLNoWildcard(requesting_origin.GetOrigin()),
Michael van Ouwerkerk 2014/07/04 10:34:32 origin.GetOrigin() looks redundant. Is any code pa
Miguel Garcia 2014/07/04 12:09:52 Good idea,added the DCHECK
170 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), 170 ContentSettingsPattern::FromURLNoWildcard(embedder_origin.GetOrigin()),
171 permission_type_, 171 permission_type_,
172 std::string(), 172 std::string(),
173 content_setting); 173 content_setting);
174 } 174 }
175
176 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698