Page 1 of 1

Scheme Registration

Posted: Wed Sep 16, 2020 12:35 pm
by dilfich
I create multiple copies almost as shown in TinyBrowser with my own ID.

Code: Select all

TempFactory: array [0..99] of ICefSchemeHandlerFactory;
......
ChromOSR[Thrd]:= TCEF.Create(nil);
ChromOSR[Thrd].CefID:= Thrd;
 ... 
TempFactory[Thrd] := TCefSchemeHandlerFactoryOwn.Create(TScheme);
ChromOSR[Thrd].Chromium.CreateBrowser(nil, '', TempContext[Thrd]);
How do I make my own SchemeRegistration for each "thread"?

Code: Select all

function TScheme.ProcessRequest(const request : ICefRequest; const callback : ICefCallback): Boolean;
....
      if (FStream <> nil) and (request <> nil) then
        begin
          FStream.Clear;

              Result      := False;
              FStatus     := 200;
              FStatusText := 'OK';
              FMimeType   := 'text/html';

              FStream.WriteBuffer(Pointer(Source[???])^, Length(Source[???]));
              FStream.Seek(0, soFromBeginning);

              TempContext[???].ClearSchemeHandlerFactories;
        end;
......
end;
I can't figure out how to correctly pass the stream \ browser number to the construction from the example.
Source[???] - String array
TempContext[???] - ICefSchemeHandlerFactory array

How can I determine the number of the created browser in TScheme?
Or what would be more correct? :(

Re: Scheme Registration

Posted: Wed Sep 16, 2020 4:55 pm
by salvadordf
Perhaps you can add a field to your TScheme class that stores the "browser.identifier" value. You can get that value overriding the TScheme constructor because it has a "browser" parameter.

Even if you don't add that field you can also add a custom HTTP header to the request with the browser.identifier value.

Later you can compare that value with TChromium.browserId.

Edit : fixed the property names. :oops:

Re: Scheme Registration

Posted: Tue Nov 10, 2020 10:02 am
by dilfich
browser.identifier
How do I reset the ID? I close the browser and create a new one, but it no longer has the same ID, if it was 1, then the new one already has 2.

Re: Scheme Registration

Posted: Wed Nov 11, 2020 9:12 am
by salvadordf
That ID is assigned by CEF internally and we can't modify it.

Re: Scheme Registration

Posted: Wed Feb 24, 2021 7:00 am
by dilfich
Faced with a problem, how to determine that the registration was successful?

Code: Select all

if TempContext[FCefID].RegisterSchemeHandlerFactory('https', '', TempFactory[FCefID]) then
Shows positive, but constructor TScheme.Create( not called sometimes.

Re: Scheme Registration

Posted: Wed Feb 24, 2021 11:42 am
by salvadordf
I haven't checked the CEF sources for that function but perhaps it requires that the browsers using those contexts are fully initialized before registering the schemes.

This is what the CEF code comments have about that function :

Code: Select all

  ///
  // Register a scheme handler factory for the specified |scheme_name| and
  // optional |domain_name|. An NULL |domain_name| value for a standard scheme
  // will cause the factory to match all domain names. The |domain_name| value
  // will be ignored for non-standard schemes. If |scheme_name| is a built-in
  // scheme and no handler is returned by |factory| then the built-in scheme
  // handler factory will be called. If |scheme_name| is a custom scheme then
  // you must also implement the cef_app_t::on_register_custom_schemes()
  // function in all processes. This function may be called multiple times to
  // change or remove the factory that matches the specified |scheme_name| and
  // optional |domain_name|. Returns false (0) if an error occurs. This function
  // may be called on any thread in the browser process.
  ///
Perhaps you need to use the GlobalCEFApp.OnRegCustomSchemes event too.