Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 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 | |
Lei Zhang | d4f2c7ad | 2021-05-13 20:10:12 | [diff] [blame] | 7 | #include "base/containers/contains.h" |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 8 | #include "content/public/browser/render_widget_host_view.h" |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 9 | #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 | |
| 16 | namespace content { |
| 17 | |
| 18 | struct ShellPlatformDelegate::ShellData { |
| 19 | gfx::NativeWindow window; |
| 20 | }; |
| 21 | |
| 22 | struct ShellPlatformDelegate::PlatformData { |
| 23 | std::unique_ptr<ShellPlatformDataAura> aura; |
| 24 | }; |
| 25 | |
| 26 | ShellPlatformDelegate::ShellPlatformDelegate() = default; |
| 27 | ShellPlatformDelegate::~ShellPlatformDelegate() = default; |
| 28 | |
danakj | d4b48df5 | 2020-07-02 18:16:48 | [diff] [blame] | 29 | ShellPlatformDataAura* ShellPlatformDelegate::GetShellPlatformDataAura() { |
| 30 | return platform_->aura.get(); |
| 31 | } |
| 32 | |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 33 | void 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 | |
| 39 | void ShellPlatformDelegate::CreatePlatformWindow( |
| 40 | Shell* shell, |
| 41 | const gfx::Size& initial_size) { |
danakj | 24577b1 | 2020-05-13 22:38:18 | [diff] [blame] | 42 | DCHECK(!base::Contains(shell_data_map_, shell)); |
| 43 | ShellData& shell_data = shell_data_map_[shell]; |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 44 | |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 45 | platform_->aura->ResizeWindow(initial_size); |
| 46 | |
danakj | 24577b1 | 2020-05-13 22:38:18 | [diff] [blame] | 47 | shell_data.window = platform_->aura->host()->window(); |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | gfx::NativeWindow ShellPlatformDelegate::GetNativeWindow(Shell* shell) { |
danakj | 24577b1 | 2020-05-13 22:38:18 | [diff] [blame] | 51 | DCHECK(base::Contains(shell_data_map_, shell)); |
| 52 | ShellData& shell_data = shell_data_map_[shell]; |
| 53 | return shell_data.window; |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void ShellPlatformDelegate::CleanUp(Shell* shell) { |
danakj | 24577b1 | 2020-05-13 22:38:18 | [diff] [blame] | 57 | DCHECK(base::Contains(shell_data_map_, shell)); |
| 58 | shell_data_map_.erase(shell); |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void 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 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 70 | void ShellPlatformDelegate::ResizeWebContent(Shell* shell, |
| 71 | const gfx::Size& content_size) { |
| 72 | shell->web_contents()->GetRenderWidgetHostView()->SetSize(content_size); |
| 73 | } |
| 74 | |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 75 | void ShellPlatformDelegate::EnableUIControl(Shell* shell, |
| 76 | UIControl control, |
| 77 | bool is_enabled) {} |
| 78 | |
| 79 | void ShellPlatformDelegate::SetAddressBarURL(Shell* shell, const GURL& url) {} |
| 80 | |
| 81 | void ShellPlatformDelegate::SetIsLoading(Shell* shell, bool loading) {} |
| 82 | |
| 83 | void ShellPlatformDelegate::SetTitle(Shell* shell, |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 84 | const std::u16string& title) {} |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 85 | |
danakj | 3dd7a610 | 2020-12-30 19:58:39 | [diff] [blame] | 86 | void ShellPlatformDelegate::MainFrameCreated(Shell* shell) {} |
danakj | 24577b1 | 2020-05-13 22:38:18 | [diff] [blame] | 87 | |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 88 | bool ShellPlatformDelegate::DestroyShell(Shell* shell) { |
| 89 | return false; // Shell destroys itself. |
| 90 | } |
| 91 | |
| 92 | } // namespace content |