Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / website_settings / permission_bubble_cocoa.mm
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h"
6
7 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
8 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
9 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
10 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_controller.h"
11 #import "chrome/browser/ui/website_settings/permission_bubble_view.h"
12 #include "content/public/browser/web_contents.h"
13
14 PermissionBubbleCocoa::PermissionBubbleCocoa(NSWindow* parent_window)
15     : parent_window_(parent_window), delegate_(NULL), bubbleController_(nil) {}
16
17 PermissionBubbleCocoa::~PermissionBubbleCocoa() {
18   if (delegate_)
19     delegate_->SetView(NULL);
20 }
21
22 void PermissionBubbleCocoa::Show(
23     const std::vector<PermissionBubbleRequest*>& requests,
24     const std::vector<bool>& accept_state,
25     bool customization_mode) {
26   DCHECK(parent_window_);
27
28   if (!bubbleController_) {
29     bubbleController_ = [[PermissionBubbleController alloc]
30         initWithParentWindow:parent_window_
31                       bridge:this];
32   }
33
34   [bubbleController_ showAtAnchor:GetAnchorPoint()
35                      withDelegate:delegate_
36                       forRequests:requests
37                      acceptStates:accept_state
38                 customizationMode:customization_mode];
39 }
40
41 void PermissionBubbleCocoa::Hide() {
42   [bubbleController_ close];
43 }
44
45 bool PermissionBubbleCocoa::IsVisible() {
46   return bubbleController_ != nil;
47 }
48
49 void PermissionBubbleCocoa::SetDelegate(Delegate* delegate) {
50   if (delegate_ == delegate)
51     return;
52   if (delegate_ && delegate)
53     delegate_->SetView(NULL);
54   delegate_ = delegate;
55 }
56
57 bool PermissionBubbleCocoa::CanAcceptRequestUpdate() {
58   // TODO(gbillock): implement. Should return true if the mouse is not over the
59   // dialog.
60   return false;
61 }
62
63 void PermissionBubbleCocoa::OnBubbleClosing() {
64   bubbleController_ = nil;
65 }
66
67 NSPoint PermissionBubbleCocoa::GetAnchorPoint() {
68   LocationBarViewMac* location_bar =
69       [[parent_window_ windowController] locationBarBridge];
70   NSPoint anchor = location_bar->GetPageInfoBubblePoint();
71   return [parent_window_ convertBaseToScreen:anchor];
72 }
73
74 NSWindow* PermissionBubbleCocoa::window() {
75   return [bubbleController_ window];
76 }