Home | History | Annotate | Download | only in extensions
      1 // Copyright (c) 2011 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_GTK_EXTENSIONS_EXTENSION_POPUP_GTK_H_
      6 #define CHROME_BROWSER_UI_GTK_EXTENSIONS_EXTENSION_POPUP_GTK_H_
      7 #pragma once
      8 
      9 #include "base/memory/scoped_ptr.h"
     10 #include "base/task.h"
     11 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h"
     12 #include "chrome/browser/ui/gtk/info_bubble_gtk.h"
     13 #include "content/common/notification_observer.h"
     14 #include "content/common/notification_registrar.h"
     15 #include "ui/gfx/rect.h"
     16 
     17 class Browser;
     18 class ExtensionHost;
     19 class GURL;
     20 
     21 class ExtensionPopupGtk : public NotificationObserver,
     22                           public InfoBubbleGtkDelegate,
     23                           public ExtensionViewGtk::Container {
     24  public:
     25   ExtensionPopupGtk(Browser* browser,
     26                     ExtensionHost* host,
     27                     GtkWidget* anchor,
     28                     bool inspect);
     29   virtual ~ExtensionPopupGtk();
     30 
     31   static void Show(const GURL& url,
     32                    Browser* browser,
     33                    GtkWidget* anchor,
     34                    bool inspect);
     35 
     36   // NotificationObserver implementation.
     37   virtual void Observe(NotificationType type,
     38                        const NotificationSource& source,
     39                        const NotificationDetails& details);
     40 
     41   // InfoBubbleGtkDelegate implementation.
     42   virtual void InfoBubbleClosing(InfoBubbleGtk* bubble,
     43                                  bool closed_by_escape);
     44 
     45   // ExtensionViewGtk::Container implementation
     46   virtual void OnExtensionPreferredSizeChanged(ExtensionViewGtk* view,
     47                                                const gfx::Size& new_size);
     48 
     49   // Destroys the popup widget. This will in turn destroy us since we delete
     50   // ourselves when the info bubble closes. Returns true if we successfully
     51   // closed the bubble.
     52   bool DestroyPopup();
     53 
     54   // Get the currently showing extension popup, or NULL.
     55   static ExtensionPopupGtk* get_current_extension_popup() {
     56     return current_extension_popup_;
     57   }
     58 
     59   bool being_inspected() const {
     60     return being_inspected_;
     61   }
     62 
     63   // Declared here for testing.
     64   static const int kMinWidth;
     65   static const int kMinHeight;
     66   static const int kMaxWidth;
     67   static const int kMaxHeight;
     68 
     69  private:
     70   // Shows the popup widget. Called after loading completes.
     71   void ShowPopup();
     72 
     73   Browser* browser_;
     74 
     75   InfoBubbleGtk* bubble_;
     76 
     77   // We take ownership of the popup ExtensionHost.
     78   scoped_ptr<ExtensionHost> host_;
     79 
     80   // The widget for anchoring the position of the info bubble.
     81   GtkWidget* anchor_;
     82 
     83   NotificationRegistrar registrar_;
     84 
     85   static ExtensionPopupGtk* current_extension_popup_;
     86 
     87   // Whether a devtools window is attached to this bubble.
     88   bool being_inspected_;
     89 
     90   ScopedRunnableMethodFactory<ExtensionPopupGtk> method_factory_;
     91 
     92   // Used for testing. ---------------------------------------------------------
     93   gfx::Rect GetViewBounds();
     94 
     95   friend class BrowserActionTestUtil;
     96 
     97   DISALLOW_COPY_AND_ASSIGN(ExtensionPopupGtk);
     98 };
     99 
    100 #endif  // CHROME_BROWSER_UI_GTK_EXTENSIONS_EXTENSION_POPUP_GTK_H_
    101