blob: c73b67fd18b113ecd32564f2f652aa30a1a723de [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"
danakjde3e2a02020-05-12 16:51:2012#include "build/build_config.h"
13#include "ui/gfx/geometry/size.h"
14#include "ui/gfx/native_widget_types.h"
15
Xiaohan Wangbd084422022-01-15 18:47:5116#if BUILDFLAG(IS_MAC)
danakjde3e2a02020-05-12 16:51:2017#include "content/public/browser/native_web_keyboard_event.h"
Dave Tapuska1f7929c2023-02-03 18:11:5618#endif
19
20#if BUILDFLAG(IS_APPLE)
Mitsuru Oshimac0a03202022-08-09 12:04:5621#include "ui/display/screen.h"
danakjde3e2a02020-05-12 16:51:2022#endif
23
24class GURL;
25
26namespace content {
danakj8de3b7492020-07-02 22:41:4227class JavaScriptDialogManager;
danakjde3e2a02020-05-12 16:51:2028class Shell;
danakjd4b48df52020-07-02 18:16:4829class ShellPlatformDataAura;
danakjde3e2a02020-05-12 16:51:2030class WebContents;
31
32class ShellPlatformDelegate {
33 public:
34 enum UIControl { BACK_BUTTON, FORWARD_BUTTON, STOP_BUTTON };
35
danakjde3e2a02020-05-12 16:51:2036 ShellPlatformDelegate();
37 virtual ~ShellPlatformDelegate();
38
39 // Helper for one time initialization of application.
40 virtual void Initialize(const gfx::Size& default_window_size);
41
42 // Called after creating a Shell instance, with its initial size.
43 virtual void CreatePlatformWindow(Shell* shell,
44 const gfx::Size& initial_size);
45
danakj8de3b7492020-07-02 22:41:4246 // Notifies of a top-level or nested web contents being created for, or
47 // attached to, the Shell.
48 virtual void DidCreateOrAttachWebContents(Shell* shell,
49 WebContents* web_contents);
50
danakjde3e2a02020-05-12 16:51:2051 // Called from the Shell destructor to let each platform do any necessary
52 // cleanup.
53 virtual void CleanUp(Shell* shell);
54
arthursonzogni75ede192021-07-06 14:45:4655 // Called from the Shell destructor after destroying the last one. This is
56 // usually a good time to call Shell::Shutdown().
57 virtual void DidCloseLastWindow();
58
danakjde3e2a02020-05-12 16:51:2059 // Links the WebContents into the newly created window.
60 virtual void SetContents(Shell* shell);
61
danakja0bce4c952020-05-12 20:40:2862 // Resize the web contents in the shell window to the given size.
danakj24577b12020-05-13 22:38:1863 virtual void ResizeWebContent(Shell* shell, const gfx::Size& content_size);
danakja0bce4c952020-05-12 20:40:2864
danakjde3e2a02020-05-12 16:51:2065 // Enable/disable a button.
66 virtual void EnableUIControl(Shell* shell,
67 UIControl control,
68 bool is_enabled);
69
70 // Updates the url in the url bar.
71 virtual void SetAddressBarURL(Shell* shell, const GURL& url);
72
73 // Sets whether the spinner is spinning.
74 virtual void SetIsLoading(Shell* shell, bool loading);
75
76 // Set the title of shell window
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:5877 virtual void SetTitle(Shell* shell, const std::u16string& title);
danakjde3e2a02020-05-12 16:51:2078
danakj3dd7a6102020-12-30 19:58:3979 // Called when the main frame is created in the renderer process; forwarded
80 // from WebContentsObserver. If navigation creates a new main frame, this may
81 // occur more than once.
82 virtual void MainFrameCreated(Shell* shell);
danakj24577b12020-05-13 22:38:1883
danakj8de3b7492020-07-02 22:41:4284 // Allows platforms to override the JavascriptDialogManager. By default
85 // returns null, which signals that the Shell should use its own instance.
86 virtual std::unique_ptr<JavaScriptDialogManager>
87 CreateJavaScriptDialogManager(Shell* shell);
88
Dave Tapuskab4998782020-10-08 17:22:4789 // Requests handling of locking the mouse. This returns true if the request
90 // has been handled, otherwise false.
91 virtual bool HandleRequestToLockMouse(Shell* shell,
92 WebContents* web_contents,
93 bool user_gesture,
94 bool last_unlocked_by_target);
95
danakj8de3b7492020-07-02 22:41:4296 // Allows platforms to prevent running insecure content. By default returns
97 // false, only allowing what Shell allows on its own.
98 virtual bool ShouldAllowRunningInsecureContent(Shell* shell);
99
danakjde3e2a02020-05-12 16:51:20100 // Destroy the Shell. Returns true if the ShellPlatformDelegate did the
101 // destruction. Returns false if the Shell should destroy itself.
102 virtual bool DestroyShell(Shell* shell);
103
Xiaohan Wangbd084422022-01-15 18:47:51104#if !BUILDFLAG(IS_ANDROID)
danakjde3e2a02020-05-12 16:51:20105 // Returns the native window. Valid after calling CreatePlatformWindow().
106 virtual gfx::NativeWindow GetNativeWindow(Shell* shell);
107#endif
108
Xiaohan Wangbd084422022-01-15 18:47:51109#if BUILDFLAG(IS_MAC)
danakjde3e2a02020-05-12 16:51:20110 // Activate (make key) the native window, and focus the web contents.
111 virtual void ActivateContents(Shell* shell, WebContents* contents);
112
Liviu Tinta40904052021-07-20 15:12:52113 virtual void DidNavigatePrimaryMainFramePostCommit(Shell* shell,
114 WebContents* contents);
Xianzhu Wang0f021a82020-07-03 01:29:47115
danakjde3e2a02020-05-12 16:51:20116 virtual bool HandleKeyboardEvent(Shell* shell,
117 WebContents* source,
118 const NativeWebKeyboardEvent& event);
119#endif
120
Xiaohan Wangbd084422022-01-15 18:47:51121#if BUILDFLAG(IS_ANDROID)
danakjde3e2a02020-05-12 16:51:20122 void ToggleFullscreenModeForTab(Shell* shell,
123 WebContents* web_contents,
124 bool enter_fullscreen);
125
126 bool IsFullscreenForTabOrPending(Shell* shell,
127 const WebContents* web_contents) const;
128
129 // Forwarded from WebContentsDelegate.
130 void SetOverlayMode(Shell* shell, bool use_overlay_mode);
131
132 // Forwarded from WebContentsObserver.
133 void LoadProgressChanged(Shell* shell, double progress);
134#endif
135
danakjd4b48df52020-07-02 18:16:48136 protected:
danakj2957b0642021-06-11 18:18:04137#if defined(USE_AURA) && !defined(SHELL_USE_TOOLKIT_VIEWS)
danakjd4b48df52020-07-02 18:16:48138 // Helper to avoid duplicating aura's ShellPlatformDelegate in web tests. If
139 // this hack gets expanded to become more expansive then we should just
140 // duplicate the aura ShellPlatformDelegate code to the web test code impl in
141 // WebTestShellPlatformDelegate.
142 ShellPlatformDataAura* GetShellPlatformDataAura();
143#endif
144
danakjde3e2a02020-05-12 16:51:20145 private:
Dave Tapuska1f7929c2023-02-03 18:11:56146#if BUILDFLAG(IS_APPLE)
Mitsuru Oshimac0a03202022-08-09 12:04:56147 std::unique_ptr<display::ScopedNativeScreen> screen_;
148#endif
danakj24577b12020-05-13 22:38:18149 // Data held for each Shell instance, since there is one ShellPlatformDelegate
150 // for the whole browser process (shared across Shells). This is defined for
151 // each platform implementation.
152 struct ShellData;
danakj24577b12020-05-13 22:38:18153 // Holds an instance of ShellData for each Shell.
154 base::flat_map<Shell*, ShellData> shell_data_map_;
155
danakjde3e2a02020-05-12 16:51:20156 // Data held in ShellPlatformDelegate that is shared between all Shells. This
157 // is created in Initialize(), and is defined for each platform
158 // implementation.
159 struct PlatformData;
160 std::unique_ptr<PlatformData> platform_;
161};
162
163} // namespace content
164
165#endif // CONTENT_SHELL_BROWSER_SHELL_PLATFORM_DELEGATE_H_