cef/libcef/browser/context.h

127 lines
4.3 KiB
C
Raw Normal View History

// 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 "base/observer_list.h"
#include "base/threading/platform_thread.h"
#include "cef/include/cef_app.h"
#include "cef/libcef/browser/main_runner.h"
#include "third_party/skia/include/core/SkColor.h"
class CefBrowserInfoManager;
class CefTraceSubscriber;
class CefContext {
public:
// 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() = default;
};
CefContext();
~CefContext();
// Returns the singleton CefContext instance.
static CefContext* Get();
// These methods will be called on the main application thread.
bool Initialize(const CefMainArgs& args,
const CefSettings& settings,
CefRefPtr<CefApp> application,
void* windows_sandbox_info);
void RunMessageLoop();
void QuitMessageLoop();
void Shutdown();
// Returns true if the current thread is the initialization thread.
bool OnInitThread();
// Returns true if the context is initialized.
bool initialized() const { return initialized_; }
// Returns true if the context is shutting down.
bool shutting_down() const { return shutting_down_; }
// Only valid after Initialize is called.
int exit_code() const { return exit_code_; }
const CefSettings& settings() const { return settings_; }
// 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;
CefTraceSubscriber* GetTraceSubscriber();
// Populate request context settings for the global system context based on
// CefSettings and command-line flags.
void PopulateGlobalRequestContextSettings(
CefRequestContextSettings* settings);
Add support for complete isolation of storage and permissions (cache, cookies, localStorage, access grants, etc) on a per-request-context basis (issue #1044). - CefRequestContext instances can be configured using a new CefRequestContextSettings structure passed to CefRequestContext::CreateContext. - Scheme registration is now per-request-context using new CefRequestContext::RegisterSchemeHandlerFactory and ClearSchemeHandlerFactories methods. - Cookie managers are now per-request-context by default and can be retrieved using a new CefRequestContext::GetDefaultCookieManager method. - CefURLRequest::Create now accepts an optional CefRequestContext argument for associating a URL request with a context (browser process only). - The CefRequestContextHandler associated with a CefRequestContext will not be released until all objects related to that context have been destroyed. - When the cache path is empty an in-memory cache ("incognito mode") will be used for storage and no data will be persisted to disk. - Add CefSettings.user_data_path which specifies the location where user data such as spell checking dictionary files will be stored on disk. - Add asynchronous callbacks for all CefCookieManager methods. - Add PK_LOCAL_APP_DATA and PK_USER_DATA path keys for retrieving user directories via CefGetPath. - cefclient: Add "New Window" test that creates a new window unrelated to existing windows. When used in combination with `--request-context-per-browser` the new window will be given a new and isolated request context. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@2040 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
2015-03-02 21:25:14 +01:00
// Normalize and validate request context settings for user-created contexts.
void NormalizeRequestContextSettings(CefRequestContextSettings* settings);
// 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;
private:
void OnContextInitialized();
// Performs shutdown actions that need to occur on the UI thread before any
// threads are destroyed.
void ShutdownOnUIThread();
// Destroys the main runner and related objects.
void FinalizeShutdown();
// Track context state.
bool initialized_ = false;
bool shutting_down_ = false;
int exit_code_ = -1;
// The thread on which the context was initialized.
base::PlatformThreadId init_thread_id_ = 0;
CefSettings settings_;
CefRefPtr<CefApp> application_;
std::unique_ptr<CefMainRunner> main_runner_;
std::unique_ptr<CefTraceSubscriber> trace_subscriber_;
std::unique_ptr<CefBrowserInfoManager> browser_info_manager_;
// Observers that want to be notified of changes to this object.
base::ObserverList<Observer>::Unchecked observers_;
};
// Helper macro that returns true if the global context is in a valid state.
#define CONTEXT_STATE_VALID() \
(CefContext::Get() && CefContext::Get()->initialized() && \
!CefContext::Get()->shutting_down())
#endif // CEF_LIBCEF_BROWSER_CONTEXT_H_