Intercepting OnBeforeBrowse Integration/thread crashes

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.

Intercepting OnBeforeBrowse Integration/thread crashes

Postby chortle » Thu May 21, 2015 8:22 am

CEF3: 3.2171.2069
Mac OS 10.10
Xcode 6.1.1


I'd like to intercept OnBeforeBrowse to open up URLs in tabs. I created a function called LaunchInNewTab (cefclient.h and cefclient_mac.mm) and then based on certain conditions (e.g. is not a local file) I call this LaunchInNewTab function. Alas, I keep getting linker errors. I've tried to enclose it in extern "C" comments in cefclient.h and cefclient_mac to no avail. Any recommendations?
Thanks.


#ifdef __cplusplus
extern "C" {
#endif
bool LaunchInNewTab(CefString& url);
#ifdef __cplusplus
}
#endif

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

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


CefString url = request->GetURL();
CefURLParts url_parts;
if (!CefParseURL(url, url_parts))
return true;

CefString scheme(&url_parts.scheme);
if (UrlIsFromPermittedHost(url_parts)
|| scheme.compare("about") == 0
|| scheme.compare("chrome-devtools") == 0
|| scheme.compare("data") == 0) {
return false;
}


bool isLocalFile = scheme.compare("file") == 0;

if (IsHerokuError(url))
return false;

if (!isLocalFile) LaunchInNewTab(url);
return true;

}
Last edited by chortle on Tue Jun 02, 2015 9:53 am, edited 2 times in total.
chortle
Techie
 
Posts: 12
Joined: Mon Apr 20, 2015 12:36 pm

Re: Intercepting OnBeforeBrowse Integration

Postby magreenblatt » Thu May 21, 2015 10:49 am

chortle wrote:I keep getting linker errors.

What linker errors? CEF has multiple targets, make sure you've added the code to the correct target(s).
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Intercepting OnBeforeBrowse Integration

Postby chortle » Thu May 21, 2015 11:06 am

The target for cefclient_mac.mm is cefclient and for client_handler.cpp are cefclient and cefclient_helper_app.
Below is the error.

ld: warning: directory not found for option '-LDebug/Chromium'
ld: warning: directory not found for option '-LEmbedded'
ld: warning: directory not found for option '-LFramework.framework'
Undefined symbols for architecture x86_64:
"_LaunchInNewTab", referenced from:
ClientHandler::OnBeforeBrowse(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefRefPtr<CefRequest>, bool) in client_handler.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
chortle
Techie
 
Posts: 12
Joined: Mon Apr 20, 2015 12:36 pm

Re: Intercepting OnBeforeBrowse Integration

Postby magreenblatt » Thu May 21, 2015 11:43 am

Where did you implement the LaunchInNewTab function? Why are you defining it as extern C?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Intercepting OnBeforeBrowse Integration

Postby chortle » Thu May 21, 2015 12:27 pm

In cefclient_mac.mm - right before main and right after the @end for ClientAppDelegate implementation.

I originally didn't have the extern "C" ... directives. But after I was having these linker errors for no immediate obvious reason, I decided to try this. I've removed it. Same problem.
chortle
Techie
 
Posts: 12
Joined: Mon Apr 20, 2015 12:36 pm

Re: Intercepting OnBeforeBrowse Integration

Postby magreenblatt » Fri May 22, 2015 10:44 am

If you added the function in cefclient_mac.mm then it won't be built as part of the cefclient_helper_app target.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Intercepting OnBeforeBrowse Integration

Postby chortle » Thu May 28, 2015 4:11 pm

Got it to work. Is there a way that I can tell OnBeforeBrowse that if it's the first cefbrowser to open up links in new tabs and if it's secondary tabs (i.e. not the first one I opened, to open links within that browser)?
chortle
Techie
 
Posts: 12
Joined: Mon Apr 20, 2015 12:36 pm

Re: Intercepting OnBeforeBrowse Integration

Postby magreenblatt » Thu May 28, 2015 5:09 pm

chortle wrote:Got it to work. Is there a way that I can tell OnBeforeBrowse that if it's the first cefbrowser to open up links in new tabs and if it's secondary tabs (i.e. not the first one I opened, to open links within that browser)?

You would need to track that state in your ClientHandler implementation.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Intercepting OnBeforeBrowse Integration/Thread crashes

Postby chortle » Tue Jun 02, 2015 8:46 am

I did the following and it was working fine on Friday. Now it seems unstable, thread crashing after a while when I click on too many links in the secondary browser.

Primary Browser is the first tab. It has some links e.g.
http://www.cnn.com
http://www.ft.com

etc.

Then when the user clicks on the links on the primary it opens up a new tab for links such as ft.com. When a user clicks in these secondary tabs, they stay within the browser (vs. being redirected to a new tab).

I used messaging to communicate with ClientAppDelegate to tell it to open up a new tab.

Your guidance is appreciated.


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


CefString url = request->GetURL();
CefURLParts url_parts;
if (!CefParseURL(url, url_parts))
return true;

CefString scheme(&url_parts.scheme);
if (UrlIsFromPermittedHost(url_parts)
|| scheme.compare("about") == 0
|| scheme.compare("chrome-devtools") == 0
|| scheme.compare("data") == 0) {
return false;
}

bool isLocalFile = scheme.compare("file") == 0;


bool isHost = true; //is the primary browser
if (browser->GetIdentifier() == browser_id_) {
isHost = false;
}

if (IsHerokuError(url))
return false;

if (!isLocalFile) {
if (!isHost &&
request->GetResourceType() == RT_MAIN_FRAME &&
request->GetTransitionType() == TT_LINK) {
LaunchTab(url);
}

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

}
return true;
}



2. LaunchTab
void ClientHandler::LaunchTab(CefString& url) {

CEF_REQUIRE_UI_THREAD();
std::string us = url.ToString();
NSString *launch_url = [NSString stringWithUTF8String:us.c_str()];
NSDictionary *userInfo = @{@"launchURL":launch_url};
[[NSNotificationCenter defaultCenter] postNotificationName:@"LaunchNewTabNotification" object:nil userInfo:userInfo];

}


3. Error looks like this:

Chromium Embedded Framework`base::debug::BreakDebugger():
0x100736820: pushq %rbp
0x100736821: movq %rsp, %rbp
0x100736824: subq $0x10, %rsp
0x100736828: movq 0xaddaec9(%rip), %rax ; (void *)0x00007fff77f56070: __stack_chk_guard
0x10073682f: movq (%rax), %rax
0x100736832: movq %rax, -0x8(%rbp)
0x100736836: int3
0x100736837: movq 0xaddaeba(%rip), %rax ; (void *)0x00007fff77f56070: __stack_chk_guard
0x10073683e: movq (%rax), %rax
0x100736841: cmpq -0x8(%rbp), %rax
0x100736845: jne 0x100736851 ; base::debug::BreakDebugger() + 49
0x10073684b: addq $0x10, %rsp
0x10073684f: popq %rbp
0x100736850: retq
0x100736851: callq 0x108a76a12
chortle
Techie
 
Posts: 12
Joined: Mon Apr 20, 2015 12:36 pm

Re: Intercepting OnBeforeBrowse Integration/thread crashes

Postby magreenblatt » Tue Jun 02, 2015 4:26 pm

A symbolized stack trace would be helpful. You can get symbol files from the same place that you downloaded CEF.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Next

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 122 guests