OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "headless/lib/browser/headless_browser_impl.h" |
| 6 |
| 7 #include "content/public/browser/render_widget_host_view.h" |
| 8 #include "content/public/browser/web_contents.h" |
| 9 #include "headless/lib/browser/headless_screen.h" |
| 10 #include "ui/aura/env.h" |
| 11 #include "ui/aura/window.h" |
| 12 #include "ui/display/screen.h" |
| 13 #include "ui/events/devices/device_data_manager.h" |
| 14 #include "ui/gfx/geometry/size.h" |
| 15 |
| 16 namespace headless { |
| 17 |
| 18 void HeadlessBrowserImpl::PlatformInitialize() { |
| 19 HeadlessScreen* screen = HeadlessScreen::Create(options()->window_size); |
| 20 display::Screen::SetScreenInstance(screen); |
| 21 } |
| 22 |
| 23 void HeadlessBrowserImpl::PlatformCreateWindow() { |
| 24 DCHECK(aura::Env::GetInstance()); |
| 25 ui::DeviceDataManager::CreateInstance(); |
| 26 |
| 27 window_tree_host_.reset( |
| 28 new HeadlessWindowTreeHost(gfx::Rect(options()->window_size))); |
| 29 window_tree_host_->InitHost(); |
| 30 window_tree_host_->window()->Show(); |
| 31 window_tree_host_->SetParentWindow(window_tree_host_->window()); |
| 32 } |
| 33 |
| 34 void HeadlessBrowserImpl::PlatformSetWebContents( |
| 35 const gfx::Size& initial_size, |
| 36 content::WebContents* web_contents) { |
| 37 gfx::NativeView contents = web_contents->GetNativeView(); |
| 38 gfx::NativeWindow parent_window = window_tree_host_->window(); |
| 39 DCHECK(!parent_window->Contains(contents)); |
| 40 parent_window->AddChild(contents); |
| 41 contents->Show(); |
| 42 contents->SetBounds(gfx::Rect(initial_size)); |
| 43 |
| 44 content::RenderWidgetHostView* host_view = |
| 45 web_contents->GetRenderWidgetHostView(); |
| 46 if (host_view) |
| 47 host_view->SetSize(initial_size); |
| 48 } |
| 49 |
| 50 } // namespace headless |
OLD | NEW |