107 lines
3.4 KiB
C++
107 lines
3.4 KiB
C++
|
// Copyright (c) 2013 The Chromium Embedded Framework 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 "Application/Application.h"
|
||
|
|
||
|
#include "include/cef_command_line.h"
|
||
|
#include "include/cef_sandbox_win.h"
|
||
|
#include "CEF/HumanAppBrowser.h"
|
||
|
#include "CEF/HumanAppRenderer.h"
|
||
|
#include "CEF/HumanAppOther.h"
|
||
|
#include "CEF/MainMessageLoopMultithreadedWin.h"
|
||
|
#include "CEF/MainMessageLoopExternalPump.h"
|
||
|
#include "CEF/TestRunner.h"
|
||
|
#include "CEF/RootWindow.h"
|
||
|
#include "CEF/HumanAppSwitches.h"
|
||
|
#include "Application/HuamnCreator.h"
|
||
|
|
||
|
|
||
|
Application::Application() {
|
||
|
// Enable High-DPI support on Windows 7 or newer.
|
||
|
CefEnableHighDPISupport();
|
||
|
|
||
|
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||
|
// Provide CEF with command-line arguments.
|
||
|
CefMainArgs main_args(hInstance);
|
||
|
|
||
|
// Parse command-line arguments for use in this method.
|
||
|
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
|
||
|
command_line->InitFromString(::GetCommandLineW());
|
||
|
|
||
|
HumanApp::ProcessType process_type = HumanApp::GetProcessType(command_line);
|
||
|
if (process_type == HumanApp::BrowserProcess) {
|
||
|
app_ = new HumanAppBrowser();
|
||
|
huamn_ = CreateHuamn();
|
||
|
huamn_->Login();
|
||
|
} else if (process_type == HumanApp::RendererProcess) {
|
||
|
app_ = new HumanAppRenderer();
|
||
|
} else if (process_type == HumanApp::OtherProcess) {
|
||
|
app_ = new HumanAppOther();
|
||
|
}
|
||
|
|
||
|
int exit_code = CefExecuteProcess(main_args, app_, nullptr);
|
||
|
CHECK(exit_code < 0);
|
||
|
|
||
|
// Create the main context object.
|
||
|
context_.reset(new HumanAppContextImpl(command_line, true));
|
||
|
|
||
|
CefSettings settings;
|
||
|
|
||
|
#if !defined(CEF_USE_SANDBOX)
|
||
|
settings.no_sandbox = true;
|
||
|
#endif
|
||
|
|
||
|
// Populate the settings based on command line arguments.
|
||
|
context_->PopulateSettings(&settings);
|
||
|
|
||
|
settings.windowless_rendering_enabled = true;
|
||
|
settings.background_color = CefColorSetARGB(0, 0, 0, 0);
|
||
|
|
||
|
// Create the main message loop object.
|
||
|
|
||
|
if (settings.multi_threaded_message_loop)
|
||
|
messageLoop_.reset(new MainMessageLoopMultithreadedWin);
|
||
|
else if (settings.external_message_pump)
|
||
|
messageLoop_ = MainMessageLoopExternalPump::Create();
|
||
|
else
|
||
|
messageLoop_.reset(new MainMessageLoopStd);
|
||
|
|
||
|
// Initialize CEF.
|
||
|
bool secuess = context_->Initialize(main_args, settings, app_, nullptr);
|
||
|
CHECK(secuess);
|
||
|
|
||
|
// Register scheme handlers.
|
||
|
test_runner::RegisterSchemeHandlers();
|
||
|
|
||
|
auto window_config = std::make_unique<RootWindowConfig>();
|
||
|
window_config->always_on_top =
|
||
|
command_line->HasSwitch(kAlwaysOnTop);
|
||
|
window_config->with_controls =
|
||
|
command_line->HasSwitch(kHideControls);
|
||
|
window_config->with_osr =
|
||
|
settings.windowless_rendering_enabled ? true : false;
|
||
|
|
||
|
window_config->url = "file:///D:/MyProgram/HumanRender/data/lrcdemo/lrcdemo.html";
|
||
|
|
||
|
window_config->background = "D:/MyProgram/HumanRender/data/background/background.jpg";
|
||
|
|
||
|
// Create the first window.
|
||
|
context_->GetRootWindowManager()->CreateRootWindow(std::move(window_config));
|
||
|
}
|
||
|
|
||
|
Application::~Application() {
|
||
|
huamn_.reset();
|
||
|
// Shut down CEF.
|
||
|
context_->Shutdown();
|
||
|
|
||
|
// Release objects in reverse order of creation.
|
||
|
messageLoop_.reset();
|
||
|
context_.reset();
|
||
|
}
|
||
|
|
||
|
int Application::Loop() {
|
||
|
int ret = messageLoop_->Run();
|
||
|
return ret;
|
||
|
}
|