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_INSTALLED_BUBBLE_CONTROLLER_H_
      6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_CONTROLLER_H_
      7 #pragma once
      8 
      9 #import <Cocoa/Cocoa.h>
     10 
     11 #import "base/mac/cocoa_protocols.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
     14 #include "third_party/skia/include/core/SkBitmap.h"
     15 
     16 class Browser;
     17 class Extension;
     18 class ExtensionLoadedNotificationObserver;
     19 @class HoverCloseButton;
     20 @class InfoBubbleView;
     21 
     22 namespace extension_installed_bubble {
     23 
     24 // Maximum height or width of extension's icon (corresponds to Windows & GTK).
     25 const int kIconSize = 43;
     26 
     27 // Outer vertical margin for text, icon, and closing x.
     28 const int kOuterVerticalMargin = 15;
     29 
     30 // Inner vertical margin for text messages.
     31 const int kInnerVerticalMargin = 10;
     32 
     33 // We use a different kind of notification for each of these extension types.
     34 typedef enum {
     35   kBrowserAction,
     36   kGeneric,
     37   kOmniboxKeyword,
     38   kPageAction
     39 } ExtensionType;
     40 
     41 }
     42 
     43 // Controller for the extension installed bubble.  This bubble pops up after
     44 // an extension has been installed to inform the user that the install happened
     45 // properly, and to let the user know how to manage this extension in the
     46 // future.
     47 @interface ExtensionInstalledBubbleController :
     48     NSWindowController<NSWindowDelegate> {
     49  @private
     50   NSWindow* parentWindow_;  // weak
     51   const Extension* extension_;  // weak
     52   Browser* browser_;  // weak
     53   scoped_nsobject<NSImage> icon_;
     54 
     55   extension_installed_bubble::ExtensionType type_;
     56 
     57   // We need to remove the page action immediately when the browser window
     58   // closes while this bubble is still open, so the bubble's closing animation
     59   // doesn't overlap browser destruction.
     60   BOOL pageActionRemoved_;
     61 
     62   // Lets us register for EXTENSION_LOADED notifications.  The actual
     63   // notifications are sent to the observer object, which proxies them
     64   // back to the controller.
     65   scoped_ptr<ExtensionLoadedNotificationObserver> extensionObserver_;
     66 
     67   // References below are weak, being obtained from the nib.
     68   IBOutlet InfoBubbleView* infoBubbleView_;
     69   IBOutlet HoverCloseButton* closeButton_;
     70   IBOutlet NSImageView* iconImage_;
     71   IBOutlet NSTextField* extensionInstalledMsg_;
     72   // Only shown for page actions and omnibox keywords.
     73   IBOutlet NSTextField* extraInfoMsg_;
     74   IBOutlet NSTextField* extensionInstalledInfoMsg_;
     75 }
     76 
     77 @property(nonatomic, readonly) const Extension* extension;
     78 @property(nonatomic) BOOL pageActionRemoved;
     79 
     80 // Initialize the window, and then create observers to wait for the extension
     81 // to complete loading, or the browser window to close.
     82 - (id)initWithParentWindow:(NSWindow*)parentWindow
     83                  extension:(const Extension*)extension
     84                    browser:(Browser*)browser
     85                       icon:(SkBitmap)icon;
     86 
     87 // Action for close button.
     88 - (IBAction)closeWindow:(id)sender;
     89 
     90 // Displays the extension installed bubble. This callback is triggered by
     91 // the extensionObserver when the extension has completed loading.
     92 - (void)showWindow:(id)sender;
     93 
     94 // Clears our weak pointer to the Extension. This callback is triggered by
     95 // the extensionObserver when the extension is unloaded.
     96 - (void)extensionUnloaded:(id)sender;
     97 
     98 @end
     99 
    100 @interface ExtensionInstalledBubbleController(ExposedForTesting)
    101 
    102 - (void)removePageActionPreviewIfNecessary;
    103 - (NSWindow*)initializeWindow;
    104 - (int)calculateWindowHeight;
    105 - (void)setMessageFrames:(int)newWindowHeight;
    106 - (NSRect)getExtensionInstalledMsgFrame;
    107 - (NSRect)getExtraInfoMsgFrame;
    108 - (NSRect)getExtensionInstalledInfoMsgFrame;
    109 
    110 @end  // ExtensionInstalledBubbleController(ExposedForTesting)
    111 
    112 #endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_CONTROLLER_H_
    113