예제 #1
0
void Cef::Init() {

  if( !Cef::initialized_ ) {
    CefLoop::Init();

    CefSettings settings;
    CefRefPtr<CefApp> app;

    // TODO: Use settings.pack_file_path to set the correct chrome.pak path
    // since it searches in execute path ( where node exists ) to find
    // the pack file in linux and it won't work.
    // settings.pack_file_path = filePath;
    settings.pack_loading_disabled = true;
    settings.multi_threaded_message_loop = false;


    g_handler = new ClientHandler();
    CefInitialize(settings, app);

    // Accoding to this thread [1], I changed appjs scheme to
    // normal http scheme with a special domain name.
    // [1] http://code.google.com/p/chromiumembedded/issues/detail?id=404

    //CefRegisterCustomScheme("appjs", true, false, false);
    CefRegisterSchemeHandlerFactory("http", "appjs",
        new AppjsSchemeHandlerFactory());

    CefBase::Init();
    Cef::initialized_ = true;
  }

};
예제 #2
0
bool CWebCore::Initialise ()
{
    CefMainArgs mainArgs;
    void* sandboxInfo = nullptr;
    CefRefPtr<CCefApp> app { new CCefApp };

#if CEF_ENABLE_SANDBOX
    CefScopedSandboxInfo scopedSandbox;
    sandboxInfo = scopedSandbox.sandbox_info();
#endif

    if ( CefExecuteProcess ( mainArgs, app, sandboxInfo ) >= 0 )
        return false;

    CefSettings settings;
#if !CEF_ENABLE_SANDBOX
    settings.no_sandbox = true;
#endif

    // Specifiy sub process executable path
#ifndef MTA_DEBUG
    CefString ( &settings.browser_subprocess_path ).FromWString( FromUTF8( CalcMTASAPath ( "MTA\\CEF\\CEFLauncher.exe" ) ) );
#else
    CefString ( &settings.browser_subprocess_path ).FromWString( FromUTF8( CalcMTASAPath ( "MTA\\CEF\\CEFLauncher_d.exe" ) ) );
#endif
    CefString ( &settings.resources_dir_path ).FromWString ( FromUTF8( CalcMTASAPath( "MTA\\CEF") ) );
    CefString ( &settings.locales_dir_path ).FromWString( FromUTF8( CalcMTASAPath( "MTA\\CEF\\locales" ) ) );
    CefString ( &settings.log_file ).FromWString ( FromUTF8( CalcMTASAPath ( "MTA\\CEF\\cefdebug.txt" ) ) );
#ifdef MTA_DEBUG
    settings.log_severity = cef_log_severity_t::LOGSEVERITY_INFO;
#else
    settings.log_severity = cef_log_severity_t::LOGSEVERITY_WARNING;
#endif

    settings.multi_threaded_message_loop = true;
    settings.windowless_rendering_enabled = true;

    bool state = CefInitialize ( mainArgs, settings, app, sandboxInfo );
    
    // Register custom scheme handler factory
    CefRegisterSchemeHandlerFactory ( "mtalocal", "", app );
    CefRegisterSchemeHandlerFactory ( "http", "mta", app );

    return state;
}
	bool registerScheme(ChromiumDLL::SchemeExtenderI* se)
	{
		if (m_mSchemeMap[se->getHostName()])
			m_mSchemeMap[se->getHostName()]->destroy();

		m_mSchemeMap[se->getHostName()] = se;

		return CefRegisterSchemeHandlerFactory(se->getSchemeName(), se->getHostName(), this);
	}
