1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
CefRequestHandler::ReturnValue SimpleHandler::OnBeforeResourceLoad(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefRequestCallback> callback)
{
CefRequest::ReferrerPolicy origin = REFERRER_POLICY_ALWAYS;
request->SetReferrer("https://www.google.com/",origin);
CefRefPtr<CefPostData> post_data = request->GetPostData();
//if (post_data.get()) {
CefPostData::ElementVector elements;
post_data->GetElements(elements);
// DLOG(INFO) << "size = " << elements.size();
// if (elements.size() > 0) {
CefPostData::ElementVector::const_iterator it = elements.begin();
CefRefPtr<CefStreamWriter> writer = CefStreamWriter::CreateForFile("this.txt");
FILE *fd = fopen("this.txt", "w+b");
size_t bytes_write = 0;
for (; it != elements.end(); ++it) {
CefRefPtr<CefPostDataElement> element = (*it);
CefPostDataElement::Type type = element->GetType();
if (type == PDE_TYPE_BYTES) {
size_t size = element->GetBytesCount();
if (size > 0) {
char *bytes = new char[size];
element->GetBytes(size, bytes);
/* TODO FIXME: not work */
//int write = writer->Write(bytes, size, bytes_write);
//CefBytesWriter::CefBytesWriter(1);
//int CefBytesWriter::Write(bytes, 1, size);
int write = writer->Write(bytes, 1, size);
bytes_write += write;
DLOG(INFO) << "write: size = " << size << ": " << std::string(bytes, size);
delete [] bytes;
}
} else if (type == PDE_TYPE_FILE) {
/* XXX: no use */
//element->GetFile();
}
}
//writer->Flush();
fclose(fd);
// }
// }
//size_t size = 10;
//char *bytes = new char[10];
//size_t bytes_write = 0;
//CefRefPtr<CefStreamWriter> writer1 =
// writer->Write(bytes, 1, size);
//int write = writer->Write(bytes, size, bytes_write);
// int write = fwrite(bytes, 1, size, fd);
return RV_CONTINUE;
}
|