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

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

Issue 2570623003: [Chromecast] Turn CastContentWindow into an abstract interface. (Closed)
Patch Set: Fix browser test Created 3 years, 11 months 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()->Show();
86 window_tree_host_->window()->SetLayoutManager(
87 new CastFillLayout(window_tree_host_->window()));
88
89 if (transparent_) {
90 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT);
91 window_tree_host_->compositor()->SetHostHasTransparentBackground(true);
92 } else {
93 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK);
94 }
95
96 CastVSyncSettings::GetInstance()->AddObserver(this);
97 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(
98 CastVSyncSettings::GetInstance()->GetVSyncInterval());
99
100 window_tree_host_->Show();
101
102 // Add and show content's view/window
103 aura::Window* content_window = web_contents->GetNativeView();
104 aura::Window* parent = window_tree_host_->window();
105 if (!parent->Contains(content_window)) {
106 parent->AddChild(content_window);
107 }
108 content_window->Show();
109 #endif
110 }
111
112 std::unique_ptr<content::WebContents> CastContentWindow::CreateWebContents(
113 content::BrowserContext* browser_context) {
114 CHECK(display::Screen::GetScreen());
115 gfx::Size display_size =
116 display::Screen::GetScreen()->GetPrimaryDisplay().size();
117
118 content::WebContents::CreateParams create_params(browser_context, NULL);
119 create_params.routing_id = MSG_ROUTING_NONE;
120 create_params.initial_size = display_size;
121 content::WebContents* web_contents = content::WebContents::Create(
122 create_params);
123
124 #if defined(USE_AURA)
125 // Resize window
126 aura::Window* content_window = web_contents->GetNativeView();
127 content_window->SetBounds(gfx::Rect(display_size.width(),
128 display_size.height()));
129 #endif
130
131 content::WebContentsObserver::Observe(web_contents);
132 return base::WrapUnique(web_contents);
133 }
134
135 void CastContentWindow::DidFirstVisuallyNonEmptyPaint() {
136 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint();
137 }
138
139 void CastContentWindow::MediaStoppedPlaying(const MediaPlayerInfo& media_info,
140 const MediaPlayerId& id) {
141 metrics::CastMetricsHelper::GetInstance()->LogMediaPause();
142 }
143
144 void CastContentWindow::MediaStartedPlaying(const MediaPlayerInfo& media_info,
145 const MediaPlayerId& id) {
146 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay();
147 }
148
149 void CastContentWindow::RenderViewCreated(
150 content::RenderViewHost* render_view_host) {
151 content::RenderWidgetHostView* view =
152 render_view_host->GetWidget()->GetView();
153 if (view)
154 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT
155 : SK_ColorBLACK);
156 }
157
158 void CastContentWindow::OnVSyncIntervalChanged(base::TimeDelta interval) {
159 #if defined(USE_AURA)
160 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(
161 interval);
162 #endif
163 }
164
165 } // namespace shell
166 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/browser/cast_content_window.h ('k') | chromecast/browser/cast_content_window_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698