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" |
| 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/screen.h" | |
| 17 | 18 |
| 18 #if defined(USE_AURA) | 19 #if defined(USE_AURA) |
| 19 #include "chromecast/graphics/cast_screen.h" | 20 #include "chromecast/graphics/cast_screen.h" |
| 20 #include "ui/aura/env.h" | 21 #include "ui/aura/env.h" |
| 21 #include "ui/aura/layout_manager.h" | 22 #include "ui/aura/layout_manager.h" |
| 22 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 23 #include "ui/aura/window_tree_host.h" | 24 #include "ui/aura/window_tree_host.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 namespace chromecast { | 27 namespace chromecast { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 } | 62 } |
| 62 | 63 |
| 63 CastContentWindow::~CastContentWindow() { | 64 CastContentWindow::~CastContentWindow() { |
| 64 #if defined(USE_AURA) | 65 #if defined(USE_AURA) |
| 65 window_tree_host_.reset(); | 66 window_tree_host_.reset(); |
| 66 // We don't delete the screen here to avoid a CHECK failure when | 67 // 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 | 68 // the screen size is queried periodically for metric gathering. b/18101124 |
| 68 #endif | 69 #endif |
| 69 } | 70 } |
| 70 | 71 |
| 71 void CastContentWindow::CreateWindowTree( | 72 void CastContentWindow::CreateWindowTree(content::WebContents* web_contents) { |
| 72 const gfx::Size& initial_size, | |
| 73 content::WebContents* web_contents) { | |
| 74 #if defined(USE_AURA) | 73 #if defined(USE_AURA) |
| 75 // Aura initialization | 74 // Aura initialization |
| 76 CastScreen* cast_screen = | 75 DCHECK(display::Screen::GetScreen()); |
| 77 shell::CastBrowserProcess::GetInstance()->cast_screen(); | 76 gfx::Size display_size = |
|
alokp
2016/05/14 05:15:32
Ideally we should query this size from WebContents
halliwell
2016/05/16 15:48:48
WebContents is currently not aware of this size.
alokp
2016/05/16 16:26:14
We already pass the size in WebContents::CreatePar
halliwell
2016/05/16 20:42:20
The NativeView's bounds appear to be 0x0 at this p
| |
| 78 if (!display::Screen::GetScreen()) | 77 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()); | 78 CHECK(aura::Env::GetInstance()); |
| 84 window_tree_host_.reset( | 79 window_tree_host_.reset( |
| 85 aura::WindowTreeHost::Create(gfx::Rect(initial_size))); | 80 aura::WindowTreeHost::Create(gfx::Rect(display_size))); |
| 86 window_tree_host_->InitHost(); | 81 window_tree_host_->InitHost(); |
| 87 window_tree_host_->window()->SetLayoutManager( | 82 window_tree_host_->window()->SetLayoutManager( |
| 88 new CastFillLayout(window_tree_host_->window())); | 83 new CastFillLayout(window_tree_host_->window())); |
| 89 | 84 |
| 90 if (transparent_) { | 85 if (transparent_) { |
| 91 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); | 86 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 92 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); | 87 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); |
| 93 } else { | 88 } else { |
| 94 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK); | 89 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK); |
| 95 } | 90 } |
| 96 window_tree_host_->Show(); | 91 window_tree_host_->Show(); |
| 97 | 92 |
| 98 // Add and show content's view/window | 93 // Add and show content's view/window |
| 99 aura::Window* content_window = web_contents->GetNativeView(); | 94 aura::Window* content_window = web_contents->GetNativeView(); |
| 100 aura::Window* parent = window_tree_host_->window(); | 95 aura::Window* parent = window_tree_host_->window(); |
| 101 if (!parent->Contains(content_window)) { | 96 if (!parent->Contains(content_window)) { |
| 102 parent->AddChild(content_window); | 97 parent->AddChild(content_window); |
| 103 } | 98 } |
| 104 content_window->Show(); | 99 content_window->Show(); |
| 105 #endif | 100 #endif |
| 106 } | 101 } |
| 107 | 102 |
| 108 std::unique_ptr<content::WebContents> CastContentWindow::CreateWebContents( | 103 std::unique_ptr<content::WebContents> CastContentWindow::CreateWebContents( |
| 109 const gfx::Size& initial_size, | |
| 110 content::BrowserContext* browser_context) { | 104 content::BrowserContext* browser_context) { |
| 105 CHECK(display::Screen::GetScreen()); | |
|
alokp
2016/05/14 05:15:32
I wonder why this is a member function for this cl
halliwell
2016/05/16 15:48:48
Good question, I don't know; maybe some historical
| |
| 106 gfx::Size display_size = | |
| 107 display::Screen::GetScreen()->GetPrimaryDisplay().size(); | |
| 108 | |
| 111 content::WebContents::CreateParams create_params(browser_context, NULL); | 109 content::WebContents::CreateParams create_params(browser_context, NULL); |
| 112 create_params.routing_id = MSG_ROUTING_NONE; | 110 create_params.routing_id = MSG_ROUTING_NONE; |
| 113 create_params.initial_size = initial_size; | 111 create_params.initial_size = display_size; |
| 114 content::WebContents* web_contents = content::WebContents::Create( | 112 content::WebContents* web_contents = content::WebContents::Create( |
| 115 create_params); | 113 create_params); |
| 116 content::WebContentsObserver::Observe(web_contents); | 114 content::WebContentsObserver::Observe(web_contents); |
| 117 return base::WrapUnique(web_contents); | 115 return base::WrapUnique(web_contents); |
| 118 } | 116 } |
| 119 | 117 |
| 120 void CastContentWindow::DidFirstVisuallyNonEmptyPaint() { | 118 void CastContentWindow::DidFirstVisuallyNonEmptyPaint() { |
| 121 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint(); | 119 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint(); |
| 122 } | 120 } |
| 123 | 121 |
| 124 void CastContentWindow::MediaStoppedPlaying(const MediaPlayerId& id) { | 122 void CastContentWindow::MediaStoppedPlaying(const MediaPlayerId& id) { |
| 125 metrics::CastMetricsHelper::GetInstance()->LogMediaPause(); | 123 metrics::CastMetricsHelper::GetInstance()->LogMediaPause(); |
| 126 } | 124 } |
| 127 | 125 |
| 128 void CastContentWindow::MediaStartedPlaying(const MediaPlayerId& id) { | 126 void CastContentWindow::MediaStartedPlaying(const MediaPlayerId& id) { |
| 129 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay(); | 127 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay(); |
| 130 } | 128 } |
| 131 | 129 |
| 132 void CastContentWindow::RenderViewCreated( | 130 void CastContentWindow::RenderViewCreated( |
| 133 content::RenderViewHost* render_view_host) { | 131 content::RenderViewHost* render_view_host) { |
| 134 content::RenderWidgetHostView* view = | 132 content::RenderWidgetHostView* view = |
| 135 render_view_host->GetWidget()->GetView(); | 133 render_view_host->GetWidget()->GetView(); |
| 136 if (view) | 134 if (view) |
| 137 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT | 135 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT |
| 138 : SK_ColorBLACK); | 136 : SK_ColorBLACK); |
| 139 } | 137 } |
| 140 | 138 |
| 141 } // namespace shell | 139 } // namespace shell |
| 142 } // namespace chromecast | 140 } // namespace chromecast |
| OLD | NEW |