Commit f898f991 authored by gunsch's avatar gunsch Committed by Commit bot

Chromecast: extracts Linux window creation code to a common place.

R=lcwu@chromium.org,gusfernandez@chromium.org
BUG=None

Review URL: https://codereview.chromium.org/659563004

Cr-Commit-Position: refs/heads/master@{#300360}
parent 21544deb
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
#include "components/crash/browser/crash_dump_manager_android.h" #include "components/crash/browser/crash_dump_manager_android.h"
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
#if defined(USE_AURA)
#include "ui/aura/env.h"
#endif
namespace chromecast { namespace chromecast {
namespace shell { namespace shell {
...@@ -34,6 +38,9 @@ CastBrowserProcess::CastBrowserProcess() { ...@@ -34,6 +38,9 @@ CastBrowserProcess::CastBrowserProcess() {
CastBrowserProcess::~CastBrowserProcess() { CastBrowserProcess::~CastBrowserProcess() {
DCHECK_EQ(g_instance, this); DCHECK_EQ(g_instance, this);
#if defined(USE_AURA)
aura::Env::DeleteInstance();
#endif
g_instance = NULL; g_instance = NULL;
} }
......
// 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/browser/cast_content_window.h"
#include "base/threading/thread_restrictions.h"
#include "content/public/browser/web_contents.h"
#include "ipc/ipc_message.h"
#if defined(USE_AURA)
#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"
#endif
namespace chromecast {
#if defined(USE_AURA)
class CastFillLayout : public aura::LayoutManager {
public:
explicit CastFillLayout(aura::Window* root) : root_(root) {}
virtual ~CastFillLayout() {}
private:
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(CastFillLayout);
};
#endif
CastContentWindow::CastContentWindow() {}
CastContentWindow::~CastContentWindow() {
#if defined(USE_AURA)
window_tree_host_.reset();
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
#endif
}
scoped_ptr<content::WebContents> CastContentWindow::Create(
const gfx::Size& initial_size,
content::BrowserContext* browser_context) {
#if defined(USE_AURA)
// Aura initialization
// TODO(lcwu): We only need a minimal implementation of gfx::screen
// and aura's TestScreen will do for us now. We should change 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 CastFillLayout(window_tree_host_->window()));
window_tree_host_->Show();
#endif
content::WebContents::CreateParams create_params(browser_context, NULL);
create_params.routing_id = MSG_ROUTING_NONE;
create_params.initial_size = initial_size;
content::WebContents* web_contents = content::WebContents::Create(
create_params);
#if defined(USE_AURA)
// 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();
#endif
return make_scoped_ptr(web_contents);
}
} // namespace chromecast
// 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_BROWSER_CAST_CONTENT_WINDOW_H_
#define CHROMECAST_BROWSER_CAST_CONTENT_WINDOW_H_
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
namespace aura {
class WindowTreeHost;
}
namespace content {
class BrowserContext;
class WebContents;
}
namespace gfx {
class Size;
}
namespace chromecast {
class CastContentWindow {
public:
CastContentWindow();
// Removes the window from the screen.
~CastContentWindow();
// Create a window with the given size.
scoped_ptr<content::WebContents> Create(
const gfx::Size& initial_size,
content::BrowserContext* browser_context);
private:
#if defined(USE_AURA)
scoped_ptr<aura::WindowTreeHost> window_tree_host_;
#endif
DISALLOW_COPY_AND_ASSIGN(CastContentWindow);
};
} // namespace chromecast
#endif // CHROMECAST_BROWSER_CAST_CONTENT_WINDOW_H_
...@@ -5,18 +5,11 @@ ...@@ -5,18 +5,11 @@
#include "chromecast/browser/service/cast_service_simple.h" #include "chromecast/browser/service/cast_service_simple.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_path.h" #include "chromecast/browser/cast_content_window.h"
#include "base/macros.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "net/base/filename_util.h" #include "net/base/filename_util.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.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" #include "url/gurl.h"
namespace chromecast { namespace chromecast {
...@@ -37,36 +30,6 @@ GURL GetStartupURL() { ...@@ -37,36 +30,6 @@ GURL GetStartupURL() {
return net::FilePathToFileURL(base::FilePath(args[0])); 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 } // namespace
// static // static
...@@ -90,34 +53,11 @@ void CastServiceSimple::Initialize() { ...@@ -90,34 +53,11 @@ void CastServiceSimple::Initialize() {
} }
void CastServiceSimple::StartInternal() { void CastServiceSimple::StartInternal() {
// Aura initialization // This is the simple version that hard-codes the size.
gfx::Size initial_size = gfx::Size(1280, 720); gfx::Size initial_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. window_.reset(new CastContentWindow);
// Change the code to use ozone's screen implementation when it is ready. web_contents_ = window_->Create(initial_size, browser_context());
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(), web_contents_->GetController().LoadURL(GetStartupURL(),
content::Referrer(), content::Referrer(),
...@@ -127,10 +67,8 @@ void CastServiceSimple::StartInternal() { ...@@ -127,10 +67,8 @@ void CastServiceSimple::StartInternal() {
void CastServiceSimple::StopInternal() { void CastServiceSimple::StopInternal() {
web_contents_->GetRenderViewHost()->ClosePage(); web_contents_->GetRenderViewHost()->ClosePage();
window_tree_host_.reset();
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
aura::Env::DeleteInstance();
web_contents_.reset(); web_contents_.reset();
window_.reset();
} }
} // namespace chromecast } // namespace chromecast
...@@ -8,15 +8,12 @@ ...@@ -8,15 +8,12 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chromecast/browser/service/cast_service.h" #include "chromecast/browser/service/cast_service.h"
namespace aura {
class WindowTreeHost;
}
namespace content { namespace content {
class WebContents; class WebContents;
} }
namespace chromecast { namespace chromecast {
class CastContentWindow;
class CastServiceSimple : public CastService { class CastServiceSimple : public CastService {
public: public:
...@@ -31,7 +28,7 @@ class CastServiceSimple : public CastService { ...@@ -31,7 +28,7 @@ class CastServiceSimple : public CastService {
virtual void StopInternal() override; virtual void StopInternal() override;
private: private:
scoped_ptr<aura::WindowTreeHost> window_tree_host_; scoped_ptr<CastContentWindow> window_;
scoped_ptr<content::WebContents> web_contents_; scoped_ptr<content::WebContents> web_contents_;
DISALLOW_COPY_AND_ASSIGN(CastServiceSimple); DISALLOW_COPY_AND_ASSIGN(CastServiceSimple);
......
...@@ -113,6 +113,8 @@ ...@@ -113,6 +113,8 @@
'browser/cast_browser_process.h', 'browser/cast_browser_process.h',
'browser/cast_content_browser_client.cc', 'browser/cast_content_browser_client.cc',
'browser/cast_content_browser_client.h', 'browser/cast_content_browser_client.h',
'browser/cast_content_window.cc',
'browser/cast_content_window.h',
'browser/cast_download_manager_delegate.cc', 'browser/cast_download_manager_delegate.cc',
'browser/cast_download_manager_delegate.h', 'browser/cast_download_manager_delegate.h',
'browser/cast_http_user_agent_settings.cc', 'browser/cast_http_user_agent_settings.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment