Redirecting the new windows to the already opened ones

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.

Redirecting the new windows to the already opened ones

Postby janholecek » Thu Jan 06, 2011 3:04 am

Hi, I need to forbid the browser window from creating a new standalone browser windows (for example after clicking on the link with target="_blank", ...), and to redirect the stopped window's URL to the already opened one.

I tried to stop popup windows from creating in the ClientHandler::HandleBeforeCreated, if the popup parameter is true, then I just return RV_HANDLED to forbid its creation (is that a correct way to do this?). The problem is, the url parameter is always empty, so I cannot send a request to open this url in some already opened window.

Is there a way to redirect a popup windows to the already existing ones?

Thanks
janholecek
Newbie
 
Posts: 6
Joined: Thu Jul 15, 2010 10:49 am

Re: Redirecting the new windows to the already opened ones

Postby magreenblatt » Thu Jan 06, 2011 3:11 pm

Unfortunately it is not possible to know the URL at the time that the new popup window is created. See http://code.google.com/p/chromiumembedd ... etail?id=5 for more details.

One potential workaround is to create the popup window as initially hidden, wait for the call to CefHandler::HandleBeforeBrowse(), and then destroy the popup window and load the URL in the main browser window.

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

Re: Redirecting the new windows to the already opened ones

Postby janholecek » Mon Jan 10, 2011 10:01 am

Okay, I will try that,
Thanks
janholecek
Newbie
 
Posts: 6
Joined: Thu Jul 15, 2010 10:49 am

Re: Redirecting the new windows to the already opened ones

Postby emerick » Sat Mar 05, 2011 8:38 pm

I use the suggested approach in my application (i.e., I create a hidden popup window and then destroy it later) and it works well. I did have to apply the following patch to browser_impl_win.cc, however, because the call to UIT_CreateBrowser calls SetWindowPos with SWP_SHOWWINDOW:

Code: Select all
Index: browser_impl_win.cc
===================================================================
--- browser_impl_win.cc   (revision 199)
+++ browser_impl_win.cc   (working copy)
@@ -141,9 +141,18 @@
   // Size the web view window to the browser window
   RECT cr;
   GetClientRect(window_info_.m_hWnd, &cr);
-  SetWindowPos(UIT_GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
-      cr.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
 
+  // Respect the WS_VISIBLE window style when setting the window's
+  // position
+  UINT flags = SWP_NOZORDER;
+  if (window_info_.m_dwStyle & WS_VISIBLE) {
+    flags |= SWP_SHOWWINDOW;
+  } else {
+    flags |= SWP_HIDEWINDOW;
+  }
+  SetWindowPos(GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
+               cr.bottom, flags);
+
   if(handler_.get()) {
     // Notify the handler that we're done creating the new window
     handler_->HandleAfterCreated(this);


Marshall, if you think it's a useful patch in general, I can create an issue for it in the tracker; I wanted to run it by you first, since I may be missing something subtle here.

Emerick
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Re: Redirecting the new windows to the already opened ones

Postby lodle » Sun Mar 06, 2011 11:56 am

I had the same issue and modified the webkit code to remove all _blank and replace with _self. Patch attached
Attachments
webkit.zip
(1.65 KiB) Downloaded 1247 times
lodle
Techie
 
Posts: 32
Joined: Tue Jun 01, 2010 4:36 am

Re: Redirecting the new windows to the already opened ones

Postby magreenblatt » Mon Mar 07, 2011 2:39 pm

Emerick -- I haven't tested it, but your patch should be OK. Please create an issue for it in the issue tracker.

Lodle -- You could probably also replace "_blank" with "_self" by walking the DOM after the page is loaded. That might be less intrusive ;-).

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

Re: Redirecting the new windows to the already opened ones

Postby emerick » Mon Mar 07, 2011 3:10 pm

magreenblatt wrote:Emerick -- I haven't tested it, but your patch should be OK. Please create an issue for it in the issue tracker.


I created http://code.google.com/p/chromiumembedd ... ail?id=201. Thanks!

Emerick
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Re: Redirecting the new windows to the already opened ones

Postby magreenblatt » Mon Mar 07, 2011 8:18 pm

Revision 200 includes a test (define TEST_REDIRECT_POPUP_URLS in cefclient.cpp) that demonstrates how to use a hidden window to intercept and redirect target="_blank" URL loading. This approach can be used as a workaround until the URL can be passed to HandleBeforeCreated.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 59 guests