Home | History | Annotate | Download | only in extensions
      1 // Copyright (c) 2011 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 #pragma once
      8 
      9 #import <Cocoa/Cocoa.h>
     10 
     11 #import "base/mac/cocoa_protocols.h"
     12 #import "base/memory/scoped_nsobject.h"
     13 #include "base/memory/scoped_ptr.h"
     14 #include "chrome/browser/ui/cocoa/info_bubble_view.h"
     15 #include "googleurl/src/gurl.h"
     16 
     17 
     18 class Browser;
     19 class DevtoolsNotificationBridge;
     20 class ExtensionHost;
     21 @class InfoBubbleWindow;
     22 class NotificationRegistrar;
     23 
     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.
     28 //
     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 : NSWindowController<NSWindowDelegate> {
     32  @private
     33   // The native extension view retrieved from the extension host. Weak.
     34   NSView* extensionView_;
     35 
     36   // The popup's parent window. Weak.
     37   NSWindow* parentWindow_;
     38 
     39   // Where the window is anchored. Right now it's the bottom center of the
     40   // browser action button.
     41   NSPoint anchor_;
     42 
     43   // The current frame of the extension view. Cached to prevent setting the
     44   // frame if the size hasn't changed.
     45   NSRect extensionFrame_;
     46 
     47   // The extension host object.
     48   scoped_ptr<ExtensionHost> host_;
     49 
     50   scoped_ptr<NotificationRegistrar> registrar_;
     51   scoped_ptr<DevtoolsNotificationBridge> notificationBridge_;
     52 
     53   // Whether the popup has a devtools window attached to it.
     54   BOOL beingInspected_;
     55 }
     56 
     57 // Returns the ExtensionHost object associated with this popup.
     58 - (ExtensionHost*)extensionHost;
     59 
     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*)showURL:(GURL)url
     72                            inBrowser:(Browser*)browser
     73                           anchoredAt:(NSPoint)anchoredAt
     74                        arrowLocation:(info_bubble::BubbleArrowLocation)
     75                                          arrowLocation
     76                              devMode:(BOOL)devMode;
     77 
     78 // Returns the controller used to display the popup being shown. If no popup is
     79 // currently open, then nil is returned. Static because only one extension popup
     80 // window can be open at a time.
     81 + (ExtensionPopupController*)popup;
     82 
     83 // Whether the popup is in the process of closing (via Core Animation).
     84 - (BOOL)isClosing;
     85 
     86 // Show the dev tools attached to the popup.
     87 - (void)showDevTools;
     88 @end
     89 
     90 @interface ExtensionPopupController(TestingAPI)
     91 // Returns a weak pointer to the current popup's view.
     92 - (NSView*)view;
     93 // Returns the minimum allowed size for an extension popup.
     94 + (NSSize)minPopupSize;
     95 // Returns the maximum allowed size for an extension popup.
     96 + (NSSize)maxPopupSize;
     97 @end
     98 
     99 #endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_POPUP_CONTROLLER_H_
    100