Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_ | 6 #define CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "content/public/browser/notification_observer.h" | 9 #include "content/public/browser/notification_observer.h" |
| 10 #include "content/public/browser/notification_registrar.h" | 10 #include "content/public/browser/notification_registrar.h" |
| 11 #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" | |
| 13 | 12 |
| 14 class Browser; | 13 class Browser; |
| 15 | 14 |
| 16 namespace extensions { | 15 namespace extensions { |
| 17 class Extension; | 16 class Extension; |
| 18 } | 17 } |
| 19 | 18 |
| 20 // Provides feedback to the user upon successful installation of an | 19 // Provides feedback to the user upon successful installation of an |
| 21 // extension. Depending on the type of extension, the Bubble will | 20 // extension. Depending on the type of extension, the Bubble will |
| 22 // point to: | 21 // point to: |
| 23 // OMNIBOX_KEYWORD-> The omnibox. | 22 // OMNIBOX_KEYWORD-> The omnibox. |
| 24 // BROWSER_ACTION -> The browserAction icon in the toolbar. | 23 // BROWSER_ACTION -> The browser action icon in the toolbar. |
| 25 // PAGE_ACTION -> A preview of the pageAction icon in the location | 24 // PAGE_ACTION -> A preview of the page action icon in the location |
| 26 // bar which is shown while the Bubble is shown. | 25 // bar which is shown while the Bubble is shown. |
| 27 // GENERIC -> The wrench menu. This case includes pageActions that | 26 // GENERIC -> The wrench menu. This case includes page actions that |
| 28 // don't specify a default icon. | 27 // don't specify a default icon. |
| 29 class ExtensionInstalledBubble | 28 // |
| 30 : public views::BubbleDelegateView, | 29 // ExtensionInstallBubble manages its own lifetime. |
| 31 public content::NotificationObserver { | 30 class ExtensionInstalledBubble : public content::NotificationObserver { |
| 32 public: | 31 public: |
| 32 virtual ~ExtensionInstalledBubble(); | |
| 33 | |
| 33 // The behavior and content of this Bubble comes in these varieties: | 34 // The behavior and content of this Bubble comes in these varieties: |
| 34 enum BubbleType { | 35 enum BubbleType { |
|
sky
2013/08/29 15:39:51
nit: enums before constructor.
Yoyo Zhou
2013/08/29 21:44:46
Done.
| |
| 35 OMNIBOX_KEYWORD = 0, | 36 OMNIBOX_KEYWORD, |
| 36 BROWSER_ACTION, | 37 BROWSER_ACTION, |
| 37 PAGE_ACTION, | 38 PAGE_ACTION, |
| 38 GENERIC, | 39 GENERIC |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 // Creates the ExtensionInstalledBubble and schedules it to be shown once | 42 protected: |
| 42 // the extension has loaded. |extension| is the installed extension. |browser| | 43 // Protected ctor. Registers a listener for EXTENSION_LOADED. |
| 43 // is the browser window which will host the bubble. |icon| is the install | |
| 44 // icon of the extension. | |
| 45 static void Show(const extensions::Extension* extension, | |
| 46 Browser *browser, | |
| 47 const SkBitmap& icon); | |
| 48 | |
| 49 private: | |
| 50 // Private ctor. Registers a listener for EXTENSION_LOADED. | |
| 51 ExtensionInstalledBubble(const extensions::Extension* extension, | 44 ExtensionInstalledBubble(const extensions::Extension* extension, |
| 52 Browser *browser, | 45 Browser *browser, |
| 53 const SkBitmap& icon); | 46 const SkBitmap& icon); |
| 54 | 47 |
| 55 virtual ~ExtensionInstalledBubble(); | 48 const extensions::Extension* extension() { return extension_; } |
| 49 Browser* browser() { return browser_; } | |
| 50 const SkBitmap& icon() { return icon_; } | |
| 51 BubbleType type() { return type_; } | |
| 52 content::NotificationRegistrar* registrar() { return ®istrar_; } | |
| 56 | 53 |
| 54 // When showing the bubble for a new browser action, we may have to wait for | |
| 55 // the toolbar to finish animating to know where the item's final position | |
| 56 // will be. | |
| 57 void MaybeShowLater(); | |
| 58 | |
| 59 private: | |
| 57 // Shows the bubble. Called internally via PostTask. | 60 // Shows the bubble. Called internally via PostTask. |
| 58 void ShowInternal(); | 61 virtual void ShowInternal() = 0; |
|
sky
2013/08/29 15:39:51
This pattern is leading to multiple inheritance of
Yoyo Zhou
2013/08/29 21:44:46
I added a View delegate. This added a bit of compl
| |
| 59 | 62 |
| 60 // content::NotificationObserver | 63 // content::NotificationObserver: |
| 61 virtual void Observe(int type, | 64 virtual void Observe(int type, |
| 62 const content::NotificationSource& source, | 65 const content::NotificationSource& source, |
| 63 const content::NotificationDetails& details) OVERRIDE; | 66 const content::NotificationDetails& details) OVERRIDE; |
| 64 | 67 |
| 65 // views::WidgetDelegate | |
| 66 virtual void WindowClosing() OVERRIDE; | |
| 67 | |
| 68 // views::BubbleDelegate | |
| 69 virtual gfx::Rect GetAnchorRect() OVERRIDE; | |
| 70 | |
| 71 const extensions::Extension* extension_; | 68 const extensions::Extension* extension_; |
| 72 Browser* browser_; | 69 Browser* browser_; |
| 73 SkBitmap icon_; | 70 SkBitmap icon_; |
|
sky
2013/08/29 15:39:51
const
Yoyo Zhou
2013/08/29 21:44:46
Done.
| |
| 71 BubbleType type_; | |
| 74 content::NotificationRegistrar registrar_; | 72 content::NotificationRegistrar registrar_; |
| 75 BubbleType type_; | |
|
sky
2013/08/29 15:39:51
const
Yoyo Zhou
2013/08/29 21:44:46
I think the type determination is too complex to p
| |
| 76 | 73 |
| 77 // How many times we've deferred due to animations being in progress. | 74 // The number of times to retry showing the bubble if the browser action |
| 75 // toolbar is animating. | |
| 78 int animation_wait_retries_; | 76 int animation_wait_retries_; |
| 79 | 77 |
| 80 base::WeakPtrFactory<ExtensionInstalledBubble> weak_factory_; | 78 base::WeakPtrFactory<ExtensionInstalledBubble> weak_factory_; |
| 81 | 79 |
| 82 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubble); | 80 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubble); |
| 83 }; | 81 }; |
| 84 | 82 |
| 85 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_ | 83 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_ |
| OLD | NEW |