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