2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 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 "libcef/browser/browser_main.h"
|
2012-05-18 22:32:28 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/browser_context.h"
|
|
|
|
#include "libcef/browser/browser_message_loop.h"
|
2013-02-23 01:43:28 +01:00
|
|
|
#include "libcef/browser/context.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/devtools_delegate.h"
|
2013-04-16 00:16:01 +02:00
|
|
|
#include "libcef/common/content_client.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include "base/bind.h"
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "base/string_number_conversions.h"
|
2013-02-06 21:41:54 +01:00
|
|
|
#include "chrome/browser/net/proxy_service_factory.h"
|
2013-03-12 21:23:24 +01:00
|
|
|
#include "content/browser/webui/content_web_ui_controller_factory.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/gpu_data_manager.h"
|
2013-03-12 21:23:24 +01:00
|
|
|
#include "content/public/browser/web_ui_controller_factory.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
|
|
|
#include "net/base/net_module.h"
|
2013-02-26 23:54:26 +01:00
|
|
|
#include "net/proxy/proxy_resolver_v8.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
2013-02-26 23:54:26 +01:00
|
|
|
#include "v8/include/v8.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
base::StringPiece ResourceProvider(int resource_id) {
|
2013-04-16 00:16:01 +02:00
|
|
|
return CefContentClient::Get()->GetDataResource(resource_id,
|
|
|
|
ui::SCALE_FACTOR_NONE);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-05-18 22:32:28 +02:00
|
|
|
} // namespace
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefBrowserMainParts::CefBrowserMainParts(
|
|
|
|
const content::MainFunctionParams& parameters)
|
|
|
|
: BrowserMainParts(),
|
2013-02-26 23:54:26 +01:00
|
|
|
devtools_delegate_(NULL),
|
|
|
|
proxy_v8_isolate_(NULL) {
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserMainParts::~CefBrowserMainParts() {
|
|
|
|
}
|
|
|
|
|
2012-04-11 20:00:55 +02:00
|
|
|
void CefBrowserMainParts::PreMainMessageLoopStart() {
|
2013-04-16 00:16:01 +02:00
|
|
|
if (!base::MessageLoop::current()) {
|
2012-04-11 20:00:55 +02:00
|
|
|
// Create the browser message loop.
|
|
|
|
message_loop_.reset(new CefBrowserMessageLoop());
|
|
|
|
message_loop_->set_thread_name("CrBrowserMain");
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-03-12 21:23:24 +01:00
|
|
|
void CefBrowserMainParts::PostMainMessageLoopStart() {
|
|
|
|
// Don't use the default WebUI controller factory because is conflicts with
|
|
|
|
// CEF's internal handling of "chrome://tracing".
|
|
|
|
content::WebUIControllerFactory::UnregisterFactoryForTesting(
|
|
|
|
content::ContentWebUIControllerFactory::GetInstance());
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
int CefBrowserMainParts::PreCreateThreads() {
|
2012-06-28 19:21:18 +02:00
|
|
|
PlatformInitialize();
|
|
|
|
net::NetModule::SetResourceProvider(&ResourceProvider);
|
|
|
|
|
|
|
|
// Initialize the GpuDataManager before IO access restrictions are applied and
|
|
|
|
// before the IO thread is started.
|
|
|
|
content::GpuDataManager::GetInstance();
|
|
|
|
|
2013-02-06 21:41:54 +01:00
|
|
|
// Initialize user preferences.
|
2013-03-07 02:20:24 +01:00
|
|
|
pref_store_ = new CefBrowserPrefStore();
|
|
|
|
pref_store_->SetInitializationCompleted();
|
|
|
|
pref_service_.reset(pref_store_->CreateService());
|
2013-02-06 21:41:54 +01:00
|
|
|
|
2013-02-26 23:54:26 +01:00
|
|
|
// Create a v8::Isolate for the current thread if it doesn't already exist.
|
|
|
|
if (!v8::Isolate::GetCurrent()) {
|
|
|
|
proxy_v8_isolate_ = v8::Isolate::New();
|
|
|
|
proxy_v8_isolate_->Enter();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the V8 proxy integration.
|
|
|
|
net::ProxyResolverV8::RememberDefaultIsolate();
|
|
|
|
|
2013-02-06 21:41:54 +01:00
|
|
|
// Initialize proxy configuration tracker.
|
|
|
|
pref_proxy_config_tracker_.reset(
|
|
|
|
ProxyServiceFactory::CreatePrefProxyConfigTracker(
|
2013-03-07 02:20:24 +01:00
|
|
|
pref_service_.get()));
|
2013-02-06 21:41:54 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PreMainMessageLoopRun() {
|
2012-04-04 20:18:09 +02:00
|
|
|
browser_context_.reset(new CefBrowserContext());
|
2012-05-18 22:32:28 +02:00
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
// Initialize the request context getter.
|
|
|
|
_Context->set_request_context(browser_context_->GetRequestContext());
|
|
|
|
|
2013-02-06 21:41:54 +01:00
|
|
|
// Initialize proxy configuration service.
|
|
|
|
ChromeProxyConfigService* chrome_proxy_config_service =
|
2013-02-23 01:43:28 +01:00
|
|
|
ProxyServiceFactory::CreateProxyConfigService();
|
2013-02-06 21:41:54 +01:00
|
|
|
proxy_config_service_.reset(chrome_proxy_config_service);
|
|
|
|
pref_proxy_config_tracker_->SetChromeProxyConfigService(
|
|
|
|
chrome_proxy_config_service);
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
|
|
|
|
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
|
|
|
|
std::string port_str =
|
|
|
|
command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
|
|
|
|
int port;
|
|
|
|
if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) {
|
2012-10-04 21:17:13 +02:00
|
|
|
devtools_delegate_ = new CefDevToolsDelegate(port);
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
2013-02-09 23:38:24 +01:00
|
|
|
LOG(WARNING) << "Invalid http debugger port number " << port;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PostMainMessageLoopRun() {
|
|
|
|
if (devtools_delegate_)
|
|
|
|
devtools_delegate_->Stop();
|
2013-02-06 21:41:54 +01:00
|
|
|
pref_proxy_config_tracker_->DetachFromPrefService();
|
2013-02-23 01:43:28 +01:00
|
|
|
_Context->set_request_context(NULL);
|
2012-04-03 03:34:16 +02:00
|
|
|
browser_context_.reset();
|
|
|
|
}
|
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
void CefBrowserMainParts::PostDestroyThreads() {
|
2013-02-06 21:41:54 +01:00
|
|
|
pref_proxy_config_tracker_.reset(NULL);
|
|
|
|
|
2013-02-26 23:54:26 +01:00
|
|
|
if (proxy_v8_isolate_) {
|
|
|
|
proxy_v8_isolate_->Exit();
|
|
|
|
proxy_v8_isolate_->Dispose();
|
|
|
|
}
|
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
PlatformCleanup();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|