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"
|
|
|
|
#include "libcef/browser/devtools_delegate.h"
|
|
|
|
|
|
|
|
#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"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/gpu_data_manager.h"
|
|
|
|
#include "content/public/common/content_client.h"
|
|
|
|
#include "content/public/common/content_switches.h"
|
|
|
|
#include "net/base/net_module.h"
|
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
base::StringPiece ResourceProvider(int resource_id) {
|
2012-05-31 17:19:33 +02:00
|
|
|
return content::GetContentClient()->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(),
|
|
|
|
devtools_delegate_(NULL) {
|
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserMainParts::~CefBrowserMainParts() {
|
|
|
|
}
|
|
|
|
|
2012-04-11 20:00:55 +02:00
|
|
|
void CefBrowserMainParts::PreMainMessageLoopStart() {
|
|
|
|
if (!MessageLoop::current()) {
|
|
|
|
// Create the browser message loop.
|
|
|
|
message_loop_.reset(new CefBrowserMessageLoop());
|
|
|
|
message_loop_->set_thread_name("CrBrowserMain");
|
|
|
|
}
|
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.
|
|
|
|
user_prefs_ = new BrowserPrefStore();
|
|
|
|
user_prefs_->SetInitializationCompleted();
|
|
|
|
|
|
|
|
// Initialize proxy configuration tracker.
|
|
|
|
pref_proxy_config_tracker_.reset(
|
|
|
|
ProxyServiceFactory::CreatePrefProxyConfigTracker(
|
|
|
|
user_prefs_->CreateService()));
|
|
|
|
|
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-06 21:41:54 +01:00
|
|
|
// Initialize proxy configuration service.
|
|
|
|
ChromeProxyConfigService* chrome_proxy_config_service =
|
|
|
|
ProxyServiceFactory::CreateProxyConfigService(true);
|
|
|
|
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 {
|
|
|
|
DLOG(WARNING) << "Invalid http debugger port number " << port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PostMainMessageLoopRun() {
|
|
|
|
if (devtools_delegate_)
|
|
|
|
devtools_delegate_->Stop();
|
2013-02-06 21:41:54 +01:00
|
|
|
pref_proxy_config_tracker_->DetachFromPrefService();
|
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);
|
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
PlatformCleanup();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|