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