1 // Copyright 2020 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 "content/shell/browser/shell_platform_delegate.h"
6
7 #include "content/public/browser/render_widget_host_view.h"
8 #include "content/public/browser/web_contents.h"
9 #include "content/shell/browser/shell.h"
10 #include "content/shell/browser/shell_platform_data_aura.h"
11 #include "ui/aura/env.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_event_dispatcher.h"
14
15 namespace content {
16
17 struct ShellPlatformDelegate::ShellData {
18 gfx::NativeWindow window;
19 };
20
21 struct ShellPlatformDelegate::PlatformData {
22 std::unique_ptr<ShellPlatformDataAura> aura;
23 };
24
25 ShellPlatformDelegate::ShellPlatformDelegate() = default;
26 ShellPlatformDelegate::~ShellPlatformDelegate() = default;
27
GetShellPlatformDataAura()28 ShellPlatformDataAura* ShellPlatformDelegate::GetShellPlatformDataAura() {
29 return platform_->aura.get();
30 }
31
Initialize(const gfx::Size & default_window_size)32 void ShellPlatformDelegate::Initialize(const gfx::Size& default_window_size) {
33 platform_ = std::make_unique<PlatformData>();
34 platform_->aura =
35 std::make_unique<ShellPlatformDataAura>(default_window_size);
36 }
37
CreatePlatformWindow(Shell * shell,const gfx::Size & initial_size)38 void ShellPlatformDelegate::CreatePlatformWindow(
39 Shell* shell,
40 const gfx::Size& initial_size) {
41 DCHECK(!base::Contains(shell_data_map_, shell));
42 ShellData& shell_data = shell_data_map_[shell];
43
44 platform_->aura->ResizeWindow(initial_size);
45
46 shell_data.window = platform_->aura->host()->window();
47 }
48
GetNativeWindow(Shell * shell)49 gfx::NativeWindow ShellPlatformDelegate::GetNativeWindow(Shell* shell) {
50 DCHECK(base::Contains(shell_data_map_, shell));
51 ShellData& shell_data = shell_data_map_[shell];
52 return shell_data.window;
53 }
54
CleanUp(Shell * shell)55 void ShellPlatformDelegate::CleanUp(Shell* shell) {
56 DCHECK(base::Contains(shell_data_map_, shell));
57 shell_data_map_.erase(shell);
58 }
59
SetContents(Shell * shell)60 void ShellPlatformDelegate::SetContents(Shell* shell) {
61 aura::Window* content = shell->web_contents()->GetNativeView();
62 aura::Window* parent = platform_->aura->host()->window();
63 if (!parent->Contains(content))
64 parent->AddChild(content);
65
66 content->Show();
67 }
68
ResizeWebContent(Shell * shell,const gfx::Size & content_size)69 void ShellPlatformDelegate::ResizeWebContent(Shell* shell,
70 const gfx::Size& content_size) {
71 shell->web_contents()->GetRenderWidgetHostView()->SetSize(content_size);
72 }
73
EnableUIControl(Shell * shell,UIControl control,bool is_enabled)74 void ShellPlatformDelegate::EnableUIControl(Shell* shell,
75 UIControl control,
76 bool is_enabled) {}
77
SetAddressBarURL(Shell * shell,const GURL & url)78 void ShellPlatformDelegate::SetAddressBarURL(Shell* shell, const GURL& url) {}
79
SetIsLoading(Shell * shell,bool loading)80 void ShellPlatformDelegate::SetIsLoading(Shell* shell, bool loading) {}
81
SetTitle(Shell * shell,const base::string16 & title)82 void ShellPlatformDelegate::SetTitle(Shell* shell,
83 const base::string16& title) {}
84
RenderViewReady(Shell * shell)85 void ShellPlatformDelegate::RenderViewReady(Shell* shell) {}
86
DestroyShell(Shell * shell)87 bool ShellPlatformDelegate::DestroyShell(Shell* shell) {
88 return false; // Shell destroys itself.
89 }
90
91 } // namespace content
92