1 // Copyright 2013 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_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_
6 #define CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/scoped_observer.h"
10 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_registrar.h"
12 #include "extensions/browser/extension_registry_observer.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
17 namespace extensions
{
20 class ExtensionRegistry
;
23 // Provides feedback to the user upon successful installation of an
24 // extension. Depending on the type of extension, the Bubble will
26 // OMNIBOX_KEYWORD-> The omnibox.
27 // BROWSER_ACTION -> The browser action icon in the toolbar.
28 // PAGE_ACTION -> A preview of the page action icon in the location
29 // bar which is shown while the Bubble is shown.
30 // GENERIC -> The wrench menu. This case includes page actions that
31 // don't specify a default icon.
33 // ExtensionInstallBubble manages its own lifetime.
34 class ExtensionInstalledBubble
: public content::NotificationObserver
,
35 public extensions::ExtensionRegistryObserver
{
37 // The behavior and content of this Bubble comes in these varieties:
45 // Implements the UI for showing the bubble. Owns us.
48 virtual ~Delegate() {}
50 // Attempts to show the bubble. Called from ShowInternal. Returns false
51 // if, because of animating (such as from adding a new browser action
52 // to the toolbar), the bubble could not be shown immediately.
53 virtual bool MaybeShowNow() = 0;
56 ExtensionInstalledBubble(Delegate
* delegate
,
57 const extensions::Extension
* extension
,
59 const SkBitmap
& icon
);
61 ~ExtensionInstalledBubble() override
;
63 const extensions::Extension
* extension() const { return extension_
; }
64 Browser
* browser() { return browser_
; }
65 const Browser
* browser() const { return browser_
; }
66 const SkBitmap
& icon() const { return icon_
; }
67 BubbleType
type() const { return type_
; }
68 bool has_command_keybinding() const { return action_command_
; }
70 // Stop listening to NOTIFICATION_BROWSER_CLOSING.
71 void IgnoreBrowserClosing();
73 // Returns the string describing how to use the new extension.
74 base::string16
GetHowToUseDescription() const;
77 // Delegates showing the view to our |view_|. Called internally via PostTask.
80 // content::NotificationObserver:
81 void Observe(int type
,
82 const content::NotificationSource
& source
,
83 const content::NotificationDetails
& details
) override
;
85 // extensions::ExtensionRegistryObserver:
86 void OnExtensionLoaded(content::BrowserContext
* browser_context
,
87 const extensions::Extension
* extension
) override
;
88 void OnExtensionUnloaded(
89 content::BrowserContext
* browser_context
,
90 const extensions::Extension
* extension
,
91 extensions::UnloadedExtensionInfo::Reason reason
) override
;
93 // The view delegate that shows the bubble. Owns us.
96 // |extension_| is NULL when we are deleted.
97 const extensions::Extension
* extension_
;
101 content::NotificationRegistrar registrar_
;
103 // The command to execute the extension action, if one exists.
104 scoped_ptr
<extensions::Command
> action_command_
;
106 // Listen to extension load, unloaded notifications.
107 ScopedObserver
<extensions::ExtensionRegistry
,
108 extensions::ExtensionRegistryObserver
>
109 extension_registry_observer_
;
111 // The number of times to retry showing the bubble if the browser action
112 // toolbar is animating.
113 int animation_wait_retries_
;
115 base::WeakPtrFactory
<ExtensionInstalledBubble
> weak_factory_
;
117 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubble
);
120 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_