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.
|
|
|
|
|
2017-05-18 22:58:12 +00:00
|
|
|
#include "brightray/common/main_delegate.h"
|
2013-03-14 13:03:50 +00:00
|
|
|
|
2016-05-23 01:59:07 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "base/command_line.h"
|
2018-05-30 07:13:34 +00:00
|
|
|
#include "base/mac/bundle_locations.h"
|
2013-05-22 15:40:43 +00:00
|
|
|
#include "base/path_service.h"
|
2017-05-18 22:58:12 +00:00
|
|
|
#include "brightray/browser/browser_client.h"
|
|
|
|
#include "brightray/common/content_client.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2013-05-22 15:40:43 +00:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
2016-01-08 04:04:23 +00:00
|
|
|
#include "ui/base/ui_base_switches.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
|
|
|
|
namespace brightray {
|
|
|
|
|
2016-01-08 04:04:23 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Returns true if this subprocess type needs the ResourceBundle initialized
|
|
|
|
// and resources loaded.
|
|
|
|
bool SubprocessNeedsResourceBundle(const std::string& process_type) {
|
|
|
|
return
|
|
|
|
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
|
|
|
// The zygote process opens the resources for the renderers.
|
|
|
|
process_type == switches::kZygoteProcess ||
|
|
|
|
#endif
|
|
|
|
#if defined(OS_MACOSX)
|
2018-04-18 01:56:12 +00:00
|
|
|
// Mac needs them too for scrollbar related images and for sandbox
|
|
|
|
// profiles.
|
2016-01-08 04:04:23 +00:00
|
|
|
process_type == switches::kPpapiPluginProcess ||
|
|
|
|
process_type == switches::kPpapiBrokerProcess ||
|
|
|
|
process_type == switches::kGpuProcess ||
|
|
|
|
#endif
|
|
|
|
process_type == switches::kRendererProcess ||
|
|
|
|
process_type == switches::kUtilityProcess;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2018-02-08 14:26:37 +00:00
|
|
|
void LoadResourceBundle(const std::string& locale) {
|
|
|
|
const bool initialized = ui::ResourceBundle::HasSharedInstance();
|
|
|
|
if (initialized)
|
|
|
|
ui::ResourceBundle::CleanupSharedInstance();
|
|
|
|
|
2018-05-30 07:13:34 +00:00
|
|
|
// Load other resource files.
|
|
|
|
base::FilePath pak_dir;
|
2016-01-08 04:04:23 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2018-07-17 22:34:19 +00:00
|
|
|
pak_dir =
|
|
|
|
base::mac::FrameworkBundlePath().Append(FILE_PATH_LITERAL("Resources"));
|
2016-01-08 04:04:23 +00:00
|
|
|
#else
|
|
|
|
PathService::Get(base::DIR_MODULE, &pak_dir);
|
2018-05-30 07:13:34 +00:00
|
|
|
#endif
|
2018-07-17 22:34:19 +00:00
|
|
|
|
|
|
|
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
|
|
|
locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
|
|
|
|
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
|
|
|
|
bundle.ReloadLocaleResources(locale);
|
|
|
|
bundle.AddDataPackFromPath(pak_dir.Append(FILE_PATH_LITERAL("resources.pak")),
|
|
|
|
ui::SCALE_FACTOR_NONE);
|
2018-03-15 13:57:06 +00:00
|
|
|
#if defined(ENABLE_PDF_VIEWER)
|
2018-09-12 18:46:42 +00:00
|
|
|
NOTIMPLEMENTED() << "Hi, whoever's fixing PDF support! Thanks! The pdf viewer "
|
|
|
|
"resources haven't been ported over to the GN build yet, so you'll "
|
|
|
|
"probably need to change this bit of code.";
|
2017-01-17 14:55:28 +00:00
|
|
|
bundle.AddDataPackFromPath(
|
|
|
|
pak_dir.Append(FILE_PATH_LITERAL("pdf_viewer_resources.pak")),
|
|
|
|
ui::GetSupportedScaleFactors()[0]);
|
2018-03-15 13:57:06 +00:00
|
|
|
#endif // defined(ENABLE_PDF_VIEWER)
|
2016-01-08 04:04:23 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
MainDelegate::MainDelegate() {}
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
MainDelegate::~MainDelegate() {}
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<ContentClient> MainDelegate::CreateContentClient() {
|
|
|
|
return std::unique_ptr<ContentClient>(new ContentClient);
|
2013-04-24 22:30:47 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 13:03:50 +00:00
|
|
|
bool MainDelegate::BasicStartupComplete(int* exit_code) {
|
2016-03-08 11:59:29 +00:00
|
|
|
content_client_ = CreateContentClient();
|
2013-03-14 13:03:50 +00:00
|
|
|
SetContentClient(content_client_.get());
|
2013-03-13 19:12:05 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
OverrideChildProcessPath();
|
|
|
|
OverrideFrameworkBundlePath();
|
2013-05-22 15:40:43 +00:00
|
|
|
#endif
|
2014-06-26 20:35:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainDelegate::PreSandboxStartup() {
|
2016-01-08 04:04:23 +00:00
|
|
|
auto cmd = *base::CommandLine::ForCurrentProcess();
|
|
|
|
std::string process_type = cmd.GetSwitchValueASCII(switches::kProcessType);
|
2013-05-22 15:40:43 +00:00
|
|
|
|
2016-01-08 04:04:23 +00:00
|
|
|
// Initialize ResourceBundle which handles files loaded from external
|
|
|
|
// sources. The language should have been passed in to us from the
|
|
|
|
// browser process as a command line flag.
|
|
|
|
if (SubprocessNeedsResourceBundle(process_type)) {
|
|
|
|
std::string locale = cmd.GetSwitchValueASCII(switches::kLang);
|
2018-02-08 14:26:37 +00:00
|
|
|
LoadResourceBundle(locale);
|
2016-01-08 04:04:23 +00:00
|
|
|
}
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2013-12-03 22:12:21 +00:00
|
|
|
content::ContentBrowserClient* MainDelegate::CreateContentBrowserClient() {
|
2016-03-08 11:59:29 +00:00
|
|
|
browser_client_ = CreateBrowserClient();
|
2013-12-03 22:12:21 +00:00
|
|
|
return browser_client_.get();
|
|
|
|
}
|
|
|
|
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<BrowserClient> MainDelegate::CreateBrowserClient() {
|
|
|
|
return std::unique_ptr<BrowserClient>(new BrowserClient);
|
2013-12-03 22:12:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 23:20:17 +00:00
|
|
|
} // namespace brightray
|