void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str) { std::stringstream ss; ss << "URL: " << std::string(request->GetURL()); ss << "\nMethod: " << std::string(request->GetMethod()); CefRequest::HeaderMap headerMap; request->GetHeaderMap(headerMap); if(headerMap.size() > 0) { ss << "\nHeaders:"; CefRequest::HeaderMap::const_iterator it = headerMap.begin(); for(; it != headerMap.end(); ++it) { ss << "\n\t" << std::string((*it).first) << ": " << std::string((*it).second); } } CefRefPtr<CefPostData> postData = request->GetPostData(); if(postData.get()) { CefPostData::ElementVector elements; postData->GetElements(elements); if(elements.size() > 0) { ss << "\nPost Data:"; CefRefPtr<CefPostDataElement> element; CefPostData::ElementVector::const_iterator it = elements.begin(); for(; it != elements.end(); ++it) { element = (*it); if(element->GetType() == PDE_TYPE_BYTES) { // the element is composed of bytes ss << "\n\tBytes: "; if(element->GetBytesCount() == 0) ss << "(empty)"; else { // retrieve the data. size_t size = element->GetBytesCount(); char* bytes = new char[size]; element->GetBytes(size, bytes); ss << std::string(bytes, size); delete [] bytes; } } else if(element->GetType() == PDE_TYPE_FILE) { ss << "\n\tFile: " << std::string(element->GetFile()); } } } } str = ss.str(); }
// Implementation of the schema handler for appjs:// requests. void AppjsSchemeHandler::Execute(CefThreadId threadId) { REQUIRE_UI_THREAD(); HandleScope scope; Local<Object> global = Context::GetCurrent()->Global(); Local<Object> emitter = global->Get(String::NewSymbol("process"))->ToObject(); const int argc = 3; Handle<Value> self = WrapObject(this); Local<Function> cb = FunctionTemplate::New(NodeCallback,self)->GetFunction(); Local<Object> req = Object::New(); Local<String> post = String::New(""); Local<Object> headers = Object::New(); Local<String> files = String::New(""); CefRequest::HeaderMap headerMap; request_->GetHeaderMap(headerMap); if (headerMap.size() > 0) { CefRequest::HeaderMap::const_iterator it = headerMap.begin(); for ( ; it != headerMap.end(); ++it) { headers->Set(String::New((uint16_t*)(*it).first.c_str()),String::New((uint16_t*)(*it).second.c_str())); } } CefRefPtr<CefPostData> postData = request_->GetPostData(); if(postData.get()){ CefPostData::ElementVector elements; postData->GetElements(elements); if (elements.size() > 0) { CefRefPtr<CefPostDataElement> element; CefPostData::ElementVector::const_iterator it = elements.begin(); for ( ; it != elements.end(); ++it) { element = (*it); if (element->GetType() == PDE_TYPE_BYTES && element->GetBytesCount()) { // retrieve the data. size_t size = element->GetBytesCount(); char* bytes = new char[size]; element->GetBytes(size, bytes); post = String::New(bytes,size); delete [] bytes; } else if (element->GetType() == PDE_TYPE_FILE) { //TODO Needs testing files = String::New((uint16_t*)element->GetFile().c_str()); } } } } Handle<Value> method = String::New((uint16_t*)request_->GetMethod().c_str()); Handle<Value> url = String::New((uint16_t*)request_->GetURL().c_str()); req->Set(String::NewSymbol("method"),method); req->Set(String::NewSymbol("url"),url); req->Set(String::NewSymbol("post"),post); req->Set(String::NewSymbol("headers"),headers); req->Set(String::NewSymbol("files"),files); Handle<Value> argv[argc] = {String::New("appjs-request"),req,cb}; node::MakeCallback(emitter,"emit",argc,argv); }