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_focus_client.h" | |
11 #include "headless/lib/browser/headless_screen.h" | 10 #include "headless/lib/browser/headless_screen.h" |
12 #include "ui/aura/client/focus_client.h" | |
13 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
14 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
15 #include "ui/base/clipboard/clipboard.h" | 13 #include "ui/base/clipboard/clipboard.h" |
16 #include "ui/display/screen.h" | 14 #include "ui/display/screen.h" |
17 #include "ui/events/devices/device_data_manager.h" | 15 #include "ui/events/devices/device_data_manager.h" |
18 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
19 | 17 |
20 namespace headless { | 18 namespace headless { |
21 | 19 |
22 void HeadlessBrowserImpl::PlatformInitialize() { | 20 void HeadlessBrowserImpl::PlatformInitialize() { |
23 HeadlessScreen* screen = HeadlessScreen::Create(options()->window_size); | 21 HeadlessScreen* screen = HeadlessScreen::Create(options()->window_size); |
24 display::Screen::SetScreenInstance(screen); | 22 display::Screen::SetScreenInstance(screen); |
25 | 23 |
24 // TODO(eseckler): We shouldn't share clipboard contents across WebContents | |
25 // (or at least BrowserContexts). | |
Sami
2017/03/31 17:53:51
N.B. this might be tricky to pull off -- after all
| |
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 | |
34 window_tree_host_.reset( | |
35 new HeadlessWindowTreeHost(gfx::Rect(options()->window_size))); | |
36 window_tree_host_->InitHost(); | |
37 window_tree_host_->window()->Show(); | |
38 window_tree_host_->SetParentWindow(window_tree_host_->window()); | |
39 | |
40 focus_client_.reset(new HeadlessFocusClient()); | |
41 aura::client::SetFocusClient(window_tree_host_->window(), | |
42 focus_client_.get()); | |
43 } | 33 } |
44 | 34 |
45 void HeadlessBrowserImpl::PlatformInitializeWebContents( | 35 void HeadlessBrowserImpl::PlatformInitializeWebContents( |
46 const gfx::Size& initial_size, | 36 const gfx::Size& initial_size, |
47 content::WebContents* web_contents) { | 37 HeadlessWebContentsImpl* web_contents) { |
48 gfx::NativeView contents = web_contents->GetNativeView(); | 38 gfx::Rect initial_rect(initial_size); |
49 gfx::NativeWindow parent_window = window_tree_host_->window(); | 39 |
40 auto window_tree_host = | |
41 base::MakeUnique<HeadlessWindowTreeHost>(initial_rect); | |
42 window_tree_host->InitHost(); | |
43 gfx::NativeWindow parent_window = window_tree_host->window(); | |
44 parent_window->Show(); | |
45 window_tree_host->SetParentWindow(parent_window); | |
46 web_contents->set_window_tree_host(std::move(window_tree_host)); | |
47 | |
48 gfx::NativeView contents = web_contents->web_contents()->GetNativeView(); | |
50 DCHECK(!parent_window->Contains(contents)); | 49 DCHECK(!parent_window->Contains(contents)); |
51 parent_window->AddChild(contents); | 50 parent_window->AddChild(contents); |
52 contents->Show(); | 51 contents->Show(); |
53 contents->SetBounds(gfx::Rect(initial_size)); | 52 contents->SetBounds(initial_rect); |
54 | 53 |
55 content::RenderWidgetHostView* host_view = | 54 content::RenderWidgetHostView* host_view = |
56 web_contents->GetRenderWidgetHostView(); | 55 web_contents->web_contents()->GetRenderWidgetHostView(); |
57 if (host_view) | 56 if (host_view) |
58 host_view->SetSize(initial_size); | 57 host_view->SetSize(initial_size); |
59 } | 58 } |
60 | 59 |
61 } // namespace headless | 60 } // namespace headless |
OLD | NEW |