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

Side by Side Diff: chrome/browser/permissions/permission_manager.cc

Issue 1337903002: permissions: remove PermissionQueueController and introduce PermissionInfoBarManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@callbacks-delegates
Patch Set: Fix compile failures Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/permissions/permission_manager.h" 5 #include "chrome/browser/permissions/permission_manager.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
9 #include "chrome/browser/permissions/permission_context.h" 9 #include "chrome/browser/permissions/permission_context.h"
10 #include "chrome/browser/permissions/permission_context_base.h" 10 #include "chrome/browser/permissions/permission_context_base.h"
11 #include "chrome/browser/permissions/permission_infobar_manager.h"
11 #include "chrome/browser/permissions/permission_request_id.h" 12 #include "chrome/browser/permissions/permission_request_id.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/tab_contents/tab_util.h" 14 #include "chrome/browser/tab_contents/tab_util.h"
14 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 15 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
15 #include "components/content_settings/core/browser/host_content_settings_map.h" 16 #include "components/content_settings/core/browser/host_content_settings_map.h"
16 #include "content/public/browser/permission_type.h" 17 #include "content/public/browser/permission_type.h"
17 #include "content/public/browser/render_frame_host.h" 18 #include "content/public/browser/render_frame_host.h"
18 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
20 21
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 160 }
160 161
161 PermissionContextBase* context = PermissionContext::Get(profile_, permission); 162 PermissionContextBase* context = PermissionContext::Get(profile_, permission);
162 if (!context) { 163 if (!context) {
163 callback.Run(content::PERMISSION_STATUS_DENIED); 164 callback.Run(content::PERMISSION_STATUS_DENIED);
164 return kNoPendingOperation; 165 return kNoPendingOperation;
165 } 166 }
166 167
167 content::WebContents* web_contents = 168 content::WebContents* web_contents =
168 content::WebContents::FromRenderFrameHost(render_frame_host); 169 content::WebContents::FromRenderFrameHost(render_frame_host);
169 if (IsPermissionBubbleManagerMissing(web_contents)) { 170 if (IsPermissionUIManagerMissing(web_contents)) {
170 callback.Run( 171 callback.Run(
171 GetPermissionStatus(permission, requesting_origin, 172 GetPermissionStatus(permission, requesting_origin,
172 web_contents->GetLastCommittedURL().GetOrigin())); 173 web_contents->GetLastCommittedURL().GetOrigin()));
173 return kNoPendingOperation; 174 return kNoPendingOperation;
174 } 175 }
175 176
176 PendingRequest* pending_request = new PendingRequest( 177 PendingRequest* pending_request = new PendingRequest(
177 permission, render_frame_host); 178 permission, render_frame_host);
178 int request_id = pending_requests_.Add(pending_request); 179 int request_id = pending_requests_.Add(pending_request);
179 const PermissionRequestID request(pending_request->render_process_id, 180 const PermissionRequestID request(pending_request->render_process_id,
(...skipping 23 matching lines...) Expand all
203 return; 204 return;
204 205
205 PermissionContextBase* context = PermissionContext::Get( 206 PermissionContextBase* context = PermissionContext::Get(
206 profile_, pending_request->permission); 207 profile_, pending_request->permission);
207 if (!context) 208 if (!context)
208 return; 209 return;
209 210
210 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID( 211 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID(
211 pending_request->render_process_id, pending_request->render_frame_id); 212 pending_request->render_process_id, pending_request->render_frame_id);
212 DCHECK(web_contents); 213 DCHECK(web_contents);
213 if (IsPermissionBubbleManagerMissing(web_contents)) { 214 if (IsPermissionUIManagerMissing(web_contents)) {
214 pending_requests_.Remove(request_id); 215 pending_requests_.Remove(request_id);
215 return; 216 return;
216 } 217 }
217 218
218 const PermissionRequestID request(pending_request->render_process_id, 219 const PermissionRequestID request(pending_request->render_process_id,
219 pending_request->render_frame_id, 220 pending_request->render_frame_id,
220 request_id); 221 request_id);
221 context->CancelPermissionRequest(web_contents, request); 222 context->CancelPermissionRequest(web_contents, request);
222 pending_requests_.Remove(request_id); 223 pending_requests_.Remove(request_id);
223 } 224 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 291
291 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { 292 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) {
292 // Whether |subscription_id| is known will be checked by the Remove() call. 293 // Whether |subscription_id| is known will be checked by the Remove() call.
293 subscriptions_.Remove(subscription_id); 294 subscriptions_.Remove(subscription_id);
294 295
295 if (subscriptions_.IsEmpty()) 296 if (subscriptions_.IsEmpty())
296 HostContentSettingsMapFactory::GetForProfile(profile_) 297 HostContentSettingsMapFactory::GetForProfile(profile_)
297 ->RemoveObserver(this); 298 ->RemoveObserver(this);
298 } 299 }
299 300
300 bool PermissionManager::IsPermissionBubbleManagerMissing( 301 bool PermissionManager::IsPermissionUIManagerMissing(
301 content::WebContents* web_contents) { 302 content::WebContents* web_contents) {
302 // Can't be missing if it isn't needed to begin with. 303 if (PermissionBubbleManager::Enabled())
303 if (!PermissionBubbleManager::Enabled()) 304 return PermissionBubbleManager::FromWebContents(web_contents) == nullptr;
304 return false;
305 305
306 return PermissionBubbleManager::FromWebContents(web_contents) == nullptr; 306 // Consider PermissionInfoBarManager's state instead
307 return PermissionInfoBarManager::FromWebContents(web_contents) == nullptr;
307 } 308 }
308 309
309 void PermissionManager::OnContentSettingChanged( 310 void PermissionManager::OnContentSettingChanged(
310 const ContentSettingsPattern& primary_pattern, 311 const ContentSettingsPattern& primary_pattern,
311 const ContentSettingsPattern& secondary_pattern, 312 const ContentSettingsPattern& secondary_pattern,
312 ContentSettingsType content_type, 313 ContentSettingsType content_type,
313 std::string resource_identifier) { 314 std::string resource_identifier) {
314 std::list<base::Closure> callbacks; 315 std::list<base::Closure> callbacks;
315 316
316 for (SubscriptionsMap::iterator iter(&subscriptions_); 317 for (SubscriptionsMap::iterator iter(&subscriptions_);
(...skipping 23 matching lines...) Expand all
340 // Add the callback to |callbacks| which will be run after the loop to 341 // Add the callback to |callbacks| which will be run after the loop to
341 // prevent re-entrance issues. 342 // prevent re-entrance issues.
342 callbacks.push_back( 343 callbacks.push_back(
343 base::Bind(subscription->callback, 344 base::Bind(subscription->callback,
344 ContentSettingToPermissionStatus(new_value))); 345 ContentSettingToPermissionStatus(new_value)));
345 } 346 }
346 347
347 for (const auto& callback : callbacks) 348 for (const auto& callback : callbacks)
348 callback.Run(); 349 callback.Run();
349 } 350 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_manager.h ('k') | chrome/browser/permissions/permission_queue_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698