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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chromecast/browser/cast_content_window.h"
6
7 #include "base/threading/thread_restrictions.h"
8 #include "content/public/browser/web_contents.h"
9 #include "ipc/ipc_message.h"
10
11 #if defined(USE_AURA)
12 #include "ui/aura/env.h"
13 #include "ui/aura/layout_manager.h"
14 #include "ui/aura/test/test_screen.h"
15 #include "ui/aura/window.h"
16 #include "ui/aura/window_tree_host.h"
17 #endif
18
19 namespace chromecast {
20
21 #if defined(USE_AURA)
22 class CastFillLayout : public aura::LayoutManager {
23 public:
24 explicit CastFillLayout(aura::Window* root) : root_(root) {}
25 virtual ~CastFillLayout() {}
26
27 private:
28 virtual void OnWindowResized() override {}
29
30 virtual void OnWindowAddedToLayout(aura::Window* child) override {
31 child->SetBounds(root_->bounds());
32 }
33
34 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
35
36 virtual void OnWindowRemovedFromLayout(aura::Window* child) override {}
37
38 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
39 bool visible) override {}
40
41 virtual void SetChildBounds(aura::Window* child,
42 const gfx::Rect& requested_bounds) override {
43 SetChildBoundsDirect(child, requested_bounds);
44 }
45
46 aura::Window* root_;
47
48 DISALLOW_COPY_AND_ASSIGN(CastFillLayout);
49 };
50 #endif
51
52 CastContentWindow::CastContentWindow() {}
53
54 CastContentWindow::~CastContentWindow() {
55 #if defined(USE_AURA)
56 window_tree_host_.reset();
57 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
58 #endif
59 }
60
61 scoped_ptr<content::WebContents> CastContentWindow::Create(
62 const gfx::Size& initial_size,
63 content::BrowserContext* browser_context) {
64 #if defined(USE_AURA)
65 // Aura initialization
66 // TODO(lcwu): We only need a minimal implementation of gfx::screen
67 // and aura's TestScreen will do for us now. We should change to use
68 // ozone's screen implementation when it is ready.
69 aura::TestScreen* screen = aura::TestScreen::Create(initial_size);
70 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen);
71 CHECK(aura::Env::GetInstance());
72 window_tree_host_.reset(
73 aura::WindowTreeHost::Create(gfx::Rect(initial_size)));
74 window_tree_host_->InitHost();
75 window_tree_host_->window()->SetLayoutManager(
76 new CastFillLayout(window_tree_host_->window()));
77 window_tree_host_->Show();
78 #endif
79
80 content::WebContents::CreateParams create_params(browser_context, NULL);
81 create_params.routing_id = MSG_ROUTING_NONE;
82 create_params.initial_size = initial_size;
83 content::WebContents* web_contents = content::WebContents::Create(
84 create_params);
85
86 #if defined(USE_AURA)
87 // Add and show content's view/window
88 aura::Window* content_window = web_contents->GetNativeView();
89 aura::Window* parent = window_tree_host_->window();
90 if (!parent->Contains(content_window)) {
91 parent->AddChild(content_window);
92 }
93 content_window->Show();
94 #endif
95
96 return make_scoped_ptr(web_contents);
97 }
98
99 } // namespace chromecast
OLDNEW
« 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