OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/ref_counted.h" | |
10 #include "chrome/browser/ui/views/bubble/bubble.h" | |
11 #include "content/public/browser/notification_observer.h" | 9 #include "content/public/browser/notification_observer.h" |
12 #include "content/public/browser/notification_registrar.h" | 10 #include "content/public/browser/notification_registrar.h" |
13 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
| 12 #include "ui/views/bubble/bubble_delegate.h" |
14 | 13 |
15 class Browser; | 14 class Browser; |
16 class Extension; | 15 class Extension; |
17 class InstalledBubbleContent; | |
18 class SkBitmap; | |
19 | 16 |
20 // Provides feedback to the user upon successful installation of an | 17 // Provides feedback to the user upon successful installation of an |
21 // extension. Depending on the type of extension, the Bubble will | 18 // extension. Depending on the type of extension, the Bubble will |
22 // point to: | 19 // point to: |
23 // OMNIBOX_KEYWORD-> The omnibox. | 20 // OMNIBOX_KEYWORD-> The omnibox. |
24 // BROWSER_ACTION -> The browserAction icon in the toolbar. | 21 // BROWSER_ACTION -> The browserAction icon in the toolbar. |
25 // PAGE_ACTION -> A preview of the pageAction icon in the location | 22 // PAGE_ACTION -> A preview of the pageAction icon in the location |
26 // bar which is shown while the Bubble is shown. | 23 // bar which is shown while the Bubble is shown. |
27 // APP -> The plus button in the tabstrip (for the New Tab Page). | 24 // APP -> The plus button in the tabstrip (for the New Tab Page). |
28 // GENERIC -> The wrench menu. This case includes pageActions that | 25 // GENERIC -> The wrench menu. This case includes pageActions that |
29 // don't specify a default icon. | 26 // don't specify a default icon. |
30 // | |
31 // ExtensionInstallBubble manages its own lifetime. | |
32 class ExtensionInstalledBubble | 27 class ExtensionInstalledBubble |
33 : public BubbleDelegate, | 28 : public views::BubbleDelegateView, |
34 public content::NotificationObserver, | 29 public content::NotificationObserver { |
35 public base::RefCountedThreadSafe<ExtensionInstalledBubble> { | |
36 public: | 30 public: |
37 // The behavior and content of this Bubble comes in these varieties: | 31 // The behavior and content of this Bubble comes in these varieties: |
38 enum BubbleType { | 32 enum BubbleType { |
39 OMNIBOX_KEYWORD, | 33 OMNIBOX_KEYWORD, |
40 BROWSER_ACTION, | 34 BROWSER_ACTION, |
41 PAGE_ACTION, | 35 PAGE_ACTION, |
42 APP, | 36 APP, |
43 GENERIC | 37 GENERIC |
44 }; | 38 }; |
45 | 39 |
46 // Creates the ExtensionInstalledBubble and schedules it to be shown once | 40 // Creates the ExtensionInstalledBubble and schedules it to be shown once |
47 // the extension has loaded. |extension| is the installed extension. |browser| | 41 // the extension has loaded. |extension| is the installed extension. |browser| |
48 // is the browser window which will host the bubble. |icon| is the install | 42 // is the browser window which will host the bubble. |icon| is the install |
49 // icon of the extension. | 43 // icon of the extension. |
50 static void Show( | 44 static void Show( |
51 const Extension* extension, Browser *browser, const SkBitmap& icon); | 45 const Extension* extension, Browser *browser, const SkBitmap& icon); |
52 | 46 |
53 private: | 47 private: |
54 friend class base::RefCountedThreadSafe<ExtensionInstalledBubble>; | |
55 | |
56 // Private ctor. Registers a listener for EXTENSION_LOADED. | 48 // Private ctor. Registers a listener for EXTENSION_LOADED. |
57 ExtensionInstalledBubble( | 49 ExtensionInstalledBubble(const Extension* extension, |
58 const Extension* extension, Browser *browser, const SkBitmap& icon); | 50 Browser *browser, |
| 51 const SkBitmap& icon); |
59 | 52 |
60 virtual ~ExtensionInstalledBubble(); | 53 virtual ~ExtensionInstalledBubble(); |
61 | 54 |
62 // Shows the bubble. Called internally via PostTask. | 55 // Shows the bubble. Called internally via PostTask. |
63 void ShowInternal(); | 56 void ShowInternal(); |
64 | 57 |
65 // content::NotificationObserver | 58 // content::NotificationObserver |
66 virtual void Observe(int type, | 59 virtual void Observe(int type, |
67 const content::NotificationSource& source, | 60 const content::NotificationSource& source, |
68 const content::NotificationDetails& details) OVERRIDE; | 61 const content::NotificationDetails& details) OVERRIDE; |
69 | 62 |
70 // BubbleDelegate | 63 // views::WidgetDelegate |
71 virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; | 64 virtual void WindowClosing() OVERRIDE; |
72 virtual bool CloseOnEscape() OVERRIDE; | 65 |
73 virtual bool FadeInOnShow() OVERRIDE; | 66 // views::BubbleDelegate |
| 67 virtual gfx::Point GetAnchorPoint() OVERRIDE; |
| 68 virtual views::BubbleBorder::ArrowLocation GetArrowLocation() const OVERRIDE; |
74 | 69 |
75 const Extension* extension_; | 70 const Extension* extension_; |
76 Browser* browser_; | 71 Browser* browser_; |
77 SkBitmap icon_; | 72 SkBitmap icon_; |
78 content::NotificationRegistrar registrar_; | 73 content::NotificationRegistrar registrar_; |
79 InstalledBubbleContent* bubble_content_; | |
80 BubbleType type_; | 74 BubbleType type_; |
81 | 75 |
82 // How many times we've deferred due to animations being in progress. | 76 // How many times we've deferred due to animations being in progress. |
83 int animation_wait_retries_; | 77 int animation_wait_retries_; |
84 | 78 |
85 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubble); | 79 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubble); |
86 }; | 80 }; |
87 | 81 |
88 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_ | 82 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_ |
OLD | NEW |