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())); }
/** * Returns all Links found in an URL * @return a vector of strings of the links we got */ vector < GURL > Page::getLinks() { vector< GURL > answer; HTML::ParserDom parser; GURL curr( url ); if (getContent() == "") return answer; tree<HTML::Node> dom = parser.parseTree(content); tree<HTML::Node>::iterator it = dom.begin(); tree<HTML::Node>::iterator end = dom.end(); for (; it != end; ++it) { if (it->tagName() == "a") { it->parseAttributes(); string relative = it->attribute("href").second; GURL resolved = curr.Resolve(relative); if (resolved.host() == curr.host() ) answer.push_back( resolved ); } } return answer; }
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())); }
void print_uri(GURL &url) { std::cout << "scheme:\t\t" << url.scheme() << "\nusername:\t" << url.username() << "\npassword:\t" << url.password() << "\nhost:\t\t" << url.host() << "\nport:\t\t" << url.port() << "\npath:\t\t" << url.path() << "\nquery:\t\t" << url.query() << "\nfragment:\t" << url.ref() << "\n\n"; }