Home | History | Annotate | Download | only in webui
      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_WEBUI_CONSTRAINED_WEB_DIALOG_DELEGATE_BASE_H_
      6 #define CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_DELEGATE_BASE_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
     10 #include "ui/web_dialogs/web_dialog_ui.h"
     11 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h"
     12 
     13 namespace content {
     14 class BrowserContext;
     15 }
     16 
     17 namespace ui {
     18 class WebDialogDelegate;
     19 }
     20 
     21 // Platform-agnostic base implementation of ConstrainedWebDialogDelegate.
     22 class ConstrainedWebDialogDelegateBase
     23     : public ConstrainedWebDialogDelegate,
     24       public ui::WebDialogWebContentsDelegate {
     25  public:
     26   ConstrainedWebDialogDelegateBase(content::BrowserContext* browser_context,
     27                                    ui::WebDialogDelegate* delegate,
     28                                    WebDialogWebContentsDelegate* tab_delegate);
     29   virtual ~ConstrainedWebDialogDelegateBase();
     30 
     31   bool closed_via_webui() const;
     32 
     33   // ConstrainedWebDialogDelegate interface.
     34   virtual const ui::WebDialogDelegate* GetWebDialogDelegate() const OVERRIDE;
     35   virtual ui::WebDialogDelegate* GetWebDialogDelegate() OVERRIDE;
     36   virtual void OnDialogCloseFromWebUI() OVERRIDE;
     37   virtual void ReleaseWebContentsOnDialogClose() OVERRIDE;
     38   virtual web_modal::NativeWebContentsModalDialog GetNativeDialog() OVERRIDE;
     39   virtual content::WebContents* GetWebContents() OVERRIDE;
     40 
     41   // WebDialogWebContentsDelegate interface.
     42   virtual void HandleKeyboardEvent(
     43       content::WebContents* source,
     44       const content::NativeWebKeyboardEvent& event) OVERRIDE;
     45 
     46  private:
     47   scoped_ptr<ui::WebDialogDelegate> web_dialog_delegate_;
     48 
     49   // Holds the HTML to display in the constrained dialog.
     50   scoped_ptr<content::WebContents> web_contents_;
     51 
     52   // Was the dialog closed from WebUI (in which case |web_dialog_delegate_|'s
     53   // OnDialogClosed() method has already been called)?
     54   bool closed_via_webui_;
     55 
     56   // If true, release |web_contents_| on close instead of destroying it.
     57   bool release_contents_on_close_;
     58 
     59   scoped_ptr<WebDialogWebContentsDelegate> override_tab_delegate_;
     60 
     61   DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateBase);
     62 };
     63 
     64 #endif  // CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_DELEGATE_BASE_H_
     65