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.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#ifndef CEF_LIBCEF_CEF_CONTEXT_H_
|
|
|
|
#define CEF_LIBCEF_CEF_CONTEXT_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-12-23 18:36:30 +01:00
|
|
|
#include "include/cef_app.h"
|
|
|
|
#include "include/cef_base.h"
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/browser_file_system.h"
|
|
|
|
#include "libcef/browser_request_context.h"
|
|
|
|
#include "libcef/cef_process.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
#include "base/at_exit.h"
|
2012-12-19 17:47:38 +01:00
|
|
|
#include "base/atomic_sequence_num.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/file_path.h"
|
2011-04-05 18:17:33 +02:00
|
|
|
#include "base/memory/ref_counted.h"
|
2012-11-30 19:30:34 +01:00
|
|
|
#include "base/files/scoped_temp_dir.h"
|
2012-06-22 16:56:07 +02:00
|
|
|
#include "base/threading/sequenced_worker_pool.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
class CefBrowserImpl;
|
2012-05-23 21:01:04 +02:00
|
|
|
class CefResourceBundleDelegate;
|
2011-02-28 01:33:11 +01:00
|
|
|
class WebViewHost;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-10-06 15:34:47 +02:00
|
|
|
namespace base {
|
|
|
|
class WaitableEvent;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
class CefContext : public CefBase {
|
|
|
|
public:
|
2010-10-03 23:04:50 +02:00
|
|
|
typedef std::list<CefRefPtr<CefBrowserImpl> > BrowserList;
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
CefContext();
|
|
|
|
~CefContext();
|
|
|
|
|
|
|
|
// These methods will be called on the main application thread.
|
2011-11-23 23:47:09 +01:00
|
|
|
bool Initialize(const CefSettings& settings, CefRefPtr<CefApp> application);
|
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_; }
|
|
|
|
|
2011-11-30 18:00:24 +01:00
|
|
|
CefProcess* process() { return process_.get(); }
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-12-19 17:47:38 +01:00
|
|
|
int GetNextBrowserID();
|
|
|
|
void AddBrowser(CefRefPtr<CefBrowserImpl> browser);
|
|
|
|
void RemoveBrowser(CefRefPtr<CefBrowserImpl> browser);
|
2010-10-03 23:04:50 +02:00
|
|
|
CefRefPtr<CefBrowserImpl> GetBrowserByID(int id);
|
|
|
|
BrowserList* GetBrowserList() { return &browserlist_; }
|
|
|
|
|
2012-02-16 18:11:49 +01:00
|
|
|
void InitializeResourceBundle();
|
|
|
|
void CleanupResourceBundle();
|
|
|
|
|
|
|
|
string16 GetLocalizedString(int message_id) const;
|
|
|
|
base::StringPiece GetDataResource(int resource_id) const;
|
|
|
|
|
|
|
|
FilePath GetResourcesFilePath() const;
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// 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_; }
|
2011-11-23 23:47:09 +01:00
|
|
|
CefRefPtr<CefApp> application() const { return application_; }
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-11-17 19:52:16 +01:00
|
|
|
// Return the locale specified in CefSettings or the default value of "en-US".
|
|
|
|
std::string locale() const;
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// The BrowserRequestContext object is managed by CefProcessIOThread.
|
2012-01-10 00:46:23 +01:00
|
|
|
void set_request_context(BrowserRequestContext* request_context) {
|
|
|
|
request_context_ = request_context;
|
|
|
|
}
|
2012-03-22 23:08:05 +01:00
|
|
|
BrowserRequestContext* request_context() { return request_context_; }
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-12-06 11:16:51 +01:00
|
|
|
BrowserFileSystem* file_system() { return &file_system_; }
|
|
|
|
|
2011-02-28 01:33:11 +01:00
|
|
|
// Used to keep track of the web view host we're dragging over. WARNING:
|
|
|
|
// this pointer should never be dereferenced. Use it only for comparing
|
|
|
|
// pointers.
|
|
|
|
WebViewHost* current_webviewhost() { return current_webviewhost_; }
|
2012-01-10 00:46:23 +01:00
|
|
|
void set_current_webviewhost(WebViewHost* host) {
|
|
|
|
current_webviewhost_ = host;
|
|
|
|
}
|
2011-02-28 01:33:11 +01:00
|
|
|
|
2012-06-22 16:56:07 +02:00
|
|
|
// The SequencedWorkerPool object is managed by CefProcessUIThread.
|
|
|
|
void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) {
|
|
|
|
blocking_pool_ = blocking_pool;
|
|
|
|
}
|
|
|
|
base::SequencedWorkerPool* blocking_pool() { return blocking_pool_.get(); }
|
|
|
|
|
2011-01-07 02:06:10 +01:00
|
|
|
static bool ImplementsThreadSafeReferenceCounting() { return true; }
|
|
|
|
|
2012-10-12 18:38:24 +02:00
|
|
|
// Keep count of DevTools windows, need to re-enable stack trace
|
|
|
|
// functionality for uncaught exceptions.
|
|
|
|
void UIT_DevToolsClientCreated();
|
|
|
|
void UIT_DevToolsClientDestroyed();
|
|
|
|
|
2012-01-10 00:46:23 +01: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.
|
2011-06-14 19:10:15 +02:00
|
|
|
void UIT_FinishShutdown(base::WaitableEvent* browser_shutdown_event,
|
|
|
|
base::WaitableEvent* uithread_shutdown_event);
|
2011-01-07 02:06:10 +01:00
|
|
|
|
|
|
|
// Track context state.
|
|
|
|
bool initialized_;
|
|
|
|
bool shutting_down_;
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Manages the various process threads.
|
2011-11-30 18:00:24 +01:00
|
|
|
scoped_ptr<CefProcess> process_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// 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_;
|
2011-11-23 23:47:09 +01:00
|
|
|
CefRefPtr<CefApp> application_;
|
2010-11-18 15:47:38 +01:00
|
|
|
FilePath cache_path_;
|
2012-11-30 19:30:34 +01:00
|
|
|
base::ScopedTempDir cache_temp_dir_;
|
2012-10-01 23:49:08 +02:00
|
|
|
|
2012-05-23 21:01:04 +02:00
|
|
|
BrowserRequestContext* request_context_;
|
2011-12-06 11:16:51 +01:00
|
|
|
BrowserFileSystem file_system_;
|
2012-05-23 21:01:04 +02:00
|
|
|
scoped_ptr<CefResourceBundleDelegate> resource_bundle_delegate_;
|
2010-11-17 18:28:32 +01:00
|
|
|
|
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.
|
2012-12-19 17:47:38 +01:00
|
|
|
base::AtomicSequenceNumber next_browser_id_;
|
2011-02-28 01:33:11 +01:00
|
|
|
|
|
|
|
WebViewHost* current_webviewhost_;
|
2011-05-20 16:42:25 +02:00
|
|
|
|
2012-06-22 16:56:07 +02:00
|
|
|
scoped_refptr<base::SequencedWorkerPool> blocking_pool_;
|
|
|
|
|
2012-10-12 18:38:24 +02:00
|
|
|
int dev_tools_client_count_;
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(CefContext);
|
|
|
|
IMPLEMENT_LOCKING(CefContext);
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
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())
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#endif // CEF_LIBCEF_CEF_CONTEXT_H_
|