Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / extensions / extension_installed_bubble.h
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.
4
5 #ifndef CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_
6 #define CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_
7
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"
14
15 class Browser;
16
17 namespace extensions {
18 class Extension;
19 class ExtensionRegistry;
20 }
21
22 // Provides feedback to the user upon successful installation of an
23 // extension. Depending on the type of extension, the Bubble will
24 // point to:
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.
31 //
32 // ExtensionInstallBubble manages its own lifetime.
33 class ExtensionInstalledBubble : public content::NotificationObserver,
34                                  public extensions::ExtensionRegistryObserver {
35  public:
36   // The behavior and content of this Bubble comes in these varieties:
37   enum BubbleType {
38     OMNIBOX_KEYWORD,
39     BROWSER_ACTION,
40     PAGE_ACTION,
41     GENERIC
42   };
43
44   // Implements the UI for showing the bubble. Owns us.
45   class Delegate {
46    public:
47     virtual ~Delegate() {}
48
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;
53   };
54
55   ExtensionInstalledBubble(Delegate* delegate,
56                            const extensions::Extension* extension,
57                            Browser *browser,
58                            const SkBitmap& icon);
59
60   ~ExtensionInstalledBubble() override;
61
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_; }
67
68   // Stop listening to NOTIFICATION_BROWSER_CLOSING.
69   void IgnoreBrowserClosing();
70
71  private:
72   // Delegates showing the view to our |view_|. Called internally via PostTask.
73   void ShowInternal();
74
75   // content::NotificationObserver:
76   void Observe(int type,
77                const content::NotificationSource& source,
78                const content::NotificationDetails& details) override;
79
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;
87
88   // The view delegate that shows the bubble. Owns us.
89   Delegate* delegate_;
90
91   // |extension_| is NULL when we are deleted.
92   const extensions::Extension* extension_;
93   Browser* browser_;
94   const SkBitmap icon_;
95   BubbleType type_;
96   content::NotificationRegistrar registrar_;
97
98   // Listen to extension load, unloaded notifications.
99   ScopedObserver<extensions::ExtensionRegistry,
100                  extensions::ExtensionRegistryObserver>
101       extension_registry_observer_;
102
103   // The number of times to retry showing the bubble if the browser action
104   // toolbar is animating.
105   int animation_wait_retries_;
106
107   base::WeakPtrFactory<ExtensionInstalledBubble> weak_factory_;
108
109   DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubble);
110 };
111
112 #endif  // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_