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

Side by Side Diff: chrome/browser/ui/cocoa/permission_bubble/permission_bubble_controller.mm

Issue 2868783002: Move requests from Show() argument to PermissionPrompt::Delegate (Closed)
Patch Set: tweak comment Created 3 years, 7 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 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 #import "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_controller. h" 5 #import "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_controller. h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/mac/bind_objc_block.h" 9 #include "base/mac/bind_objc_block.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // Override the base class implementation, which sets the anchor point. But 274 // Override the base class implementation, which sets the anchor point. But
275 // it's not necessary since BrowserWindowController will notify the 275 // it's not necessary since BrowserWindowController will notify the
276 // PermissionRequestManager to update the anchor position on a resize. 276 // PermissionRequestManager to update the anchor position on a resize.
277 } 277 }
278 278
279 - (void)parentWindowDidMove:(NSNotification*)notification { 279 - (void)parentWindowDidMove:(NSNotification*)notification {
280 DCHECK(bridge_); 280 DCHECK(bridge_);
281 [self setAnchorPoint:[self getExpectedAnchorPoint]]; 281 [self setAnchorPoint:[self getExpectedAnchorPoint]];
282 } 282 }
283 283
284 - (void)showWithDelegate:(PermissionPrompt::Delegate*)delegate 284 - (void)showWithDelegate:(PermissionPrompt::Delegate*)delegate {
285 forRequests:(const std::vector<PermissionRequest*>&)requests
286 acceptStates:(const std::vector<bool>&)acceptStates {
287 DCHECK(!requests.empty());
288 DCHECK(delegate); 285 DCHECK(delegate);
289 delegate_ = delegate; 286 delegate_ = delegate;
290 287
288 const std::vector<PermissionRequest*>& requests = delegate->Requests();
289 DCHECK(!requests.empty());
290
291 NSView* contentView = [[self window] contentView]; 291 NSView* contentView = [[self window] contentView];
292 [contentView setSubviews:@[]]; 292 [contentView setSubviews:@[]];
293 293
294 BOOL singlePermission = requests.size() == 1; 294 BOOL singlePermission = requests.size() == 1;
295 295
296 // Create one button to use as a guide for the permissions' y-offsets. 296 // Create one button to use as a guide for the permissions' y-offsets.
297 base::scoped_nsobject<NSView> allowOrOkButton; 297 base::scoped_nsobject<NSView> allowOrOkButton;
298 if (singlePermission) { 298 if (singlePermission) {
299 NSString* allowTitle = l10n_util::GetNSString(IDS_PERMISSION_ALLOW); 299 NSString* allowTitle = l10n_util::GetNSString(IDS_PERMISSION_ALLOW);
300 allowOrOkButton.reset([[self buttonWithTitle:allowTitle 300 allowOrOkButton.reset([[self buttonWithTitle:allowTitle
(...skipping 15 matching lines...) Expand all
316 base::scoped_nsobject<NSView> permissionView( 316 base::scoped_nsobject<NSView> permissionView(
317 [[self labelForRequest:(*it)] retain]); 317 [[self labelForRequest:(*it)] retain]);
318 NSPoint origin = [permissionView frame].origin; 318 NSPoint origin = [permissionView frame].origin;
319 origin.x += kHorizontalPadding; 319 origin.x += kHorizontalPadding;
320 origin.y += yOffset + verticalPadding; 320 origin.y += yOffset + verticalPadding;
321 [permissionView setFrameOrigin:origin]; 321 [permissionView setFrameOrigin:origin];
322 [contentView addSubview:permissionView]; 322 [contentView addSubview:permissionView];
323 323
324 if (!singlePermission) { 324 if (!singlePermission) {
325 int index = it - requests.begin(); 325 int index = it - requests.begin();
326 base::scoped_nsobject<NSView> menu( 326 base::scoped_nsobject<NSView> menu([[self
327 [[self menuForRequest:(*it) 327 menuForRequest:(*it)atIndex:index
328 atIndex:index 328 allow:delegate->AcceptStates()[index] ? YES : NO] retain]);
329 allow:acceptStates[index] ? YES : NO] retain]);
330 // Align vertically. Horizontal alignment will be adjusted once the 329 // Align vertically. Horizontal alignment will be adjusted once the
331 // widest permission is know. 330 // widest permission is know.
332 [PermissionBubbleController alignCenterOf:menu 331 [PermissionBubbleController alignCenterOf:menu
333 verticallyToCenterOf:permissionView]; 332 verticallyToCenterOf:permissionView];
334 [permissionMenus addObject:menu]; 333 [permissionMenus addObject:menu];
335 [contentView addSubview:menu]; 334 [contentView addSubview:menu];
336 } 335 }
337 maxPermissionLineWidth = std::max( 336 maxPermissionLineWidth = std::max(
338 maxPermissionLineWidth, NSMaxX([permissionView frame])); 337 maxPermissionLineWidth, NSMaxX([permissionView frame]));
339 yOffset += NSHeight([permissionView frame]); 338 yOffset += NSHeight([permissionView frame]);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 } 620 }
622 621
623 - (IBAction)cancel:(id)sender { 622 - (IBAction)cancel:(id)sender {
624 // This is triggered by ESC when the bubble has focus. 623 // This is triggered by ESC when the bubble has focus.
625 if (delegate_) 624 if (delegate_)
626 delegate_->Closing(); 625 delegate_->Closing();
627 [super cancel:sender]; 626 [super cancel:sender];
628 } 627 }
629 628
630 @end // implementation PermissionBubbleController 629 @end // implementation PermissionBubbleController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698