2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_CONTEXT_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_CONTEXT_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "include/cef_app.h"
|
2020-06-24 22:26:12 +02:00
|
|
|
#include "libcef/browser/main_runner.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-05-31 11:50:12 +02:00
|
|
|
#include "base/observer_list.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/threading/platform_thread.h"
|
2017-04-20 21:28:17 +02:00
|
|
|
#include "third_party/skia/include/core/SkColor.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
class CefBrowserInfoManager;
|
2012-10-18 00:45:49 +02:00
|
|
|
class CefTraceSubscriber;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
class CefContext {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
2019-05-31 11:50:12 +02:00
|
|
|
// Interface to implement for observers that wish to be informed of changes
|
|
|
|
// to the context. All methods will be called on the UI thread.
|
|
|
|
class Observer {
|
|
|
|
public:
|
|
|
|
// Called before the context is destroyed.
|
|
|
|
virtual void OnContextDestroyed() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~Observer() {}
|
|
|
|
};
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefContext();
|
2015-02-14 00:17:08 +01:00
|
|
|
~CefContext();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-09-03 20:06:25 +02:00
|
|
|
// Returns the singleton CefContext instance.
|
|
|
|
static CefContext* Get();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// These methods will be called on the main application thread.
|
|
|
|
bool Initialize(const CefMainArgs& args,
|
|
|
|
const CefSettings& settings,
|
2013-11-15 19:47:02 +01:00
|
|
|
CefRefPtr<CefApp> application,
|
|
|
|
void* windows_sandbox_info);
|
2020-06-25 04:34:12 +02:00
|
|
|
void RunMessageLoop();
|
|
|
|
void QuitMessageLoop();
|
2012-04-03 03:34:16 +02:00
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
// Returns true if the current thread is the initialization thread.
|
|
|
|
bool OnInitThread();
|
|
|
|
|
|
|
|
// Returns true if the context is initialized.
|
|
|
|
bool initialized() { return initialized_; }
|
|
|
|
|
|
|
|
// Returns true if the context is shutting down.
|
|
|
|
bool shutting_down() { return shutting_down_; }
|
|
|
|
|
|
|
|
const CefSettings& settings() const { return settings_; }
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
// Returns the background color for the browser. If |browser_settings| is
|
|
|
|
// nullptr or does not specify a color then the global settings will be used.
|
|
|
|
// The alpha component will be either SK_AlphaTRANSPARENT or SK_AlphaOPAQUE
|
|
|
|
// (e.g. fully transparent or fully opaque). If |is_windowless| is
|
|
|
|
// STATE_DISABLED then SK_AlphaTRANSPARENT will always be returned. If
|
|
|
|
// |is_windowless| is STATE_ENABLED then SK_ColorTRANSPARENT may be returned
|
|
|
|
// to enable transparency for windowless browsers. See additional comments on
|
|
|
|
// CefSettings.background_color and CefBrowserSettings.background_color.
|
|
|
|
SkColor GetBackgroundColor(const CefBrowserSettings* browser_settings,
|
|
|
|
cef_state_t windowless_state) const;
|
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
CefTraceSubscriber* GetTraceSubscriber();
|
|
|
|
|
2019-03-24 19:41:42 +01:00
|
|
|
// Populate request context settings for the global system context based on
|
|
|
|
// CefSettings and command-line flags.
|
2020-04-23 23:45:04 +02:00
|
|
|
void PopulateGlobalRequestContextSettings(
|
|
|
|
CefRequestContextSettings* settings);
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2020-04-23 23:45:04 +02:00
|
|
|
// Normalize and validate request context settings for user-created contexts.
|
|
|
|
void NormalizeRequestContextSettings(CefRequestContextSettings* settings);
|
2019-03-24 19:41:42 +01:00
|
|
|
|
2019-05-31 11:50:12 +02:00
|
|
|
// Manage observer objects. The observer must either outlive this object or
|
|
|
|
// remove itself before destruction. These methods can only be called on the
|
|
|
|
// UI thread.
|
|
|
|
void AddObserver(Observer* observer);
|
|
|
|
void RemoveObserver(Observer* observer);
|
|
|
|
bool HasObserver(Observer* observer) const;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
private:
|
2012-06-19 18:29:49 +02:00
|
|
|
void OnContextInitialized();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Performs shutdown actions that need to occur on the UI thread before any
|
|
|
|
// threads are destroyed.
|
2020-06-24 22:26:12 +02:00
|
|
|
void ShutdownOnUIThread();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Destroys the main runner and related objects.
|
|
|
|
void FinalizeShutdown();
|
|
|
|
|
|
|
|
// Track context state.
|
|
|
|
bool initialized_;
|
|
|
|
bool shutting_down_;
|
|
|
|
|
|
|
|
// The thread on which the context was initialized.
|
|
|
|
base::PlatformThreadId init_thread_id_;
|
|
|
|
|
|
|
|
CefSettings settings_;
|
2020-06-25 04:34:12 +02:00
|
|
|
CefRefPtr<CefApp> application_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
std::unique_ptr<CefMainRunner> main_runner_;
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefTraceSubscriber> trace_subscriber_;
|
|
|
|
std::unique_ptr<CefBrowserInfoManager> browser_info_manager_;
|
2019-05-31 11:50:12 +02:00
|
|
|
|
|
|
|
// Observers that want to be notified of changes to this object.
|
|
|
|
base::ObserverList<Observer>::Unchecked observers_;
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Helper macro that returns true if the global context is in a valid state.
|
2017-05-17 11:29:28 +02:00
|
|
|
#define CONTEXT_STATE_VALID() \
|
|
|
|
(CefContext::Get() && CefContext::Get()->initialized() && \
|
|
|
|
!CefContext::Get()->shutting_down())
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_CONTEXT_H_
|