static const char divider = '/';
-static inline WTF::String pathSuitableForTestResult(WKURLRef fileUrl, WKURLRef mainFrameURL)
+static inline WTF::String pathSuitableForTestResult(WKURLRef fileUrl)
{
if (!fileUrl)
return String();
return toWTFString(adoptWK(WKURLCopyString(fileUrl)));
String pathString = toWTFString(adoptWK(WKURLCopyPath(fileUrl)));
- String mainFrameURLPathString = toWTFString(adoptWK(WKURLCopyPath(mainFrameURL)));
- String basePath = mainFrameURLPathString.substring(0, mainFrameURLPathString.reverseFind(divider)+1);
-
- if (pathString.startsWith(basePath))
- return pathString.substring(basePath.length());
- return toWTFString(adoptWK(WKURLCopyString(fileUrl)));
+ StringBuilder stringBuilder;
+
+ // Remove the leading path from file urls.
+ const size_t indexBaseName = pathString.reverseFind(divider);
+ if (indexBaseName != notFound) {
+ const size_t indexDirName = pathString.reverseFind(divider, indexBaseName - 1);
+ if (indexDirName != notFound)
+ stringBuilder.append(pathString.substring(indexDirName + 1, indexBaseName - indexDirName - 1));
+ stringBuilder.append(divider);
+ stringBuilder.append(pathString.substring(indexBaseName + 1)); // Filename.
+ } else {
+ stringBuilder.append(divider);
+ stringBuilder.append(pathString); // Return "/pathString".
+ }
+
+ return stringBuilder.toString();
}
static inline WTF::String urlSuitableForTestResult(WKURLRef fileUrl)
InjectedBundle::shared().outputText(stringBuilder.toString());
}
-static inline void dumpRequestDescriptionSuitableForTestResult(WKURLRequestRef request, StringBuilder& stringBuilder, WKURLRef mainFrameURL)
+static inline void dumpRequestDescriptionSuitableForTestResult(WKURLRequestRef request, StringBuilder& stringBuilder)
{
WKRetainPtr<WKURLRef> url = adoptWK(WKURLRequestCopyURL(request));
WKRetainPtr<WKURLRef> firstParty = adoptWK(WKURLRequestCopyFirstPartyForCookies(request));
WKRetainPtr<WKStringRef> httpMethod = adoptWK(WKURLRequestCopyHTTPMethod(request));
stringBuilder.appendLiteral("<NSURLRequest URL ");
- stringBuilder.append(pathSuitableForTestResult(url.get(), mainFrameURL));
+ stringBuilder.append(pathSuitableForTestResult(url.get()));
stringBuilder.appendLiteral(", main document URL ");
stringBuilder.append(urlSuitableForTestResult(firstParty.get()));
stringBuilder.appendLiteral(", http method ");
stringBuilder.append('>');
}
-static inline void dumpResponseDescriptionSuitableForTestResult(WKURLResponseRef response, StringBuilder& stringBuilder, WKURLRef mainFrameURL)
+static inline void dumpResponseDescriptionSuitableForTestResult(WKURLResponseRef response, StringBuilder& stringBuilder)
{
WKRetainPtr<WKURLRef> url = adoptWK(WKURLResponseCopyURL(response));
if (!url) {
return;
}
stringBuilder.appendLiteral("<NSURLResponse ");
- stringBuilder.append(pathSuitableForTestResult(url.get(), mainFrameURL));
+ stringBuilder.append(pathSuitableForTestResult(url.get()));
stringBuilder.appendLiteral(", http status code ");
stringBuilder.appendNumber(WKURLResponseHTTPStatusCode(response));
stringBuilder.append('>');
void InjectedBundlePage::willPerformClientRedirectForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKURLRef url, double delay, double date, const void* clientInfo)
{
- static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willPerformClientRedirectForFrame(page, frame, url, delay, date);
+ static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willPerformClientRedirectForFrame(frame, url, delay, date);
}
void InjectedBundlePage::didSameDocumentNavigationForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef*, const void* clientInfo)
dumpLoadEvent(frame, "didCancelClientRedirectForFrame");
}
-void InjectedBundlePage::willPerformClientRedirectForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKURLRef url, double delay, double date)
+void InjectedBundlePage::willPerformClientRedirectForFrame(WKBundleFrameRef frame, WKURLRef url, double delay, double date)
{
if (!InjectedBundle::shared().isTestRunning())
return;
return;
StringBuilder stringBuilder;
- WKRetainPtr<WKURLRef> mainFrameURL = adoptWK(WKBundleFrameCopyURL(WKBundlePageGetMainFrame(page)));
dumpFrameDescriptionSuitableForTestResult(frame, stringBuilder);
stringBuilder.appendLiteral(" - willPerformClientRedirectToURL: ");
- stringBuilder.append(pathSuitableForTestResult(url, mainFrameURL.get()));
+ stringBuilder.append(pathSuitableForTestResult(url));
stringBuilder.appendLiteral(" \n");
InjectedBundle::shared().outputText(stringBuilder.toString());
}
InjectedBundle::shared().outputText("didDetectXSS\n");
}
-void InjectedBundlePage::didInitiateLoadForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLRequestRef request, bool)
+void InjectedBundlePage::didInitiateLoadForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKURLRequestRef request, bool)
{
if (!InjectedBundle::shared().isTestRunning())
return;
return;
WKRetainPtr<WKURLRef> url = adoptWK(WKURLRequestCopyURL(request));
- WKRetainPtr<WKURLRef> mainFrameURL = adoptWK(WKBundleFrameCopyURL(WKBundlePageGetMainFrame(page)));
- assignedUrlsCache.add(identifier, pathSuitableForTestResult(url.get(), mainFrameURL.get()));
+ assignedUrlsCache.add(identifier, pathSuitableForTestResult(url.get()));
}
// Resource Load Client Callbacks
return WKStringIsEqualToUTF8CStringIgnoringCase(scheme, "http") || WKStringIsEqualToUTF8CStringIgnoringCase(scheme, "https");
}
-WKURLRequestRef InjectedBundlePage::willSendRequestForFrame(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKURLRequestRef request, WKURLResponseRef response)
+WKURLRequestRef InjectedBundlePage::willSendRequestForFrame(WKBundlePageRef, WKBundleFrameRef frame, uint64_t identifier, WKURLRequestRef request, WKURLResponseRef response)
{
if (InjectedBundle::shared().isTestRunning()
&& InjectedBundle::shared().testRunner()->shouldDumpResourceLoadCallbacks()) {
StringBuilder stringBuilder;
dumpResourceURL(identifier, stringBuilder);
stringBuilder.appendLiteral(" - willSendRequest ");
- WKRetainPtr<WKURLRef> mainFrameURL = adoptWK(WKBundleFrameCopyURL(WKBundlePageGetMainFrame(page)));
- dumpRequestDescriptionSuitableForTestResult(request, stringBuilder, mainFrameURL.get());
+ dumpRequestDescriptionSuitableForTestResult(request, stringBuilder);
stringBuilder.appendLiteral(" redirectResponse ");
- dumpResponseDescriptionSuitableForTestResult(response, stringBuilder, mainFrameURL.get());
+ dumpResponseDescriptionSuitableForTestResult(response, stringBuilder);
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
return request;
}
-void InjectedBundlePage::didReceiveResponseForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLResponseRef response)
+void InjectedBundlePage::didReceiveResponseForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKURLResponseRef response)
{
if (!InjectedBundle::shared().isTestRunning())
return;
StringBuilder stringBuilder;
dumpResourceURL(identifier, stringBuilder);
stringBuilder.appendLiteral(" - didReceiveResponse ");
- WKRetainPtr<WKURLRef> mainFrameURL = adoptWK(WKBundleFrameCopyURL(WKBundlePageGetMainFrame(page)));
- dumpResponseDescriptionSuitableForTestResult(response, stringBuilder, mainFrameURL.get());
+ dumpResponseDescriptionSuitableForTestResult(response, stringBuilder);
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}