danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 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 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7 | #include "content/public/browser/render_widget_host_view.h" |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 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 | |
danakj | d4b48df5 | 2020-07-02 18:16:48 | [diff] [blame] | 28 | ShellPlatformDataAura* ShellPlatformDelegate::GetShellPlatformDataAura() { |
| 29 | return platform_->aura.get(); |
| 30 | } |
| 31 | |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 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 | |
| 38 | void ShellPlatformDelegate::CreatePlatformWindow( |
| 39 | Shell* shell, |
| 40 | const gfx::Size& initial_size) { |
danakj | 24577b1 | 2020-05-13 22:38:18 | [diff] [blame] | 41 | DCHECK(!base::Contains(shell_data_map_, shell)); |
| 42 | ShellData& shell_data = shell_data_map_[shell]; |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 43 | |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 44 | platform_->aura->ResizeWindow(initial_size); |
| 45 | |
danakj | 24577b1 | 2020-05-13 22:38:18 | [diff] [blame] | 46 | shell_data.window = platform_->aura->host()->window(); |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | gfx::NativeWindow ShellPlatformDelegate::GetNativeWindow(Shell* shell) { |
danakj | 24577b1 | 2020-05-13 22:38:18 | [diff] [blame] | 50 | DCHECK(base::Contains(shell_data_map_, shell)); |
| 51 | ShellData& shell_data = shell_data_map_[shell]; |
| 52 | return shell_data.window; |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void ShellPlatformDelegate::CleanUp(Shell* shell) { |
danakj | 24577b1 | 2020-05-13 22:38:18 | [diff] [blame] | 56 | DCHECK(base::Contains(shell_data_map_, shell)); |
| 57 | shell_data_map_.erase(shell); |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 58 | } |
| 59 | |
| 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 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 69 | void ShellPlatformDelegate::ResizeWebContent(Shell* shell, |
| 70 | const gfx::Size& content_size) { |
| 71 | shell->web_contents()->GetRenderWidgetHostView()->SetSize(content_size); |
| 72 | } |
| 73 | |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 74 | void ShellPlatformDelegate::EnableUIControl(Shell* shell, |
| 75 | UIControl control, |
| 76 | bool is_enabled) {} |
| 77 | |
| 78 | void ShellPlatformDelegate::SetAddressBarURL(Shell* shell, const GURL& url) {} |
| 79 | |
| 80 | void ShellPlatformDelegate::SetIsLoading(Shell* shell, bool loading) {} |
| 81 | |
| 82 | void ShellPlatformDelegate::SetTitle(Shell* shell, |
| 83 | const base::string16& title) {} |
| 84 | |
danakj | 3dd7a610 | 2020-12-30 19:58:39 | [diff] [blame^] | 85 | void ShellPlatformDelegate::MainFrameCreated(Shell* shell) {} |
danakj | 24577b1 | 2020-05-13 22:38:18 | [diff] [blame] | 86 | |
danakj | de3e2a0 | 2020-05-12 16:51:20 | [diff] [blame] | 87 | bool ShellPlatformDelegate::DestroyShell(Shell* shell) { |
| 88 | return false; // Shell destroys itself. |
| 89 | } |
| 90 | |
| 91 | } // namespace content |