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 #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" | 8 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" |
9 #import "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_controller.
h" | 9 #import "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_controller.
h" |
10 #import "chrome/browser/ui/permission_bubble/permission_prompt.h" | 10 #import "chrome/browser/ui/permission_bubble/permission_prompt.h" |
11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
12 #import "ui/base/cocoa/nsview_additions.h" | 12 #import "ui/base/cocoa/nsview_additions.h" |
13 | 13 |
14 PermissionBubbleCocoa::PermissionBubbleCocoa(Browser* browser) | 14 PermissionBubbleCocoa::PermissionBubbleCocoa(Browser* browser) |
15 : browser_(browser), delegate_(nullptr), bubbleController_(nil) {} | 15 : browser_(browser), delegate_(nullptr), bubbleController_(nil) {} |
16 | 16 |
17 PermissionBubbleCocoa::~PermissionBubbleCocoa() { | 17 PermissionBubbleCocoa::~PermissionBubbleCocoa() { |
18 } | 18 } |
19 | 19 |
20 void PermissionBubbleCocoa::Show( | 20 void PermissionBubbleCocoa::Show( |
21 const std::vector<PermissionRequest*>& requests, | 21 const std::vector<PermissionRequest*>& requests, |
22 const std::vector<bool>& accept_state) { | 22 const std::vector<bool>& accept_state) { |
23 DCHECK(browser_); | 23 DCHECK(browser_); |
24 | 24 |
25 if (!bubbleController_) { | 25 if (IsVisible()) { |
26 bubbleController_ = | 26 // We just rejected a MaybeCancelRequest() call. |
27 [[PermissionBubbleController alloc] initWithBrowser:browser_ | 27 return; |
28 bridge:this]; | |
29 } | 28 } |
30 | 29 |
| 30 bubbleController_ = |
| 31 [[PermissionBubbleController alloc] initWithBrowser:browser_ bridge:this]; |
| 32 |
31 [bubbleController_ showWithDelegate:delegate_ | 33 [bubbleController_ showWithDelegate:delegate_ |
32 forRequests:requests | 34 forRequests:requests |
33 acceptStates:accept_state]; | 35 acceptStates:accept_state]; |
34 } | 36 } |
35 | 37 |
36 void PermissionBubbleCocoa::Hide() { | 38 void PermissionBubbleCocoa::Hide() { |
37 [bubbleController_ close]; | 39 [bubbleController_ close]; |
38 } | 40 } |
39 | 41 |
40 bool PermissionBubbleCocoa::IsVisible() { | 42 bool PermissionBubbleCocoa::IsVisible() { |
41 return bubbleController_ != nil; | 43 return bubbleController_ != nil; |
42 } | 44 } |
43 | 45 |
44 void PermissionBubbleCocoa::SetDelegate(Delegate* delegate) { | 46 void PermissionBubbleCocoa::SetDelegate(Delegate* delegate) { |
45 if (delegate_ == delegate) | 47 if (delegate_ == delegate) |
46 return; | 48 return; |
47 delegate_ = delegate; | 49 delegate_ = delegate; |
48 } | 50 } |
49 | 51 |
50 bool PermissionBubbleCocoa::CanAcceptRequestUpdate() { | 52 bool PermissionBubbleCocoa::MaybeCancelRequest() { |
51 return ![[[bubbleController_ window] contentView] cr_isMouseInView]; | 53 if ([[[bubbleController_ window] contentView] cr_isMouseInView]) |
| 54 return false; |
| 55 Hide(); |
| 56 return true; |
52 } | 57 } |
53 | 58 |
54 bool PermissionBubbleCocoa::HidesAutomatically() { | 59 bool PermissionBubbleCocoa::HidesAutomatically() { |
55 return false; | 60 return false; |
56 } | 61 } |
57 | 62 |
58 void PermissionBubbleCocoa::UpdateAnchorPosition() { | 63 void PermissionBubbleCocoa::UpdateAnchorPosition() { |
59 [bubbleController_ updateAnchorPosition]; | 64 [bubbleController_ updateAnchorPosition]; |
60 } | 65 } |
61 | 66 |
62 gfx::NativeWindow PermissionBubbleCocoa::GetNativeWindow() { | 67 gfx::NativeWindow PermissionBubbleCocoa::GetNativeWindow() { |
63 return [bubbleController_ window]; | 68 return [bubbleController_ window]; |
64 } | 69 } |
65 | 70 |
66 void PermissionBubbleCocoa::OnBubbleClosing() { | 71 void PermissionBubbleCocoa::OnBubbleClosing() { |
67 bubbleController_ = nil; | 72 bubbleController_ = nil; |
68 } | 73 } |
OLD | NEW |