| 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/service/cast_service.h" | 5 #include "chromecast/service/cast_service_simple.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/threading/thread_checker.h" | |
| 11 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 12 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 13 #include "net/base/filename_util.h" | 12 #include "net/base/filename_util.h" |
| 14 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 15 #include "ui/aura/layout_manager.h" | 14 #include "ui/aura/layout_manager.h" |
| 16 #include "ui/aura/test/test_screen.h" | 15 #include "ui/aura/test/test_screen.h" |
| 17 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 18 #include "ui/aura/window_tree_host.h" | 17 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/gfx/size.h" | 18 #include "ui/gfx/size.h" |
| 20 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 SetChildBoundsDirect(child, requested_bounds); | 61 SetChildBoundsDirect(child, requested_bounds); |
| 63 } | 62 } |
| 64 | 63 |
| 65 aura::Window* root_; | 64 aura::Window* root_; |
| 66 | 65 |
| 67 DISALLOW_COPY_AND_ASSIGN(FillLayout); | 66 DISALLOW_COPY_AND_ASSIGN(FillLayout); |
| 68 }; | 67 }; |
| 69 | 68 |
| 70 } // namespace | 69 } // namespace |
| 71 | 70 |
| 72 CastService::CastService(content::BrowserContext* browser_context) | 71 // static |
| 73 : browser_context_(browser_context), | 72 CastService* CastService::Create(content::BrowserContext* browser_context) { |
| 74 stopped_(true), | 73 return new CastServiceSimple(browser_context); |
| 75 thread_checker_(new base::ThreadChecker()) { | |
| 76 } | 74 } |
| 77 | 75 |
| 78 CastService::~CastService() { | 76 CastServiceSimple::CastServiceSimple(content::BrowserContext* browser_context) |
| 79 DCHECK(thread_checker_->CalledOnValidThread()); | 77 : CastService(browser_context) { |
| 80 DCHECK(stopped_); | |
| 81 } | 78 } |
| 82 | 79 |
| 83 void CastService::Initialize() { | 80 CastServiceSimple::~CastServiceSimple() { |
| 84 PlatformInitialize(); | |
| 85 } | 81 } |
| 86 | 82 |
| 87 void CastService::Start() { | 83 void CastServiceSimple::Initialize() { |
| 88 DCHECK(thread_checker_->CalledOnValidThread()); | 84 } |
| 89 | 85 |
| 90 Initialize(); | 86 void CastServiceSimple::StartInternal() { |
| 91 | |
| 92 // Aura initialization | 87 // Aura initialization |
| 93 gfx::Size initial_size = gfx::Size(1280, 720); | 88 gfx::Size initial_size = gfx::Size(1280, 720); |
| 94 // TODO(lcwu): http://crbug.com/391074. Chromecast only needs a minimal | 89 // TODO(lcwu): http://crbug.com/391074. Chromecast only needs a minimal |
| 95 // implementation of gfx::screen and aura's TestScreen will do for now. | 90 // implementation of gfx::screen and aura's TestScreen will do for now. |
| 96 // Change the code to use ozone's screen implementation when it is ready. | 91 // Change the code to use ozone's screen implementation when it is ready. |
| 97 aura::TestScreen* screen = aura::TestScreen::Create(initial_size); | 92 aura::TestScreen* screen = aura::TestScreen::Create(initial_size); |
| 98 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen); | 93 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen); |
| 99 CHECK(aura::Env::GetInstance()); | 94 CHECK(aura::Env::GetInstance()); |
| 100 window_tree_host_.reset( | 95 window_tree_host_.reset( |
| 101 aura::WindowTreeHost::Create(gfx::Rect(initial_size))); | 96 aura::WindowTreeHost::Create(gfx::Rect(initial_size))); |
| 102 window_tree_host_->InitHost(); | 97 window_tree_host_->InitHost(); |
| 103 window_tree_host_->window()->SetLayoutManager( | 98 window_tree_host_->window()->SetLayoutManager( |
| 104 new FillLayout(window_tree_host_->window())); | 99 new FillLayout(window_tree_host_->window())); |
| 105 window_tree_host_->Show(); | 100 window_tree_host_->Show(); |
| 106 | 101 |
| 107 // Create a WebContents | 102 // Create a WebContents |
| 108 content::WebContents::CreateParams create_params(browser_context_, NULL); | 103 content::WebContents::CreateParams create_params(browser_context(), NULL); |
| 109 create_params.routing_id = MSG_ROUTING_NONE; | 104 create_params.routing_id = MSG_ROUTING_NONE; |
| 110 create_params.initial_size = initial_size; | 105 create_params.initial_size = initial_size; |
| 111 web_contents_.reset(content::WebContents::Create(create_params)); | 106 web_contents_.reset(content::WebContents::Create(create_params)); |
| 112 | 107 |
| 113 // Add and show content's view/window | 108 // Add and show content's view/window |
| 114 aura::Window* content_window = web_contents_->GetNativeView(); | 109 aura::Window* content_window = web_contents_->GetNativeView(); |
| 115 aura::Window* parent = window_tree_host_->window(); | 110 aura::Window* parent = window_tree_host_->window(); |
| 116 if (!parent->Contains(content_window)) { | 111 if (!parent->Contains(content_window)) { |
| 117 parent->AddChild(content_window); | 112 parent->AddChild(content_window); |
| 118 } | 113 } |
| 119 content_window->Show(); | 114 content_window->Show(); |
| 120 | 115 |
| 121 web_contents_->GetController().LoadURL(GetStartupURL(), | 116 web_contents_->GetController().LoadURL(GetStartupURL(), |
| 122 content::Referrer(), | 117 content::Referrer(), |
| 123 content::PAGE_TRANSITION_TYPED, | 118 content::PAGE_TRANSITION_TYPED, |
| 124 std::string()); | 119 std::string()); |
| 125 | |
| 126 stopped_ = false; | |
| 127 } | 120 } |
| 128 | 121 |
| 129 void CastService::Stop() { | 122 void CastServiceSimple::StopInternal() { |
| 130 DCHECK(thread_checker_->CalledOnValidThread()); | |
| 131 | |
| 132 web_contents_->GetRenderViewHost()->ClosePage(); | 123 web_contents_->GetRenderViewHost()->ClosePage(); |
| 133 window_tree_host_.reset(); | 124 window_tree_host_.reset(); |
| 134 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); | 125 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); |
| 135 aura::Env::DeleteInstance(); | 126 aura::Env::DeleteInstance(); |
| 136 web_contents_.reset(); | 127 web_contents_.reset(); |
| 137 stopped_ = true; | |
| 138 } | 128 } |
| 139 | 129 |
| 140 } // namespace chromecast | 130 } // namespace chromecast |
| OLD | NEW |