| 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" | |
| 10 #include "chromecast/base/metrics/cast_metrics_helper.h" | 9 #include "chromecast/base/metrics/cast_metrics_helper.h" |
| 11 #include "chromecast/browser/cast_browser_process.h" | 10 #include "chromecast/browser/cast_browser_process.h" |
| 12 #include "chromecast/graphics/cast_vsync_settings.h" | |
| 13 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 14 #include "content/public/browser/render_widget_host.h" | 12 #include "content/public/browser/render_widget_host.h" |
| 15 #include "content/public/browser/render_widget_host_view.h" | 13 #include "content/public/browser/render_widget_host_view.h" |
| 16 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 17 #include "ipc/ipc_message.h" | |
| 18 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
| 19 #include "ui/display/screen.h" | 16 #include "ui/display/screen.h" |
| 20 | 17 |
| 21 #if defined(USE_AURA) | 18 #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" | 19 #include "ui/aura/window.h" |
| 26 #include "ui/aura/window_tree_host.h" | |
| 27 #endif | 20 #endif |
| 28 | 21 |
| 29 namespace chromecast { | 22 namespace chromecast { |
| 30 namespace shell { | 23 namespace shell { |
| 31 | 24 |
| 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) { | 25 CastContentWindow::CastContentWindow() : transparent_(false) { |
| 64 } | 26 } |
| 65 | 27 |
| 66 CastContentWindow::~CastContentWindow() { | 28 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 | 29 |
| 111 std::unique_ptr<content::WebContents> CastContentWindow::CreateWebContents( | 30 std::unique_ptr<content::WebContents> CastContentWindow::CreateWebContents( |
| 112 content::BrowserContext* browser_context) { | 31 content::BrowserContext* browser_context) { |
| 113 CHECK(display::Screen::GetScreen()); | 32 CHECK(display::Screen::GetScreen()); |
| 114 gfx::Size display_size = | 33 gfx::Size display_size = |
| 115 display::Screen::GetScreen()->GetPrimaryDisplay().size(); | 34 display::Screen::GetScreen()->GetPrimaryDisplay().size(); |
| 116 | 35 |
| 117 content::WebContents::CreateParams create_params(browser_context, NULL); | 36 content::WebContents::CreateParams create_params(browser_context, NULL); |
| 118 create_params.routing_id = MSG_ROUTING_NONE; | 37 create_params.routing_id = MSG_ROUTING_NONE; |
| 119 create_params.initial_size = display_size; | 38 create_params.initial_size = display_size; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 140 } | 59 } |
| 141 | 60 |
| 142 void CastContentWindow::MediaStartedPlaying(const MediaPlayerId& id) { | 61 void CastContentWindow::MediaStartedPlaying(const MediaPlayerId& id) { |
| 143 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay(); | 62 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay(); |
| 144 } | 63 } |
| 145 | 64 |
| 146 void CastContentWindow::RenderViewCreated( | 65 void CastContentWindow::RenderViewCreated( |
| 147 content::RenderViewHost* render_view_host) { | 66 content::RenderViewHost* render_view_host) { |
| 148 content::RenderWidgetHostView* view = | 67 content::RenderWidgetHostView* view = |
| 149 render_view_host->GetWidget()->GetView(); | 68 render_view_host->GetWidget()->GetView(); |
| 150 if (view) | 69 if (view) { |
| 151 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT | 70 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT |
| 152 : SK_ColorBLACK); | 71 : SK_ColorBLACK); |
| 153 } | 72 } |
| 154 | |
| 155 void CastContentWindow::OnVSyncIntervalChanged(base::TimeDelta interval) { | |
| 156 #if defined(USE_AURA) | |
| 157 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval( | |
| 158 interval); | |
| 159 #endif | |
| 160 } | 73 } |
| 161 | 74 |
| 162 } // namespace shell | 75 } // namespace shell |
| 163 } // namespace chromecast | 76 } // namespace chromecast |
| OLD | NEW |