blob: 1831839cda1d65850d02e40d1294c993735708ed [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2020 The Chromium Authors
danakjde3e2a02020-05-12 16:51:202// 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
Lei Zhangd4f2c7ad2021-05-13 20:10:127#include "base/containers/contains.h"
danakja0bce4c952020-05-12 20:40:288#include "content/public/browser/render_widget_host_view.h"
danakjde3e2a02020-05-12 16:51:209#include "content/public/browser/web_contents.h"
10#include "content/shell/browser/shell.h"
11#include "content/shell/browser/shell_platform_data_aura.h"
12#include "ui/aura/env.h"
13#include "ui/aura/window.h"
14#include "ui/aura/window_event_dispatcher.h"
15
16namespace content {
17
18struct ShellPlatformDelegate::ShellData {
19 gfx::NativeWindow window;
20};
21
22struct ShellPlatformDelegate::PlatformData {
23 std::unique_ptr<ShellPlatformDataAura> aura;
24};
25
26ShellPlatformDelegate::ShellPlatformDelegate() = default;
27ShellPlatformDelegate::~ShellPlatformDelegate() = default;
28
danakjd4b48df52020-07-02 18:16:4829ShellPlatformDataAura* ShellPlatformDelegate::GetShellPlatformDataAura() {
30 return platform_->aura.get();
31}
32
danakjde3e2a02020-05-12 16:51:2033void ShellPlatformDelegate::Initialize(const gfx::Size& default_window_size) {
34 platform_ = std::make_unique<PlatformData>();
35 platform_->aura =
36 std::make_unique<ShellPlatformDataAura>(default_window_size);
37}
38
39void ShellPlatformDelegate::CreatePlatformWindow(
40 Shell* shell,
41 const gfx::Size& initial_size) {
danakj24577b12020-05-13 22:38:1842 DCHECK(!base::Contains(shell_data_map_, shell));
43 ShellData& shell_data = shell_data_map_[shell];
danakjde3e2a02020-05-12 16:51:2044
danakjde3e2a02020-05-12 16:51:2045 platform_->aura->ResizeWindow(initial_size);
46
danakj24577b12020-05-13 22:38:1847 shell_data.window = platform_->aura->host()->window();
danakjde3e2a02020-05-12 16:51:2048}
49
50gfx::NativeWindow ShellPlatformDelegate::GetNativeWindow(Shell* shell) {
danakj24577b12020-05-13 22:38:1851 DCHECK(base::Contains(shell_data_map_, shell));
52 ShellData& shell_data = shell_data_map_[shell];
53 return shell_data.window;
danakjde3e2a02020-05-12 16:51:2054}
55
56void ShellPlatformDelegate::CleanUp(Shell* shell) {
danakj24577b12020-05-13 22:38:1857 DCHECK(base::Contains(shell_data_map_, shell));
58 shell_data_map_.erase(shell);
danakjde3e2a02020-05-12 16:51:2059}
60
61void ShellPlatformDelegate::SetContents(Shell* shell) {
62 aura::Window* content = shell->web_contents()->GetNativeView();
63 aura::Window* parent = platform_->aura->host()->window();
64 if (!parent->Contains(content))
65 parent->AddChild(content);
66
67 content->Show();
68}
69
danakja0bce4c952020-05-12 20:40:2870void ShellPlatformDelegate::ResizeWebContent(Shell* shell,
71 const gfx::Size& content_size) {
72 shell->web_contents()->GetRenderWidgetHostView()->SetSize(content_size);
73}
74
danakjde3e2a02020-05-12 16:51:2075void ShellPlatformDelegate::EnableUIControl(Shell* shell,
76 UIControl control,
77 bool is_enabled) {}
78
79void ShellPlatformDelegate::SetAddressBarURL(Shell* shell, const GURL& url) {}
80
81void ShellPlatformDelegate::SetIsLoading(Shell* shell, bool loading) {}
82
83void ShellPlatformDelegate::SetTitle(Shell* shell,
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:5884 const std::u16string& title) {}
danakjde3e2a02020-05-12 16:51:2085
danakj3dd7a6102020-12-30 19:58:3986void ShellPlatformDelegate::MainFrameCreated(Shell* shell) {}
danakj24577b12020-05-13 22:38:1887
danakjde3e2a02020-05-12 16:51:2088bool ShellPlatformDelegate::DestroyShell(Shell* shell) {
89 return false; // Shell destroys itself.
90}
91
92} // namespace content