1d67b3cedffdb6280760f5c27215b474202d9af7
[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   LocationBarViewMac* location_bar =
35       [[parent_window_ windowController] locationBarBridge];
36   NSPoint anchor = location_bar->GetPageInfoBubblePoint();
37   [bubbleController_ showAtAnchor:[parent_window_ convertBaseToScreen:anchor]
38                      withDelegate:delegate_
39                       forRequests:requests
40                      acceptStates:accept_state
41                 customizationMode:customization_mode];
42 }
43
44 void PermissionBubbleCocoa::Hide() {
45   [bubbleController_ close];
46 }
47
48 void PermissionBubbleCocoa::SetDelegate(Delegate* delegate) {
49   if (delegate_ == delegate)
50     return;
51   if (delegate_ && delegate)
52     delegate_->SetView(NULL);
53   delegate_ = delegate;
54 }
55
56 bool PermissionBubbleCocoa::CanAcceptRequestUpdate() {
57   // TODO(gbillock): implement. Should return true if the mouse is not over the
58   // dialog.
59   return false;
60 }
61
62 void PermissionBubbleCocoa::OnBubbleClosing() {
63   bubbleController_ = nil;
64 }