Reland "Close web contents modal dialogs on content load start"
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / constrained_window / constrained_window_mac.h
blobd6f071502cde9ff3d85394b21291c52309cf2fbd
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_MAC_
6 #define CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_MAC_
8 #import <Cocoa/Cocoa.h>
10 #include "base/mac/scoped_nsobject.h"
11 #include "components/web_modal/native_web_contents_modal_dialog.h"
13 namespace content {
14 class WebContents;
16 class ConstrainedWindowMac;
17 @protocol ConstrainedWindowSheet;
19 // A delegate for a constrained window. The delegate is notified when the
20 // window closes.
21 class ConstrainedWindowMacDelegate {
22 public:
23 virtual void OnConstrainedWindowClosed(ConstrainedWindowMac* window) = 0;
26 // Constrained window implementation for Mac.
27 // Normally an instance of this class is owned by the delegate. The delegate
28 // should delete the instance when the window is closed.
29 class ConstrainedWindowMac {
30 public:
31 ConstrainedWindowMac(
32 ConstrainedWindowMacDelegate* delegate,
33 content::WebContents* web_contents,
34 id<ConstrainedWindowSheet> sheet);
35 virtual ~ConstrainedWindowMac();
37 void ShowWebContentsModalDialog();
38 // Closes the constrained window and deletes this instance.
39 void CloseWebContentsModalDialog();
40 void FocusWebContentsModalDialog();
41 void PulseWebContentsModalDialog();
42 web_modal::NativeWebContentsModalDialog GetNativeDialog();
44 void SetPreventCloseOnLoadStart(bool prevent);
46 private:
47 // Gets the parent window of the dialog.
48 NSWindow* GetParentWindow() const;
50 ConstrainedWindowMacDelegate* delegate_; // weak, owns us.
52 // The WebContents that owns and constrains this ConstrainedWindowMac. Weak.
53 content::WebContents* web_contents_;
55 base::scoped_nsprotocol<id<ConstrainedWindowSheet>> sheet_;
57 // This is true if the constrained window has been shown.
58 bool shown_;
61 #endif // CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_MAC_