Use realpath to resolve paths

This commit is contained in:
Kevin Sawicki
2012-06-11 18:43:37 -07:00
parent 2cbe4e7f0d
commit 7e2eb5414d
2 changed files with 22 additions and 5 deletions

View File

@@ -96,12 +96,19 @@ int main(int argc, char *argv[]) {
window_info.SetAsChild(vbox);
std::string path;
path.append("file://");
path.append(szPath);
path.append("/../index.html");
char* realPath;
realPath = realpath(path.c_str(), NULL);
if (realPath == NULL)
return -1;
std::string resolved("file://");
resolved.append(realPath);
free(realPath);
CefBrowser::CreateBrowserSync(window_info,
static_cast<CefRefPtr<CefClient> >(g_handler), path,
static_cast<CefRefPtr<CefClient> >(g_handler), resolved,
browserSettings);
gtk_container_add(GTK_CONTAINER(window), vbox);

View File

@@ -11,6 +11,7 @@
#include "include/cef_frame.h"
#include "cefclient.h"
#include "native_handler.h"
#include <stdlib.h>
ClientHandler::ClientHandler() :
m_MainHwnd(NULL), m_BrowserHwnd(NULL), m_bFormElementHasFocus(false) {
@@ -90,9 +91,18 @@ void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefV8Value> atom = CefV8Value::CreateObject(NULL, NULL);
global->SetValue("atom", atom, V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<CefV8Value> loadPath = CefV8Value::CreateString(
AppPath() + "/..");
atom->SetValue("loadPath", loadPath, V8_PROPERTY_ATTRIBUTE_NONE);
std::string relativePath(AppPath());
relativePath.append("/..");
char* realLoadPath;
realLoadPath = realpath(relativePath.c_str(), NULL);
if (realLoadPath != NULL) {
std::string resolvedLoadPath(realLoadPath);
free(realLoadPath);
CefRefPtr<CefV8Value> loadPath = CefV8Value::CreateString(
resolvedLoadPath);
atom->SetValue("loadPath", loadPath, V8_PROPERTY_ATTRIBUTE_NONE);
}
CefRefPtr<CefV8Value> bootstrapScript = CefV8Value::CreateString(
"single-window-bootstrap");