blob: 61006b9e995d839f559147cad3f3802e43048cec [file] [log] [blame]
danakjde3e2a02020-05-12 16:51:201// 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
danakja0bce4c952020-05-12 20:40:287#include "content/public/browser/render_widget_host_view.h"
danakjde3e2a02020-05-12 16:51:208#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
15namespace content {
16
17struct ShellPlatformDelegate::ShellData {
18 gfx::NativeWindow window;
19};
20
21struct ShellPlatformDelegate::PlatformData {
22 std::unique_ptr<ShellPlatformDataAura> aura;
23};
24
25ShellPlatformDelegate::ShellPlatformDelegate() = default;
26ShellPlatformDelegate::~ShellPlatformDelegate() = default;
27
danakjd4b48df52020-07-02 18:16:4828ShellPlatformDataAura* ShellPlatformDelegate::GetShellPlatformDataAura() {
29 return platform_->aura.get();
30}
31
danakjde3e2a02020-05-12 16:51:2032void 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
38void ShellPlatformDelegate::CreatePlatformWindow(
39 Shell* shell,
40 const gfx::Size& initial_size) {
danakj24577b12020-05-13 22:38:1841 DCHECK(!base::Contains(shell_data_map_, shell));
42 ShellData& shell_data = shell_data_map_[shell];
danakjde3e2a02020-05-12 16:51:2043
danakjde3e2a02020-05-12 16:51:2044 platform_->aura->ResizeWindow(initial_size);
45
danakj24577b12020-05-13 22:38:1846 shell_data.window = platform_->aura->host()->window();
danakjde3e2a02020-05-12 16:51:2047}
48
49gfx::NativeWindow ShellPlatformDelegate::GetNativeWindow(Shell* shell) {
danakj24577b12020-05-13 22:38:1850 DCHECK(base::Contains(shell_data_map_, shell));
51 ShellData& shell_data = shell_data_map_[shell];
52 return shell_data.window;
danakjde3e2a02020-05-12 16:51:2053}
54
55void ShellPlatformDelegate::CleanUp(Shell* shell) {
danakj24577b12020-05-13 22:38:1856 DCHECK(base::Contains(shell_data_map_, shell));
57 shell_data_map_.erase(shell);
danakjde3e2a02020-05-12 16:51:2058}
59
60void 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
danakja0bce4c952020-05-12 20:40:2869void ShellPlatformDelegate::ResizeWebContent(Shell* shell,
70 const gfx::Size& content_size) {
71 shell->web_contents()->GetRenderWidgetHostView()->SetSize(content_size);
72}
73
danakjde3e2a02020-05-12 16:51:2074void ShellPlatformDelegate::EnableUIControl(Shell* shell,
75 UIControl control,
76 bool is_enabled) {}
77
78void ShellPlatformDelegate::SetAddressBarURL(Shell* shell, const GURL& url) {}
79
80void ShellPlatformDelegate::SetIsLoading(Shell* shell, bool loading) {}
81
82void ShellPlatformDelegate::SetTitle(Shell* shell,
83 const base::string16& title) {}
84
danakj3dd7a6102020-12-30 19:58:3985void ShellPlatformDelegate::MainFrameCreated(Shell* shell) {}
danakj24577b12020-05-13 22:38:1886
danakjde3e2a02020-05-12 16:51:2087bool ShellPlatformDelegate::DestroyShell(Shell* shell) {
88 return false; // Shell destroys itself.
89}
90
91} // namespace content