summaryrefslogtreecommitdiffstats
path: root/headless/lib/browser/headless_web_contents_impl.h
blob: b272bfe9dab44cca80bb5a2c24e0eb4694774070 (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
// Copyright 2015 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 HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_
#define HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_

#include "headless/public/headless_web_contents.h"

#include <unordered_map>

namespace aura {
class Window;
}

namespace content {
class WebContents;
class BrowserContext;
}

namespace gfx {
class Size;
}

namespace headless {
class WebContentsObserverAdapter;

class HeadlessWebContentsImpl : public HeadlessWebContents {
 public:
  ~HeadlessWebContentsImpl() override;

  // HeadlessWebContents implementation:
  bool OpenURL(const GURL& url) override;
  void AddObserver(Observer* observer) override;
  void RemoveObserver(Observer* observer) override;

  content::WebContents* web_contents() const;

 private:
  friend class HeadlessBrowserImpl;

  HeadlessWebContentsImpl(content::BrowserContext* context,
                          aura::Window* parent_window,
                          const gfx::Size& initial_size);

  class Delegate;
  scoped_ptr<Delegate> web_contents_delegate_;
  scoped_ptr<content::WebContents> web_contents_;

  using ObserverMap =
      std::unordered_map<HeadlessWebContents::Observer*,
                         scoped_ptr<WebContentsObserverAdapter>>;
  ObserverMap observer_map_;

  DISALLOW_COPY_AND_ASSIGN(HeadlessWebContentsImpl);
};

}  // namespace headless

#endif  // HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_