2010-10-03 23:04:50 +02:00
|
|
|
// Copyright (c) 2010 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2010 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "cef_process_ui_thread.h"
|
|
|
|
#include "browser_webkit_glue.h"
|
|
|
|
#include "browser_webkit_init.h"
|
|
|
|
#include "cef_context.h"
|
2011-10-18 19:56:10 +02:00
|
|
|
#include "../version.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-09-30 11:22:54 +02:00
|
|
|
#include "base/bind.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/i18n/icu_util.h"
|
2010-10-15 20:37:25 +02:00
|
|
|
#include "base/metrics/stats_table.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/rand_util.h"
|
|
|
|
#include "base/string_number_conversions.h"
|
2011-10-18 19:56:10 +02:00
|
|
|
#include "base/stringprintf.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "build/build_config.h"
|
|
|
|
#include "net/base/net_module.h"
|
2011-05-18 17:49:52 +02:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
|
2011-09-10 21:40:03 +02:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h"
|
2011-09-30 11:22:54 +02:00
|
|
|
#include "ui/base/ui_base_paths.h"
|
2011-04-05 18:17:33 +02:00
|
|
|
#include "ui/gfx/gl/gl_implementation.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "webkit/extensions/v8/gc_extension.h"
|
2011-10-12 21:09:15 +02:00
|
|
|
#include "webkit/glue/user_agent.h"
|
2011-09-10 21:40:03 +02:00
|
|
|
#include "webkit/glue/webkit_glue.h"
|
2011-01-07 22:34:20 +01:00
|
|
|
#include "webkit/plugins/npapi/plugin_list.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include <commctrl.h>
|
|
|
|
#include <Objbase.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const char* kStatsFilePrefix = "libcef_";
|
|
|
|
static int kStatsFileThreads = 20;
|
|
|
|
static int kStatsFileCounters = 200;
|
|
|
|
|
|
|
|
CefProcessUIThread::CefProcessUIThread()
|
|
|
|
: CefThread(CefThread::UI), statstable_(NULL), webkit_init_(NULL) {}
|
|
|
|
|
|
|
|
CefProcessUIThread::CefProcessUIThread(MessageLoop* message_loop)
|
|
|
|
: CefThread(CefThread::UI, message_loop), statstable_(NULL),
|
|
|
|
webkit_init_(NULL) {}
|
|
|
|
|
|
|
|
CefProcessUIThread::~CefProcessUIThread() {
|
|
|
|
// We cannot rely on our base class to stop the thread since we want our
|
|
|
|
// CleanUp function to run.
|
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefProcessUIThread::Init() {
|
|
|
|
// Initialize the global CommandLine object.
|
|
|
|
CommandLine::Init(0, NULL);
|
|
|
|
|
2011-01-24 21:41:07 +01:00
|
|
|
const CefSettings& settings = _Context->settings();
|
|
|
|
|
|
|
|
// Initialize logging.
|
|
|
|
logging::LoggingDestination logging_dest;
|
|
|
|
if (settings.log_severity == LOGSEVERITY_DISABLE) {
|
|
|
|
logging_dest = logging::LOG_NONE;
|
|
|
|
} else {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
logging_dest = logging::LOG_ONLY_TO_FILE;
|
|
|
|
#else
|
|
|
|
logging_dest = logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG;
|
|
|
|
#endif
|
|
|
|
logging::SetMinLogLevel(settings.log_severity);
|
|
|
|
}
|
|
|
|
|
|
|
|
FilePath log_file = FilePath(CefString(&settings.log_file));
|
|
|
|
logging::InitLogging(log_file.value().c_str(), logging_dest,
|
|
|
|
logging::DONT_LOCK_LOG_FILE, logging::APPEND_TO_OLD_LOG_FILE,
|
|
|
|
logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Load ICU data tables.
|
|
|
|
bool ret = icu_util::Initialize();
|
|
|
|
if(!ret) {
|
|
|
|
#if defined(OS_WIN)
|
2011-09-30 11:22:54 +02:00
|
|
|
MessageBox(NULL, L"Failed to load the required icudt library",
|
2010-10-03 23:04:50 +02:00
|
|
|
L"CEF Initialization Error", MB_ICONERROR | MB_OK);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-30 11:22:54 +02:00
|
|
|
// Provides path resolution required for locating locale pack files.
|
|
|
|
ui::RegisterPathProvider();
|
|
|
|
|
2011-11-17 19:52:16 +01:00
|
|
|
webkit_glue::InitializeResourceBundle(_Context->locale());
|
2011-09-30 11:22:54 +02:00
|
|
|
|
|
|
|
PlatformInit();
|
|
|
|
|
|
|
|
// Initialize WebKit.
|
|
|
|
webkit_init_ = new BrowserWebKitInit();
|
|
|
|
|
|
|
|
// Initialize WebKit encodings
|
|
|
|
webkit_glue::InitializeTextEncoding();
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Config the network module so it has access to a limited set of resources.
|
2011-09-30 11:22:54 +02:00
|
|
|
net::NetModule::SetResourceProvider(webkit_glue::GetDataResource);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// Load and initialize the stats table. Attempt to construct a somewhat
|
|
|
|
// unique name to isolate separate instances from each other.
|
2010-10-15 20:37:25 +02:00
|
|
|
statstable_ = new base::StatsTable(
|
2010-10-03 23:04:50 +02:00
|
|
|
kStatsFilePrefix + base::Uint64ToString(base::RandUint64()),
|
|
|
|
kStatsFileThreads,
|
|
|
|
kStatsFileCounters);
|
2010-10-15 20:37:25 +02:00
|
|
|
base::StatsTable::set_current(statstable_);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// CEF always exposes the GC.
|
2011-11-07 23:46:34 +01:00
|
|
|
std::string javascript_flags = "--expose-gc";
|
|
|
|
if (settings.javascript_flags.length > 0)
|
|
|
|
javascript_flags += " " + CefString(&settings.javascript_flags).ToString();
|
|
|
|
webkit_glue::SetJavaScriptFlags(javascript_flags);
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Expose GCController to JavaScript.
|
|
|
|
WebKit::WebScriptController::registerExtension(
|
|
|
|
extensions_v8::GCExtension::Get());
|
|
|
|
|
2011-05-21 01:39:33 +02:00
|
|
|
#if defined(OS_WIN)
|
2011-09-10 21:40:03 +02:00
|
|
|
if (settings.graphics_implementation == ANGLE_IN_PROCESS ||
|
|
|
|
settings.graphics_implementation == ANGLE_IN_PROCESS_COMMAND_BUFFER) {
|
|
|
|
gfx::InitializeGLBindings(gfx::kGLImplementationEGLGLES2);
|
|
|
|
} else {
|
|
|
|
gfx::InitializeGLBindings(gfx::kGLImplementationDesktopGL);
|
|
|
|
}
|
2011-05-21 01:39:33 +02:00
|
|
|
#else
|
|
|
|
gfx::InitializeGLBindings(gfx::kGLImplementationDesktopGL);
|
|
|
|
#endif
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-10-06 15:34:47 +02:00
|
|
|
// Set storage quota limits.
|
|
|
|
if (settings.local_storage_quota != 0)
|
|
|
|
DOMStorageContext::set_local_storage_quota(settings.local_storage_quota);
|
|
|
|
if (settings.session_storage_quota != 0)
|
|
|
|
DOMStorageContext::set_session_storage_quota(settings.session_storage_quota);
|
|
|
|
|
|
|
|
// Create the storage context object.
|
|
|
|
_Context->set_storage_context(new DOMStorageContext(_Context->cache_path()));
|
2010-11-18 22:05:25 +01:00
|
|
|
|
2011-10-12 21:09:15 +02:00
|
|
|
if (settings.user_agent.length > 0) {
|
|
|
|
webkit_glue::SetUserAgent(CefString(&settings.user_agent), false);
|
|
|
|
} else {
|
|
|
|
std::string product_version;
|
|
|
|
|
|
|
|
if (settings.product_version.length > 0) {
|
|
|
|
product_version = CefString(&settings.product_version).ToString();
|
|
|
|
} else {
|
2011-10-18 19:56:10 +02:00
|
|
|
product_version = base::StringPrintf("Chrome/%d.%d.%d.%d",
|
|
|
|
CHROME_VERSION_MAJOR, CHROME_VERSION_MINOR, CHROME_VERSION_BUILD,
|
|
|
|
CHROME_VERSION_PATCH);
|
2011-10-12 21:09:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
webkit_glue::SetUserAgent(
|
|
|
|
webkit_glue::BuildUserAgentFromProduct(product_version), false);
|
|
|
|
}
|
2010-11-18 22:05:25 +01:00
|
|
|
|
|
|
|
if (settings.extra_plugin_paths) {
|
|
|
|
cef_string_t str;
|
2011-01-07 22:34:20 +01:00
|
|
|
memset(&str, 0, sizeof(str));
|
|
|
|
|
2010-11-18 22:05:25 +01:00
|
|
|
FilePath path;
|
|
|
|
int size = cef_string_list_size(settings.extra_plugin_paths);
|
|
|
|
for(int i = 0; i < size; ++i) {
|
2010-11-22 18:49:46 +01:00
|
|
|
if (!cef_string_list_value(settings.extra_plugin_paths, i, &str))
|
|
|
|
continue;
|
|
|
|
path = FilePath(CefString(&str));
|
2011-01-07 22:34:20 +01:00
|
|
|
webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path);
|
2010-11-18 22:05:25 +01:00
|
|
|
}
|
|
|
|
}
|
2011-05-18 17:49:52 +02:00
|
|
|
|
|
|
|
// Create a network change notifier before starting the IO & File threads.
|
|
|
|
network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
|
|
|
|
|
|
|
|
// Add a listener for OnOnlineStateChanged to notify WebKit of changes.
|
|
|
|
net::NetworkChangeNotifier::AddOnlineStateObserver(this);
|
|
|
|
|
|
|
|
// Initialize WebKit with the current state.
|
|
|
|
WebKit::WebNetworkStateNotifier::setOnLine(
|
|
|
|
!net::NetworkChangeNotifier::IsOffline());
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefProcessUIThread::CleanUp() {
|
|
|
|
// Flush any remaining messages. This ensures that any accumulated
|
|
|
|
// Task objects get destroyed before we exit, which avoids noise in
|
|
|
|
// purify leak-test results.
|
|
|
|
MessageLoop::current()->RunAllPending();
|
|
|
|
|
2010-11-17 18:28:32 +01:00
|
|
|
// Destroy the storage context object.
|
|
|
|
_Context->set_storage_context(NULL);
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Tear down the shared StatsTable.
|
2010-10-15 20:37:25 +02:00
|
|
|
base::StatsTable::set_current(NULL);
|
2010-10-03 23:04:50 +02:00
|
|
|
delete statstable_;
|
|
|
|
statstable_ = NULL;
|
|
|
|
|
|
|
|
// Shut down WebKit.
|
|
|
|
delete webkit_init_;
|
|
|
|
webkit_init_ = NULL;
|
|
|
|
|
2011-05-18 17:49:52 +02:00
|
|
|
// Release the network change notifier after all other threads end.
|
|
|
|
net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
|
|
|
|
network_change_notifier_.reset();
|
|
|
|
|
2010-11-15 16:39:56 +01:00
|
|
|
PlatformCleanUp();
|
2011-10-31 16:40:54 +01:00
|
|
|
|
|
|
|
webkit_glue::CleanupResourceBundle();
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2011-05-18 17:49:52 +02:00
|
|
|
|
|
|
|
void CefProcessUIThread::OnOnlineStateChanged(bool online) {
|
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::UI));
|
|
|
|
WebKit::WebNetworkStateNotifier::setOnLine(online);
|
|
|
|
}
|
|
|
|
|