Home | History | Annotate | Download | only in extensions
      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 "ui/views/bubble/bubble_delegate.h"
     14 #include "ui/views/focus/widget_focus_manager.h"
     15 #include "url/gurl.h"
     16 
     17 class Browser;
     18 namespace views {
     19 class Widget;
     20 }
     21 
     22 namespace content {
     23 class DevToolsAgentHost;
     24 }
     25 
     26 class 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(extensions::ExtensionHost* host,
     77                  views::View* anchor_view,
     78                  views::BubbleBorder::Arrow arrow,
     79                  ShowAction show_action);
     80 
     81   // Show the bubble, focus on its content, and register listeners.
     82   void ShowBubble();
     83 
     84   void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached);
     85 
     86   // The contained host for the view.
     87   scoped_ptr<extensions::ExtensionHost> extension_host_;
     88 
     89   // Flag used to indicate if the pop-up should open a devtools window once
     90   // it is shown inspecting it.
     91   bool inspect_with_devtools_;
     92 
     93   content::NotificationRegistrar registrar_;
     94 
     95   base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_;
     96 
     97   DISALLOW_COPY_AND_ASSIGN(ExtensionPopup);
     98 };
     99 
    100 #endif  // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_
    101