summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/extensions/extension_dialog.h
blob: 272f27091a823a7e81f4eed390d58d88d5f99e77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// 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<ExtensionDialog> {
 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<ExtensionHost> 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_