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