OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "headless/lib/browser/headless_browser_impl.h" | 5 #include "headless/lib/browser/headless_browser_impl.h" |
6 | 6 |
7 #include "content/public/browser/render_widget_host_view.h" | 7 #include "content/public/browser/render_widget_host_view.h" |
8 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
9 #include "headless/lib/browser/headless_clipboard.h" | 9 #include "headless/lib/browser/headless_clipboard.h" |
10 #include "headless/lib/browser/headless_screen.h" | 10 #include "headless/lib/browser/headless_screen.h" |
11 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
13 #include "ui/base/clipboard/clipboard.h" | 13 #include "ui/base/clipboard/clipboard.h" |
14 #include "ui/display/screen.h" | 14 #include "ui/display/screen.h" |
15 #include "ui/events/devices/device_data_manager.h" | 15 #include "ui/events/devices/device_data_manager.h" |
16 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
17 | 17 |
18 namespace headless { | 18 namespace headless { |
19 | 19 |
20 void HeadlessBrowserImpl::PlatformInitialize() { | 20 void HeadlessBrowserImpl::PlatformInitialize() { |
21 HeadlessScreen* screen = HeadlessScreen::Create(options()->window_size); | 21 HeadlessScreen* screen = HeadlessScreen::Create(options()->screen_size); |
22 display::Screen::SetScreenInstance(screen); | 22 display::Screen::SetScreenInstance(screen); |
23 | 23 |
24 // TODO(eseckler): We shouldn't share clipboard contents across WebContents | 24 // TODO(eseckler): We shouldn't share clipboard contents across WebContents |
25 // (or at least BrowserContexts). | 25 // (or at least BrowserContexts). |
26 ui::Clipboard::SetClipboardForCurrentThread( | 26 ui::Clipboard::SetClipboardForCurrentThread( |
27 base::MakeUnique<HeadlessClipboard>()); | 27 base::MakeUnique<HeadlessClipboard>()); |
28 } | 28 } |
29 | 29 |
30 void HeadlessBrowserImpl::PlatformCreateWindow() { | 30 void HeadlessBrowserImpl::PlatformCreateWindow() { |
31 DCHECK(aura::Env::GetInstance()); | 31 DCHECK(aura::Env::GetInstance()); |
32 ui::DeviceDataManager::CreateInstance(); | 32 ui::DeviceDataManager::CreateInstance(); |
33 } | 33 } |
34 | 34 |
35 void HeadlessBrowserImpl::PlatformInitializeWebContents( | 35 void HeadlessBrowserImpl::PlatformInitializeWebContents( |
36 const gfx::Size& initial_size, | 36 const gfx::Size& initial_window_size, |
37 const gfx::Size& screen_size, | |
37 HeadlessWebContentsImpl* web_contents) { | 38 HeadlessWebContentsImpl* web_contents) { |
38 gfx::Rect initial_rect(initial_size); | 39 gfx::Rect initial_rect(initial_window_size); |
39 | 40 |
40 auto window_tree_host = | 41 auto window_tree_host = |
41 base::MakeUnique<HeadlessWindowTreeHost>(initial_rect); | 42 base::MakeUnique<HeadlessWindowTreeHost>(initial_rect); |
42 window_tree_host->InitHost(); | 43 window_tree_host->InitHost(); |
43 gfx::NativeWindow parent_window = window_tree_host->window(); | 44 gfx::NativeWindow parent_window = window_tree_host->window(); |
44 parent_window->Show(); | 45 parent_window->Show(); |
45 window_tree_host->SetParentWindow(parent_window); | 46 window_tree_host->SetParentWindow(parent_window); |
46 web_contents->set_window_tree_host(std::move(window_tree_host)); | 47 web_contents->set_window_tree_host(std::move(window_tree_host)); |
47 | 48 |
48 gfx::NativeView contents = web_contents->web_contents()->GetNativeView(); | 49 gfx::NativeView contents = web_contents->web_contents()->GetNativeView(); |
49 DCHECK(!parent_window->Contains(contents)); | 50 DCHECK(!parent_window->Contains(contents)); |
50 parent_window->AddChild(contents); | 51 parent_window->AddChild(contents); |
51 contents->Show(); | 52 contents->Show(); |
52 contents->SetBounds(initial_rect); | 53 contents->SetBounds(initial_rect); |
53 | 54 |
54 content::RenderWidgetHostView* host_view = | 55 content::RenderWidgetHostView* host_view = |
55 web_contents->web_contents()->GetRenderWidgetHostView(); | 56 web_contents->web_contents()->GetRenderWidgetHostView(); |
56 if (host_view) | 57 if (host_view) |
57 host_view->SetSize(initial_size); | 58 host_view->SetSize(screen_size); |
Eric Seckler
2017/05/22 19:13:40
Hm, I don't quite understand screen_size. - Why do
| |
58 } | 59 } |
59 | 60 |
60 } // namespace headless | 61 } // namespace headless |
OLD | NEW |