Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: chromecast/browser/cast_content_window.cc

Issue 2570623003: [Chromecast] Turn CastContentWindow into an abstract interface. (Closed)
Patch Set: Set user data outside of contructor Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 #include "chromecast/browser/cast_content_window.h"
6
7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h"
9 #include "base/threading/thread_restrictions.h"
10 #include "chromecast/base/metrics/cast_metrics_helper.h"
11 #include "chromecast/browser/cast_browser_process.h"
12 #include "chromecast/graphics/cast_vsync_settings.h"
13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/render_widget_host.h"
15 #include "content/public/browser/render_widget_host_view.h"
16 #include "content/public/browser/web_contents.h"
17 #include "ipc/ipc_message.h"
18 #include "ui/display/display.h"
19 #include "ui/display/screen.h"
20
21 #if defined(USE_AURA)
22 #include "chromecast/graphics/cast_screen.h"
23 #include "ui/aura/env.h"
24 #include "ui/aura/layout_manager.h"
25 #include "ui/aura/window.h"
26 #include "ui/aura/window_tree_host.h"
27 #endif
28
29 namespace chromecast {
30 namespace shell {
31
32 #if defined(USE_AURA)
33 class CastFillLayout : public aura::LayoutManager {
34 public:
35 explicit CastFillLayout(aura::Window* root) : root_(root) {}
36 ~CastFillLayout() override {}
37
38 private:
39 void OnWindowResized() override {}
40
41 void OnWindowAddedToLayout(aura::Window* child) override {
42 child->SetBounds(root_->bounds());
43 }
44
45 void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
46
47 void OnWindowRemovedFromLayout(aura::Window* child) override {}
48
49 void OnChildWindowVisibilityChanged(aura::Window* child,
50 bool visible) override {}
51
52 void SetChildBounds(aura::Window* child,
53 const gfx::Rect& requested_bounds) override {
54 SetChildBoundsDirect(child, requested_bounds);
55 }
56
57 aura::Window* root_;
58
59 DISALLOW_COPY_AND_ASSIGN(CastFillLayout);
60 };
61 #endif
62
63 CastContentWindow::CastContentWindow() : transparent_(false) {
64 }
65
66 CastContentWindow::~CastContentWindow() {
67 #if defined(USE_AURA)
68 CastVSyncSettings::GetInstance()->RemoveObserver(this);
69 window_tree_host_.reset();
70 // We don't delete the screen here to avoid a CHECK failure when
71 // the screen size is queried periodically for metric gathering. b/18101124
72 #endif
73 }
74
75 void CastContentWindow::CreateWindowTree(content::WebContents* web_contents) {
76 #if defined(USE_AURA)
77 // Aura initialization
78 DCHECK(display::Screen::GetScreen());
79 gfx::Size display_size =
80 display::Screen::GetScreen()->GetPrimaryDisplay().GetSizeInPixel();
81 CHECK(aura::Env::GetInstance());
82 window_tree_host_.reset(
83 aura::WindowTreeHost::Create(gfx::Rect(display_size)));
84 window_tree_host_->InitHost();
85 window_tree_host_->window()->SetLayoutManager(
86 new CastFillLayout(window_tree_host_->window()));
87
88 if (transparent_) {
89 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT);
90 window_tree_host_->compositor()->SetHostHasTransparentBackground(true);
91 } else {
92 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK);
93 }
94
95 CastVSyncSettings::GetInstance()->AddObserver(this);
96 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(
97 CastVSyncSettings::GetInstance()->GetVSyncInterval());
98
99 window_tree_host_->Show();
100
101 // Add and show content's view/window
102 aura::Window* content_window = web_contents->GetNativeView();
103 aura::Window* parent = window_tree_host_->window();
104 if (!parent->Contains(content_window)) {
105 parent->AddChild(content_window);
106 }
107 content_window->Show();
108 #endif
109 }
110
111 std::unique_ptr<content::WebContents> CastContentWindow::CreateWebContents(
112 content::BrowserContext* browser_context) {
113 CHECK(display::Screen::GetScreen());
114 gfx::Size display_size =
115 display::Screen::GetScreen()->GetPrimaryDisplay().size();
116
117 content::WebContents::CreateParams create_params(browser_context, NULL);
118 create_params.routing_id = MSG_ROUTING_NONE;
119 create_params.initial_size = display_size;
120 content::WebContents* web_contents = content::WebContents::Create(
121 create_params);
122
123 #if defined(USE_AURA)
124 // Resize window
125 aura::Window* content_window = web_contents->GetNativeView();
126 content_window->SetBounds(gfx::Rect(display_size.width(),
127 display_size.height()));
128 #endif
129
130 content::WebContentsObserver::Observe(web_contents);
131 return base::WrapUnique(web_contents);
132 }
133
134 void CastContentWindow::DidFirstVisuallyNonEmptyPaint() {
135 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint();
136 }
137
138 void CastContentWindow::MediaStoppedPlaying(const MediaPlayerInfo& media_info,
139 const MediaPlayerId& id) {
140 metrics::CastMetricsHelper::GetInstance()->LogMediaPause();
141 }
142
143 void CastContentWindow::MediaStartedPlaying(const MediaPlayerInfo& media_info,
144 const MediaPlayerId& id) {
145 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay();
146 }
147
148 void CastContentWindow::RenderViewCreated(
149 content::RenderViewHost* render_view_host) {
150 content::RenderWidgetHostView* view =
151 render_view_host->GetWidget()->GetView();
152 if (view)
153 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT
154 : SK_ColorBLACK);
155 }
156
157 void CastContentWindow::OnVSyncIntervalChanged(base::TimeDelta interval) {
158 #if defined(USE_AURA)
159 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(
160 interval);
161 #endif
162 }
163
164 } // namespace shell
165 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698