OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromecast/browser/cast_content_window.h" | 5 #include "chromecast/browser/cast_content_window.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "chromecast/base/metrics/cast_metrics_helper.h" | 10 #include "chromecast/base/metrics/cast_metrics_helper.h" |
11 #include "chromecast/browser/cast_browser_process.h" | 11 #include "chromecast/browser/cast_browser_process.h" |
12 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
13 #include "content/public/browser/render_widget_host.h" | 13 #include "content/public/browser/render_widget_host.h" |
14 #include "content/public/browser/render_widget_host_view.h" | 14 #include "content/public/browser/render_widget_host_view.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
| 17 #include "ui/display/display.h" |
| 18 #include "ui/display/screen.h" |
17 | 19 |
18 #if defined(USE_AURA) | 20 #if defined(USE_AURA) |
19 #include "chromecast/graphics/cast_screen.h" | 21 #include "chromecast/graphics/cast_screen.h" |
20 #include "ui/aura/env.h" | 22 #include "ui/aura/env.h" |
21 #include "ui/aura/layout_manager.h" | 23 #include "ui/aura/layout_manager.h" |
22 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
23 #include "ui/aura/window_tree_host.h" | 25 #include "ui/aura/window_tree_host.h" |
24 #endif | 26 #endif |
25 | 27 |
26 namespace chromecast { | 28 namespace chromecast { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 63 } |
62 | 64 |
63 CastContentWindow::~CastContentWindow() { | 65 CastContentWindow::~CastContentWindow() { |
64 #if defined(USE_AURA) | 66 #if defined(USE_AURA) |
65 window_tree_host_.reset(); | 67 window_tree_host_.reset(); |
66 // We don't delete the screen here to avoid a CHECK failure when | 68 // We don't delete the screen here to avoid a CHECK failure when |
67 // the screen size is queried periodically for metric gathering. b/18101124 | 69 // the screen size is queried periodically for metric gathering. b/18101124 |
68 #endif | 70 #endif |
69 } | 71 } |
70 | 72 |
71 void CastContentWindow::CreateWindowTree( | 73 void CastContentWindow::CreateWindowTree(content::WebContents* web_contents) { |
72 const gfx::Size& initial_size, | |
73 content::WebContents* web_contents) { | |
74 #if defined(USE_AURA) | 74 #if defined(USE_AURA) |
75 // Aura initialization | 75 // Aura initialization |
76 CastScreen* cast_screen = | 76 DCHECK(display::Screen::GetScreen()); |
77 shell::CastBrowserProcess::GetInstance()->cast_screen(); | 77 gfx::Size display_size = |
78 if (!display::Screen::GetScreen()) | 78 display::Screen::GetScreen()->GetPrimaryDisplay().GetSizeInPixel(); |
79 display::Screen::SetScreenInstance(cast_screen); | |
80 if (cast_screen->GetPrimaryDisplay().size() != initial_size) | |
81 cast_screen->UpdateDisplaySize(initial_size); | |
82 | |
83 CHECK(aura::Env::GetInstance()); | 79 CHECK(aura::Env::GetInstance()); |
84 window_tree_host_.reset( | 80 window_tree_host_.reset( |
85 aura::WindowTreeHost::Create(gfx::Rect(initial_size))); | 81 aura::WindowTreeHost::Create(gfx::Rect(display_size))); |
86 window_tree_host_->InitHost(); | 82 window_tree_host_->InitHost(); |
87 window_tree_host_->window()->SetLayoutManager( | 83 window_tree_host_->window()->SetLayoutManager( |
88 new CastFillLayout(window_tree_host_->window())); | 84 new CastFillLayout(window_tree_host_->window())); |
89 | 85 |
90 if (transparent_) { | 86 if (transparent_) { |
91 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); | 87 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); |
92 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); | 88 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); |
93 } else { | 89 } else { |
94 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK); | 90 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK); |
95 } | 91 } |
96 window_tree_host_->Show(); | 92 window_tree_host_->Show(); |
97 | 93 |
98 // Add and show content's view/window | 94 // Add and show content's view/window |
99 aura::Window* content_window = web_contents->GetNativeView(); | 95 aura::Window* content_window = web_contents->GetNativeView(); |
100 aura::Window* parent = window_tree_host_->window(); | 96 aura::Window* parent = window_tree_host_->window(); |
101 if (!parent->Contains(content_window)) { | 97 if (!parent->Contains(content_window)) { |
102 parent->AddChild(content_window); | 98 parent->AddChild(content_window); |
103 } | 99 } |
104 content_window->Show(); | 100 content_window->Show(); |
105 #endif | 101 #endif |
106 } | 102 } |
107 | 103 |
108 std::unique_ptr<content::WebContents> CastContentWindow::CreateWebContents( | 104 std::unique_ptr<content::WebContents> CastContentWindow::CreateWebContents( |
109 const gfx::Size& initial_size, | |
110 content::BrowserContext* browser_context) { | 105 content::BrowserContext* browser_context) { |
| 106 CHECK(display::Screen::GetScreen()); |
| 107 gfx::Size display_size = |
| 108 display::Screen::GetScreen()->GetPrimaryDisplay().size(); |
| 109 |
111 content::WebContents::CreateParams create_params(browser_context, NULL); | 110 content::WebContents::CreateParams create_params(browser_context, NULL); |
112 create_params.routing_id = MSG_ROUTING_NONE; | 111 create_params.routing_id = MSG_ROUTING_NONE; |
113 create_params.initial_size = initial_size; | 112 create_params.initial_size = display_size; |
114 content::WebContents* web_contents = content::WebContents::Create( | 113 content::WebContents* web_contents = content::WebContents::Create( |
115 create_params); | 114 create_params); |
116 content::WebContentsObserver::Observe(web_contents); | 115 content::WebContentsObserver::Observe(web_contents); |
117 return base::WrapUnique(web_contents); | 116 return base::WrapUnique(web_contents); |
118 } | 117 } |
119 | 118 |
120 void CastContentWindow::DidFirstVisuallyNonEmptyPaint() { | 119 void CastContentWindow::DidFirstVisuallyNonEmptyPaint() { |
121 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint(); | 120 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint(); |
122 } | 121 } |
123 | 122 |
124 void CastContentWindow::MediaStoppedPlaying(const MediaPlayerId& id) { | 123 void CastContentWindow::MediaStoppedPlaying(const MediaPlayerId& id) { |
125 metrics::CastMetricsHelper::GetInstance()->LogMediaPause(); | 124 metrics::CastMetricsHelper::GetInstance()->LogMediaPause(); |
126 } | 125 } |
127 | 126 |
128 void CastContentWindow::MediaStartedPlaying(const MediaPlayerId& id) { | 127 void CastContentWindow::MediaStartedPlaying(const MediaPlayerId& id) { |
129 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay(); | 128 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay(); |
130 } | 129 } |
131 | 130 |
132 void CastContentWindow::RenderViewCreated( | 131 void CastContentWindow::RenderViewCreated( |
133 content::RenderViewHost* render_view_host) { | 132 content::RenderViewHost* render_view_host) { |
134 content::RenderWidgetHostView* view = | 133 content::RenderWidgetHostView* view = |
135 render_view_host->GetWidget()->GetView(); | 134 render_view_host->GetWidget()->GetView(); |
136 if (view) | 135 if (view) |
137 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT | 136 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT |
138 : SK_ColorBLACK); | 137 : SK_ColorBLACK); |
139 } | 138 } |
140 | 139 |
141 } // namespace shell | 140 } // namespace shell |
142 } // namespace chromecast | 141 } // namespace chromecast |
OLD | NEW |