Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Unified Diff: chromecast/browser/cast_content_window.cc

Issue 659563004: Chromecast: extracts Linux window creation code to a common place. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, delete aura instance in ~CastBrowserProcess Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromecast/browser/cast_content_window.h ('k') | chromecast/browser/service/cast_service_simple.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/browser/cast_content_window.cc
diff --git a/chromecast/browser/cast_content_window.cc b/chromecast/browser/cast_content_window.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2e76eafa205cdbb6b5fe2d34aa32624e2b480f06
--- /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
« no previous file with comments | « chromecast/browser/cast_content_window.h ('k') | chromecast/browser/service/cast_service_simple.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698