CEF1 Win: XmlHttpRequest custom scheme no PostData

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

CEF1 Win: XmlHttpRequest custom scheme no PostData

Postby Mirco » Wed Apr 18, 2012 1:03 pm

Dear reader,

(Using Cef1 binary distribution version 1.963.439 on Windows XP and Windows Vista)

I'm issuing a XmlHttpRequest POST request with Content-Type: text/plain; charset=UTF-8 and a text as request data. Implementing my own scheme, I noticed that the ProcessRequest() does not hold any postdata in this case.
Code: Select all
ProcessRequest() request->GetPostData() returns a NULL pointer.

I found issue 404 http://code.google.com/p/chromiumembedd ... ail?id=404 with status WontFix. But I'm not sure issue 404 hits the same problem as I'm doing.

I modified the scheme_test.cpp file. When running the "Scheme handler" test, a new hyperlink "Test XmlHttpRequest POST" is at the bottom of the page. Clicking this link shows an Alert-Box. In the Alert-Box the string "This is the postdata payload." should be shown, but it isn't.
Code: Select all
  virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
                              CefRefPtr<CefSchemeHandlerCallback> callback)
                              OVERRIDE
  {
    REQUIRE_IO_THREAD();

    bool handled = false;

    AutoLock lock_scope(this);
   
    std::string url = request->GetURL();
    if(strstr(url.c_str(), "handler.html") != NULL) {
      // Build the response html
      data_ = "<html><head><title>Client Scheme Handler</title></head><body>"
              "This contents of this page page are served by the "
              "ClientSchemeHandler class handling the client:// protocol."
              "<br/>You should see an image:"
              "<br/><img src=\"client://tests/client.png\"><pre>";
     
      // Output a string representation of the request
      std::string dump;
      DumpRequestContents(request, dump);
      data_.append(dump);

      data_.append("</pre><br/>Try the test form:"
                   "<form method=\"POST\" action=\"handler.html\">"
                   "<input type=\"text\" name=\"field1\">"
                   "<input type=\"text\" name=\"field2\">"
                   "<input type=\"submit\">"
                   "</form>");
//
//MODIFIED START
//
      data_.append("\r\n<script language=\"javascript\">\r\n"
                   "function XHR_Post()\r\n"
                   "{\r\n"
                   "    var xhr = new XMLHttpRequest();\r\n"
                   "    xhr.open(\"POST\", \"dump.html?action=XHR_Post\", true);\r\n"
                   "    xhr.setRequestHeader(\"Content-Type\", \"text/plain; charset=UTF-8\");\r\n"
                   "    xhr.onreadystatechange = function() \r\n"
                   "        {\r\n"
                   "            if (xhr.readyState == 4)\r\n"
                   "                {\r\n"
                   "                    alert(xhr.responseText);\r\n"
                   "                }\r\n"
                   "        }\r\n"
                   "    xhr.send(\"This is the postdata payload.\");\r\n"
                   "}\r\n"
                   "</script>\r\n"
                   "<p><a href=\"javascript:XHR_Post();\">Test XmlHttpRequest POST</a></p>\r\n");

      data_.append("</body></html>");
//
//MODIFIED END
//

      handled = true;

      // Set the resulting mime type
      mime_type_ = "text/html";
    }
//
//MODIFIED START
//
    else if(strstr(url.c_str(), "dump.html") != NULL) {
      // Output a string representation of the request
      data_.clear();

      std::string dump;
      DumpRequestContents(request, dump);
      data_.append(dump);

      mime_type_ = "text/plain";
      handled = true;
    }
//
//MODIFIED END
//
    else if(strstr(url.c_str(), "client.png") != NULL) {
      // Load the response image
#if defined(OS_WIN)
      DWORD dwSize;
      LPBYTE pBytes;
      if(LoadBinaryResource(IDS_LOGO, dwSize, pBytes)) {
        data_ = std::string(reinterpret_cast<const char*>(pBytes), dwSize);
        handled = true;
        // Set the resulting mime type
        mime_type_ = "image/jpg";
      }
#elif (defined(OS_MACOSX) || defined(OS_LINUX))
      if(LoadBinaryResource("logo.png", data_)) {
        handled = true;
        // Set the resulting mime type
        mime_type_ = "image/png";
      }
#else
#error "Unsupported platform"
#endif
    }

    if (handled) {
      // Indicate the headers are available.
      callback->HeadersAvailable();
      return true;
    }

    return false;
  }


