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

Side by Side Diff: headless/lib/browser/headless_browser_impl_aura.cc

Issue 2792883002: Revert of [headless] Use individual aura::WindowTreeHosts per WebContents. (Closed)
Patch Set: Created 3 years, 8 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
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"
10 #include "headless/lib/browser/headless_screen.h" 11 #include "headless/lib/browser/headless_screen.h"
12 #include "ui/aura/client/focus_client.h"
11 #include "ui/aura/env.h" 13 #include "ui/aura/env.h"
12 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
13 #include "ui/base/clipboard/clipboard.h" 15 #include "ui/base/clipboard/clipboard.h"
14 #include "ui/display/screen.h" 16 #include "ui/display/screen.h"
15 #include "ui/events/devices/device_data_manager.h" 17 #include "ui/events/devices/device_data_manager.h"
16 #include "ui/gfx/geometry/size.h" 18 #include "ui/gfx/geometry/size.h"
17 19
18 namespace headless { 20 namespace headless {
19 21
20 void HeadlessBrowserImpl::PlatformInitialize() { 22 void HeadlessBrowserImpl::PlatformInitialize() {
21 HeadlessScreen* screen = HeadlessScreen::Create(options()->window_size); 23 HeadlessScreen* screen = HeadlessScreen::Create(options()->window_size);
22 display::Screen::SetScreenInstance(screen); 24 display::Screen::SetScreenInstance(screen);
23 25
24 // TODO(eseckler): We shouldn't share clipboard contents across WebContents
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
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());
33 } 43 }
34 44
35 void HeadlessBrowserImpl::PlatformInitializeWebContents( 45 void HeadlessBrowserImpl::PlatformInitializeWebContents(
36 const gfx::Size& initial_size, 46 const gfx::Size& initial_size,
37 HeadlessWebContentsImpl* web_contents) { 47 content::WebContents* web_contents) {
38 gfx::Rect initial_rect(initial_size); 48 gfx::NativeView contents = web_contents->GetNativeView();
39 49 gfx::NativeWindow parent_window = window_tree_host_->window();
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();
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(gfx::Rect(initial_size));
53 54
54 content::RenderWidgetHostView* host_view = 55 content::RenderWidgetHostView* host_view =
55 web_contents->web_contents()->GetRenderWidgetHostView(); 56 web_contents->GetRenderWidgetHostView();
56 if (host_view) 57 if (host_view)
57 host_view->SetSize(initial_size); 58 host_view->SetSize(initial_size);
58 } 59 }
59 60
60 } // namespace headless 61 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/browser/headless_browser_impl.h ('k') | headless/lib/browser/headless_browser_impl_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698