// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_ #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_ #pragma once #include "base/memory/ref_counted.h" #include "base/logging.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "ui/views/widget/widget_delegate.h" class Browser; class ExtensionDialogObserver; class ExtensionHost; class GURL; class Profile; namespace content { class WebContents; } // Modal dialog containing contents provided by an extension. // Dialog is automatically centered in the browser window and has fixed size. // For example, used by the Chrome OS file browser. class ExtensionDialog : public views::WidgetDelegate, public content::NotificationObserver, public base::RefCounted { public: virtual ~ExtensionDialog(); // Create and show a dialog with |url| centered over the browser window. // |browser| is the browser to which the pop-up will be attached. // |web_contents| is the tab that spawned the dialog. // |width| and |height| are the size of the dialog in pixels. static ExtensionDialog* Show(const GURL& url, Browser* browser, content::WebContents* web_contents, int width, int height, const string16& title, ExtensionDialogObserver* observer); #if defined(USE_AURA) // Create and show a fullscreen dialog with |url|. // |profile| is the profile that the extension is registered with. // |web_contents| is the tab that spawned the dialog. static ExtensionDialog* ShowFullscreen(const GURL& url, Profile* profile, const string16& title, ExtensionDialogObserver* observer); #else static ExtensionDialog* ShowFullscreen(const GURL& url, Profile* profile, const string16& title, ExtensionDialogObserver* observer) { NOTIMPLEMENTED(); return NULL; } #endif // Notifies the dialog that the observer has been destroyed and should not // be sent notifications. void ObserverDestroyed(); // Closes the ExtensionDialog. void Close(); // Focus to the render view if possible. void MaybeFocusRenderView(); // Sets the window title. void set_title(const string16& title) { window_title_ = title; } ExtensionHost* host() const { return extension_host_.get(); } // views::WidgetDelegate overrides. virtual bool CanResize() const OVERRIDE; virtual ui::ModalType GetModalType() const OVERRIDE; virtual bool ShouldShowWindowTitle() const OVERRIDE; virtual string16 GetWindowTitle() const OVERRIDE; virtual void WindowClosing() OVERRIDE; virtual void DeleteDelegate() OVERRIDE; virtual views::Widget* GetWidget() OVERRIDE; virtual const views::Widget* GetWidget() const OVERRIDE; virtual views::View* GetContentsView() OVERRIDE; // content::NotificationObserver overrides. virtual void Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; private: // Use Show() to create instances. ExtensionDialog(ExtensionHost* host, ExtensionDialogObserver* observer); static ExtensionDialog* ShowInternal(const GURL& url, Browser* browser, ExtensionHost* host, int width, int height, bool fullscreen, const string16& title, ExtensionDialogObserver* observer); static ExtensionHost* CreateExtensionHost(const GURL& url, Browser* browser, Profile* profile); void InitWindow(Browser* browser, int width, int height); void InitWindowFullscreen(); // Window that holds the extension host view. views::Widget* window_; // Window Title string16 window_title_; // The contained host for the view. scoped_ptr extension_host_; content::NotificationRegistrar registrar_; // The observer of this popup. ExtensionDialogObserver* observer_; DISALLOW_COPY_AND_ASSIGN(ExtensionDialog); }; #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_DIALOG_H_