| OLD | NEW |
| 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" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/permissions/permission_request.h" |
| 13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 16 #import "chrome/browser/ui/chrome_style.h" | 17 #import "chrome/browser/ui/chrome_style.h" |
| 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 18 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 18 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 19 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 19 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 20 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| 20 #import "chrome/browser/ui/cocoa/hover_close_button.h" | 21 #import "chrome/browser/ui/cocoa/hover_close_button.h" |
| 21 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 22 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 22 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 23 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 23 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 24 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 24 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" | 25 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" |
| 25 #include "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" | 26 #include "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" |
| 26 #include "chrome/browser/ui/cocoa/website_settings/split_block_button.h" | 27 #include "chrome/browser/ui/cocoa/website_settings/split_block_button.h" |
| 27 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa.
h" | 28 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa.
h" |
| 28 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" | 29 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
| 29 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" | 30 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
| 30 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 31 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 31 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | |
| 32 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" | 32 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" |
| 33 #include "chrome/browser/ui/website_settings/permission_menu_model.h" | 33 #include "chrome/browser/ui/website_settings/permission_menu_model.h" |
| 34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/grit/generated_resources.h" | 35 #include "chrome/grit/generated_resources.h" |
| 36 #include "components/prefs/pref_service.h" | 36 #include "components/prefs/pref_service.h" |
| 37 #include "components/url_formatter/elide_url.h" | 37 #include "components/url_formatter/elide_url.h" |
| 38 #include "content/public/browser/native_web_keyboard_event.h" | 38 #include "content/public/browser/native_web_keyboard_event.h" |
| 39 #include "content/public/browser/user_metrics.h" | 39 #include "content/public/browser/user_metrics.h" |
| 40 #include "grit/components_strings.h" | 40 #include "grit/components_strings.h" |
| 41 #include "skia/ext/skia_utils_mac.h" | 41 #include "skia/ext/skia_utils_mac.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 167 |
| 168 @interface PermissionBubbleController () | 168 @interface PermissionBubbleController () |
| 169 | 169 |
| 170 // Determines if the bubble has an anchor in a corner or no anchor at all. | 170 // Determines if the bubble has an anchor in a corner or no anchor at all. |
| 171 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation; | 171 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation; |
| 172 | 172 |
| 173 // Returns the expected parent for this bubble. | 173 // Returns the expected parent for this bubble. |
| 174 - (NSWindow*)getExpectedParentWindow; | 174 - (NSWindow*)getExpectedParentWindow; |
| 175 | 175 |
| 176 // Returns an autoreleased NSView displaying the icon and label for |request|. | 176 // Returns an autoreleased NSView displaying the icon and label for |request|. |
| 177 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request; | 177 - (NSView*)labelForRequest:(PermissionRequest*)request; |
| 178 | 178 |
| 179 // Returns an autoreleased NSView displaying the title for the bubble | 179 // Returns an autoreleased NSView displaying the title for the bubble |
| 180 // requesting settings for |host|. | 180 // requesting settings for |host|. |
| 181 - (NSView*)titleWithOrigin:(const GURL&)origin; | 181 - (NSView*)titleWithOrigin:(const GURL&)origin; |
| 182 | 182 |
| 183 // Returns an autoreleased NSView displaying a menu for |request|. The | 183 // Returns an autoreleased NSView displaying a menu for |request|. The |
| 184 // menu will be initialized as 'allow' if |allow| is YES. | 184 // menu will be initialized as 'allow' if |allow| is YES. |
| 185 - (NSView*)menuForRequest:(PermissionBubbleRequest*)request | 185 - (NSView*)menuForRequest:(PermissionRequest*)request |
| 186 atIndex:(int)index | 186 atIndex:(int)index |
| 187 allow:(BOOL)allow; | 187 allow:(BOOL)allow; |
| 188 | 188 |
| 189 // Returns an autoreleased NSView of a button with |title| and |action|. | 189 // Returns an autoreleased NSView of a button with |title| and |action|. |
| 190 - (NSView*)buttonWithTitle:(NSString*)title | 190 - (NSView*)buttonWithTitle:(NSString*)title |
| 191 action:(SEL)action; | 191 action:(SEL)action; |
| 192 | 192 |
| 193 // Returns an autoreleased NSView displaying a block button. | 193 // Returns an autoreleased NSView displaying a block button. |
| 194 - (NSView*)blockButton; | 194 - (NSView*)blockButton; |
| 195 | 195 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 DCHECK(bridge_); | 303 DCHECK(bridge_); |
| 304 [self updateAnchorPosition]; | 304 [self updateAnchorPosition]; |
| 305 } | 305 } |
| 306 | 306 |
| 307 - (void)parentWindowDidMove:(NSNotification*)notification { | 307 - (void)parentWindowDidMove:(NSNotification*)notification { |
| 308 DCHECK(bridge_); | 308 DCHECK(bridge_); |
| 309 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 309 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 310 } | 310 } |
| 311 | 311 |
| 312 - (void)showWithDelegate:(PermissionBubbleView::Delegate*)delegate | 312 - (void)showWithDelegate:(PermissionBubbleView::Delegate*)delegate |
| 313 forRequests:(const std::vector<PermissionBubbleRequest*>&)requests | 313 forRequests:(const std::vector<PermissionRequest*>&)requests |
| 314 acceptStates:(const std::vector<bool>&)acceptStates { | 314 acceptStates:(const std::vector<bool>&)acceptStates { |
| 315 DCHECK(!requests.empty()); | 315 DCHECK(!requests.empty()); |
| 316 DCHECK(delegate); | 316 DCHECK(delegate); |
| 317 delegate_ = delegate; | 317 delegate_ = delegate; |
| 318 | 318 |
| 319 NSView* contentView = [[self window] contentView]; | 319 NSView* contentView = [[self window] contentView]; |
| 320 [contentView setSubviews:@[]]; | 320 [contentView setSubviews:@[]]; |
| 321 | 321 |
| 322 BOOL singlePermission = requests.size() == 1; | 322 BOOL singlePermission = requests.size() == 1; |
| 323 | 323 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { | 485 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { |
| 486 return [self hasVisibleLocationBar] ? info_bubble::kTopLeft | 486 return [self hasVisibleLocationBar] ? info_bubble::kTopLeft |
| 487 : info_bubble::kNoArrow; | 487 : info_bubble::kNoArrow; |
| 488 } | 488 } |
| 489 | 489 |
| 490 - (NSWindow*)getExpectedParentWindow { | 490 - (NSWindow*)getExpectedParentWindow { |
| 491 DCHECK(browser_->window()); | 491 DCHECK(browser_->window()); |
| 492 return browser_->window()->GetNativeWindow(); | 492 return browser_->window()->GetNativeWindow(); |
| 493 } | 493 } |
| 494 | 494 |
| 495 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request { | 495 - (NSView*)labelForRequest:(PermissionRequest*)request { |
| 496 DCHECK(request); | 496 DCHECK(request); |
| 497 base::scoped_nsobject<NSView> permissionView( | 497 base::scoped_nsobject<NSView> permissionView( |
| 498 [[NSView alloc] initWithFrame:NSZeroRect]); | 498 [[NSView alloc] initWithFrame:NSZeroRect]); |
| 499 base::scoped_nsobject<NSImageView> permissionIcon( | 499 base::scoped_nsobject<NSImageView> permissionIcon( |
| 500 [[NSImageView alloc] initWithFrame:NSZeroRect]); | 500 [[NSImageView alloc] initWithFrame:NSZeroRect]); |
| 501 [permissionIcon setImage:ui::ResourceBundle::GetSharedInstance(). | 501 [permissionIcon setImage:ui::ResourceBundle::GetSharedInstance(). |
| 502 GetNativeImageNamed(request->GetIconId()).ToNSImage()]; | 502 GetNativeImageNamed(request->GetIconId()).ToNSImage()]; |
| 503 [permissionIcon setFrameSize:kPermissionIconSize]; | 503 [permissionIcon setFrameSize:kPermissionIconSize]; |
| 504 [permissionView addSubview:permissionIcon]; | 504 [permissionView addSubview:permissionIcon]; |
| 505 | 505 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 origin, url_formatter::SchemeDisplay:: | 551 origin, url_formatter::SchemeDisplay:: |
| 552 OMIT_CRYPTOGRAPHIC))]; | 552 OMIT_CRYPTOGRAPHIC))]; |
| 553 [titleView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 553 [titleView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| 554 [titleView sizeToFit]; | 554 [titleView sizeToFit]; |
| 555 NSRect titleFrame = [titleView frame]; | 555 NSRect titleFrame = [titleView frame]; |
| 556 [titleView setFrameSize:NSMakeSize(NSWidth(titleFrame) + kTitlePaddingX, | 556 [titleView setFrameSize:NSMakeSize(NSWidth(titleFrame) + kTitlePaddingX, |
| 557 NSHeight(titleFrame))]; | 557 NSHeight(titleFrame))]; |
| 558 return titleView.autorelease(); | 558 return titleView.autorelease(); |
| 559 } | 559 } |
| 560 | 560 |
| 561 - (NSView*)menuForRequest:(PermissionBubbleRequest*)request | 561 - (NSView*)menuForRequest:(PermissionRequest*)request |
| 562 atIndex:(int)index | 562 atIndex:(int)index |
| 563 allow:(BOOL)allow { | 563 allow:(BOOL)allow { |
| 564 DCHECK(request); | 564 DCHECK(request); |
| 565 DCHECK(delegate_); | 565 DCHECK(delegate_); |
| 566 base::scoped_nsobject<AllowBlockMenuButton> button( | 566 base::scoped_nsobject<AllowBlockMenuButton> button( |
| 567 [[AllowBlockMenuButton alloc] initForURL:request->GetOrigin() | 567 [[AllowBlockMenuButton alloc] initForURL:request->GetOrigin() |
| 568 allowed:allow | 568 allowed:allow |
| 569 index:index | 569 index:index |
| 570 delegate:delegate_]); | 570 delegate:delegate_]); |
| 571 return button.autorelease(); | 571 return button.autorelease(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 | 638 |
| 639 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 639 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { |
| 640 NSRect frameA = [viewA frame]; | 640 NSRect frameA = [viewA frame]; |
| 641 NSRect frameB = [viewB frame]; | 641 NSRect frameB = [viewB frame]; |
| 642 frameA.origin.y = | 642 frameA.origin.y = |
| 643 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); | 643 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); |
| 644 [viewA setFrameOrigin:frameA.origin]; | 644 [viewA setFrameOrigin:frameA.origin]; |
| 645 } | 645 } |
| 646 | 646 |
| 647 @end // implementation PermissionBubbleController | 647 @end // implementation PermissionBubbleController |
| OLD | NEW |