Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / extension_popup_controller.h
blob07652262c6ffcb428da3402d3ccf2a8e71731a23
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_EXTENSIONS_EXTENSION_POPUP_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_POPUP_CONTROLLER_H_
8 #import <Cocoa/Cocoa.h>
9 #include <string>
11 #include "base/memory/scoped_ptr.h"
12 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
13 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
14 #include "content/public/browser/notification_registrar.h"
16 class Browser;
17 class ExtensionPopupNotificationBridge;
18 class ExtensionPopupContainer;
20 namespace extensions {
21 class ExtensionViewHost;
24 // This controller manages a single browser action popup that can appear once a
25 // user has clicked on a browser action button. It instantiates the extension
26 // popup view showing the content and resizes the window to accomodate any size
27 // changes as they occur.
29 // There can only be one browser action popup open at a time, so a static
30 // variable holds a reference to the current popup.
31 @interface ExtensionPopupController : BaseBubbleController {
32 @private
33 // The native extension view retrieved from the extension host. Weak.
34 NSView* extensionView_;
36 // The current frame of the extension view. Cached to prevent setting the
37 // frame if the size hasn't changed.
38 NSRect extensionFrame_;
40 // The extension host object.
41 scoped_ptr<extensions::ExtensionViewHost> host_;
43 content::NotificationRegistrar registrar_;
44 scoped_ptr<ExtensionPopupNotificationBridge> notificationBridge_;
45 scoped_ptr<ExtensionPopupContainer> container_;
47 std::string extensionId_;
49 // Whether the popup has a devtools window attached to it.
50 BOOL beingInspected_;
52 // There's an extra windowDidResignKey: notification right after a
53 // ConstrainedWindow closes that should be ignored.
54 BOOL ignoreWindowDidResignKey_;
56 // The size once the ExtensionView has loaded.
57 NSSize pendingSize_;
60 // Starts the process of showing the given popup URL. Instantiates an
61 // ExtensionPopupController with the parent window retrieved from |browser|, a
62 // host for the popup created by the extension process manager specific to the
63 // browser profile and the remaining arguments |anchoredAt| and |arrowLocation|.
64 // |anchoredAt| is expected to be in the window's coordinates at the bottom
65 // center of the browser action button.
66 // The actual display of the popup is delayed until the page contents finish
67 // loading in order to minimize UI flashing and resizing.
68 // Passing YES to |devMode| will launch the webkit inspector for the popup,
69 // and prevent the popup from closing when focus is lost. It will be closed
70 // after the inspector is closed, or another popup is opened.
71 + (ExtensionPopupController*)host:(scoped_ptr<extensions::ExtensionViewHost>)
72 host
73 inBrowser:(Browser*)browser
74 anchoredAt:(NSPoint)anchoredAt
75 arrowLocation:(info_bubble::BubbleArrowLocation)
76 arrowLocation
77 devMode:(BOOL)devMode;
79 // Returns the controller used to display the popup being shown. If no popup is
80 // currently open, then nil is returned. Static because only one extension popup
81 // window can be open at a time.
82 + (ExtensionPopupController*)popup;
84 // Whether the popup is in the process of closing (via Core Animation).
85 - (BOOL)isClosing;
87 // Show the dev tools attached to the popup.
88 - (void)showDevTools;
90 // Set whether the popup is being inspected or not. If it is being inspected
91 // it will not be hidden when it loses focus.
92 - (void)setBeingInspected:(BOOL)beingInspected;
94 @property(readonly, nonatomic) std::string extensionId;
96 @end
98 @interface ExtensionPopupController(TestingAPI)
99 // Sets whether or not animations are enabled.
100 + (void)setAnimationsEnabledForTesting:(BOOL)enabled;
101 // Returns a weak pointer to the current popup's view.
102 - (NSView*)view;
103 // Returns the minimum allowed size for an extension popup.
104 + (NSSize)minPopupSize;
105 // Returns the maximum allowed size for an extension popup.
106 + (NSSize)maxPopupSize;
107 @end
109 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_POPUP_CONTROLLER_H_