| 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_linux.h" | 5 #include "chromecast/browser/cast_content_window_linux.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 "chromecast/base/metrics/cast_metrics_helper.h" | |
| 10 #include "chromecast/base/version.h" | |
| 11 #include "chromecast/browser/cast_browser_process.h" | |
| 12 #include "chromecast/graphics/cast_window_manager.h" | 9 #include "chromecast/graphics/cast_window_manager.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" | 10 #include "content/public/browser/web_contents.h" |
| 17 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
| 18 #include "ui/display/display.h" | 12 #include "ui/display/display.h" |
| 19 #include "ui/display/screen.h" | 13 #include "ui/display/screen.h" |
| 20 | 14 |
| 21 #if defined(USE_AURA) | 15 #if defined(USE_AURA) |
| 22 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 23 #endif | 17 #endif // defined(USE_AURA) |
| 24 | 18 |
| 25 namespace chromecast { | 19 namespace chromecast { |
| 26 namespace shell { | 20 namespace shell { |
| 27 | 21 |
| 28 // static | 22 // static |
| 29 std::unique_ptr<CastContentWindow> CastContentWindow::Create( | 23 std::unique_ptr<CastContentWindow> CastContentWindow::Create( |
| 30 CastContentWindow::Delegate* delegate) { | 24 CastContentWindow::Delegate* delegate) { |
| 31 DCHECK(delegate); | 25 DCHECK(delegate); |
| 32 return base::WrapUnique(new CastContentWindowLinux()); | 26 return base::WrapUnique(new CastContentWindowLinux()); |
| 33 } | 27 } |
| 34 | 28 |
| 35 CastContentWindowLinux::CastContentWindowLinux() : transparent_(false) {} | 29 CastContentWindowLinux::CastContentWindowLinux() : transparent_(false) {} |
| 36 | 30 |
| 37 CastContentWindowLinux::~CastContentWindowLinux() {} | 31 CastContentWindowLinux::~CastContentWindowLinux() {} |
| 38 | 32 |
| 39 void CastContentWindowLinux::SetTransparent() { | 33 void CastContentWindowLinux::SetTransparent() { |
| 40 transparent_ = true; | 34 transparent_ = true; |
| 41 } | 35 } |
| 42 | 36 |
| 43 std::unique_ptr<content::WebContents> CastContentWindowLinux::CreateWebContents( | |
| 44 content::BrowserContext* browser_context, | |
| 45 scoped_refptr<content::SiteInstance> site_instance) { | |
| 46 CHECK(display::Screen::GetScreen()); | |
| 47 gfx::Size display_size = | |
| 48 display::Screen::GetScreen()->GetPrimaryDisplay().size(); | |
| 49 | |
| 50 content::WebContents::CreateParams create_params(browser_context, NULL); | |
| 51 create_params.routing_id = MSG_ROUTING_NONE; | |
| 52 create_params.initial_size = display_size; | |
| 53 create_params.site_instance = site_instance; | |
| 54 content::WebContents* web_contents = | |
| 55 content::WebContents::Create(create_params); | |
| 56 | |
| 57 content::WebContentsObserver::Observe(web_contents); | |
| 58 return base::WrapUnique(web_contents); | |
| 59 } | |
| 60 | |
| 61 void CastContentWindowLinux::DidStartNavigation( | |
| 62 content::NavigationHandle* navigation_handle) { | |
| 63 #if defined(USE_AURA) | |
| 64 // Resize window | |
| 65 gfx::Size display_size = | |
| 66 display::Screen::GetScreen()->GetPrimaryDisplay().size(); | |
| 67 aura::Window* content_window = web_contents()->GetNativeView(); | |
| 68 content_window->SetBounds( | |
| 69 gfx::Rect(display_size.width(), display_size.height())); | |
| 70 #endif | |
| 71 } | |
| 72 | |
| 73 void CastContentWindowLinux::ShowWebContents( | 37 void CastContentWindowLinux::ShowWebContents( |
| 74 content::WebContents* web_contents, | 38 content::WebContents* web_contents, |
| 75 CastWindowManager* window_manager) { | 39 CastWindowManager* window_manager) { |
| 76 DCHECK(window_manager); | 40 DCHECK(window_manager); |
| 77 gfx::NativeView window = web_contents->GetNativeView(); | 41 gfx::NativeView window = web_contents->GetNativeView(); |
| 78 window_manager->SetWindowId(window, CastWindowManager::APP); | 42 window_manager->SetWindowId(window, CastWindowManager::APP); |
| 79 window_manager->AddWindow(window); | 43 window_manager->AddWindow(window); |
| 80 window->Show(); | 44 window->Show(); |
| 81 } | 45 } |
| 82 | 46 |
| 83 void CastContentWindowLinux::DidFirstVisuallyNonEmptyPaint() { | |
| 84 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint(); | |
| 85 } | |
| 86 | |
| 87 void CastContentWindowLinux::MediaStartedPlaying( | |
| 88 const MediaPlayerInfo& media_info, | |
| 89 const MediaPlayerId& id) { | |
| 90 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay(); | |
| 91 } | |
| 92 | |
| 93 void CastContentWindowLinux::MediaStoppedPlaying( | |
| 94 const MediaPlayerInfo& media_info, | |
| 95 const MediaPlayerId& id) { | |
| 96 metrics::CastMetricsHelper::GetInstance()->LogMediaPause(); | |
| 97 } | |
| 98 | |
| 99 void CastContentWindowLinux::RenderViewCreated( | |
| 100 content::RenderViewHost* render_view_host) { | |
| 101 content::RenderWidgetHostView* view = | |
| 102 render_view_host->GetWidget()->GetView(); | |
| 103 if (view) { | |
| 104 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT | |
| 105 : SK_ColorBLACK); | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 } // namespace shell | 47 } // namespace shell |
| 110 } // namespace chromecast | 48 } // namespace chromecast |
| OLD | NEW |