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_DIALOG_H_
      6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_
      7 
      8 #include "base/logging.h"
      9 #include "base/memory/ref_counted.h"
     10 #include "content/public/browser/notification_observer.h"
     11 #include "content/public/browser/notification_registrar.h"
     12 #include "ui/aura/window.h"
     13 #include "ui/gfx/native_widget_types.h"
     14 #include "ui/views/window/dialog_delegate.h"
     15 
     16 class ExtensionDialogObserver;
     17 class GURL;
     18 class Profile;
     19 
     20 namespace content {
     21 class WebContents;
     22 }
     23 
     24 namespace extensions {
     25 class ExtensionViewHost;
     26 }
     27 
     28 // Modal dialog containing contents provided by an extension.
     29 // Dialog is automatically centered in the owning window and has fixed size.
     30 // For example, used by the Chrome OS file browser.
     31 class ExtensionDialog : public views::DialogDelegate,
     32                         public content::NotificationObserver,
     33                         public base::RefCounted<ExtensionDialog> {
     34  public:
     35   // Create and show a dialog with |url| centered over the provided window.
     36   // |parent_window| is the parent window to which the pop-up will be attached.
     37   // |profile| is the profile that the extension is registered with.
     38   // |web_contents| is the tab that spawned the dialog.
     39   // |width| and |height| are the size of the dialog in pixels.
     40   static ExtensionDialog* Show(const GURL& url,
     41                                aura::Window* parent_window,
     42                                Profile* profile,
     43                                content::WebContents* web_contents,
     44                                int width,
     45                                int height,
     46                                int min_width,
     47                                int min_height,
     48                                const base::string16& title,
     49                                ExtensionDialogObserver* observer);
     50 
     51   // Notifies the dialog that the observer has been destroyed and should not
     52   // be sent notifications.
     53   void ObserverDestroyed();
     54 
     55   // Focus to the render view if possible.
     56   void MaybeFocusRenderView();
     57 
     58   // Sets the window title.
     59   void set_title(const base::string16& title) { window_title_ = title; }
     60 
     61   // Sets minimum contents size in pixels and makes the window resizable.
     62   void SetMinimumContentsSize(int width, int height);
     63 
     64   extensions::ExtensionViewHost* host() const { return host_.get(); }
     65 
     66   // views::DialogDelegate override.
     67   virtual int GetDialogButtons() const OVERRIDE;
     68   virtual bool CanResize() const OVERRIDE;
     69   virtual ui::ModalType GetModalType() const OVERRIDE;
     70   virtual bool ShouldShowWindowTitle() const OVERRIDE;
     71   virtual base::string16 GetWindowTitle() const OVERRIDE;
     72   virtual void WindowClosing() OVERRIDE;
     73   virtual void DeleteDelegate() OVERRIDE;
     74   virtual views::Widget* GetWidget() OVERRIDE;
     75   virtual const views::Widget* GetWidget() const OVERRIDE;
     76   virtual views::View* GetContentsView() OVERRIDE;
     77   virtual bool UseNewStyleForThisDialog() const OVERRIDE;
     78 
     79   // content::NotificationObserver overrides.
     80   virtual void Observe(int type,
     81                        const content::NotificationSource& source,
     82                        const content::NotificationDetails& details) OVERRIDE;
     83 
     84  protected:
     85   virtual ~ExtensionDialog();
     86 
     87  private:
     88   friend class base::RefCounted<ExtensionDialog>;
     89 
     90   // Use Show() to create instances.
     91   ExtensionDialog(extensions::ExtensionViewHost* host,
     92                   ExtensionDialogObserver* observer);
     93 
     94   void InitWindow(aura::Window* parent_window, int width, int height);
     95 
     96   // Window Title
     97   base::string16 window_title_;
     98 
     99   // The contained host for the view.
    100   scoped_ptr<extensions::ExtensionViewHost> host_;
    101 
    102   content::NotificationRegistrar registrar_;
    103 
    104   // The observer of this popup.
    105   ExtensionDialogObserver* observer_;
    106 
    107   DISALLOW_COPY_AND_ASSIGN(ExtensionDialog);
    108 };
    109 
    110 #endif  // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_
    111