void WebViewHost::willSendRequest(WebFrame* frame, unsigned identifier, WebURLRequest& request, const WebURLResponse& redirectResponse) { if (request.url().isEmpty()) return; // Need to use GURL for host() and SchemeIs() GURL url = request.url(); string requestURL = url.possibly_invalid_spec(); GURL mainDocumentURL = request.firstPartyForCookies(); request.setExtraData(webkit_support::CreateWebURLRequestExtraData(frame->document().referrerPolicy())); string host = url.host(); if (!host.empty() && (url.SchemeIs("http") || url.SchemeIs("https"))) { if (!isLocalhost(host) && !hostIsUsedBySomeTestsToGenerateError(host) && ((!mainDocumentURL.SchemeIs("http") && !mainDocumentURL.SchemeIs("https")) || isLocalhost(mainDocumentURL.host())) && !m_shell->allowExternalPages()) { printf("Blocked access to external URL %s\n", requestURL.c_str()); blockRequest(request); return; } } // Set the new substituted URL. request.setURL(webkit_support::RewriteLayoutTestsURL(request.url().spec())); }
void WebViewHost::willSendRequest(WebFrame*, unsigned identifier, WebURLRequest& request, const WebURLResponse& redirectResponse) { // Need to use GURL for host() and SchemeIs() GURL url = request.url(); string requestURL = url.possibly_invalid_spec(); if (layoutTestController()->shouldDumpResourceLoadCallbacks()) { GURL mainDocumentURL = request.firstPartyForCookies(); printResourceDescription(identifier); printf(" - willSendRequest <NSURLRequest URL %s, main document URL %s," " http method %s> redirectResponse ", descriptionSuitableForTestResult(requestURL).c_str(), URLDescription(mainDocumentURL).c_str(), request.httpMethod().utf8().data()); printResponseDescription(redirectResponse); fputs("\n", stdout); } if (!redirectResponse.isNull() && m_blocksRedirects) { fputs("Returning null for this redirect\n", stdout); // To block the request, we set its URL to an empty one. request.setURL(WebURL()); return; } if (m_requestReturnNull) { // To block the request, we set its URL to an empty one. request.setURL(WebURL()); return; } string host = url.host(); // 255.255.255.255 is used in some tests that expect to get back an error. if (!host.empty() && (url.SchemeIs("http") || url.SchemeIs("https")) && host != "127.0.0.1" && host != "255.255.255.255" && host != "localhost" && !m_shell->allowExternalPages()) { printf("Blocked access to external URL %s\n", requestURL.c_str()); // To block the request, we set its URL to an empty one. request.setURL(WebURL()); return; } HashSet<String>::const_iterator end = m_clearHeaders.end(); for (HashSet<String>::const_iterator header = m_clearHeaders.begin(); header != end; ++header) request.clearHTTPHeaderField(WebString(header->characters(), header->length())); // Set the new substituted URL. request.setURL(webkit_support::RewriteLayoutTestsURL(request.url().spec())); }
bool WebViewHost::canHandleRequest(WebFrame*, const WebURLRequest& request) { GURL url = request.url(); // Just reject the scheme used in // LayoutTests/http/tests/misc/redirect-to-external-url.html return !url.SchemeIs("spaceballs"); }
string URLDescription(const GURL& url) { if (url.SchemeIs("file")) return url.ExtractFileName(); return url.possibly_invalid_spec(); }