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

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

Issue 1843063002: Don't show scheme in permission prompts if it is HTTPS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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/website_settings/permission_bubble_controller.h " 5 #import "chrome/browser/ui/cocoa/website_settings/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 11 matching lines...) Expand all
22 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 22 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
23 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 23 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
24 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" 24 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h"
25 #include "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" 25 #include "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h"
26 #include "chrome/browser/ui/cocoa/website_settings/split_block_button.h" 26 #include "chrome/browser/ui/cocoa/website_settings/split_block_button.h"
27 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa. h" 27 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa. h"
28 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" 28 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
29 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" 29 #include "chrome/browser/ui/website_settings/permission_bubble_view.h"
30 #include "chrome/browser/ui/website_settings/permission_menu_model.h" 30 #include "chrome/browser/ui/website_settings/permission_menu_model.h"
31 #include "chrome/grit/generated_resources.h" 31 #include "chrome/grit/generated_resources.h"
32 #include "components/url_formatter/elide_url.h"
32 #include "content/public/browser/native_web_keyboard_event.h" 33 #include "content/public/browser/native_web_keyboard_event.h"
33 #include "content/public/browser/user_metrics.h" 34 #include "content/public/browser/user_metrics.h"
34 #include "grit/components_strings.h" 35 #include "grit/components_strings.h"
35 #include "skia/ext/skia_utils_mac.h" 36 #include "skia/ext/skia_utils_mac.h"
36 #include "ui/base/cocoa/cocoa_base_utils.h" 37 #include "ui/base/cocoa/cocoa_base_utils.h"
37 #import "ui/base/cocoa/controls/hyperlink_text_view.h" 38 #import "ui/base/cocoa/controls/hyperlink_text_view.h"
38 #import "ui/base/cocoa/menu_controller.h" 39 #import "ui/base/cocoa/menu_controller.h"
39 #include "ui/base/cocoa/window_size_constants.h" 40 #include "ui/base/cocoa/window_size_constants.h"
40 #include "ui/base/l10n/l10n_util_mac.h" 41 #include "ui/base/l10n/l10n_util_mac.h"
41 #include "ui/base/models/simple_menu_model.h" 42 #include "ui/base/models/simple_menu_model.h"
43 #include "url/gurl.h"
42 44
43 using base::UserMetricsAction; 45 using base::UserMetricsAction;
44 46
45 namespace { 47 namespace {
46 48
47 // Distance between permission icon and permission label. 49 // Distance between permission icon and permission label.
48 const CGFloat kHorizontalIconPadding = 8.0f; 50 const CGFloat kHorizontalIconPadding = 8.0f;
49 51
50 // Distance between two permission labels. 52 // Distance between two permission labels.
51 const CGFloat kVerticalPermissionPadding = 2.0f; 53 const CGFloat kVerticalPermissionPadding = 2.0f;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation; 181 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation;
180 182
181 // Returns the expected parent for this bubble. 183 // Returns the expected parent for this bubble.
182 - (NSWindow*)getExpectedParentWindow; 184 - (NSWindow*)getExpectedParentWindow;
183 185
184 // Returns an autoreleased NSView displaying the icon and label for |request|. 186 // Returns an autoreleased NSView displaying the icon and label for |request|.
185 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request; 187 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request;
186 188
187 // Returns an autoreleased NSView displaying the title for the bubble 189 // Returns an autoreleased NSView displaying the title for the bubble
188 // requesting settings for |host|. 190 // requesting settings for |host|.
189 - (NSView*)titleWithHostname:(const std::string&)host; 191 - (NSView*)titleWithOrigin:(const GURL&)origin;
190 192
191 // Returns an autoreleased NSView displaying a menu for |request|. The 193 // Returns an autoreleased NSView displaying a menu for |request|. The
192 // menu will be initialized as 'allow' if |allow| is YES. 194 // menu will be initialized as 'allow' if |allow| is YES.
193 - (NSView*)menuForRequest:(PermissionBubbleRequest*)request 195 - (NSView*)menuForRequest:(PermissionBubbleRequest*)request
194 atIndex:(int)index 196 atIndex:(int)index
195 allow:(BOOL)allow; 197 allow:(BOOL)allow;
196 198
197 // Returns an autoreleased NSView of a button with |title| and |action|. 199 // Returns an autoreleased NSView of a button with |title| and |action|.
198 - (NSView*)buttonWithTitle:(NSString*)title 200 - (NSView*)buttonWithTitle:(NSString*)title
199 action:(SEL)action; 201 action:(SEL)action;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 336 }
335 maxPermissionLineWidth = std::max( 337 maxPermissionLineWidth = std::max(
336 maxPermissionLineWidth, NSMaxX([permissionView frame])); 338 maxPermissionLineWidth, NSMaxX([permissionView frame]));
337 yOffset += NSHeight([permissionView frame]); 339 yOffset += NSHeight([permissionView frame]);
338 340
339 // Add extra padding for all but first permission. 341 // Add extra padding for all but first permission.
340 verticalPadding = kVerticalPermissionPadding; 342 verticalPadding = kVerticalPermissionPadding;
341 } 343 }
342 344
343 base::scoped_nsobject<NSView> titleView( 345 base::scoped_nsobject<NSView> titleView(
344 [[self titleWithHostname:requests[0]->GetOrigin().host()] retain]); 346 [[self titleWithOrigin:requests[0]->GetOrigin()] retain]);
345 [contentView addSubview:titleView]; 347 [contentView addSubview:titleView];
346 [titleView setFrameOrigin:NSMakePoint(kHorizontalPadding, 348 [titleView setFrameOrigin:NSMakePoint(kHorizontalPadding,
347 kVerticalPadding + yOffset)]; 349 kVerticalPadding + yOffset)];
348 350
349 // 'x' button in the upper-right-hand corner. 351 // 'x' button in the upper-right-hand corner.
350 base::scoped_nsobject<NSView> closeButton([[self closeButton] retain]); 352 base::scoped_nsobject<NSView> closeButton([[self closeButton] retain]);
351 353
352 // Determine the dimensions of the bubble. 354 // Determine the dimensions of the bubble.
353 // Once the height and width are set, the buttons and permission menus can 355 // Once the height and width are set, the buttons and permission menus can
354 // be laid out correctly. 356 // be laid out correctly.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 labelFrame.origin.y = 513 labelFrame.origin.y =
512 std::floor((NSHeight(unionFrame) - NSHeight(labelFrame)) / 2); 514 std::floor((NSHeight(unionFrame) - NSHeight(labelFrame)) / 2);
513 515
514 [permissionLabel setFrame:labelFrame]; 516 [permissionLabel setFrame:labelFrame];
515 [permissionIcon setFrame:iconFrame]; 517 [permissionIcon setFrame:iconFrame];
516 [permissionView setFrame:unionFrame]; 518 [permissionView setFrame:unionFrame];
517 519
518 return permissionView.autorelease(); 520 return permissionView.autorelease();
519 } 521 }
520 522
521 - (NSView*)titleWithHostname:(const std::string&)host { 523 - (NSView*)titleWithOrigin:(const GURL&)origin {
522 base::scoped_nsobject<NSTextField> titleView( 524 base::scoped_nsobject<NSTextField> titleView(
523 [[NSTextField alloc] initWithFrame:NSZeroRect]); 525 [[NSTextField alloc] initWithFrame:NSZeroRect]);
524 [titleView setDrawsBackground:NO]; 526 [titleView setDrawsBackground:NO];
525 [titleView setBezeled:NO]; 527 [titleView setBezeled:NO];
526 [titleView setEditable:NO]; 528 [titleView setEditable:NO];
527 [titleView setSelectable:NO]; 529 [titleView setSelectable:NO];
528 [titleView setStringValue: 530 [titleView setStringValue:l10n_util::GetNSStringF(
529 l10n_util::GetNSStringF(IDS_PERMISSIONS_BUBBLE_PROMPT, 531 IDS_PERMISSIONS_BUBBLE_PROMPT,
530 base::UTF8ToUTF16(host))]; 532 url_formatter::FormatUrlForSecurityDisplay(
533 origin, url_formatter::SchemeDisplay::
534 OMIT_CRYPTOGRAPHIC))];
531 [titleView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; 535 [titleView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
532 [titleView sizeToFit]; 536 [titleView sizeToFit];
533 NSRect titleFrame = [titleView frame]; 537 NSRect titleFrame = [titleView frame];
534 [titleView setFrameSize:NSMakeSize(NSWidth(titleFrame) + kTitlePaddingX, 538 [titleView setFrameSize:NSMakeSize(NSWidth(titleFrame) + kTitlePaddingX,
535 NSHeight(titleFrame))]; 539 NSHeight(titleFrame))];
536 return titleView.autorelease(); 540 return titleView.autorelease();
537 } 541 }
538 542
539 - (NSView*)menuForRequest:(PermissionBubbleRequest*)request 543 - (NSView*)menuForRequest:(PermissionBubbleRequest*)request
540 atIndex:(int)index 544 atIndex:(int)index
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 620
617 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { 621 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB {
618 NSRect frameA = [viewA frame]; 622 NSRect frameA = [viewA frame];
619 NSRect frameB = [viewB frame]; 623 NSRect frameB = [viewB frame];
620 frameA.origin.y = 624 frameA.origin.y =
621 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); 625 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2);
622 [viewA setFrameOrigin:frameA.origin]; 626 [viewA setFrameOrigin:frameA.origin];
623 } 627 }
624 628
625 @end // implementation PermissionBubbleController 629 @end // implementation PermissionBubbleController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698