CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request) { std::string url = request->GetURL(); if (url.find(kTestOrigin) == 0) { // Handle URLs in the test origin. std::string file_name, mime_type; if (ParseTestUrl(url, &file_name, &mime_type)) { if (file_name == "request.html") { // Show the request contents. std::string dump; DumpRequestContents(request, dump); CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForData( static_cast<void*>(const_cast<char*>(dump.c_str())), dump.size()); ASSERT(stream.get()); return new CefStreamResourceHandler("text/plain", stream); } else { // Load the resource from file. CefRefPtr<CefStreamReader> stream = GetBinaryResourceReader(file_name.c_str()); if (stream.get()) return new CefStreamResourceHandler(mime_type, stream); } } } return NULL; }
CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request) { CEF_REQUIRE_IO_THREAD(); std::string url = request->GetURL(); if (url.find(kTestOrigin) == 0) { // Handle URLs in the test origin. std::string file_name, mime_type; if (ParseTestUrl(url, &file_name, &mime_type)) { if (file_name == "request.html") { // Show the request contents. std::string dump; DumpRequestContents(request, dump); std::string str = "<html><body bgcolor=\"white\"><pre>" + dump + "</pre></body></html>"; CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForData( static_cast<void*>(const_cast<char*>(str.c_str())), str.size()); DCHECK(stream.get()); return new CefStreamResourceHandler("text/html", stream); } else { // Load the resource from file. CefRefPtr<CefStreamReader> stream = GetBinaryResourceReader(file_name.c_str()); if (stream.get()) return new CefStreamResourceHandler(mime_type, stream); } } } return NULL; }
bool ClientHandler::OnBeforeResourceLoad( CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request, CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream, CefRefPtr<CefResponse> response, int loadFlags) { std::string url = request->GetURL(); if (url.find(kTestOrigin) == 0) { // Handle URLs in the test origin. std::string file_name, mime_type; if (ParseTestUrl(url, &file_name, &mime_type)) { if (file_name == "request.html") { // Show the request contents. std::string dump; DumpRequestContents(request, dump); resourceStream = CefStreamReader::CreateForData( static_cast<void*>(const_cast<char*>(dump.c_str())), dump.size()); response->SetMimeType("text/plain"); response->SetStatus(200); } else { // Load the resource from file. resourceStream = GetBinaryResourceReader(file_name.c_str()); if (resourceStream.get()) { response->SetMimeType(mime_type); response->SetStatus(200); } } } } return false; }
CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request) { std::string url = request->GetURL(); if (url == "http://tests/request") { // Show the request contents std::string dump; DumpRequestContents(request, dump); CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForData( static_cast<void*>(const_cast<char*>(dump.c_str())), dump.size()); ASSERT(stream.get()); return new CefStreamResourceHandler("text/plain", stream); } else if (url == "http://tests/dialogs") { // Show the dialogs contents CefRefPtr<CefStreamReader> stream = GetBinaryResourceReader("dialogs.html"); ASSERT(stream.get()); return new CefStreamResourceHandler("text/html", stream); } else if (url == dom_test::kTestUrl) { // Show the domaccess contents CefRefPtr<CefStreamReader> stream = GetBinaryResourceReader("domaccess.html"); ASSERT(stream.get()); return new CefStreamResourceHandler("text/html", stream); } else if (url == "http://tests/localstorage") { // Show the localstorage contents CefRefPtr<CefStreamReader> stream = GetBinaryResourceReader("localstorage.html"); ASSERT(stream.get()); return new CefStreamResourceHandler("text/html", stream); } else if (url == "http://tests/transparency") { // Show the transparency contents CefRefPtr<CefStreamReader> stream = GetBinaryResourceReader("transparency.html"); ASSERT(stream.get()); return new CefStreamResourceHandler("text/html", stream); } else if (url == "http://tests/xmlhttprequest") { // Show the xmlhttprequest contents CefRefPtr<CefStreamReader> stream = GetBinaryResourceReader("xmlhttprequest.html"); ASSERT(stream.get()); return new CefStreamResourceHandler("text/html", stream); } CefRefPtr<CefResourceHandler> handler; // Execute delegate callbacks. RequestDelegateSet::iterator it = request_delegates_.begin(); for (; it != request_delegates_.end() && !handler.get(); ++it) handler = (*it)->GetResourceHandler(this, browser, frame, request); return handler; }
bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request, CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream, CefRefPtr<CefResponse> response, int loadFlags) { REQUIRE_IO_THREAD(); std::string url = request->GetURL(); if(url == "http://tests/request") { // Show the request contents std::string dump; DumpRequestContents(request, dump); resourceStream = CefStreamReader::CreateForData((void*)dump.c_str(), dump.size()); response->SetMimeType("text/plain"); response->SetStatus(200); } else if(strstr(url.c_str(), "/ps_logo2.png") != NULL) { // Any time we find "ps_logo2.png" in the URL substitute in our own image resourceStream = GetBinaryResourceReader(IDS_LOGO); response->SetMimeType("image/png"); response->SetStatus(200); } else if(url == "http://tests/uiapp") { // Show the uiapp contents resourceStream = GetBinaryResourceReader(IDS_UIPLUGIN); response->SetMimeType("text/html"); response->SetStatus(200); } else if(url == "http://tests/osrapp") { // Show the osrapp contents resourceStream = GetBinaryResourceReader(IDS_OSRPLUGIN); response->SetMimeType("text/html"); response->SetStatus(200); } else if(url == "http://tests/localstorage") { // Show the localstorage contents resourceStream = GetBinaryResourceReader(IDS_LOCALSTORAGE); response->SetMimeType("text/html"); response->SetStatus(200); } else if(url == "http://tests/xmlhttprequest") { // Show the xmlhttprequest HTML contents resourceStream = GetBinaryResourceReader(IDS_XMLHTTPREQUEST); response->SetMimeType("text/html"); response->SetStatus(200); } else if(url == "http://tests/domaccess") { // Show the domaccess HTML contents resourceStream = GetBinaryResourceReader(IDS_DOMACCESS); response->SetMimeType("text/html"); response->SetStatus(200); } else if(strstr(url.c_str(), "/logoball.png") != NULL) { // Load the "logoball.png" image resource. resourceStream = GetBinaryResourceReader(IDS_LOGOBALL); response->SetMimeType("image/png"); response->SetStatus(200); } else if(url == "http://tests/modalmain") { resourceStream = GetBinaryResourceReader(IDS_MODALMAIN); response->SetMimeType("text/html"); response->SetStatus(200); } else if(url == "http://tests/modaldialog") { resourceStream = GetBinaryResourceReader(IDS_MODALDIALOG); response->SetMimeType("text/html"); response->SetStatus(200); } return false; }
bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request, CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream, CefRefPtr<CefResponse> response, int loadFlags) { REQUIRE_IO_THREAD(); std::string url = request->GetURL(); if (url == "http://tests/request") { // Show the request contents std::string dump; DumpRequestContents(request, dump); resourceStream = CefStreamReader::CreateForData( static_cast<void*>(const_cast<char*>(dump.c_str())), dump.size()); response->SetMimeType("text/plain"); response->SetStatus(200); } else if (strstr(url.c_str(), "/ps_logo2.png") != NULL) { // Any time we find "ps_logo2.png" in the URL substitute in our own image resourceStream = GetBinaryResourceReader(IDS_LOGO); response->SetMimeType("image/png"); response->SetStatus(200); } else if (url == "http://tests/uiapp") { // Show the uiapp contents resourceStream = GetBinaryResourceReader(IDS_UIPLUGIN); response->SetMimeType("text/html"); response->SetStatus(200); } else if (url == "http://tests/osrapp") { // Show the osrapp contents resourceStream = GetBinaryResourceReader(IDS_OSRPLUGIN); response->SetMimeType("text/html"); response->SetStatus(200); } else if (url == "http://tests/localstorage") { // Show the localstorage contents resourceStream = GetBinaryResourceReader(IDS_LOCALSTORAGE); response->SetMimeType("text/html"); response->SetStatus(200); } else if (url == "http://tests/xmlhttprequest") { // Show the xmlhttprequest HTML contents resourceStream = GetBinaryResourceReader(IDS_XMLHTTPREQUEST); response->SetMimeType("text/html"); response->SetStatus(200); } else if (url == "http://tests/domaccess") { // Show the domaccess HTML contents resourceStream = GetBinaryResourceReader(IDS_DOMACCESS); response->SetMimeType("text/html"); response->SetStatus(200); } else if (strstr(url.c_str(), "/logoball.png") != NULL) { // Load the "logoball.png" image resource. resourceStream = GetBinaryResourceReader(IDS_LOGOBALL); response->SetMimeType("image/png"); response->SetStatus(200); } else if (url == "http://tests/modalmain") { resourceStream = GetBinaryResourceReader(IDS_MODALMAIN); response->SetMimeType("text/html"); response->SetStatus(200); } else if (url == "http://tests/modaldialog") { resourceStream = GetBinaryResourceReader(IDS_MODALDIALOG); response->SetMimeType("text/html"); response->SetStatus(200); } else if (url == "http://tests/transparency") { resourceStream = GetBinaryResourceReader(IDS_TRANSPARENCY); response->SetMimeType("text/html"); response->SetStatus(200); } else if (url == "http://tests/plugin") { std::string html = "<html><body>\n" "Client Plugin loaded by Mime Type:<br>\n" "<embed type=\"application/x-client-plugin\" width=600 height=40>\n" "<br><br>Client Plugin loaded by File Extension:<br>\n" "<embed src=\"test.xcp\" width=600 height=40>\n" // Add some extra space below the plugin to allow scrolling. "<div style=\"height:1000px;\"> </div>\n" "</body></html>"; resourceStream = CefStreamReader::CreateForData( static_cast<void*>(const_cast<char*>(html.c_str())), html.size()); response->SetMimeType("text/html"); response->SetStatus(200); } return false; }