This example isn't good for me, I don't want to run a blocking run loop for CEF. Besides
- (void)createApplication:(id)object
uses deprecated methods for loading nibs. I have a window configured in my nib with a NSView and I want to attach CEF to it. I need to run NSApplicationMain(argc, argv);.
This method is called inside appplicationDidFinishLaunching:
- Code: Select all
- (void)initializeCef:(CmdlineOptions)options
{
std::vector<std::string> arguments = options.createArgumentsList();
std::vector<std::string>::const_iterator it;
NSUInteger argc = arguments.size();
char *argv[argc];
for (it = arguments.cbegin(); it != arguments.cend(); it++)
{
NSUInteger index = it - arguments.begin();
argv[index] = const_cast<char *>((*it).c_str());
}
CefMainArgs main_args(argc, argv);
m_cefApp = new GCefClientApp();
CefSettings settings;
#ifndef PRODUCTION_ENVIRONMENT
settings.ignore_certificate_errors = true;
settings.remote_debugging_port = 12345;
#endif
if (m_cefCmdLine == "disable")
settings.log_severity = LOGSEVERITY_DISABLE;
if (m_cefCmdLine == "info")
settings.log_severity = LOGSEVERITY_INFO;
if (m_cefCmdLine == "warning")
settings.log_severity = LOGSEVERITY_WARNING;
if (m_cefCmdLine == "error")
settings.log_severity = LOGSEVERITY_ERROR;
if (m_cefCmdLine == "error-report")
settings.log_severity = LOGSEVERITY_ERROR_REPORT;
std::string cefLogFile = Utilities::AppendPath(ApplicationEnvironment::GetLogsPath(), "cef.log");
CefString(&settings.log_file) = CefString(cefLogFile);
std::string webcachePath = Utilities::AppendPath(ApplicationEnvironment::GetWebcachePath(), "common");
CefString(&settings.cache_path) = webcachePath;
CefExecuteProcess(main_args, m_cefApp.get(), nullptr);
m_cefInitialized = CefInitialize(main_args, settings, m_cefApp.get(), nullptr);
CefCookieManager::GetGlobalManager()->SetStoragePath(CefString(), false); //store all cookies in memory only.
m_cefHandler = new GCefClientHandler();
m_cefApp->setCefClientHandler(m_cefHandler);
NSView *view = [[self window] contentView];
CefWindowInfo info;
info.SetAsChild(view, view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height);
CefBrowserSettings browserSettings;
browserSettings.webgl = STATE_ENABLED;
browserSettings.universal_access_from_file_urls = STATE_ENABLED;
#ifndef PRODUCTION_ENVIRONMENT
browserSettings.javascript_open_windows = STATE_ENABLED;
#endif
CefBrowserHost::CreateBrowserSync(info, static_cast<CefRefPtr<CefClient>>(m_cefHandler), "", browserSettings, nullptr);
}