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