electron/brightray/browser/browser_main_parts.cc

156 lines
3.8 KiB
C++
Raw Normal View History

2013-03-13 19:12:05 +00: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-CHROMIUM file.
#include "browser/browser_main_parts.h"
2013-03-13 19:12:05 +00:00
#include "browser/browser_context.h"
2015-03-09 02:53:37 +00:00
#include "browser/devtools_manager_delegate.h"
#include "browser/web_ui_controller_factory.h"
2015-01-10 01:14:52 +00:00
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
2015-03-09 02:53:37 +00:00
#include "content/public/browser/devtools_http_handler.h"
2014-07-30 03:40:17 +00:00
#include "content/public/common/content_switches.h"
#include "net/proxy/proxy_resolver_v8.h"
2014-07-03 09:04:03 +00:00
#if defined(USE_AURA)
#include "ui/gfx/screen.h"
#include "ui/views/widget/desktop_aura/desktop_screen.h"
#endif
2014-07-03 08:28:14 +00:00
#if defined(USE_AURA) && defined(USE_X11)
#include "chrome/browser/ui/libgtk2ui/gtk2_ui.h"
#include "ui/views/linux_ui/linux_ui.h"
2014-07-09 12:05:02 +00:00
#include "ui/wm/core/wm_state.h"
2014-07-03 08:28:14 +00:00
#endif
#if defined(TOOLKIT_VIEWS)
#include "browser/views/views_delegate.h"
#endif
#if defined(OS_LINUX)
#include "base/environment.h"
#include "base/path_service.h"
#include "base/nix/xdg_util.h"
#include "browser/brightray_paths.h"
#endif
2014-07-12 11:46:26 +00:00
#if defined(OS_WIN)
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_win.h"
#include "ui/gfx/platform_font_win.h"
#endif
2013-03-13 19:12:05 +00:00
namespace brightray {
2014-07-12 11:46:26 +00:00
namespace {
#if defined(OS_WIN)
2014-07-12 11:46:26 +00:00
// gfx::Font callbacks
void AdjustUIFont(LOGFONT* logfont) {
l10n_util::AdjustUIFont(logfont);
}
int GetMinimumFontSize() {
return 10;
}
#endif
2014-07-12 11:46:26 +00:00
#if defined(OS_LINUX)
void OverrideLinuxAppDataPath() {
base::FilePath path;
if (PathService::Get(DIR_APP_DATA, &path))
return;
scoped_ptr<base::Environment> env(base::Environment::Create());
path = base::nix::GetXDGDirectory(env.get(),
base::nix::kXdgConfigHomeEnvVar,
base::nix::kDotConfigDir);
PathService::Override(DIR_APP_DATA, path);
}
2014-07-12 11:46:26 +00:00
#endif
} // namespace
2013-03-13 19:12:05 +00:00
BrowserMainParts::BrowserMainParts() {
}
BrowserMainParts::~BrowserMainParts() {
}
void BrowserMainParts::PreEarlyInitialization() {
#if defined(OS_MACOSX)
IncreaseFileDescriptorLimit();
#endif
2014-07-03 08:28:14 +00:00
#if defined(USE_AURA) && defined(USE_X11)
views::LinuxUI::SetInstance(BuildGtk2UI());
#endif
#if defined(OS_LINUX)
OverrideLinuxAppDataPath();
#endif
InitProxyResolverV8();
}
void BrowserMainParts::ToolkitInitialized() {
2014-07-03 08:28:14 +00:00
#if defined(USE_AURA) && defined(USE_X11)
views::LinuxUI::instance()->Initialize();
2014-07-09 12:05:02 +00:00
wm_state_.reset(new wm::WMState);
2014-07-03 08:28:14 +00:00
#endif
#if defined(TOOLKIT_VIEWS)
2014-07-04 13:41:22 +00:00
views_delegate_.reset(new ViewsDelegate);
#endif
2014-07-12 11:46:26 +00:00
#if defined(OS_WIN)
gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont;
gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize;
#endif
}
void BrowserMainParts::PreMainMessageLoopStart() {
#if defined(OS_MACOSX)
InitializeMainNib();
#endif
}
2013-03-13 19:12:05 +00:00
void BrowserMainParts::PreMainMessageLoopRun() {
browser_context_.reset(CreateBrowserContext());
browser_context_->Initialize();
web_ui_controller_factory_.reset(
new WebUIControllerFactory(browser_context_.get()));
content::WebUIControllerFactory::RegisterFactory(
web_ui_controller_factory_.get());
2015-01-10 01:14:52 +00:00
// --remote-debugging-port
2015-03-09 02:53:37 +00:00
auto command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kRemoteDebuggingPort))
devtools_http_handler_.reset(DevToolsManagerDelegate::CreateHttpHandler());
2013-03-13 19:12:05 +00:00
}
Fix a hang on quit when application cache is used If you navigated to a page that used the HTML Application Cache, you'd see a hang on quit with a backtrace like so: + 2825 content::ContentMain(int, char const**, content::ContentMainDelegate*) (in libchromiumcontent.dylib) + 64 [0xb33190] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0x96b261 [0xb34261] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0x96a409 [0xb33409] + 2825 content::BrowserMain(content::MainFunctionParams const&) (in libchromiumcontent.dylib) + 200 [0x14290b8] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0x1265426 [0x142e426] + 2825 content::BrowserMainLoop::~BrowserMainLoop() (in libchromiumcontent.dylib) + 17 [0x14294a1] + 2825 content::BrowserMainLoop::~BrowserMainLoop() (in libchromiumcontent.dylib) + 357 [0x1429625] + 2825 brightray::BrowserMainParts::~BrowserMainParts() (in ) + 70 [0x68df6] + 2825 scoped_ptr<brightray::BrowserContext, base::DefaultDeleter<brightray::BrowserContext> >::~scoped_ptr() (in ) + 23 [0x68ff7] + 2825 scoped_ptr<brightray::BrowserContext, base::DefaultDeleter<brightray::BrowserContext> >::~scoped_ptr() (in ) + 23 [0x69297] + 2825 base::internal::scoped_ptr_impl<brightray::BrowserContext, base::DefaultDeleter<brightray::BrowserContext> >::~scoped_ptr_impl() (in ) + 23 [0x692b7] + 2825 base::internal::scoped_ptr_impl<brightray::BrowserContext, base::DefaultDeleter<brightray::BrowserContext> >::~scoped_ptr_impl() (in ) + 50 [0x692f2] + 2825 base::DefaultDeleter<brightray::BrowserContext>::operator()(brightray::BrowserContext*) const (in ) + 46 [0x6916e] + 2825 brightray::BrowserContext::~BrowserContext() (in ) + 127 [0x672bf] + 2825 base::SupportsUserData::~SupportsUserData() (in libchromiumcontent.dylib) + 57 [0xccc019] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0xb03230 [0xccc230] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0xb0324e [0xccc24e] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0x14c4239 [0x168d239] + 2825 content::StoragePartitionImpl::~StoragePartitionImpl() (in libchromiumcontent.dylib) + 17 [0x16899a1] + 2825 content::StoragePartitionImpl::~StoragePartitionImpl() (in libchromiumcontent.dylib) + 491 [0x1689bab] + 2825 content::ChromeAppCacheService::DeleteOnCorrectThread() const (in libchromiumcontent.dylib) + 66 [0x1424f32] + 2825 content::ChromeAppCacheService::~ChromeAppCacheService() (in libchromiumcontent.dylib) + 50 [0x1424e32] + 2825 appcache::AppCacheService::~AppCacheService() (in libchromiumcontent.dylib) + 301 [0x2b8ad2d] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0x29c9b81 [0x2b92b81] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0x29c9da4 [0x2b92da4] + 2825 appcache::AppCacheDiskCache::~AppCacheDiskCache() (in libchromiumcontent.dylib) + 17 [0x2b78c71] + 2825 appcache::AppCacheDiskCache::~AppCacheDiskCache() (in libchromiumcontent.dylib) + 135 [0x2b78d17] + 2825 disk_cache::BackendImpl::~BackendImpl() (in libchromiumcontent.dylib) + 17 [0x25979a1] + 2825 disk_cache::BackendImpl::~BackendImpl() (in libchromiumcontent.dylib) + 305 [0x2597af1] + 2825 base::WaitableEvent::Wait() (in libchromiumcontent.dylib) + 50 [0xccd942] + 2825 base::WaitableEvent::TimedWait(base::TimeDelta const&) (in libchromiumcontent.dylib) + 347 [0xccdb3b] + 2825 base::ConditionVariable::Wait() (in libchromiumcontent.dylib) + 35 [0xcccbb3] + 2825 pthread_cond_wait$UNIX2003 (in libsystem_c.dylib) + 71 [0x964d3089] + 2825 _pthread_cond_wait (in libsystem_c.dylib) + 833 [0x9644d280] + 2825 __psynch_cvwait (in libsystem_kernel.dylib) + 10 [0x94b8e8e2] BackendImpl was waiting on BrowserThread::CACHE, but that thread had already been stopped. The solution is to destroy the BrowserContext before threads have been stopped. We now do this in BrowserMainParts::PostMainMessageLoopRun, which matches content_shell.
2013-10-23 16:13:24 +00:00
void BrowserMainParts::PostMainMessageLoopRun() {
browser_context_.reset();
}
int BrowserMainParts::PreCreateThreads() {
2014-07-03 09:04:03 +00:00
#if defined(USE_AURA)
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE,
views::CreateDesktopScreen());
#endif
return 0;
}
BrowserContext* BrowserMainParts::CreateBrowserContext() {
return new BrowserContext;
}
void BrowserMainParts::InitProxyResolverV8() {
net::ProxyResolverV8::EnsureIsolateCreated();
}
} // namespace brightray