Disable flaky testHTTPResponseTimelineRecorder on Mac
[chromium-blink-merge.git] / chromecast / browser / cast_content_window.cc
blob6a03016cc6c6c4523b8c97822976104212596a86
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.
5 #include "chromecast/browser/cast_content_window.h"
7 #include "base/threading/thread_restrictions.h"
8 #include "chromecast/base/metrics/cast_metrics_helper.h"
9 #include "content/public/browser/web_contents.h"
10 #include "ipc/ipc_message.h"
12 #if defined(USE_AURA)
13 #include "ui/aura/env.h"
14 #include "ui/aura/layout_manager.h"
15 #include "ui/aura/test/test_focus_client.h"
16 #include "ui/aura/test/test_screen.h"
17 #include "ui/aura/window.h"
18 #include "ui/aura/window_tree_host.h"
19 #endif
21 namespace chromecast {
23 #if defined(USE_AURA)
24 class CastFillLayout : public aura::LayoutManager {
25 public:
26 explicit CastFillLayout(aura::Window* root) : root_(root) {}
27 ~CastFillLayout() override {}
29 private:
30 void OnWindowResized() override {}
32 void OnWindowAddedToLayout(aura::Window* child) override {
33 child->SetBounds(root_->bounds());
36 void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
38 void OnWindowRemovedFromLayout(aura::Window* child) override {}
40 void OnChildWindowVisibilityChanged(aura::Window* child,
41 bool visible) override {}
43 void SetChildBounds(aura::Window* child,
44 const gfx::Rect& requested_bounds) override {
45 SetChildBoundsDirect(child, requested_bounds);
48 aura::Window* root_;
50 DISALLOW_COPY_AND_ASSIGN(CastFillLayout);
52 #endif
54 CastContentWindow::CastContentWindow() {}
56 CastContentWindow::~CastContentWindow() {
57 #if defined(USE_AURA)
58 window_tree_host_.reset();
59 // We don't delete the screen here to avoid a CHECK failure when
60 // the screen size is queried periodically for metric gathering. b/18101124
61 #endif
64 void CastContentWindow::CreateWindowTree(
65 const gfx::Size& initial_size,
66 content::WebContents* web_contents) {
67 #if defined(USE_AURA)
68 // Aura initialization
69 // TODO(lcwu): We only need a minimal implementation of gfx::Screen
70 // and aura's TestScreen will do for us now. We should change to use
71 // ozone's screen implementation when it is ready.
72 gfx::Screen* old_screen =
73 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE);
74 if (!old_screen || old_screen->GetPrimaryDisplay().size() != initial_size) {
75 gfx::Screen* new_screen = aura::TestScreen::Create(initial_size);
76 DCHECK(new_screen) << "New screen not created.";
77 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, new_screen);
78 if (old_screen) {
79 delete old_screen;
82 CHECK(aura::Env::GetInstance());
83 window_tree_host_.reset(
84 aura::WindowTreeHost::Create(gfx::Rect(initial_size)));
85 window_tree_host_->InitHost();
86 window_tree_host_->window()->SetLayoutManager(
87 new CastFillLayout(window_tree_host_->window()));
89 focus_client_.reset(new aura::test::TestFocusClient());
90 aura::client::SetFocusClient(
91 window_tree_host_->window(), focus_client_.get());
93 window_tree_host_->Show();
95 // Add and show content's view/window
96 aura::Window* content_window = web_contents->GetNativeView();
97 aura::Window* parent = window_tree_host_->window();
98 if (!parent->Contains(content_window)) {
99 parent->AddChild(content_window);
101 content_window->Show();
102 #endif
105 scoped_ptr<content::WebContents> CastContentWindow::CreateWebContents(
106 const gfx::Size& initial_size,
107 content::BrowserContext* browser_context) {
108 content::WebContents::CreateParams create_params(browser_context, NULL);
109 create_params.routing_id = MSG_ROUTING_NONE;
110 create_params.initial_size = initial_size;
111 content::WebContents* web_contents = content::WebContents::Create(
112 create_params);
113 content::WebContentsObserver::Observe(web_contents);
114 return make_scoped_ptr(web_contents);
117 void CastContentWindow::DidFirstVisuallyNonEmptyPaint() {
118 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint();
121 } // namespace chromecast