summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/extensions/shell_window.h
blob: dec4dd82715e5dd53c26a4dd252db4d839d25537 (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
// 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_EXTENSIONS_SHELL_WINDOW_H_
#define CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_
#pragma once

#include "base/memory/scoped_ptr.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
#include "chrome/browser/sessions/session_id.h"
#include "chrome/browser/ui/base_window.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"

class Extension;
class ExtensionWindowController;
class GURL;
class Profile;

namespace content {
class WebContents;
}

// ShellWindow is the type of window used by platform apps. Shell windows
// have a WebContents but none of the chrome of normal browser windows.
class ShellWindow : public content::NotificationObserver,
                    public content::WebContentsDelegate,
                    public content::WebContentsObserver,
                    public ExtensionFunctionDispatcher::Delegate,
                    public BaseWindow {
 public:
  static ShellWindow* Create(Profile* profile,
                             const Extension* extension,
                             const GURL& url);

  const SessionID& session_id() const { return session_id_; }
  const ExtensionWindowController* extension_window_controller() const {
    return extension_window_controller_.get();
  }

 protected:
  // TODO(mihaip): Switch from hardcoded defaults to passing in the window
  // creation parameters to ShellWindow::Create.
  static const int kDefaultWidth = 512;
  static const int kDefaultHeight = 384;

  ShellWindow(Profile* profile,
              const Extension* extension,
              const GURL& url);
  virtual ~ShellWindow();

  const Extension* extension() const { return extension_; }
  content::WebContents* web_contents() const { return web_contents_.get(); }

 private:
  // PlatformAppBrowserTest needs access to web_contents()
  friend class PlatformAppBrowserTest;

  // Instantiates a platform-specific ShellWindow subclass (one implementation
  // per platform). Public users of ShellWindow should use ShellWindow::Create.
  static ShellWindow* CreateImpl(Profile* profile,
                                 const Extension* extension,
                                 const GURL& url);

  // content::WebContentsObserver
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;

  // content::WebContentsDelegate
  virtual void CloseContents(content::WebContents* contents) OVERRIDE;
  virtual bool ShouldSuppressDialogs() OVERRIDE;

  // content::NotificationObserver implementation.
  virtual void Observe(int type,
                       const content::NotificationSource& source,
                       const content::NotificationDetails& details) OVERRIDE;

  virtual ExtensionWindowController* GetExtensionWindowController() const
      OVERRIDE;

  // Message handlers.
  void OnRequest(const ExtensionHostMsg_Request_Params& params);

  Profile* profile_;  // weak pointer - owned by ProfileManager.
  const Extension* extension_;  // weak pointer - owned by ExtensionService.

  const SessionID session_id_;
  scoped_ptr<content::WebContents> web_contents_;
  content::NotificationRegistrar registrar_;
  scoped_ptr<ExtensionWindowController> extension_window_controller_;
  ExtensionFunctionDispatcher extension_function_dispatcher_;

  DISALLOW_COPY_AND_ASSIGN(ShellWindow);
};

#endif  // CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_