ClientHandler::OnBeforeBrowse - no POST data?

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.

ClientHandler::OnBeforeBrowse - no POST data?

Postby HarmlessDave » Thu Feb 01, 2018 3:05 pm

CEF 3.3239.1723.g071d1c1, Windows 32-bit, Spotify binaries.

I'm updating from 2924 and needed to move my event handler from the (now removed) render process' OnBeforeNavigation to the browser process ClientHandler::OnBeforeBrowse. This is mostly working, except that now I'm not getting any POST data, request->GetPostData returns null.

I tried modifying the stock CEFClient and I am not seeing any POST data there, for a simple search form that doesn't use AJAX or any modern HTML.

Code: Select all
bool ClientHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
                                   CefRefPtr<CefFrame> frame,
                                   CefRefPtr<CefRequest> request,
                                   bool is_redirect) {
  CEF_REQUIRE_UI_THREAD();

  int count = 0;
  CefRefPtr<CefPostData> post = request->GetPostData();
  if (post.get())
  {
     CefPostData::ElementVector elements;
     post->GetElements(elements);
     count = elements.size();
     if (count > 0)
     {
        MessageBoxA(NULL, "Test - POST data found", "POST OK", MB_OK);
     }
  }
  else
  {
     std::string strURL = request->GetURL();
     if (strURL.find("search.php") != std::string::npos)
        MessageBoxA(NULL, "No POST data", "POST FAIL", MB_OK);
  }

  message_router_->OnBeforeBrowse(browser, frame);
  return false;
}


This always displays the "No POST data" message box on form submit.

Am I attaching to the wrong OnBeforeBrowse event? Or do I need to do something like explicitly cast the request pointer to a more specific type than CefRequest?
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: ClientHandler::OnBeforeBrowse - no POST data?

Postby magreenblatt » Thu Feb 01, 2018 10:53 pm

Is the POST data available from other CefRequestHandler callbacks like OnBeforeResourceLoad?
magreenblatt
Site Admin
 
Posts: 12402
Joined: Fri May 29, 2009 6:57 pm

Re: ClientHandler::OnBeforeBrowse - no POST data?

Postby HarmlessDave » Fri Feb 02, 2018 3:23 pm

Yes, I can see the POST data in OnBeforeResourceLoad using the exact same code.

Here is an updated sample that can be used in CEFCleint in both events with any page, for example the ArsTechnica forums login page - https://arstechnica.com/civis/ucp.php?m ... 2Fcivis%2F

Code: Select all
  // std::string strURL = request->GetURL();
  // if (strURL.find("search.php") != std::string::npos && (request->GetMethod() == "POST"))
  if (request->GetMethod() == "POST")
  {
     int count = 0;
     CefRefPtr<CefPostData> post = request->GetPostData();
     if (post.get())
     {
        CefPostData::ElementVector elements;
        post->GetElements(elements);
        count = elements.size();
        if (count > 0)
           MessageBoxA(NULL, "B4Br - POST data found", "POST OK", MB_OK);
        else
           MessageBoxA(NULL, "B4Br - POST data found but empty", "POST OK", MB_OK);
     }
     else
        MessageBoxA(NULL, "B4Br - No POST data", "POST FAIL", MB_OK);
  }


For OnBeforeResourceLoad I change the message box text from "B4Br" to "OnRL," and for BeforeBrowse I get "No POST data" while for ResourceLoad I get "Post data found."

Is working as intended? In our use case we need to be able to see the POST data to tell apart navigations that share the same server URL with POST values specifying different actions. In some cases we need to delay or cancel these navigations.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: ClientHandler::OnBeforeBrowse - no POST data?

Postby magreenblatt » Fri Feb 02, 2018 5:13 pm

It may be working as intended from Chromium's perspective. You can add a comment about this problem on https://bitbucket.org/chromiumembedded/cef/issues/2290 and I'll see what can be done when I get back to that issue.
magreenblatt
Site Admin
 
Posts: 12402
Joined: Fri May 29, 2009 6:57 pm

Re: ClientHandler::OnBeforeBrowse - no POST data?

Postby HarmlessDave » Fri Feb 02, 2018 6:59 pm

Thanks, I've added a comment. Let me know if you need any additional details.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: ClientHandler::OnBeforeBrowse - no POST data?

Postby chromodo » Thu Apr 05, 2018 4:35 am

I'd like to hijack this thread for another issue with the missing OnBeforeNavigation callback.

with OnBeforeNavigation we used to have cef_navigation_type_t navigation_type
now that seem not to exist with OnBeforeBrowse.
however i found this:
Code: Select all
public virtual bool OnOpenURLFromTab( CefRefPtr< CefBrowser > browser, CefRefPtr< CefFrame > frame, const CefString& target_url, CefRequestHandler::WindowOpenDisposition target_disposition, bool user_gesture );


which has bool user_gesture!

could you please confirm whether navigation_type is gone for good and user_gesture is what you need to use if you want to detect whether it was a click.

what is the general difference between OnBeforeBrowse and OnOpenURLFromTab?

thanks alot
chromodo
Newbie
 
Posts: 1
Joined: Thu Apr 05, 2018 3:42 am

Re: ClientHandler::OnBeforeBrowse - no POST data?

Postby magreenblatt » Thu Apr 05, 2018 12:52 pm

chromodo wrote:could you please confirm whether navigation_type is gone for good and user_gesture is what you need to use if you want to detect whether it was a click.

CefRequest::GetTransitionType is equivalent to navigation_type. user_gesture tells you whether a user explicitly triggered the event (by clicking something, for example).

chromodo wrote:what is the general difference between OnBeforeBrowse and OnOpenURLFromTab?

See the documentation on OnOpenURLFromTab.
magreenblatt
Site Admin
 
Posts: 12402
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 40 guests