blob: ef6ec51152404cf46c596b84f680c1cc44dba2a7 [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#ifndef CONTENT_SHELL_BROWSER_SHELL_PLATFORM_DELEGATE_H_
6#define CONTENT_SHELL_BROWSER_SHELL_PLATFORM_DELEGATE_H_
7
Piotr Tworek21c18ed52020-05-18 14:30:298#include <memory>
Jan Wilken Dörriead587c32021-03-11 14:09:279#include <string>
Piotr Tworek21c18ed52020-05-18 14:30:2910
danakj24577b12020-05-13 22:38:1811#include "base/containers/flat_map.h"
Julie Jeongeun Kimec508272023-03-17 04:17:1212#include "base/memory/scoped_refptr.h"
danakjde3e2a02020-05-12 16:51:2013#include "build/build_config.h"
Julie Jeongeun Kim88ce9ec2023-07-28 02:25:4014#include "third_party/blink/public/mojom/choosers/color_chooser.mojom-forward.h"
Julie Jeongeun Kimec508272023-03-17 04:17:1215#include "third_party/blink/public/mojom/choosers/file_chooser.mojom-forward.h"
Julie Jeongeun Kim88ce9ec2023-07-28 02:25:4016#include "third_party/skia/include/core/SkColor.h"
danakjde3e2a02020-05-12 16:51:2017#include "ui/gfx/geometry/size.h"
18#include "ui/gfx/native_widget_types.h"
19
Xiaohan Wangbd084422022-01-15 18:47:5120#if BUILDFLAG(IS_MAC)
Kartar Singh746606522024-05-29 09:34:3021#include "components/input/native_web_keyboard_event.h"
Dave Tapuska1f7929c2023-02-03 18:11:5622#endif
23
24#if BUILDFLAG(IS_APPLE)
Mitsuru Oshimac0a03202022-08-09 12:04:5625#include "ui/display/screen.h"
danakjde3e2a02020-05-12 16:51:2026#endif
27
28class GURL;
29
30namespace content {
Julie Jeongeun Kim88ce9ec2023-07-28 02:25:4031class ColorChooser;
Julie Jeongeun Kimec508272023-03-17 04:17:1232class FileSelectListener;
danakj8de3b7492020-07-02 22:41:4233class JavaScriptDialogManager;
danakjde3e2a02020-05-12 16:51:2034class Shell;
danakjd4b48df52020-07-02 18:16:4835class ShellPlatformDataAura;
Julie Jeongeun Kimec508272023-03-17 04:17:1236class RenderFrameHost;
danakjde3e2a02020-05-12 16:51:2037class WebContents;
38
39class ShellPlatformDelegate {
40 public:
41 enum UIControl { BACK_BUTTON, FORWARD_BUTTON, STOP_BUTTON };
42
danakjde3e2a02020-05-12 16:51:2043 ShellPlatformDelegate();
44 virtual ~ShellPlatformDelegate();
45
46 // Helper for one time initialization of application.
47 virtual void Initialize(const gfx::Size& default_window_size);
48
49 // Called after creating a Shell instance, with its initial size.
50 virtual void CreatePlatformWindow(Shell* shell,
51 const gfx::Size& initial_size);
52
danakj8de3b7492020-07-02 22:41:4253 // Notifies of a top-level or nested web contents being created for, or
54 // attached to, the Shell.
55 virtual void DidCreateOrAttachWebContents(Shell* shell,
56 WebContents* web_contents);
57
danakjde3e2a02020-05-12 16:51:2058 // Called from the Shell destructor to let each platform do any necessary
59 // cleanup.
60 virtual void CleanUp(Shell* shell);
61
arthursonzogni75ede192021-07-06 14:45:4662 // Called from the Shell destructor after destroying the last one. This is
63 // usually a good time to call Shell::Shutdown().
64 virtual void DidCloseLastWindow();
65
danakjde3e2a02020-05-12 16:51:2066 // Links the WebContents into the newly created window.
67 virtual void SetContents(Shell* shell);
68
danakja0bce4c952020-05-12 20:40:2869 // Resize the web contents in the shell window to the given size.
danakj24577b12020-05-13 22:38:1870 virtual void ResizeWebContent(Shell* shell, const gfx::Size& content_size);
danakja0bce4c952020-05-12 20:40:2871
danakjde3e2a02020-05-12 16:51:2072 // Enable/disable a button.
73 virtual void EnableUIControl(Shell* shell,
74 UIControl control,
75 bool is_enabled);
76
77 // Updates the url in the url bar.
78 virtual void SetAddressBarURL(Shell* shell, const GURL& url);
79
80 // Sets whether the spinner is spinning.
81 virtual void SetIsLoading(Shell* shell, bool loading);
82
83 // Set the title of shell window
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:5884 virtual void SetTitle(Shell* shell, const std::u16string& title);
danakjde3e2a02020-05-12 16:51:2085
danakj3dd7a6102020-12-30 19:58:3986 // Called when the main frame is created in the renderer process; forwarded
87 // from WebContentsObserver. If navigation creates a new main frame, this may
88 // occur more than once.
89 virtual void MainFrameCreated(Shell* shell);
danakj24577b12020-05-13 22:38:1890
danakj8de3b7492020-07-02 22:41:4291 // Allows platforms to override the JavascriptDialogManager. By default
92 // returns null, which signals that the Shell should use its own instance.
93 virtual std::unique_ptr<JavaScriptDialogManager>
94 CreateJavaScriptDialogManager(Shell* shell);
95
Takumi Fujimoto4661871d2024-01-25 02:04:1896 // Requests handling of locking the mouse pointer. This returns true if the
97 // request has been handled, otherwise false.
98 virtual bool HandlePointerLockRequest(Shell* shell,
Dave Tapuskab4998782020-10-08 17:22:4799 WebContents* web_contents,
100 bool user_gesture,
101 bool last_unlocked_by_target);
102
danakj8de3b7492020-07-02 22:41:42103 // Allows platforms to prevent running insecure content. By default returns
104 // false, only allowing what Shell allows on its own.
105 virtual bool ShouldAllowRunningInsecureContent(Shell* shell);
106
danakjde3e2a02020-05-12 16:51:20107 // Destroy the Shell. Returns true if the ShellPlatformDelegate did the
108 // destruction. Returns false if the Shell should destroy itself.
109 virtual bool DestroyShell(Shell* shell);
110
Julie Jeongeun Kim88ce9ec2023-07-28 02:25:40111 // Called when color chooser should open. Returns the opened color chooser.
112 // Returns nullptr if we failed to open the color chooser. The color chooser
113 // is supported/required for Android or iOS.
114 virtual std::unique_ptr<ColorChooser> OpenColorChooser(
115 WebContents* web_contents,
116 SkColor color,
117 const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions);
118
Julie Jeongeun Kimec508272023-03-17 04:17:12119 // Called when a file selection is to be done.
120 // This function is responsible for calling listener->FileSelected() or
121 // listener->FileSelectionCanceled().
122 virtual void RunFileChooser(RenderFrameHost* render_frame_host,
123 scoped_refptr<FileSelectListener> listener,
124 const blink::mojom::FileChooserParams& params);
125
Xiaohan Wangbd084422022-01-15 18:47:51126#if !BUILDFLAG(IS_ANDROID)
danakjde3e2a02020-05-12 16:51:20127 // Returns the native window. Valid after calling CreatePlatformWindow().
128 virtual gfx::NativeWindow GetNativeWindow(Shell* shell);
129#endif
130
Xiaohan Wangbd084422022-01-15 18:47:51131#if BUILDFLAG(IS_MAC)
danakjde3e2a02020-05-12 16:51:20132 // Activate (make key) the native window, and focus the web contents.
133 virtual void ActivateContents(Shell* shell, WebContents* contents);
134
Liviu Tinta40904052021-07-20 15:12:52135 virtual void DidNavigatePrimaryMainFramePostCommit(Shell* shell,
136 WebContents* contents);
Xianzhu Wang0f021a82020-07-03 01:29:47137
danakjde3e2a02020-05-12 16:51:20138 virtual bool HandleKeyboardEvent(Shell* shell,
139 WebContents* source,
Kartar Singh5c8e0b22024-05-30 10:32:14140 const input::NativeWebKeyboardEvent& event);
danakjde3e2a02020-05-12 16:51:20141#endif
142
Dave Tapuska1efc3012023-02-23 17:27:17143#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
danakjde3e2a02020-05-12 16:51:20144 void ToggleFullscreenModeForTab(Shell* shell,
145 WebContents* web_contents,
146 bool enter_fullscreen);
147
148 bool IsFullscreenForTabOrPending(Shell* shell,
149 const WebContents* web_contents) const;
Dave Tapuska1efc3012023-02-23 17:27:17150#endif
danakjde3e2a02020-05-12 16:51:20151
Dave Tapuska1efc3012023-02-23 17:27:17152#if BUILDFLAG(IS_ANDROID)
danakjde3e2a02020-05-12 16:51:20153 // Forwarded from WebContentsDelegate.
154 void SetOverlayMode(Shell* shell, bool use_overlay_mode);
155
156 // Forwarded from WebContentsObserver.
157 void LoadProgressChanged(Shell* shell, double progress);
158#endif
159
danakjd4b48df52020-07-02 18:16:48160 protected:
danakj2957b0642021-06-11 18:18:04161#if defined(USE_AURA) && !defined(SHELL_USE_TOOLKIT_VIEWS)
danakjd4b48df52020-07-02 18:16:48162 // Helper to avoid duplicating aura's ShellPlatformDelegate in web tests. If
163 // this hack gets expanded to become more expansive then we should just
164 // duplicate the aura ShellPlatformDelegate code to the web test code impl in
165 // WebTestShellPlatformDelegate.
166 ShellPlatformDataAura* GetShellPlatformDataAura();
167#endif
168
danakjde3e2a02020-05-12 16:51:20169 private:
Dave Tapuska1f7929c2023-02-03 18:11:56170#if BUILDFLAG(IS_APPLE)
Mitsuru Oshimac0a03202022-08-09 12:04:56171 std::unique_ptr<display::ScopedNativeScreen> screen_;
172#endif
danakj24577b12020-05-13 22:38:18173 // Data held for each Shell instance, since there is one ShellPlatformDelegate
174 // for the whole browser process (shared across Shells). This is defined for
175 // each platform implementation.
176 struct ShellData;
danakj24577b12020-05-13 22:38:18177 // Holds an instance of ShellData for each Shell.
178 base::flat_map<Shell*, ShellData> shell_data_map_;
179
danakjde3e2a02020-05-12 16:51:20180 // Data held in ShellPlatformDelegate that is shared between all Shells. This
181 // is created in Initialize(), and is defined for each platform
182 // implementation.
183 struct PlatformData;
184 std::unique_ptr<PlatformData> platform_;
185};
186
187} // namespace content
188
189#endif // CONTENT_SHELL_BROWSER_SHELL_PLATFORM_DELEGATE_H_