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#ifndef CHROME_BROWSER_UI_COCOA_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_COCOA_H_ 6#define CHROME_BROWSER_UI_COCOA_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_COCOA_H_ 7 8#import <Cocoa/Cocoa.h> 9 10#include "base/mac/scoped_nsobject.h" 11#import "chrome/browser/ui/passwords/manage_passwords_bubble.h" 12 13namespace content { 14class WebContents; 15} 16 17namespace chrome { 18void ShowManagePasswordsBubble(content::WebContents* webContents); 19} 20 21@class ManagePasswordsBubbleController; 22@class ManagePasswordsBubbleCocoaNotificationBridge; 23class ManagePasswordsIcon; 24 25// Cocoa implementation of the platform-independent password bubble interface. 26class ManagePasswordsBubbleCocoa : public ManagePasswordsBubble { 27 public: 28 // Creates and shows the bubble, which owns itself. Does nothing if the bubble 29 // is already shown. 30 static void ShowBubble(content::WebContents* webContents, 31 DisplayReason displayReason, 32 ManagePasswordsIcon* icon); 33 34 // Closes and deletes the bubble. 35 void Close(); 36 37 // Sets the location bar icon that should be updated with state changes. 38 void SetIcon(ManagePasswordsIcon* icon) { icon_ = icon; } 39 40 // Accessor for the global bubble. 41 static ManagePasswordsBubbleCocoa* instance() { return bubble_; } 42 43 private: 44 friend class ManagePasswordsBubbleCocoaTest; 45 friend class ManagePasswordsBubbleTest; 46 friend void chrome::ShowManagePasswordsBubble( 47 content::WebContents* webContents); 48 49 // Instance-specific logic. Clients should use the static interface. 50 ManagePasswordsBubbleCocoa(content::WebContents* webContents, 51 DisplayReason displayReason, 52 ManagePasswordsIcon* icon); 53 virtual ~ManagePasswordsBubbleCocoa(); 54 void Show(); 55 56 // Cleans up state and deletes itself. Called when the bubble is closed. 57 void OnClose(); 58 59 // The location bar icon corresponding to the bubble. 60 ManagePasswordsIcon* icon_; 61 62 // Whether there is currently a close operation taking place. Prevents 63 // multiple attempts to close the window. 64 bool closing_; 65 66 // The view controller for the bubble. Weak; owns itself. Must be nilled 67 // after the bubble is closed. 68 ManagePasswordsBubbleController* controller_; 69 70 // WebContents on which the bubble should be displayed. Weak. 71 content::WebContents* webContents_; 72 73 // Listens for NSNotificationCenter notifications. 74 base::scoped_nsobject<ManagePasswordsBubbleCocoaNotificationBridge> bridge_; 75 76 // The global bubble instance. Deleted by Close(). 77 static ManagePasswordsBubbleCocoa* bubble_; 78 79 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleCocoa); 80}; 81 82#endif // CHROME_BROWSER_UI_COCOA_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_COCOA_H_ 83