2010-10-03 23:04:50 +02:00
|
|
|
// Copyright (c) 2010 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_CONTEXT_H
|
|
|
|
#define _CEF_CONTEXT_H
|
|
|
|
|
|
|
|
#include "../include/cef.h"
|
|
|
|
#include "browser_request_context.h"
|
|
|
|
#include "cef_process.h"
|
|
|
|
#include "cef_thread.h"
|
2010-11-17 18:28:32 +01:00
|
|
|
#include "dom_storage_context.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
#include "base/at_exit.h"
|
|
|
|
#include "base/file_path.h"
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "base/ref_counted.h"
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
class BrowserRequestContext;
|
|
|
|
class CefBrowserImpl;
|
|
|
|
|
|
|
|
class CefContext : public CefThreadSafeBase<CefBase>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef std::list<CefRefPtr<CefBrowserImpl> > BrowserList;
|
|
|
|
|
|
|
|
CefContext();
|
|
|
|
~CefContext();
|
|
|
|
|
|
|
|
// These methods will be called on the main application thread.
|
2010-11-18 22:05:25 +01:00
|
|
|
bool Initialize(const CefSettings& settings,
|
|
|
|
const CefBrowserSettings& browser_defaults);
|
2010-10-03 23:04:50 +02:00
|
|
|
void Shutdown();
|
|
|
|
|
2011-01-07 02:06:10 +01:00
|
|
|
// 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_; }
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
scoped_refptr<CefProcess> process() { return process_; }
|
|
|
|
|
|
|
|
bool AddBrowser(CefRefPtr<CefBrowserImpl> browser);
|
|
|
|
bool RemoveBrowser(CefRefPtr<CefBrowserImpl> browser);
|
|
|
|
CefRefPtr<CefBrowserImpl> GetBrowserByID(int id);
|
|
|
|
BrowserList* GetBrowserList() { return &browserlist_; }
|
|
|
|
|
|
|
|
// Retrieve the path at which cache data will be stored on disk. If empty,
|
|
|
|
// cache data will be stored in-memory.
|
2010-11-18 22:05:25 +01:00
|
|
|
const FilePath& cache_path() const { return cache_path_; }
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2010-11-18 22:05:25 +01:00
|
|
|
const CefSettings& settings() const { return settings_; }
|
|
|
|
const CefBrowserSettings& browser_defaults() const
|
|
|
|
{ return browser_defaults_; }
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// The BrowserRequestContext object is managed by CefProcessIOThread.
|
|
|
|
void set_request_context(BrowserRequestContext* request_context)
|
|
|
|
{ request_context_ = request_context; }
|
|
|
|
scoped_refptr<BrowserRequestContext> request_context()
|
|
|
|
{ return request_context_; }
|
|
|
|
|
2010-11-17 18:28:32 +01:00
|
|
|
// The DOMStorageContext object is managed by CefProcessUIThread.
|
|
|
|
void set_storage_context(DOMStorageContext* storage_context)
|
|
|
|
{ storage_context_.reset(storage_context); }
|
|
|
|
DOMStorageContext* storage_context() { return storage_context_.get(); }
|
|
|
|
|
2011-01-07 02:06:10 +01:00
|
|
|
static bool ImplementsThreadSafeReferenceCounting() { return true; }
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
private:
|
2011-01-07 02:06:10 +01:00
|
|
|
// Performs shutdown actions that need to occur on the UI thread before any
|
|
|
|
// threads are destroyed.
|
|
|
|
void UIT_FinishShutdown(base::WaitableEvent* event);
|
|
|
|
|
|
|
|
// Track context state.
|
|
|
|
bool initialized_;
|
|
|
|
bool shutting_down_;
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Manages the various process threads.
|
|
|
|
scoped_refptr<CefProcess> process_;
|
|
|
|
|
|
|
|
// Initialize the AtExitManager on the main application thread to avoid
|
|
|
|
// asserts and possible memory leaks.
|
|
|
|
base::AtExitManager at_exit_manager_;
|
|
|
|
|
2010-11-18 22:05:25 +01:00
|
|
|
CefSettings settings_;
|
|
|
|
CefBrowserSettings browser_defaults_;
|
2010-11-18 15:47:38 +01:00
|
|
|
FilePath cache_path_;
|
2010-10-03 23:04:50 +02:00
|
|
|
scoped_refptr<BrowserRequestContext> request_context_;
|
2010-11-17 18:28:32 +01:00
|
|
|
scoped_ptr<DOMStorageContext> storage_context_;
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Map of browsers that currently exist.
|
|
|
|
BrowserList browserlist_;
|
2010-11-17 18:28:32 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Used for assigning unique IDs to browser instances.
|
|
|
|
int next_browser_id_;
|
|
|
|
};
|
|
|
|
|
2011-01-07 02:06:10 +01:00
|
|
|
// Global context object pointer.
|
2010-10-03 23:04:50 +02:00
|
|
|
extern CefRefPtr<CefContext> _Context;
|
|
|
|
|
2011-01-07 02:06:10 +01:00
|
|
|
// Helper macro that returns true if the global context is in a valid state.
|
|
|
|
#define CONTEXT_STATE_VALID() \
|
|
|
|
(_Context.get() && _Context->initialized() && !_Context->shutting_down())
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
#endif // _CEF_CONTEXT_H
|