Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / extension_installed_bubble_controller.h
blob2d3f2a193c6fbbe541e68385992e27cba4d93fa9
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/mac/scoped_nsobject.h"
11 #include "base/memory/scoped_ptr.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 ExtensionInstalledBubble;
17 class ExtensionInstalledBubbleBridge;
18 @class HyperlinkTextView;
19 @class HoverCloseButton;
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 // The bridge to the C++ object that performs shared logic across platforms,
73 // like listening for the notification that the extension is loaded. This
74 // tells us when to show the bubble.
75 scoped_ptr<ExtensionInstalledBubbleBridge> installedBubbleBridge_;
76 scoped_ptr<ExtensionInstalledBubble> installedBubble_;
78 // References below are weak, being obtained from the nib.
79 IBOutlet HoverCloseButton* closeButton_;
80 IBOutlet NSImageView* iconImage_;
81 IBOutlet NSTextField* heading_;
82 // Only shown for browser actions, page actions and omnibox keywords.
83 IBOutlet NSTextField* howToUse_;
84 IBOutlet NSTextField* howToManage_;
85 // Only shown for app installs.
86 IBOutlet NSButton* appShortcutLink_;
87 // Only shown for extensions with commands.
88 IBOutlet NSButton* manageShortcutLink_;
89 // Only shown if the sign-in promo is active.
90 IBOutlet NSTextField* promoPlaceholder_;
91 // Text fields don't work as well with embedded links as text views, but
92 // text views cannot conveniently be created in IB. The xib file contains
93 // a text field |promoPlaceholder_| that's replaced by this text view |promo_|
94 // in -awakeFromNib.
95 base::scoped_nsobject<HyperlinkTextView> promo_;
96 // Only shown for bundle installs.
97 IBOutlet NSTextField* installedHeadingMsg_;
98 IBOutlet NSView* installedItemsView_;
99 IBOutlet NSTextField* failedHeadingMsg_;
100 IBOutlet NSView* failedItemsView_;
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 // Opens the shortcut configuration UI.
127 - (IBAction)onManageShortcutClicked:(id)sender;
129 // Shows the new app installed animation.
130 - (IBAction)onAppShortcutClicked:(id)sender;
132 @end
134 @interface ExtensionInstalledBubbleController (ExposedForTesting)
136 - (void)removePageActionPreviewIfNecessary;
137 - (NSWindow*)initializeWindow;
138 - (int)calculateWindowHeight;
139 - (void)setMessageFrames:(int)newWindowHeight;
140 - (NSRect)headingFrame;
141 - (NSRect)frameOfHowToUse;
142 - (NSRect)frameOfHowToManage;
143 - (NSRect)frameOfSigninPromo;
144 - (BOOL)showSyncPromo;
145 - (NSButton*)appInstalledShortcutLink;
147 @end // ExtensionInstalledBubbleController(ExposedForTesting)
149 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_CONTROLLER_H_