15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_POPUP_CONTROLLER_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_POPUP_CONTROLLER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import <Cocoa/Cocoa.h>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import "chrome/browser/ui/cocoa/base_bubble_controller.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import "chrome/browser/ui/cocoa/info_bubble_view.h"
137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Browser;
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DevtoolsNotificationBridge;
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ExtensionPopupContainer;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NotificationRegistrar;
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace extensions {
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class ExtensionViewHost;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This controller manages a single browser action popup that can appear once a
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// user has clicked on a browser action button. It instantiates the extension
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// popup view showing the content and resizes the window to accomodate any size
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// changes as they occur.
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// There can only be one browser action popup open at a time, so a static
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// variable holds a reference to the current popup.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@interface ExtensionPopupController : BaseBubbleController {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) @private
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The native extension view retrieved from the extension host. Weak.
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NSView* extensionView_;
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The current frame of the extension view. Cached to prevent setting the
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // frame if the size hasn't changed.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NSRect extensionFrame_;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The extension host object.
45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<extensions::ExtensionViewHost> host_;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<content::NotificationRegistrar> registrar_;
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<DevtoolsNotificationBridge> notificationBridge_;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<ExtensionPopupContainer> container_;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Whether the popup has a devtools window attached to it.
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BOOL beingInspected_;
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
54424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // There's an extra windowDidResignKey: notification right after a
55424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // ConstrainedWindow closes that should be ignored.
56424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  BOOL ignoreWindowDidResignKey_;
57424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The size once the ExtensionView has loaded.
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NSSize pendingSize_;
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Returns the ExtensionViewHost object associated with this popup.
63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)- (extensions::ExtensionViewHost*)extensionViewHost;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Starts the process of showing the given popup URL. Instantiates an
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ExtensionPopupController with the parent window retrieved from |browser|, a
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// host for the popup created by the extension process manager specific to the
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// browser profile and the remaining arguments |anchoredAt| and |arrowLocation|.
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |anchoredAt| is expected to be in the window's coordinates at the bottom
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// center of the browser action button.
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The actual display of the popup is delayed until the page contents finish
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// loading in order to minimize UI flashing and resizing.
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Passing YES to |devMode| will launch the webkit inspector for the popup,
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and prevent the popup from closing when focus is lost.  It will be closed
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// after the inspector is closed, or another popup is opened.
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)+ (ExtensionPopupController*)showURL:(GURL)url
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           inBrowser:(Browser*)browser
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          anchoredAt:(NSPoint)anchoredAt
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       arrowLocation:(info_bubble::BubbleArrowLocation)
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                         arrowLocation
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             devMode:(BOOL)devMode;
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the controller used to display the popup being shown. If no popup is
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// currently open, then nil is returned. Static because only one extension popup
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// window can be open at a time.
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)+ (ExtensionPopupController*)popup;
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Whether the popup is in the process of closing (via Core Animation).
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (BOOL)isClosing;
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Show the dev tools attached to the popup.
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)showDevTools;
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Set whether the popup is being inspected or not. If it is being inspected
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// it will not be hidden when it loses focus.
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)setBeingInspected:(BOOL)beingInspected;
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@end
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@interface ExtensionPopupController(TestingAPI)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns a weak pointer to the current popup's view.
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (NSView*)view;
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the minimum allowed size for an extension popup.
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)+ (NSSize)minPopupSize;
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the maximum allowed size for an extension popup.
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)+ (NSSize)maxPopupSize;
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@end
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_POPUP_CONTROLLER_H_
109