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>
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/browser/browser_context_impl.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
#include "libcef/browser/browser_context_proxy.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/browser_message_loop.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/browser/content_browser_client.h"
|
2015-03-02 21:25:14 +01:00
|
|
|
#include "libcef/browser/context.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/devtools_delegate.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2013-06-24 20:57:05 +02:00
|
|
|
#include "libcef/common/net_resource_provider.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include "base/bind.h"
|
|
|
|
#include "base/command_line.h"
|
2013-07-24 22:15:18 +02:00
|
|
|
#include "base/message_loop/message_loop.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/string_number_conversions.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"
|
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
|
2013-12-07 02:55:22 +01:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
#include "ui/aura/env.h"
|
|
|
|
#include "ui/gfx/screen.h"
|
|
|
|
#include "ui/views/test/desktop_test_views_delegate.h"
|
|
|
|
#include "ui/views/widget/desktop_aura/desktop_screen.h"
|
2014-05-06 19:20:43 +02:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "ui/base/cursor/cursor_loader_win.h"
|
|
|
|
#endif
|
2013-12-07 02:55:22 +01:00
|
|
|
#endif // defined(USE_AURA)
|
|
|
|
|
2014-06-12 22:28:58 +02:00
|
|
|
#if defined(USE_AURA) && defined(OS_LINUX)
|
2014-05-22 23:01:22 +02:00
|
|
|
#include "ui/base/ime/input_method_initializer.h"
|
|
|
|
#endif
|
|
|
|
|
2014-07-10 17:41:30 +02:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
#include "libcef/browser/printing/print_dialog_linux.h"
|
|
|
|
#endif
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefBrowserMainParts::CefBrowserMainParts(
|
|
|
|
const content::MainFunctionParams& parameters)
|
2014-12-13 21:18:31 +01:00
|
|
|
: BrowserMainParts(),
|
|
|
|
devtools_delegate_(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
|
|
|
}
|
|
|
|
|
2014-05-22 23:01:22 +02:00
|
|
|
void CefBrowserMainParts::PreEarlyInitialization() {
|
2014-06-12 22:28:58 +02:00
|
|
|
#if defined(USE_AURA) && defined(OS_LINUX)
|
2014-05-22 23:01:22 +02:00
|
|
|
// TODO(linux): Consider using a real input method or
|
|
|
|
// views::LinuxUI::SetInstance.
|
|
|
|
ui::InitializeInputMethodForTesting();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-12-07 02:55:22 +01:00
|
|
|
void CefBrowserMainParts::ToolkitInitialized() {
|
|
|
|
#if defined(USE_AURA)
|
2014-05-29 19:15:34 +02:00
|
|
|
CHECK(aura::Env::GetInstance());
|
2013-12-07 02:55:22 +01:00
|
|
|
|
|
|
|
DCHECK(!views::ViewsDelegate::views_delegate);
|
|
|
|
new views::DesktopTestViewsDelegate;
|
2014-05-06 19:20:43 +02:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
ui::CursorLoaderWin::SetCursorResourceModule(
|
|
|
|
CefContentBrowserClient::Get()->GetResourceDllName());
|
2013-12-07 02:55:22 +01:00
|
|
|
#endif
|
2014-05-06 19:20:43 +02:00
|
|
|
#endif // defined(USE_AURA)
|
2013-12-07 02:55:22 +01: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());
|
2014-07-10 17:41:30 +02:00
|
|
|
|
|
|
|
#if defined(OS_LINUX)
|
|
|
|
printing::PrintingContextLinux::SetCreatePrintDialogFunction(
|
|
|
|
&CefPrintDialogLinux::CreatePrintDialog);
|
2015-03-24 16:40:08 +01:00
|
|
|
printing::PrintingContextLinux::SetPdfPaperSizeFunction(
|
|
|
|
&CefPrintDialogLinux::GetPdfPaperSize);
|
2014-07-10 17:41:30 +02:00
|
|
|
#endif
|
2013-03-12 21:23:24 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
int CefBrowserMainParts::PreCreateThreads() {
|
2015-06-12 00:08:33 +02:00
|
|
|
#if defined(OS_WIN)
|
2012-06-28 19:21:18 +02:00
|
|
|
PlatformInitialize();
|
2015-06-12 00:08:33 +02:00
|
|
|
#endif
|
|
|
|
|
2013-06-24 20:57:05 +02:00
|
|
|
net::NetModule::SetResourceProvider(&NetResourceProvider);
|
2012-06-28 19:21:18 +02:00
|
|
|
|
|
|
|
// Initialize the GpuDataManager before IO access restrictions are applied and
|
|
|
|
// before the IO thread is started.
|
|
|
|
content::GpuDataManager::GetInstance();
|
|
|
|
|
2013-12-07 02:55:22 +01:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE,
|
|
|
|
views::CreateDesktopScreen());
|
|
|
|
#endif
|
|
|
|
|
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();
|
2013-11-26 00:04:25 +01:00
|
|
|
pref_service_ = pref_store_->CreateService().Pass();
|
2013-02-06 21:41:54 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PreMainMessageLoopRun() {
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRequestContextSettings settings;
|
|
|
|
CefContext::Get()->PopulateRequestContextSettings(&settings);
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
// Create the global BrowserContext.
|
2015-03-02 21:25:14 +01:00
|
|
|
global_browser_context_ = new CefBrowserContextImpl(settings);
|
|
|
|
global_browser_context_->Initialize();
|
2013-05-08 20:21:18 +02:00
|
|
|
|
2015-01-09 18:22:10 +01:00
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
|
|
|
if (command_line->HasSwitch(switches::kRemoteDebuggingPort)) {
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string port_str =
|
2015-01-09 18:22:10 +01:00
|
|
|
command_line->GetSwitchValueASCII(switches::kRemoteDebuggingPort);
|
2012-04-03 03:34:16 +02:00
|
|
|
int port;
|
|
|
|
if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) {
|
2014-12-13 21:18:31 +01:00
|
|
|
devtools_delegate_ =
|
|
|
|
new CefDevToolsDelegate(static_cast<uint16>(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
|
|
|
}
|
|
|
|
}
|
2015-06-12 00:08:33 +02:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
PlatformPreMainMessageLoopRun();
|
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PostMainMessageLoopRun() {
|
2014-12-13 21:18:31 +01:00
|
|
|
if (devtools_delegate_) {
|
2012-04-03 03:34:16 +02:00
|
|
|
devtools_delegate_->Stop();
|
2014-12-13 21:18:31 +01:00
|
|
|
devtools_delegate_ = NULL;
|
|
|
|
}
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
global_browser_context_ = NULL;
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// No CefBrowserContext instances should exist at this point.
|
|
|
|
DCHECK_EQ(0, CefBrowserContext::DebugObjCt);
|
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
void CefBrowserMainParts::PostDestroyThreads() {
|
2013-12-07 02:55:22 +01:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
aura::Env::DeleteInstance();
|
|
|
|
delete views::ViewsDelegate::views_delegate;
|
|
|
|
#endif
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// No CefURLRequestContext instances should exist at this point.
|
|
|
|
DCHECK_EQ(0, CefURLRequestContext::DebugObjCt);
|
|
|
|
#endif
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|