Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / extensions / extension_popup.h
1 // Copyright (c) 2012 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_POPUP_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_
7
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
11 #include "chrome/browser/ui/views/extensions/extension_view_views.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "ui/views/bubble/bubble_delegate.h"
15 #include "ui/wm/public/activation_change_observer.h"
16 #include "url/gurl.h"
17
18
19 class Browser;
20 namespace views {
21 class Widget;
22 }
23
24 namespace content {
25 class DevToolsAgentHost;
26 }
27
28 namespace extensions {
29 class ExtensionViewHost;
30 }
31
32 class ExtensionPopup : public views::BubbleDelegateView,
33                        public aura::client::ActivationChangeObserver,
34                        public ExtensionViewViews::Container,
35                        public content::NotificationObserver,
36                        public TabStripModelObserver {
37  public:
38   enum ShowAction {
39     SHOW,
40     SHOW_AND_INSPECT,
41   };
42
43   ~ExtensionPopup() override;
44
45   // Create and show a popup with |url| positioned adjacent to |anchor_view|.
46   // |browser| is the browser to which the pop-up will be attached.  NULL is a
47   // valid parameter for pop-ups not associated with a browser.
48   // The positioning of the pop-up is determined by |arrow| according to the
49   // following logic:  The popup is anchored so that the corner indicated by the
50   // value of |arrow| remains fixed during popup resizes.  If |arrow| is
51   // BOTTOM_*, then the popup 'pops up', otherwise the popup 'drops down'.
52   // The actual display of the popup is delayed until the page contents
53   // finish loading in order to minimize UI flashing and resizing.
54   static ExtensionPopup* ShowPopup(const GURL& url,
55                                    Browser* browser,
56                                    views::View* anchor_view,
57                                    views::BubbleBorder::Arrow arrow,
58                                    ShowAction show_action);
59
60   extensions::ExtensionViewHost* host() const { return host_.get(); }
61
62   // content::NotificationObserver overrides.
63   void Observe(int type,
64                const content::NotificationSource& source,
65                const content::NotificationDetails& details) override;
66
67   // ExtensionViewViews::Container overrides.
68   void OnExtensionSizeChanged(ExtensionViewViews* view) override;
69
70   // views::View overrides.
71   gfx::Size GetPreferredSize() const override;
72   void ViewHierarchyChanged(
73       const ViewHierarchyChangedDetails& details) override;
74
75   // views::WidgetObserver overrides.
76   void OnWidgetDestroying(views::Widget* widget) override;
77   void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
78
79   // aura::client::ActivationChangeObserver overrides.
80   void OnWindowActivated(aura::Window* gained_active,
81                          aura::Window* lost_active) override;
82
83   // TabStripModelObserver overrides.
84   void ActiveTabChanged(content::WebContents* old_contents,
85                         content::WebContents* new_contents,
86                         int index,
87                         int reason) override;
88
89   // The min/max height of popups.
90   static const int kMinWidth;
91   static const int kMinHeight;
92   static const int kMaxWidth;
93   static const int kMaxHeight;
94
95  private:
96   ExtensionPopup(extensions::ExtensionViewHost* host,
97                  views::View* anchor_view,
98                  views::BubbleBorder::Arrow arrow,
99                  ShowAction show_action);
100
101   // Show the bubble, focus on its content, and register listeners.
102   void ShowBubble();
103
104   void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached);
105
106   // The contained host for the view.
107   scoped_ptr<extensions::ExtensionViewHost> host_;
108
109   // Flag used to indicate if the pop-up should open a devtools window once
110   // it is shown inspecting it.
111   bool inspect_with_devtools_;
112
113   content::NotificationRegistrar registrar_;
114
115   base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_;
116
117   bool widget_initialized_;
118
119   DISALLOW_COPY_AND_ASSIGN(ExtensionPopup);
120 };
121
122 #endif  // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_