Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

How to get and control the newly opened page window?

Post Reply
yiqianyishi
Posts: 18
Joined: Sun Jan 07, 2018 1:08 am

How to get and control the newly opened page window?

Post by yiqianyishi »

Hi,
When I was running TabBrowser demo, when the page click on a hyperlink, it will be a new page pop-up window, the window is independent of program UI window. I want to get this window in the Tab display, and use it as a Tab child window embedded in the Tab, how can I get to the window and how to control it? Is processing in the OnAfterCreated event? How to deal with this, thank you.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to get and control the newly opened page window?

Post by salvadordf »

Hi,
yiqianyishi wrote: Sun Jan 07, 2018 3:26 am When I was running TabBrowser demo, when the page click on a hyperlink, it will be a new page pop-up window, the window is independent of program UI window. I want to get this window in the Tab display, and use it as a Tab child window embedded in the Tab, how can I get to the window and how to control it? Is processing in the OnAfterCreated event? How to deal with this, thank you.
You need to use the TChromium.OnBeforePopup and TChromium.OnOpenUrlFromTab events.

These are the code comments for TChromium.OnBeforePopup :

Code: Select all

  ///
  // Called on the UI thread before a new popup browser is created. The
  // |browser| and |frame| values represent the source of the popup request. The
  // |target_url| and |target_frame_name| values indicate where the popup
  // browser should navigate and may be NULL if not specified with the request.
  // The |target_disposition| value indicates where the user intended to open
  // the popup (e.g. current tab, new tab, etc). The |user_gesture| value will
  // be true (1) if the popup was opened via explicit user gesture (e.g.
  // clicking a link) or false (0) if the popup opened automatically (e.g. via
  // the DomContentLoaded event). The |popupFeatures| structure contains
  // additional information about the requested popup window. To allow creation
  // of the popup browser optionally modify |windowInfo|, |client|, |settings|
  // and |no_javascript_access| and return false (0). To cancel creation of the
  // popup browser return true (1). The |client| and |settings| values will
  // default to the source browser's values. If the |no_javascript_access| value
  // is set to false (0) the new browser will not be scriptable and may not be
  // hosted in the same renderer process as the source browser. Any
  // modifications to |windowInfo| will be ignored if the parent browser is
  // wrapped in a cef_browser_view_t. Popup browser creation will be canceled if
  // the parent browser is destroyed before the popup browser creation completes
  // (indicated by a call to OnAfterCreated for the popup browser).
  ///
These are the code comments for TChromium.OnOpenUrlFromTab :

Code: Select all

  ///
  // Called on the UI thread before OnBeforeBrowse in certain limited cases
  // where navigating a new or different browser might be desirable. This
  // includes user-initiated navigation that might open in a special way (e.g.
  // links clicked via middle-click or ctrl + left-click) and certain types of
  // cross-origin navigation initiated from the renderer process (e.g.
  // navigating the top-level frame to/from a file URL). The |browser| and
  // |frame| values represent the source of the navigation. The
  // |target_disposition| value indicates where the user intended to navigate
  // the browser based on standard Chromium behaviors (e.g. current tab, new
  // tab, etc). The |user_gesture| value will be true (1) if the browser
  // navigated via explicit user gesture (e.g. clicking a link) or false (0) if
  // it navigated automatically (e.g. via the DomContentLoaded event). Return
  // true (1) to cancel the navigation or false (0) to allow the navigation to
  // proceed in the source browser's top-level frame.
  ///
Both events are executed in the UI thread, which is NOT the same as the main form thread. This is very important because you must not create or destroy VCL components in different threads.

You should save the targetUrl and targetDisposition parameters and send a message to your main form to create a new tab that opens targetUrl.

targetDisposition can have these values :

Code: Select all

  WOD_UNKNOWN,
  WOD_CURRENT_TAB,
  WOD_SINGLETON_TAB,
  WOD_NEW_FOREGROUND_TAB,
  WOD_NEW_BACKGROUND_TAB,
  WOD_NEW_POPUP,
  WOD_NEW_WINDOW,
  WOD_SAVE_TO_DISK,
  WOD_OFF_THE_RECORD,
  WOD_IGNORE_ACTION
yiqianyishi
Posts: 18
Joined: Sun Jan 07, 2018 1:08 am

Re: How to get and control the newly opened page window?

Post by yiqianyishi »

Thank you for your detailed analysis. These are very useful.

I just found a simple solution, which is a reference.

Https://github.com/AmesianX/NinjaBrowser

It is also a simple browser based on CEF4Delphi.

Thanks for your help.
Post Reply