Home | History | Annotate | Download | only in extensions
      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_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_
      6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_
      7 #pragma once
      8 
      9 #include "base/memory/ref_counted.h"
     10 #include "chrome/browser/ui/views/bubble/bubble.h"
     11 #include "content/common/notification_observer.h"
     12 #include "content/common/notification_registrar.h"
     13 #include "third_party/skia/include/core/SkBitmap.h"
     14 
     15 class Browser;
     16 class Extension;
     17 class InstalledBubbleContent;
     18 class SkBitmap;
     19 
     20 // Provides feedback to the user upon successful installation of an
     21 // extension. Depending on the type of extension, the Bubble will
     22 // point to:
     23 //    OMNIBOX_KEYWORD-> The omnibox.
     24 //    BROWSER_ACTION -> The browserAction icon in the toolbar.
     25 //    PAGE_ACTION    -> A preview of the pageAction icon in the location
     26 //                      bar which is shown while the Bubble is shown.
     27 //    GENERIC        -> The wrench menu. This case includes pageActions that
     28 //                      don't specify a default icon.
     29 //
     30 // ExtensionInstallBubble manages its own lifetime.
     31 class ExtensionInstalledBubble
     32     : public BubbleDelegate,
     33       public NotificationObserver,
     34       public base::RefCountedThreadSafe<ExtensionInstalledBubble> {
     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   // Creates the ExtensionInstalledBubble and schedules it to be shown once
     45   // the extension has loaded. |extension| is the installed extension. |browser|
     46   // is the browser window which will host the bubble. |icon| is the install
     47   // icon of the extension.
     48   static void Show(
     49       const Extension* extension, Browser *browser, const SkBitmap& icon);
     50 
     51  private:
     52   friend class base::RefCountedThreadSafe<ExtensionInstalledBubble>;
     53 
     54   // Private ctor. Registers a listener for EXTENSION_LOADED.
     55   ExtensionInstalledBubble(
     56       const Extension* extension, Browser *browser, const SkBitmap& icon);
     57 
     58   virtual ~ExtensionInstalledBubble();
     59 
     60   // Shows the bubble. Called internally via PostTask.
     61   void ShowInternal();
     62 
     63   // NotificationObserver
     64   virtual void Observe(NotificationType type,
     65                        const NotificationSource& source,
     66                        const NotificationDetails& details);
     67 
     68   // BubbleDelegate
     69   virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape);
     70   virtual bool CloseOnEscape();
     71   virtual bool FadeInOnShow();
     72 
     73   const Extension* extension_;
     74   Browser* browser_;
     75   SkBitmap icon_;
     76   NotificationRegistrar registrar_;
     77   InstalledBubbleContent* bubble_content_;
     78   BubbleType type_;
     79 
     80   // How many times we've deferred due to animations being in progress.
     81   int animation_wait_retries_;
     82 
     83   DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubble);
     84 };
     85 
     86 #endif  // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_
     87