• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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_GTK_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_GTK_H_
7 #pragma once
8 
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/ui/gtk/custom_button.h"
12 #include "chrome/browser/ui/gtk/info_bubble_gtk.h"
13 #include "content/common/notification_observer.h"
14 #include "content/common/notification_registrar.h"
15 #include "third_party/skia/include/core/SkBitmap.h"
16 
17 class Browser;
18 class BrowserWindowGtk;
19 class Extension;
20 class SkBitmap;
21 
22 // Provides feedback to the user upon successful installation of an
23 // extension. Depending on the type of extension, the InfoBubble will
24 // point to:
25 //    OMNIBOX_KEYWORD-> The omnibox.
26 //    BROWSER_ACTION -> The browserAction icon in the toolbar.
27 //    PAGE_ACTION    -> A preview of the page action icon in the location
28 //                      bar which is shown while the InfoBubble 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 ExtensionInstalledBubbleGtk
34     : public InfoBubbleGtkDelegate,
35       public NotificationObserver,
36       public base::RefCountedThreadSafe<ExtensionInstalledBubbleGtk> {
37  public:
38   // The behavior and content of this InfoBubble comes in three varieties.
39   enum BubbleType {
40     OMNIBOX_KEYWORD,
41     BROWSER_ACTION,
42     PAGE_ACTION,
43     GENERIC
44   };
45 
46   // Creates the ExtensionInstalledBubble and schedules it to be shown once
47   // the extension has loaded. |extension| is the installed extension. |browser|
48   // is the browser window which will host the bubble. |icon| is the install
49   // icon of the extension.
50   static void Show(
51       const Extension* extension, Browser *browser, const SkBitmap& icon);
52 
53  private:
54   friend class base::RefCountedThreadSafe<ExtensionInstalledBubbleGtk>;
55 
56   // Private ctor. Registers a listener for EXTENSION_LOADED.
57   ExtensionInstalledBubbleGtk(const Extension* extension, Browser *browser,
58                               const SkBitmap& icon);
59 
60   virtual ~ExtensionInstalledBubbleGtk();
61 
62   // Shows the bubble. Called internally via PostTask.
63   void ShowInternal();
64 
65   // NotificationObserver
66   virtual void Observe(NotificationType type,
67                        const NotificationSource& source,
68                        const NotificationDetails& details);
69 
70   // InfoBubbleDelegate
71   virtual void InfoBubbleClosing(InfoBubbleGtk* info_bubble,
72                                  bool closed_by_escape);
73 
74   // Calls Release() internally. Called internally via PostTask.
75   void Close();
76 
77   static void OnButtonClick(GtkWidget* button,
78                             ExtensionInstalledBubbleGtk* toolbar);
79 
80   const Extension* extension_;
81   Browser *browser_;
82   SkBitmap icon_;
83   NotificationRegistrar registrar_;
84   BubbleType type_;
85 
86   // The number of times to retry showing the bubble if the browser action
87   // toolbar is animating.
88   int animation_wait_retries_;
89 
90   // The 'x' that the user can press to hide the info bubble shelf.
91   scoped_ptr<CustomDrawButton> close_button_;
92 
93   InfoBubbleGtk* info_bubble_;
94 
95   DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubbleGtk);
96 };
97 
98 #endif  // CHROME_BROWSER_UI_GTK_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_GTK_H_
99