diff options
author | gunsch <gunsch@chromium.org> | 2014-10-20 15:39:59 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-20 22:40:16 +0000 |
commit | f898f99146b7cde544c9c10d7cbe9861a6c71bc5 (patch) | |
tree | 8b642b8eb67355f2cfd7f047dad48a974c5c3216 | |
parent | 21544debbe5eebb4dd14cab8a55090b71a41ebc4 (diff) | |
download | chromium_src-f898f99146b7cde544c9c10d7cbe9861a6c71bc5.zip chromium_src-f898f99146b7cde544c9c10d7cbe9861a6c71bc5.tar.gz chromium_src-f898f99146b7cde544c9c10d7cbe9861a6c71bc5.tar.bz2 |
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}
-rw-r--r-- | chromecast/browser/cast_browser_process.cc | 7 | ||||
-rw-r--r-- | chromecast/browser/cast_content_window.cc | 99 | ||||
-rw-r--r-- | chromecast/browser/cast_content_window.h | 48 | ||||
-rw-r--r-- | chromecast/browser/service/cast_service_simple.cc | 76 | ||||
-rw-r--r-- | chromecast/browser/service/cast_service_simple.h | 7 | ||||
-rw-r--r-- | chromecast/chromecast.gyp | 2 |
6 files changed, 165 insertions, 74 deletions
diff --git a/chromecast/browser/cast_browser_process.cc b/chromecast/browser/cast_browser_process.cc index 03377d4..8a3057c 100644 --- a/chromecast/browser/cast_browser_process.cc +++ b/chromecast/browser/cast_browser_process.cc @@ -14,6 +14,10 @@ #include "components/crash/browser/crash_dump_manager_android.h" #endif // defined(OS_ANDROID) +#if defined(USE_AURA) +#include "ui/aura/env.h" +#endif + namespace chromecast { namespace shell { @@ -34,6 +38,9 @@ CastBrowserProcess::CastBrowserProcess() { CastBrowserProcess::~CastBrowserProcess() { DCHECK_EQ(g_instance, this); +#if defined(USE_AURA) + aura::Env::DeleteInstance(); +#endif g_instance = NULL; } diff --git a/chromecast/browser/cast_content_window.cc b/chromecast/browser/cast_content_window.cc new file mode 100644 index 0000000..2e76eaf --- /dev/null +++ b/chromecast/browser/cast_content_window.cc @@ -0,0 +1,99 @@ +// 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 diff --git a/chromecast/browser/cast_content_window.h b/chromecast/browser/cast_content_window.h new file mode 100644 index 0000000..7101db1 --- /dev/null +++ b/chromecast/browser/cast_content_window.h @@ -0,0 +1,48 @@ +// 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_ diff --git a/chromecast/browser/service/cast_service_simple.cc b/chromecast/browser/service/cast_service_simple.cc index c5e591a..9ac90b0 100644 --- a/chromecast/browser/service/cast_service_simple.cc +++ b/chromecast/browser/service/cast_service_simple.cc @@ -5,18 +5,11 @@ #include "chromecast/browser/service/cast_service_simple.h" #include "base/command_line.h" -#include "base/files/file_path.h" -#include "base/macros.h" +#include "chromecast/browser/cast_content_window.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "net/base/filename_util.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" namespace chromecast { @@ -37,36 +30,6 @@ GURL GetStartupURL() { 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 @@ -90,34 +53,11 @@ 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(); + // This is the simple version that hard-codes the size. + gfx::Size initial_size(1280, 720); + + window_.reset(new CastContentWindow); + web_contents_ = window_->Create(initial_size, browser_context()); web_contents_->GetController().LoadURL(GetStartupURL(), content::Referrer(), @@ -127,10 +67,8 @@ void CastServiceSimple::StartInternal() { 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(); + window_.reset(); } } // namespace chromecast diff --git a/chromecast/browser/service/cast_service_simple.h b/chromecast/browser/service/cast_service_simple.h index 4939e5d..f1fb5c8 100644 --- a/chromecast/browser/service/cast_service_simple.h +++ b/chromecast/browser/service/cast_service_simple.h @@ -8,15 +8,12 @@ #include "base/memory/scoped_ptr.h" #include "chromecast/browser/service/cast_service.h" -namespace aura { -class WindowTreeHost; -} - namespace content { class WebContents; } namespace chromecast { +class CastContentWindow; class CastServiceSimple : public CastService { public: @@ -31,7 +28,7 @@ class CastServiceSimple : public CastService { virtual void StopInternal() override; private: - scoped_ptr<aura::WindowTreeHost> window_tree_host_; + scoped_ptr<CastContentWindow> window_; scoped_ptr<content::WebContents> web_contents_; DISALLOW_COPY_AND_ASSIGN(CastServiceSimple); diff --git a/chromecast/chromecast.gyp b/chromecast/chromecast.gyp index 7485fad..1178d40 100644 --- a/chromecast/chromecast.gyp +++ b/chromecast/chromecast.gyp @@ -113,6 +113,8 @@ 'browser/cast_browser_process.h', 'browser/cast_content_browser_client.cc', '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.h', 'browser/cast_http_user_agent_settings.cc', |