[SOLVED] CefFrame::GetIdentifier returns unexpected value

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.

[SOLVED] CefFrame::GetIdentifier returns unexpected value

Postby ndesktop » Thu Dec 17, 2020 11:37 am

I am using a forked CEF 4240 (but I did not changed the CefFrame::GetIdentifier) and in debugger on Windows 10 x64, VS2019 I am seeing this:

Code: Select all
void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame,
    CefLoadHandler::TransitionType transition_type)
{
...
   if(frame) {
      int64 fid = frame->GetIdentifier();  ==> 0x0000000400000001
      int ifid = (int)fid;                           ==> 0x00000001
      int brk__ = 0; brk__++;
   }
...


Browser identifier is 1, but frame identifier is not 1, but 0x0000000400000001 (or 0x0000000300000001 etc.).

This looks to come from
Code: Select all
int64_t MakeFrameId(int32_t render_process_id, int32_t render_routing_id) {
  return (static_cast<uint64_t>(render_process_id) << 32) |
         static_cast<uint64_t>(render_routing_id);
}

where render_process_id is also used.

On the other hand, in InitState, for example, both parameters are explicitely passed to Initialize:
Code: Select all
    void Initialize(content::BrowserContext* browser_context,
                    CefRefPtr<CefBrowserHostImpl> browser,
                    CefRefPtr<CefFrame> frame,
                    int render_process_id,
                    int render_frame_id,
...
      render_process_id_ = render_process_id;  // 4
      render_frame_id_ = render_frame_id;      // 1
...

(render_frame_id_ seems unused, btw).

CefFrame::GetIdentifier returns the frame_id passed in constructor, in GetWebFrameImpl, where is
int64_t frame_id = render_frame_util::GetIdentifier(frame);
so it's the 0x0000000400000001 value.

I would say two things are needed:
- clarify the documentation of CefFrame::GetIdentifier to clearly state it returns a 64 bit integer composed from 32-bit render pid and 32 bit frame ID
- maybe add two helper methods (without being in a class), such as
Code: Select all
int32_t RenderProcessIdFromFrameIdentifier(int64_t render_frame_id) {
   return (static_cast<uint64_t>(render_frame_id) >> 32);
}
int32_t FrameRoutingIdFromFrameIdentifier(int64_t render_frame_id) {
   return (static_cast<uint64_t>(render_frame_id) & 0xffffffff);
}


The question is: this behavior of int64 frame identifier is intentional and I need to do the unmasking to get the frame ID without the render process id?
The reason I am asking this is - without getting into too much details - is because I need to know a variable inside a v8 extension running in the context of a frame to not be tampered by function replacement or object shadowing.
Last edited by ndesktop on Thu Dec 17, 2020 12:13 pm, edited 1 time in total.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: CefFrame::GetIdentifier returns strange value

Postby magreenblatt » Thu Dec 17, 2020 12:07 pm

The frame identifier is a globally unique ID. The way this ID is generated is an implementation detail subject to change and the value is not intended to be decomposed by the client. The API uses int64 as the return type for GetIdentifier, which should make it clear that the value is 64-bit without further documentation.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CefFrame::GetIdentifier returns strange value

Postby ndesktop » Thu Dec 17, 2020 12:12 pm

Got it.
I understood frame ID is a globally unique ID, but for some reason I did not make the connection with the render/routing paradigm.
Thank you !
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 80 guests