1 // Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_MAIN_CONTEXT_IMPL_H_ 6 #define CEF_TESTS_CEFCLIENT_BROWSER_MAIN_CONTEXT_IMPL_H_ 7 #pragma once 8 9 #include <memory> 10 11 #include "include/base/cef_thread_checker.h" 12 #include "include/cef_app.h" 13 #include "include/cef_command_line.h" 14 #include "tests/cefclient/browser/main_context.h" 15 #include "tests/cefclient/browser/root_window_manager.h" 16 17 namespace client { 18 19 // Used to store global context in the browser process. 20 class MainContextImpl : public MainContext { 21 public: 22 MainContextImpl(CefRefPtr<CefCommandLine> command_line, 23 bool terminate_when_all_windows_closed); 24 25 // MainContext members. 26 std::string GetConsoleLogPath() override; 27 std::string GetDownloadPath(const std::string& file_name) override; 28 std::string GetAppWorkingDirectory() override; 29 std::string GetMainURL() override; 30 cef_color_t GetBackgroundColor() override; 31 bool UseChromeRuntime() override; 32 bool UseViews() override; 33 bool UseWindowlessRendering() override; 34 bool TouchEventsEnabled() override; 35 void PopulateSettings(CefSettings* settings) override; 36 void PopulateBrowserSettings(CefBrowserSettings* settings) override; 37 void PopulateOsrSettings(OsrRendererSettings* settings) override; 38 RootWindowManager* GetRootWindowManager() override; 39 40 // Initialize CEF and associated main context state. This method must be 41 // called on the same thread that created this object. 42 bool Initialize(const CefMainArgs& args, 43 const CefSettings& settings, 44 CefRefPtr<CefApp> application, 45 void* windows_sandbox_info); 46 47 // Shut down CEF and associated context state. This method must be called on 48 // the same thread that created this object. 49 void Shutdown(); 50 51 private: 52 // Allow deletion via std::unique_ptr only. 53 friend std::default_delete<MainContextImpl>; 54 55 ~MainContextImpl(); 56 57 // Returns true if the context is in a valid state (initialized and not yet 58 // shut down). InValidState()59 bool InValidState() const { return initialized_ && !shutdown_; } 60 61 CefRefPtr<CefCommandLine> command_line_; 62 const bool terminate_when_all_windows_closed_; 63 64 // Track context state. Accessing these variables from multiple threads is 65 // safe because only a single thread will exist at the time that they're set 66 // (during context initialization and shutdown). 67 bool initialized_; 68 bool shutdown_; 69 70 std::string main_url_; 71 cef_color_t background_color_; 72 cef_color_t browser_background_color_; 73 bool use_windowless_rendering_; 74 int windowless_frame_rate_; 75 bool use_chrome_runtime_; 76 bool use_views_; 77 bool touch_events_enabled_; 78 79 std::unique_ptr<RootWindowManager> root_window_manager_; 80 81 #if defined(OS_WIN) 82 bool shared_texture_enabled_; 83 #endif 84 85 bool external_begin_frame_enabled_; 86 87 // Used to verify that methods are called on the correct thread. 88 base::ThreadChecker thread_checker_; 89 90 DISALLOW_COPY_AND_ASSIGN(MainContextImpl); 91 }; 92 93 } // namespace client 94 95 #endif // CEF_TESTS_CEFCLIENT_BROWSER_MAIN_CONTEXT_IMPL_H_ 96