[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / extension_installed_bubble_controller.h
blobaec68981ac6511392286cada9fa4502e544751b9
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_INSTALLED_BUBBLE_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_CONTROLLER_H_
8 #import <Cocoa/Cocoa.h>
10 #include "base/memory/scoped_ptr.h"
11 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
12 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
15 class Browser;
16 class ExtensionLoadedNotificationObserver;
17 @class HyperlinkTextView;
18 @class HoverCloseButton;
19 @class InfoBubbleView;
21 namespace extensions {
22 class BundleInstaller;
23 class Extension;
26 namespace extension_installed_bubble {
28 // Maximum height or width of extension's icon (corresponds to Windows & GTK).
29 const int kIconSize = 43;
31 // Outer vertical margin for text, icon, and closing x.
32 const int kOuterVerticalMargin = 15;
34 // Inner vertical margin for text messages.
35 const int kInnerVerticalMargin = 10;
37 // An offset we apply to position the point of the bubble's arrow pointing at
38 // the NewTabButton.
39 const int kAppsBubbleArrowOffset = 4;
41 // We use a different kind of notification for each of these extension types.
42 typedef enum {
43 kApp,
44 kBrowserAction,
45 kGeneric,
46 kOmniboxKeyword,
47 kPageAction,
48 kBundle,
49 } ExtensionType;
51 } // namespace extension_installed_bubble
53 // Controller for the extension installed bubble. This bubble pops up after
54 // an extension has been installed to inform the user that the install happened
55 // properly, and to let the user know how to manage this extension in the
56 // future.
57 @interface ExtensionInstalledBubbleController :
58 BaseBubbleController<NSTextViewDelegate> {
59 @private
60 const extensions::Extension* extension_; // weak
61 const extensions::BundleInstaller* bundle_; // weak
62 Browser* browser_; // weak
63 base::scoped_nsobject<NSImage> icon_;
65 extension_installed_bubble::ExtensionType type_;
67 // We need to remove the page action immediately when the browser window
68 // closes while this bubble is still open, so the bubble's closing animation
69 // doesn't overlap browser destruction.
70 BOOL pageActionPreviewShowing_;
72 // Lets us register for EXTENSION_LOADED notifications. The actual
73 // notifications are sent to the observer object, which proxies them
74 // back to the controller.
75 scoped_ptr<ExtensionLoadedNotificationObserver> extensionObserver_;
77 // References below are weak, being obtained from the nib.
78 IBOutlet HoverCloseButton* closeButton_;
79 IBOutlet NSImageView* iconImage_;
80 IBOutlet NSTextField* heading_;
81 // Only shown for browser actions, page actions and omnibox keywords.
82 IBOutlet NSTextField* howToUse_;
83 IBOutlet NSTextField* howToManage_;
84 // Only shown for app installs.
85 IBOutlet NSButton* appShortcutLink_;
86 // Only shown for extensions with commands.
87 IBOutlet NSButton* manageShortcutLink_;
88 // Only shown if the sign-in promo is active.
89 IBOutlet NSTextField* promoPlaceholder_;
90 // Text fields don't work as well with embedded links as text views, but
91 // text views cannot conveniently be created in IB. The xib file contains
92 // a text field |promoPlaceholder_| that's replaced by this text view |promo_|
93 // in -awakeFromNib.
94 base::scoped_nsobject<HyperlinkTextView> promo_;
95 // Only shown for bundle installs.
96 IBOutlet NSTextField* installedHeadingMsg_;
97 IBOutlet NSTextField* installedItemsMsg_;
98 IBOutlet NSTextField* failedHeadingMsg_;
99 IBOutlet NSTextField* failedItemsMsg_;
102 @property(nonatomic, readonly) const extensions::Extension* extension;
103 @property(nonatomic, readonly) const extensions::BundleInstaller* bundle;
104 @property(nonatomic) BOOL pageActionPreviewShowing;
106 // Initialize the window, and then create observers to wait for the extension
107 // to complete loading, or the browser window to close.
108 - (id)initWithParentWindow:(NSWindow*)parentWindow
109 extension:(const extensions::Extension*)extension
110 bundle:(const extensions::BundleInstaller*)bundle
111 browser:(Browser*)browser
112 icon:(SkBitmap)icon;
114 // Action for close button.
115 - (IBAction)closeWindow:(id)sender;
117 // From NSTextViewDelegate:
118 - (BOOL)textView:(NSTextView*)aTextView
119 clickedOnLink:(id)link
120 atIndex:(NSUInteger)charIndex;
122 // Displays the extension installed bubble. This callback is triggered by
123 // the extensionObserver when the extension has completed loading.
124 - (void)showWindow:(id)sender;
126 // Clears our weak pointer to the Extension. This callback is triggered by
127 // the extensionObserver when the extension is unloaded.
128 - (void)extensionUnloaded:(id)sender;
130 // Opens the shortcut configuration UI.
131 - (IBAction)onManageShortcutClicked:(id)sender;
133 // Shows the new app installed animation.
134 - (IBAction)onAppShortcutClicked:(id)sender;
136 @end
138 @interface ExtensionInstalledBubbleController (ExposedForTesting)
140 - (void)removePageActionPreviewIfNecessary;
141 - (NSWindow*)initializeWindow;
142 - (int)calculateWindowHeight;
143 - (void)setMessageFrames:(int)newWindowHeight;
144 - (NSRect)headingFrame;
145 - (NSRect)frameOfHowToUse;
146 - (NSRect)frameOfHowToManage;
147 - (NSRect)frameOfSigninPromo;
148 - (BOOL)showSyncPromo;
149 - (NSButton*)appInstalledShortcutLink;
151 @end // ExtensionInstalledBubbleController(ExposedForTesting)
153 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_CONTROLLER_H_