This problem is really a showstopper for me: not being able to call XmlHttpRequest on my custom scheme.

I hope somebody is willing to look into this problem and hopefully prove that I'm wrong or fix CEF1 ;)

Kind Regards,
Mirco Babin
Mirco
Techie
 
Posts: 29
Joined: Mon Jun 06, 2011 1:24 pm

Re: CEF1 Win: XmlHttpRequest custom scheme no PostData

Postby magreenblatt » Thu Apr 19, 2012 8:58 am

You can register a scheme handler factory using the http scheme. Try that and see if it fixes your problem:
Code: Select all
CefRegisterSchemeHandlerFactory("http", "myfakedomain", new SchemeHandlerFactory());
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: CEF1 Win: XmlHttpRequest custom scheme no PostData

Postby Mirco » Fri Apr 20, 2012 9:53 am

Hello Marshall,

CefRegisterSchemeHandlerFactory("http", "localexe", new SchemeHandlerFactory());

Using your suggestion, the GetPostData() is populated correctly, and the test result is correct.

So it seems there is a problem with a custom scheme in CEF and the XmlHttpRequest POST function.

I can't use your suggested solution. This is because I build a system around the "localexe://localhost/..." scheme. This scheme extends beyond CEF and goes into a PHP streamhandler for "localexe://localhost/".

Converting an URL string from "http://localexe/..." to "localexe://localhost/" is a piece of cake from a CEF view, but nearly impossible from a CEF and PHP integration point of view. PHP would get "localexe://localhost/" as base-url and might produce invalid html, because it produces html with links to "localexe://localhost/" wich are passed back to CEF. And CEF then will complain, because "localexe://localhost/" is unknown.

I would really appreciate it, if this problem could be solved in a new binary CEF1 distribution.

Kind regards,
Mirco Babin
Mirco
Techie
 
Posts: 29
Joined: Mon Jun 06, 2011 1:24 pm

Re: CEF1 Win: XmlHttpRequest custom scheme no PostData

Postby magreenblatt » Fri Apr 20, 2012 10:01 am

Hi Micro,

Issue #404 is WontFix. As stated in that issue this is an intentional WebKit design feature.

Regards,
Marshall
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: CEF1 Win: XmlHttpRequest custom scheme no PostData

Postby Mirco » Fri Apr 20, 2012 10:45 am

Hello Marshall,

WebKit does not pass POST data to the request for synchronous XHRs executed on non-HTTP schemes. See the m_url.protocolInHTTPFamily() check in XMLHttpRequest::send() in third_party/WebKit/Source/WebCore/xml/XMLHttpRequest.cpp. If you need to use XHR POST requests you should register your custom handler using the HTTP or HTTPS protocol. Since this is an intentional WebKit design feature it will likely not be changed for CEF.

The attached patch demonstrates this problem using the "Scheme Handler" test in cefclient.


I tried async TRUE and FALSE and neither works, so above statement should be: XHR Post request executed on non-HTTP-schemes does not work.
Code: Select all
xhr.open("POST", "testxhrpost.php?action=XHR_Post", async);


Unfortunatly I don't have the sources, so I can't check. But could it be possible to register my custom scheme as an protocolInHTTPFamily(). So the whole of webkit knows my scheme is HTTP compatible ? To put it stronger, my scheme *is* http compatible as it is backed by PHP.

Kind regards,
Mirco Babin
Mirco
Techie
 
Posts: 29
Joined: Mon Jun 06, 2011 1:24 pm

Re: CEF1 Win: XmlHttpRequest custom scheme no PostData

Postby magreenblatt » Fri Apr 20, 2012 10:57 am

You are of course welcome to build Chromium/CEF locally and make the changes that you need.
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: CEF1 Win: XmlHttpRequest custom scheme no PostData

Postby Mirco » Fri Apr 20, 2012 10:59 am

Well I would actually make the adjustments if the whole would compile in a VirtualBox XP 32bit machine. But according to the compile page you need at least a 64bit machine.

I'll try to find another solution. Thanks for your time !

Kind regards,
Mirco Babin
Mirco
Techie
 
Posts: 29
Joined: Mon Jun 06, 2011 1:24 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot], salvadordf and 34 guests