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
{
19 class ExtensionRegistry
;
22 // Provides feedback to the user upon successful installation of an
23 // extension. Depending on the type of extension, the Bubble will
25 // OMNIBOX_KEYWORD-> The omnibox.
26 // BROWSER_ACTION -> The browser action icon in the toolbar.
27 // PAGE_ACTION -> A preview of the page action icon in the location
28 // bar which is shown while the Bubble is shown.
29 // GENERIC -> The wrench menu. This case includes page actions that
30 // don't specify a default icon.
32 // ExtensionInstallBubble manages its own lifetime.
33 class ExtensionInstalledBubble
: public content::NotificationObserver
,
34 public extensions::ExtensionRegistryObserver
{
36 // The behavior and content of this Bubble comes in these varieties:
44 // Implements the UI for showing the bubble. Owns us.
47 virtual ~Delegate() {}
49 // Attempts to show the bubble. Called from ShowInternal. Returns false
50 // if, because of animating (such as from adding a new browser action
51 // to the toolbar), the bubble could not be shown immediately.
52 virtual bool MaybeShowNow() = 0;
55 ExtensionInstalledBubble(Delegate
* delegate
,
56 const extensions::Extension
* extension
,
58 const SkBitmap
& icon
);
60 ~ExtensionInstalledBubble() override
;
62 const extensions::Extension
* extension() const { return extension_
; }
63 Browser
* browser() { return browser_
; }
64 const Browser
* browser() const { return browser_
; }
65 const SkBitmap
& icon() const { return icon_
; }
66 BubbleType
type() const { return type_
; }
68 // Stop listening to NOTIFICATION_BROWSER_CLOSING.
69 void IgnoreBrowserClosing();
72 // Delegates showing the view to our |view_|. Called internally via PostTask.
75 // content::NotificationObserver:
76 void Observe(int type
,
77 const content::NotificationSource
& source
,
78 const content::NotificationDetails
& details
) override
;
80 // extensions::ExtensionRegistryObserver:
81 void OnExtensionLoaded(content::BrowserContext
* browser_context
,
82 const extensions::Extension
* extension
) override
;
83 void OnExtensionUnloaded(
84 content::BrowserContext
* browser_context
,
85 const extensions::Extension
* extension
,
86 extensions::UnloadedExtensionInfo::Reason reason
) override
;
88 // The view delegate that shows the bubble. Owns us.
91 // |extension_| is NULL when we are deleted.
92 const extensions::Extension
* extension_
;
96 content::NotificationRegistrar registrar_
;
98 // Listen to extension load, unloaded notifications.
99 ScopedObserver
<extensions::ExtensionRegistry
,
100 extensions::ExtensionRegistryObserver
>
101 extension_registry_observer_
;
103 // The number of times to retry showing the bubble if the browser action
104 // toolbar is animating.
105 int animation_wait_retries_
;
107 base::WeakPtrFactory
<ExtensionInstalledBubble
> weak_factory_
;
109 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubble
);
112 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_