Skip to content

Commit

Permalink
WebKit API should support loading file reference URLs
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=267928
rdar://120389511

Reviewed by Brent Fulgham.

WebKit API should support loading file reference URLs with the form file:///.file/id=...
A file reference URL can be resolved to the actual file with the NSURL method filePathURL.

* Source/WebKit/Shared/Cocoa/SandboxExtensionCocoa.mm:
(WebKit::SandboxExtensionImpl::consume):
(WebKit::resolvePathForSandboxExtension):
(WebKit::SandboxExtension::createHandleWithoutResolvingPath):
(WebKit::SandboxExtension::createHandleForReadByAuditToken):
(WebKit::SandboxExtension::createHandleForIOKitClassExtension):
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView loadFileURL:allowingReadAccessToURL:]):

Canonical link: https://commits.webkit.org/273367@main
  • Loading branch information
pvollan committed Jan 23, 2024
1 parent 2743761 commit 4b0d92f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions Source/WebKit/Shared/Cocoa/SandboxExtensionCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
return !sandbox_check(getpid(), 0, SANDBOX_FILTER_NONE);
#else
if (m_handle == -1) {
LOG_ERROR("Could not create a sandbox extension for '%s', errno = %d", m_token, errno);
RELEASE_LOG_ERROR(Sandbox, "Could not create a sandbox extension for '%s', errno = %d", m_token, errno);
return false;
}
return true;
Expand Down Expand Up @@ -173,7 +173,7 @@ String resolvePathForSandboxExtension(StringView path)
{
String resolvedPath = stringByResolvingSymlinksInPath(path);
if (resolvedPath.isNull()) {
LOG_ERROR("Could not create a valid file system representation for the string '%s' of length %lu", resolvedPath.utf8().data(), resolvedPath.length());
RELEASE_LOG_ERROR(Sandbox, "Could not create a valid file system representation for the string '%s' of length %u", resolvedPath.utf8().data(), resolvedPath.length());
return { };
}

Expand All @@ -187,7 +187,7 @@ String resolvePathForSandboxExtension(StringView path)

handle.m_sandboxExtension = SandboxExtensionImpl::create(path.utf8().data(), type, std::nullopt, Flags::DoNotCanonicalize);
if (!handle.m_sandboxExtension) {
LOG_ERROR("Could not create a sandbox extension for '%s'", path.utf8().data());
RELEASE_LOG_ERROR(Sandbox, "Could not create a sandbox extension for '%s'", path.utf8().data());
return std::nullopt;
}
return WTFMove(handle);
Expand Down Expand Up @@ -324,7 +324,7 @@ String resolvePathForSandboxExtension(StringView path)

handle.m_sandboxExtension = SandboxExtensionImpl::create(path.utf8().data(), Type::ReadByProcess, auditToken);
if (!handle.m_sandboxExtension) {
LOG_ERROR("Could not create a sandbox extension for '%s'", path.utf8().data());
RELEASE_LOG_ERROR(Sandbox, "Could not create a sandbox extension for '%s'", path.utf8().data());
return std::nullopt;
}

Expand All @@ -338,7 +338,7 @@ String resolvePathForSandboxExtension(StringView path)

handle.m_sandboxExtension = SandboxExtensionImpl::create(ioKitClass.characters(), Type::IOKit, auditToken);
if (!handle.m_sandboxExtension) {
LOG_ERROR("Could not create a sandbox extension for '%s'", ioKitClass.characters());
RELEASE_LOG_ERROR(Sandbox, "Could not create a sandbox extension for '%s'", ioKitClass.characters());
return std::nullopt;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ - (WKNavigation *)loadFileURL:(NSURL *)URL allowingReadAccessToURL:(NSURL *)read
if (![readAccessURL isFileURL])
[NSException raise:NSInvalidArgumentException format:@"%@ is not a file URL", readAccessURL];

return wrapper(_page->loadFile(URL.absoluteString, readAccessURL.absoluteString)).autorelease();
return wrapper(_page->loadFile(URL.filePathURL.absoluteString, readAccessURL.absoluteString)).autorelease();
}

- (WKNavigation *)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
Expand Down

0 comments on commit 4b0d92f

Please sign in to comment.