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