예제 #4
0
bool ResourceUI::Create()
{
	// get the metadata component
	fwRefContainer<fx::ResourceMetaDataComponent> metaData = m_resource->GetComponent<fx::ResourceMetaDataComponent>();

	// get the UI page list and a number of pages
	auto uiPageData = metaData->GetEntries("ui_page");
	int pageCount = std::distance(uiPageData.begin(), uiPageData.end());

	// if no page exists, return
	if (pageCount == 0)
	{
		return false;
	}

	// if more than one, warn
	if (pageCount > 1)
	{
		trace(__FUNCTION__ ": more than one ui_page in resource %s\n", m_resource->GetName().c_str());
		return false;
	}

	// mark us as having a frame
	m_hasFrame = true;

	// get the page name from the iterator
	std::string pageName = uiPageData.begin()->second;

	// initialize the page
	auto resourceName = m_resource->GetName();
	std::transform(resourceName.begin(), resourceName.end(), resourceName.begin(), ::ToLower);
	CefRegisterSchemeHandlerFactory("http", resourceName, Instance<NUISchemeHandlerFactory>::Get());

	// create the NUI frame
	std::string path = "nui://" + m_resource->GetName() + "/" + pageName;
	nui::CreateFrame(m_resource->GetName(), path);

	// add a cross-origin entry to allow fetching the callback handler
	CefAddCrossOriginWhitelistEntry(va("nui://%s", m_resource->GetName().c_str()), "http", m_resource->GetName(), true);

	return true;
}
예제 #5
0
bool ResourceUI::Create()
{
	auto& metaData = m_resource->GetMetaData();
	auto it = metaData.find("uiPage");

	CefRegisterSchemeHandlerFactory("http", m_resource->GetName(), nui::GetSchemeHandlerFactory());

	if (it == metaData.end())
	{
		return false;
	}

	std::string path = "nui://" + m_resource->GetName() + "/" + it->second;

	nui::CreateFrame(m_resource->GetName(), path);

	CefAddCrossOriginWhitelistEntry(va("nui://%s", m_resource->GetName().c_str()), "http", m_resource->GetName(), true);

	return true;
}
예제 #6
0
void LootApp::OnContextInitialized() {
    //Make sure this is running in the UI thread.
  assert(CefCurrentlyOn(TID_UI));

  // Information used when creating the native window.
  CefWindowInfo window_info;

#ifdef _WIN32
  // On Windows we need to specify certain flags that will be passed to CreateWindowEx().
  window_info.SetAsPopup(NULL, "LOOT");
#endif

  // Set the handler for browser-level callbacks.
  CefRefPtr<LootHandler> handler(new LootHandler(lootState_));

  // Register the custom "loot" domain handler.
  CefRegisterSchemeHandlerFactory("http", "loot", new LootSchemeHandlerFactory());

  // Specify CEF browser settings here.
  CefBrowserSettings browser_settings;

  // Need to set the global locale for this process so that messages will
  // be translated.
  BOOST_LOG_TRIVIAL(debug) << "Initialising language settings in UI thread.";
  if (lootState_.getLanguage().GetCode() != LanguageCode::english) {
    boost::locale::generator gen;
    gen.add_messages_path(LootPaths::getL10nPath().string());
    gen.add_messages_domain("loot");

    BOOST_LOG_TRIVIAL(debug) << "Selected language: " << lootState_.getLanguage().GetName();
    std::locale::global(gen(lootState_.getLanguage().GetLocale() + ".UTF-8"));
    boost::filesystem::path::imbue(std::locale());
  }

  // Set URL to load. Ignore any command line values.
  const std::string url = "http://loot/ui/index.html";

  // Create the first browser window.
  CefBrowserHost::CreateBrowser(window_info, handler.get(), url, browser_settings, NULL);
}
void BrowserManager::Impl::BrowserManagerEntry()
{
	std::string bootstrapPath = getBootstrap();
	bool thread_exit = false;
	PushEvent([] {
		CefMainArgs mainArgs;
		CefSettings settings;
		settings.log_severity = LOGSEVERITY_VERBOSE;
		settings.windowless_rendering_enabled = true;
		settings.no_sandbox = true;
		CefString(&settings.cache_path).FromASCII(obs_module_config_path(""));
		CefString(&settings.browser_subprocess_path) = getBootstrap();
		CefRefPtr<BrowserApp> app(new BrowserApp());
		CefExecuteProcess(mainArgs, app, nullptr);
		CefInitialize(mainArgs, settings, app, nullptr);
		CefRegisterSchemeHandlerFactory("http", "absolute", new BrowserSchemeHandlerFactory());
		CefRunMessageLoop();
		CefShutdown();
	});

	while (true) {
		
		if (os_event_timedwait(dispatchEvent, 10) != ETIMEDOUT) {
			pthread_mutex_lock(&dispatchLock);
			while (!queue.empty()) {
				auto event = queue[0];
				event();
				queue.erase(queue.begin());
			}
			thread_exit = !threadAlive;
			pthread_mutex_unlock(&dispatchLock);
			if (thread_exit) {
				return;
			}
		}
	}
}
예제 #8
0
void CSSchemeFactory::Register()
{
    CefRegisterCustomScheme(LOCAL_SCHEME, true, false, false);
    CefRegisterSchemeHandlerFactory(LOCAL_SCHEME, "file", new CSSchemeFactory());
    //CefRegisterSchemeHandlerFactory(LOCAL_SCHEME, "zip", new CSZipSchemeFactory());
}
예제 #9
0
void FinalizeInitNUI()
{
    if (getenv("CitizenFX_ToolMode"))
    {
        return;
    }

	std::wstring cachePath = MakeRelativeCitPath(L"cache\\browser\\");
	CreateDirectory(cachePath.c_str(), nullptr);

	// delete any old CEF logs
	DeleteFile(MakeRelativeCitPath(L"debug.log").c_str());

	auto selfApp = Instance<NUIApp>::Get();

	CefMainArgs args(GetModuleHandle(NULL));
	CefRefPtr<CefApp> app(selfApp);

	CefSettings cSettings;
		
	cSettings.multi_threaded_message_loop = true;
	cSettings.remote_debugging_port = 13172;
	cSettings.pack_loading_disabled = false; // true;
	cSettings.windowless_rendering_enabled = false; // true;
	cSettings.log_severity = LOGSEVERITY_DISABLE;
	
	CefString(&cSettings.browser_subprocess_path).FromWString(MakeCfxSubProcess(L"ChromeBrowser"));

	CefString(&cSettings.locale).FromASCII("en-US");

	std::wstring resPath = MakeRelativeCitPath(L"bin/cef/");

	CefString(&cSettings.resources_dir_path).FromWString(resPath);
	CefString(&cSettings.locales_dir_path).FromWString(resPath);
	CefString(&cSettings.cache_path).FromWString(cachePath);

	// 2014-06-30: sandbox disabled as it breaks scheme handler factories (results in blank page being loaded)
	CefInitialize(args, cSettings, app.get(), /*cefSandbox*/ nullptr);
	CefRegisterSchemeHandlerFactory("nui", "", Instance<NUISchemeHandlerFactory>::Get());
	CefAddCrossOriginWhitelistEntry("nui://game", "http", "", true);
	CefAddCrossOriginWhitelistEntry("nui://game", "nui", "", true);

    HookFunctionBase::RunAll();

#if defined(GTA_NY)
	OnGrcBeginScene.Connect([] ()
	{
		Instance<NUIWindowManager>::Get()->ForAllWindows([] (fwRefContainer<NUIWindow> window)
		{
			window->UpdateFrame();
		});
	});
#else

#endif

	//g_hooksDLL->SetHookCallback(StringHash("d3dCreate"), [] (void*)
	OnGrcCreateDevice.Connect([]()
	{
		//int resX = *(int*)0xFDCEAC;
		//int resY = *(int*)0xFDCEB0;
		int resX, resY;
		GetGameResolution(resX, resY);

		auto rootWindow = NUIWindow::Create(true, resX, resY, "nui://game/ui/root.html");
		rootWindow->SetPaintType(NUIPaintTypePostRender);

		Instance<NUIWindowManager>::Get()->SetRootWindow(rootWindow);
	});
}