Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose CefOverridePath to allow overriding DIR_EXE/DIR_MODULE paths (Issue 1936) #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -51,6 +51,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 @@ -51,3 +51,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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently allow customization of DIR_USER_DATA via CefSettings.user_data_path (in CefMainDelegate::PreSandboxStartup). If we add this method then we should delete CefSettings.user_data_path.

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 @@ -959,6 +959,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 @@ -880,6 +880,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