Skip to content

Commit

Permalink
Add cef_override_path
Browse files Browse the repository at this point in the history
Patch by Czarek Tomczak

chromiumembedded/cef#4

Signed-off-by: Jiří Janoušek <[email protected]>
  • Loading branch information
jiri-janousek committed Dec 21, 2017
1 parent cd33baa commit 1d8cb13
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/capi/cef_path_util_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ extern "C" {
///
CEF_EXPORT int cef_get_path(cef_path_key_t key, cef_string_t* path);

///
// Override the path associated with the specified |key|. This cannot be used to
// change the value of PK_DIR_CURRENT, but that should be obvious. Also, if the
// path specifies a directory that does not exist, the directory will be created
// by this function. This function returns true (1) if successful. WARNING:
// Consumers of CefGetPath may expect paths to be constant over the lifetime of
// the app, so this function should be used with caution.
///
CEF_EXPORT int cef_override_path(cef_path_key_t key, const cef_string_t* path);

#ifdef __cplusplus
}
#endif
Expand Down
11 changes: 11 additions & 0 deletions include/cef_path_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,15 @@ typedef cef_path_key_t PathKey;
/*--cef()--*/
bool CefGetPath(PathKey key, CefString& path);

///
// Override the path associated with the specified |key|. This cannot
// be used to change the value of PK_DIR_CURRENT, but that should be obvious.
// Also, if the path specifies a directory that does not exist, the directory
// will be created by this method. This method returns true if successful.
// WARNING: Consumers of CefGetPath may expect paths to be constant
// over the lifetime of the app, so this method should be used with caution.
///
/*--cef()--*/
bool CefOverridePath(PathKey key, const CefString& path);

#endif // CEF_INCLUDE_CEF_PATH_UTIL_H_
35 changes: 35 additions & 0 deletions libcef/browser/path_util_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,38 @@ bool CefGetPath(PathKey key, CefString& path) {

return false;
}

bool CefOverridePath(PathKey key, const CefString& path) {
int pref_key = base::PATH_START;
switch(key) {
case PK_DIR_EXE:
pref_key = base::DIR_EXE;
break;
case PK_DIR_MODULE:
pref_key = base::DIR_MODULE;
break;
case PK_DIR_TEMP:
pref_key = base::DIR_TEMP;
break;
case PK_FILE_EXE:
pref_key = base::FILE_EXE;
break;
case PK_FILE_MODULE:
pref_key = base::FILE_MODULE;
break;
#if defined(OS_WIN)
case PK_LOCAL_APP_DATA:
pref_key = base::DIR_LOCAL_APP_DATA;
break;
#endif
case PK_USER_DATA:
pref_key = chrome::DIR_USER_DATA;
break;
default:
NOTREACHED() << "invalid argument";
return false;
}

base::FilePath file_path = base::FilePath(path);
return PathService::Override(pref_key, file_path);
}
17 changes: 17 additions & 0 deletions libcef_dll/libcef_dll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,23 @@ CEF_EXPORT int cef_get_path(cef_path_key_t key, cef_string_t* path) {
return _retval;
}

CEF_EXPORT int cef_override_path(cef_path_key_t key, const cef_string_t* path) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

// Verify param: path; type: string_byref_const
DCHECK(path);
if (!path)
return 0;

// Execute
bool _retval = CefOverridePath(
key,
CefString(path));

// Return type: bool
return _retval;
}

CEF_EXPORT int cef_launch_process(struct _cef_command_line_t* command_line) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

Expand Down
17 changes: 17 additions & 0 deletions libcef_dll/wrapper/libcef_dll_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,23 @@ CEF_GLOBAL bool CefGetPath(PathKey key, CefString& path) {
return _retval ? true : false;
}

CEF_GLOBAL bool CefOverridePath(PathKey key, const CefString& path) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

// Verify param: path; type: string_byref_const
DCHECK(!path.empty());
if (path.empty())
return false;

// Execute
int _retval = cef_override_path(
key,
path.GetStruct());

// Return type: bool
return _retval?true:false;
}

CEF_GLOBAL bool CefLaunchProcess(CefRefPtr<CefCommandLine> command_line) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

Expand Down

0 comments on commit 1d8cb13

Please sign in to comment.