void LayoutTestController::queueLoad(JSStringRef url, JSStringRef target) { COMPtr<IWebDataSource> dataSource; if (FAILED(frame->dataSource(&dataSource))) return; COMPtr<IWebURLResponse> response; if (FAILED(dataSource->response(&response)) || !response) return; BSTR responseURLBSTR; if (FAILED(response->URL(&responseURLBSTR))) return; wstring responseURL(responseURLBSTR, SysStringLen(responseURLBSTR)); SysFreeString(responseURLBSTR); // FIXME: We should do real relative URL resolution here. int lastSlash = responseURL.rfind('/'); if (lastSlash != -1) responseURL = responseURL.substr(0, lastSlash); wstring wURL = jsStringRefToWString(url); wstring wAbsoluteURL = responseURL + TEXT("/") + wURL; JSRetainPtr<JSStringRef> jsAbsoluteURL(Adopt, JSStringCreateWithCharacters(wAbsoluteURL.data(), wAbsoluteURL.length())); WorkQueue::shared()->queue(new LoadItem(jsAbsoluteURL.get(), target)); }
wstring urlSuitableForTestResult(const wstring& urlString) { RetainPtr<CFURLRef> url = adoptCF(CFURLCreateWithBytes(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(urlString.c_str()), urlString.length() * sizeof(wstring::value_type), kCFStringEncodingUTF16, 0)); RetainPtr<CFStringRef> scheme = adoptCF(CFURLCopyScheme(url.get())); if (scheme && CFStringCompare(scheme.get(), CFSTR("file"), kCFCompareCaseInsensitive) != kCFCompareEqualTo) return urlString; COMPtr<IWebDataSource> dataSource; if (FAILED(frame->dataSource(&dataSource))) { if (FAILED(frame->provisionalDataSource(&dataSource))) return lastPathComponentAsWString(url.get()); } COMPtr<IWebMutableURLRequest> request; if (FAILED(dataSource->request(&request))) return lastPathComponentAsWString(url.get()); _bstr_t requestURLString; if (FAILED(request->URL(requestURLString.GetAddress()))) return lastPathComponentAsWString(url.get()); RetainPtr<CFURLRef> requestURL = adoptCF(CFURLCreateWithBytes(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(requestURLString.GetBSTR()), requestURLString.length() * sizeof(OLECHAR), kCFStringEncodingUTF16, 0)); RetainPtr<CFURLRef> baseURL = adoptCF(CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, requestURL.get())); RetainPtr<CFStringRef> basePath = adoptCF(CFURLCopyPath(baseURL.get())); RetainPtr<CFStringRef> path = adoptCF(CFURLCopyPath(url.get())); if (basePath.get() && CFStringHasPrefix(path.get(), basePath.get())) return cfStringRefToWString(substringFromIndex(path.get(), CFStringGetLength(basePath.get())).get()); return lastPathComponentAsWString(url.get()); }