Chromium Code Reviews| 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" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 } | 61 } |
| 62 | 62 |
| 63 CastContentWindow::~CastContentWindow() { | 63 CastContentWindow::~CastContentWindow() { |
| 64 #if defined(USE_AURA) | 64 #if defined(USE_AURA) |
| 65 window_tree_host_.reset(); | 65 window_tree_host_.reset(); |
| 66 // We don't delete the screen here to avoid a CHECK failure when | 66 // 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 | 67 // the screen size is queried periodically for metric gathering. b/18101124 |
| 68 #endif | 68 #endif |
| 69 } | 69 } |
| 70 | 70 |
| 71 void CastContentWindow::CreateWindowTree( | 71 void CastContentWindow::CreateWindowTree(content::WebContents* web_contents) { |
| 72 const gfx::Size& initial_size, | |
| 73 content::WebContents* web_contents) { | |
| 74 #if defined(USE_AURA) | 72 #if defined(USE_AURA) |
| 75 // Aura initialization | 73 // Aura initialization |
| 76 CastScreen* cast_screen = | 74 CHECK(display::Screen::GetScreen()); |
|
alokp
2016/05/12 21:35:16
Can this be a DCHECK?
halliwell
2016/05/13 23:48:03
sure, done.
| |
| 77 shell::CastBrowserProcess::GetInstance()->cast_screen(); | 75 gfx::Size display_size = |
| 78 if (!display::Screen::GetScreen()) | 76 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()); | 77 CHECK(aura::Env::GetInstance()); |
| 84 window_tree_host_.reset( | 78 window_tree_host_.reset( |
| 85 aura::WindowTreeHost::Create(gfx::Rect(initial_size))); | 79 aura::WindowTreeHost::Create(gfx::Rect(display_size))); |
| 86 window_tree_host_->InitHost(); | 80 window_tree_host_->InitHost(); |
| 87 window_tree_host_->window()->SetLayoutManager( | 81 window_tree_host_->window()->SetLayoutManager( |
| 88 new CastFillLayout(window_tree_host_->window())); | 82 new CastFillLayout(window_tree_host_->window())); |
| 89 | 83 |
| 90 if (transparent_) { | 84 if (transparent_) { |
| 91 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); | 85 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 92 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); | 86 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); |
| 93 } else { | 87 } else { |
| 94 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK); | 88 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK); |
| 95 } | 89 } |
| 96 window_tree_host_->Show(); | 90 window_tree_host_->Show(); |
| 97 | 91 |
| 98 // Add and show content's view/window | 92 // Add and show content's view/window |
| 99 aura::Window* content_window = web_contents->GetNativeView(); | 93 aura::Window* content_window = web_contents->GetNativeView(); |
| 100 aura::Window* parent = window_tree_host_->window(); | 94 aura::Window* parent = window_tree_host_->window(); |
| 101 if (!parent->Contains(content_window)) { | 95 if (!parent->Contains(content_window)) { |
| 102 parent->AddChild(content_window); | 96 parent->AddChild(content_window); |
| 103 } | 97 } |
| 104 content_window->Show(); | 98 content_window->Show(); |
| 105 #endif | 99 #endif |
| 106 } | 100 } |
| 107 | 101 |
| 108 std::unique_ptr<content::WebContents> CastContentWindow::CreateWebContents( | 102 std::unique_ptr<content::WebContents> CastContentWindow::CreateWebContents( |
| 109 const gfx::Size& initial_size, | |
| 110 content::BrowserContext* browser_context) { | 103 content::BrowserContext* browser_context) { |
| 104 CHECK(display::Screen::GetScreen()); | |
| 105 gfx::Size display_size = | |
| 106 display::Screen::GetScreen()->GetPrimaryDisplay().size(); | |
| 107 | |
| 111 content::WebContents::CreateParams create_params(browser_context, NULL); | 108 content::WebContents::CreateParams create_params(browser_context, NULL); |
| 112 create_params.routing_id = MSG_ROUTING_NONE; | 109 create_params.routing_id = MSG_ROUTING_NONE; |
| 113 create_params.initial_size = initial_size; | 110 create_params.initial_size = display_size; |
| 114 content::WebContents* web_contents = content::WebContents::Create( | 111 content::WebContents* web_contents = content::WebContents::Create( |
| 115 create_params); | 112 create_params); |
| 116 content::WebContentsObserver::Observe(web_contents); | 113 content::WebContentsObserver::Observe(web_contents); |
| 117 return base::WrapUnique(web_contents); | 114 return base::WrapUnique(web_contents); |
| 118 } | 115 } |
| 119 | 116 |
| 120 void CastContentWindow::DidFirstVisuallyNonEmptyPaint() { | 117 void CastContentWindow::DidFirstVisuallyNonEmptyPaint() { |
| 121 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint(); | 118 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint(); |
| 122 } | 119 } |
| 123 | 120 |
| 124 void CastContentWindow::MediaStoppedPlaying(const MediaPlayerId& id) { | 121 void CastContentWindow::MediaStoppedPlaying(const MediaPlayerId& id) { |
| 125 metrics::CastMetricsHelper::GetInstance()->LogMediaPause(); | 122 metrics::CastMetricsHelper::GetInstance()->LogMediaPause(); |
| 126 } | 123 } |
| 127 | 124 |
| 128 void CastContentWindow::MediaStartedPlaying(const MediaPlayerId& id) { | 125 void CastContentWindow::MediaStartedPlaying(const MediaPlayerId& id) { |
| 129 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay(); | 126 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay(); |
| 130 } | 127 } |
| 131 | 128 |
| 132 void CastContentWindow::RenderViewCreated( | 129 void CastContentWindow::RenderViewCreated( |
| 133 content::RenderViewHost* render_view_host) { | 130 content::RenderViewHost* render_view_host) { |
| 134 content::RenderWidgetHostView* view = | 131 content::RenderWidgetHostView* view = |
| 135 render_view_host->GetWidget()->GetView(); | 132 render_view_host->GetWidget()->GetView(); |
| 136 if (view) | 133 if (view) |
| 137 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT | 134 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT |
| 138 : SK_ColorBLACK); | 135 : SK_ColorBLACK); |
| 139 } | 136 } |
| 140 | 137 |
| 141 } // namespace shell | 138 } // namespace shell |
| 142 } // namespace chromecast | 139 } // namespace chromecast |
| OLD | NEW |