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/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" |
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/permissions/permission_request.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
18 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 18 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
19 #import "chrome/browser/ui/cocoa/chrome_style.h" | 19 #import "chrome/browser/ui/cocoa/chrome_style.h" |
20 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 20 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
21 #import "chrome/browser/ui/cocoa/hover_close_button.h" | 21 #import "chrome/browser/ui/cocoa/hover_close_button.h" |
22 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 22 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
23 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 23 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 24 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
24 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 25 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
25 #include "chrome/browser/ui/cocoa/page_info/permission_selector_button.h" | 26 #include "chrome/browser/ui/cocoa/page_info/permission_selector_button.h" |
26 #include "chrome/browser/ui/cocoa/page_info/split_block_button.h" | 27 #include "chrome/browser/ui/cocoa/page_info/split_block_button.h" |
27 #include "chrome/browser/ui/cocoa/page_info/website_settings_utils_cocoa.h" | 28 #include "chrome/browser/ui/cocoa/page_info/website_settings_utils_cocoa.h" |
28 #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h" | 29 #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h" |
29 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" | 30 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
30 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" | 31 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
31 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 32 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
32 #include "chrome/browser/ui/page_info/permission_menu_model.h" | 33 #include "chrome/browser/ui/page_info/permission_menu_model.h" |
33 #include "chrome/browser/ui/permission_bubble/permission_prompt.h" | 34 #include "chrome/browser/ui/permission_bubble/permission_prompt.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 bridge_ = bridge; | 227 bridge_ = bridge; |
227 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 228 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
228 [center addObserver:self | 229 [center addObserver:self |
229 selector:@selector(parentWindowDidMove:) | 230 selector:@selector(parentWindowDidMove:) |
230 name:NSWindowDidMoveNotification | 231 name:NSWindowDidMoveNotification |
231 object:[self getExpectedParentWindow]]; | 232 object:[self getExpectedParentWindow]]; |
232 } | 233 } |
233 return self; | 234 return self; |
234 } | 235 } |
235 | 236 |
236 - (LocationBarDecoration*)decorationForBubble { | |
237 if (![self hasVisibleLocationBar]) | |
238 return nullptr; | |
239 | |
240 LocationBarViewMac* location_bar = | |
241 [[self.parentWindow windowController] locationBarBridge]; | |
242 return location_bar->GetPageInfoDecoration(); | |
243 } | |
244 | |
245 + (NSPoint)getAnchorPointForBrowser:(Browser*)browser { | 237 + (NSPoint)getAnchorPointForBrowser:(Browser*)browser { |
246 NSPoint anchor; | 238 NSPoint anchor; |
247 NSWindow* parentWindow = browser->window()->GetNativeWindow(); | 239 NSWindow* parentWindow = browser->window()->GetNativeWindow(); |
248 if ([PermissionBubbleController hasVisibleLocationBarForBrowser:browser]) { | 240 if ([PermissionBubbleController hasVisibleLocationBarForBrowser:browser]) { |
249 LocationBarViewMac* location_bar = | 241 LocationBarViewMac* location_bar = |
250 [[parentWindow windowController] locationBarBridge]; | 242 [[parentWindow windowController] locationBarBridge]; |
251 anchor = location_bar->GetPageInfoBubblePoint(); | 243 anchor = location_bar->GetPageInfoBubblePoint(); |
252 } else { | 244 } else { |
253 // Position the bubble on the left of the screen if there is no page info | 245 // Position the bubble on the left of the screen if there is no page info |
254 // button to point at. | 246 // button to point at. |
(...skipping 29 matching lines...) Expand all Loading... |
284 | 276 |
285 - (void)windowWillClose:(NSNotification*)notification { | 277 - (void)windowWillClose:(NSNotification*)notification { |
286 [[NSNotificationCenter defaultCenter] | 278 [[NSNotificationCenter defaultCenter] |
287 removeObserver:self | 279 removeObserver:self |
288 name:NSWindowDidMoveNotification | 280 name:NSWindowDidMoveNotification |
289 object:nil]; | 281 object:nil]; |
290 bridge_->OnBubbleClosing(); | 282 bridge_->OnBubbleClosing(); |
291 [super windowWillClose:notification]; | 283 [super windowWillClose:notification]; |
292 } | 284 } |
293 | 285 |
| 286 - (void)showWindow:(id)sender { |
| 287 if ([self hasVisibleLocationBar]) { |
| 288 decoration_ = [[self.parentWindow windowController] locationBarBridge] |
| 289 ->GetPageInfoDecoration(); |
| 290 decoration_->SetActive(true); |
| 291 } |
| 292 |
| 293 [super showWindow:sender]; |
| 294 } |
| 295 |
| 296 - (void)close { |
| 297 if (decoration_) { |
| 298 decoration_->SetActive(false); |
| 299 decoration_ = nullptr; |
| 300 } |
| 301 |
| 302 [super close]; |
| 303 } |
| 304 |
294 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { | 305 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { |
295 // Override the base class implementation, which would have closed the bubble. | 306 // Override the base class implementation, which would have closed the bubble. |
296 } | 307 } |
297 | 308 |
298 - (void)parentWindowDidResize:(NSNotification*)notification { | 309 - (void)parentWindowDidResize:(NSNotification*)notification { |
299 // Override the base class implementation, which sets the anchor point. But | 310 // Override the base class implementation, which sets the anchor point. But |
300 // it's not necessary since BrowserWindowController will notify the | 311 // it's not necessary since BrowserWindowController will notify the |
301 // PermissionRequestManager to update the anchor position on a resize. | 312 // PermissionRequestManager to update the anchor position on a resize. |
302 } | 313 } |
303 | 314 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 } | 659 } |
649 | 660 |
650 - (IBAction)cancel:(id)sender { | 661 - (IBAction)cancel:(id)sender { |
651 // This is triggered by ESC when the bubble has focus. | 662 // This is triggered by ESC when the bubble has focus. |
652 if (delegate_) | 663 if (delegate_) |
653 delegate_->Closing(); | 664 delegate_->Closing(); |
654 [super cancel:sender]; | 665 [super cancel:sender]; |
655 } | 666 } |
656 | 667 |
657 @end // implementation PermissionBubbleController | 668 @end // implementation PermissionBubbleController |
OLD | NEW |