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 #ifndef CONTENT_WEB_TEST_BROWSER_WEB_TEST_SHELL_PLATFORM_DELEGATE_H_ 6 #define CONTENT_WEB_TEST_BROWSER_WEB_TEST_SHELL_PLATFORM_DELEGATE_H_ 7 8 #include "build/build_config.h" 9 #include "content/shell/browser/shell_platform_delegate.h" 10 11 namespace content { 12 13 class WebTestShellPlatformDelegate : public ShellPlatformDelegate { 14 public: 15 WebTestShellPlatformDelegate(); 16 ~WebTestShellPlatformDelegate() override; 17 18 // ShellPlatformDelegate overrides. 19 void Initialize(const gfx::Size& default_window_size) override; 20 void CreatePlatformWindow(Shell* shell, 21 const gfx::Size& initial_size) override; 22 void DidCreateOrAttachWebContents(Shell* shell, 23 WebContents* web_contents) override; 24 gfx::NativeWindow GetNativeWindow(Shell* shell) override; 25 void CleanUp(Shell* shell) override; 26 void SetContents(Shell* shell) override; 27 void EnableUIControl(Shell* shell, 28 UIControl control, 29 bool is_enabled) override; 30 void SetAddressBarURL(Shell* shell, const GURL& url) override; 31 void SetTitle(Shell* shell, const base::string16& title) override; 32 void RenderViewReady(Shell* shell) override; 33 std::unique_ptr<JavaScriptDialogManager> CreateJavaScriptDialogManager( 34 Shell* shell) override; 35 bool HandleRequestToLockMouse(Shell* shell, 36 WebContents* web_contents, 37 bool user_gesture, 38 bool last_unlocked_by_target) override; 39 bool ShouldAllowRunningInsecureContent(Shell* shell) override; 40 bool DestroyShell(Shell* shell) override; 41 void ResizeWebContent(Shell* shell, const gfx::Size& content_size) override; 42 #if defined(OS_MAC) 43 void ActivateContents(Shell* shell, WebContents* top_contents) override; 44 void DidNavigateMainFramePostCommit(Shell*, WebContents* contents) override; 45 bool HandleKeyboardEvent(Shell* shell, 46 WebContents* source, 47 const NativeWebKeyboardEvent& event) override; 48 #endif 49 50 private: 51 // When headless, no window is shown while running the tests. 52 static bool IsHeadless(); 53 54 // Data held for each Shell instance, since there is one ShellPlatformDelegate 55 // for the whole browser process (shared across Shells). This is defined for 56 // each platform implementation. 57 struct WebTestShellData; 58 59 // Holds an instance of WebTestShellData for each Shell. 60 base::flat_map<Shell*, WebTestShellData> web_test_shell_data_map_; 61 62 // Data held in ShellPlatformDelegate that is shared between all Shells. This 63 // is created in Initialize(), and is defined for each platform 64 // implementation. 65 struct WebTestPlatformData; 66 std::unique_ptr<WebTestPlatformData> web_test_platform_; 67 68 #if defined(OS_MAC) 69 // The last headless shell that called ActivateContents(). 70 Shell* activated_headless_shell_ = nullptr; 71 #endif 72 }; 73 74 } // namespace content 75 76 #endif // CONTENT_WEB_TEST_BROWSER_WEB_TEST_SHELL_PLATFORM_DELEGATE_H_ 77