summaryrefslogtreecommitdiffstats
path: root/blimp/engine/browser/blimp_engine_session.h
blob: 3d8e695763531eee402f30773c916df0aadbb988 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// 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 BLIMP_ENGINE_BROWSER_BLIMP_ENGINE_SESSION_H_
#define BLIMP_ENGINE_BROWSER_BLIMP_ENGINE_SESSION_H_

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "blimp/engine/browser/engine_render_widget_message_processor.h"
#include "blimp/net/blimp_message_processor.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "net/base/completion_callback.h"
#include "ui/gfx/geometry/size.h"

namespace aura {
class WindowTreeHost;

namespace client {
class DefaultCaptureClient;
class WindowTreeClient;
}  // namespace client
}  // namespace aura

namespace content {
class BrowserContext;
class RenderViewHost;
class WebContents;
}

namespace gfx {
class Size;
}

namespace wm {
class FocusController;
}

namespace blimp {

class BlimpConnection;
class BlimpMessage;

namespace engine {

class BlimpBrowserContext;
class BlimpFocusClient;
class BlimpScreen;
class BlimpUiContextFactory;
class BlimpWindowTreeHost;

class BlimpEngineSession
    : public BlimpMessageProcessor,
      public content::WebContentsDelegate,
      public content::WebContentsObserver,
      public EngineRenderWidgetMessageProcessor::RenderWidgetMessageDelegate {
 public:
  explicit BlimpEngineSession(scoped_ptr<BlimpBrowserContext> browser_context);
  ~BlimpEngineSession() override;

  void Initialize();

  BlimpBrowserContext* browser_context() { return browser_context_.get(); }

  // BlimpMessageProcessor implementation.
  // TODO(haibinlu): Delete this and move to BlimpMessageDemultiplexer.
  void ProcessMessage(scoped_ptr<BlimpMessage> message,
                      const net::CompletionCallback& callback) override;

 private:
  // TabControlMessage handler methods.
  // Creates a new WebContents, which will be indexed by |target_tab_id|.
  void CreateWebContents(const int target_tab_id);
  void CloseWebContents(const int target_tab_id);
  void HandleResize(float device_pixel_ratio, const gfx::Size& size);

  // NavigationMessage handler methods.
  // Navigates the target tab to the |url|.
  void LoadUrl(const int target_tab_id, const GURL& url);
  void GoBack(const int target_tab_id);
  void GoForward(const int target_tab_id);
  void Reload(const int target_tab_id);

  // RenderWidgetMessage handler methods.
  // RenderWidgetMessageDelegate implementation.
  void OnWebInputEvent(scoped_ptr<blink::WebInputEvent> event) override;
  void OnCompositorMessageReceived(
      const std::vector<uint8_t>& message) override;

  // content::WebContentsDelegate implementation.
  content::WebContents* OpenURLFromTab(
      content::WebContents* source,
      const content::OpenURLParams& params) override;
  void AddNewContents(content::WebContents* source,
                      content::WebContents* new_contents,
                      WindowOpenDisposition disposition,
                      const gfx::Rect& initial_rect,
                      bool user_gesture,
                      bool* was_blocked) override;
  void RequestToLockMouse(content::WebContents* web_contents,
                          bool user_gesture,
                          bool last_unlocked_by_target) override;
  void CloseContents(content::WebContents* source) override;
  void ActivateContents(content::WebContents* contents) override;
  void ForwardCompositorProto(const std::vector<uint8_t>& proto) override;
  void NavigationStateChanged(content::WebContents* source,
                              content::InvalidateTypes changed_flags) override;

  // content::WebContentsObserver implementation.
  void RenderViewHostChanged(content::RenderViewHost* old_host,
                             content::RenderViewHost* new_host) override;

  // Sets up and owns |new_contents|.
  void PlatformSetContents(scoped_ptr<content::WebContents> new_contents);

  scoped_ptr<BlimpBrowserContext> browser_context_;
  scoped_ptr<BlimpScreen> screen_;

  // Context factory for compositor.
  scoped_ptr<BlimpUiContextFactory> context_factory_;

  // Represents the (currently single) browser window into which tab(s) will
  // be rendered.
  scoped_ptr<aura::WindowTreeHost> window_tree_host_;

  // Used to apply standard focus conventions to the windows in the
  // WindowTreeHost hierarchy.
  scoped_ptr<wm::FocusController> focus_client_;

  // Used to manage input capture.
  scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;

  // Only one web_contents is supported for blimp 0.5
  scoped_ptr<content::WebContents> web_contents_;

  // Currently attached client connection.
  scoped_ptr<BlimpConnection> client_connection_;

  // The bridge to the network layer that does the RenderWidget proto/id work.
  // TODO(dtrainor, haibinlu): Move this to a higher level once we start dealing
  // with multiple tabs.
  EngineRenderWidgetMessageProcessor render_widget_processor_;

  DISALLOW_COPY_AND_ASSIGN(BlimpEngineSession);
};

}  // namespace engine
}  // namespace blimp

#endif  // BLIMP_ENGINE_BROWSER_BLIMP_ENGINE_SESSION_H_