forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build-level separation of default CastService implementation.
The default implementation (CastServiceSimple) starts up a single page passed in on the command line. R=damienv@chromium.org,lcwu@chromium.org,jam@chromium.org BUG=336640 Review URL: https://codereview.chromium.org/397143003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283812 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
gunsch@chromium.org
committed
Jul 17, 2014
1 parent
4f1ded8
commit 791733d
Showing
7 changed files
with
192 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chromecast/service/cast_service_simple.h" | ||
|
||
#include "base/command_line.h" | ||
#include "base/files/file_path.h" | ||
#include "base/macros.h" | ||
#include "content/public/browser/render_view_host.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "net/base/filename_util.h" | ||
#include "ui/aura/env.h" | ||
#include "ui/aura/layout_manager.h" | ||
#include "ui/aura/test/test_screen.h" | ||
#include "ui/aura/window.h" | ||
#include "ui/aura/window_tree_host.h" | ||
#include "ui/gfx/size.h" | ||
#include "url/gurl.h" | ||
|
||
namespace chromecast { | ||
|
||
namespace { | ||
|
||
GURL GetStartupURL() { | ||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | ||
const base::CommandLine::StringVector& args = command_line->GetArgs(); | ||
|
||
if (args.empty()) | ||
return GURL("http://www.google.com/"); | ||
|
||
GURL url(args[0]); | ||
if (url.is_valid() && url.has_scheme()) | ||
return url; | ||
|
||
return net::FilePathToFileURL(base::FilePath(args[0])); | ||
} | ||
|
||
class FillLayout : public aura::LayoutManager { | ||
public: | ||
explicit FillLayout(aura::Window* root) : root_(root) {} | ||
virtual ~FillLayout() {} | ||
|
||
private: | ||
// aura::LayoutManager: | ||
virtual void OnWindowResized() OVERRIDE {} | ||
|
||
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { | ||
child->SetBounds(root_->bounds()); | ||
} | ||
|
||
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} | ||
|
||
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} | ||
|
||
virtual void OnChildWindowVisibilityChanged(aura::Window* child, | ||
bool visible) OVERRIDE {} | ||
|
||
virtual void SetChildBounds(aura::Window* child, | ||
const gfx::Rect& requested_bounds) OVERRIDE { | ||
SetChildBoundsDirect(child, requested_bounds); | ||
} | ||
|
||
aura::Window* root_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(FillLayout); | ||
}; | ||
|
||
} // namespace | ||
|
||
// static | ||
CastService* CastService::Create(content::BrowserContext* browser_context) { | ||
return new CastServiceSimple(browser_context); | ||
} | ||
|
||
CastServiceSimple::CastServiceSimple(content::BrowserContext* browser_context) | ||
: CastService(browser_context) { | ||
} | ||
|
||
CastServiceSimple::~CastServiceSimple() { | ||
} | ||
|
||
void CastServiceSimple::Initialize() { | ||
} | ||
|
||
void CastServiceSimple::StartInternal() { | ||
// Aura initialization | ||
gfx::Size initial_size = gfx::Size(1280, 720); | ||
// TODO(lcwu): http://crbug.com/391074. Chromecast only needs a minimal | ||
// implementation of gfx::screen and aura's TestScreen will do for now. | ||
// Change the code to use ozone's screen implementation when it is ready. | ||
aura::TestScreen* screen = aura::TestScreen::Create(initial_size); | ||
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen); | ||
CHECK(aura::Env::GetInstance()); | ||
window_tree_host_.reset( | ||
aura::WindowTreeHost::Create(gfx::Rect(initial_size))); | ||
window_tree_host_->InitHost(); | ||
window_tree_host_->window()->SetLayoutManager( | ||
new FillLayout(window_tree_host_->window())); | ||
window_tree_host_->Show(); | ||
|
||
// Create a WebContents | ||
content::WebContents::CreateParams create_params(browser_context(), NULL); | ||
create_params.routing_id = MSG_ROUTING_NONE; | ||
create_params.initial_size = initial_size; | ||
web_contents_.reset(content::WebContents::Create(create_params)); | ||
|
||
// Add and show content's view/window | ||
aura::Window* content_window = web_contents_->GetNativeView(); | ||
aura::Window* parent = window_tree_host_->window(); | ||
if (!parent->Contains(content_window)) { | ||
parent->AddChild(content_window); | ||
} | ||
content_window->Show(); | ||
|
||
web_contents_->GetController().LoadURL(GetStartupURL(), | ||
content::Referrer(), | ||
content::PAGE_TRANSITION_TYPED, | ||
std::string()); | ||
} | ||
|
||
void CastServiceSimple::StopInternal() { | ||
web_contents_->GetRenderViewHost()->ClosePage(); | ||
window_tree_host_.reset(); | ||
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); | ||
aura::Env::DeleteInstance(); | ||
web_contents_.reset(); | ||
} | ||
|
||
} // namespace chromecast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROMECAST_SERVICE_CAST_SERVICE_SIMPLE_H_ | ||
#define CHROMECAST_SERVICE_CAST_SERVICE_SIMPLE_H_ | ||
|
||
#include "base/memory/scoped_ptr.h" | ||
#include "chromecast/service/cast_service.h" | ||
|
||
namespace aura { | ||
class WindowTreeHost; | ||
} | ||
|
||
namespace content { | ||
class WebContents; | ||
} | ||
|
||
namespace chromecast { | ||
|
||
class CastServiceSimple : public CastService { | ||
public: | ||
explicit CastServiceSimple(content::BrowserContext* browser_context); | ||
virtual ~CastServiceSimple(); | ||
|
||
protected: | ||
// CastService implementation. | ||
virtual void Initialize() OVERRIDE; | ||
virtual void StartInternal() OVERRIDE; | ||
virtual void StopInternal() OVERRIDE; | ||
|
||
private: | ||
scoped_ptr<aura::WindowTreeHost> window_tree_host_; | ||
scoped_ptr<content::WebContents> web_contents_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(CastServiceSimple); | ||
}; | ||
|
||
} // namespace chromecast | ||
|
||
#endif // CHROMECAST_SERVICE_CAST_SERVICE_SIMPLE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters