Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 7db2bf0

Browse files
committed
[[ CefBrowserErrorMsg ]] Store error message with failed urls.
[[ CefBrowserErrorMsg ]] Send appropriate callback if url failed to load in OnLoadEnd handler
1 parent 321b37d commit 7db2bf0

1 file changed

Lines changed: 38 additions & 13 deletions

File tree

revbrowser/src/cefbrowser.cpp

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ class MCCefMessageResult
373373
////////////////////////////////////////////////////////////////////////////////
374374
// Browser client - receives callback messages from the browser
375375

376+
struct MCCefErrorInfo
377+
{
378+
CefString url;
379+
CefString error_message;
380+
};
381+
376382
class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandler, CefDownloadHandler, CefLoadHandler, CefContextMenuHandler
377383
{
378384
private:
@@ -381,7 +387,7 @@ class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandl
381387
MCCefBrowserBase *m_owner;
382388

383389
MCCefMessageResult m_message_result;
384-
std::map<int64_t, CefString> m_load_error_frames;
390+
std::map<int64_t, MCCefErrorInfo> m_load_error_frames;
385391

386392
// IM-2014-05-06: [[ Bug 12384 ]] Set of URLs for which callback messages will not be sent
387393
std::set<CefString> m_ignore_urls;
@@ -390,20 +396,22 @@ class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandl
390396

391397
// Error handling - we need to keep track of url that failed to load in a
392398
// frame so we can send the correct url in onLoadEnd()
393-
void AddLoadErrorFrame(int64_t p_id, const CefString &p_url)
399+
void AddLoadErrorFrame(int64_t p_id, const CefString &p_url, const CefString &p_error_msg)
394400
{
395-
m_load_error_frames[p_id] = p_url;
401+
m_load_error_frames[p_id].url = p_url;
402+
m_load_error_frames[p_id].error_message = p_error_msg;
396403
}
397404

398-
bool RemoveLoadErrorFrame(int64_t p_id, CefString &r_error_url)
405+
bool RemoveLoadErrorFrame(int64_t p_id, CefString &r_error_url, CefString &r_error_msg)
399406
{
400-
std::map<int64_t, CefString>::iterator t_iter;
407+
std::map<int64_t, MCCefErrorInfo>::iterator t_iter;
401408
t_iter = m_load_error_frames.find(p_id);
402409

403410
if (t_iter == m_load_error_frames.end())
404411
return false;
405412

406-
r_error_url = t_iter->second;
413+
r_error_url = t_iter->second.url;
414+
r_error_msg = t_iter->second.error_message;
407415
m_load_error_frames.erase(t_iter);
408416

409417
return true;
@@ -760,10 +768,10 @@ class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandl
760768
if (nil == m_owner)
761769
return;
762770

763-
CefString t_url;
771+
CefString t_url, t_error;
764772

765773
bool t_is_error;
766-
t_is_error = RemoveLoadErrorFrame(p_frame->GetIdentifier(), t_url);
774+
t_is_error = RemoveLoadErrorFrame(p_frame->GetIdentifier(), t_url, t_error);
767775

768776
/* TODO - Load error handling */
769777
// For now we don't send a browser load error message - instead make sure documentComplete is sent with the correct url
@@ -777,11 +785,28 @@ class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandl
777785
t_url_str = nil;
778786
/* UNCHECKED */ MCCefStringToCString(t_url, t_url_str);
779787

780-
if (p_frame->IsMain())
781-
CB_DocumentComplete(m_owner->GetInst(), t_url_str);
788+
if (t_is_error)
789+
{
790+
char *t_err_str;
791+
t_err_str = nil;
792+
/* UNCHECKED */ MCCefStringToCString(t_error, t_err_str);
793+
794+
if (p_frame->IsMain())
795+
CB_DocumentFailed(m_owner->GetInst(), t_url_str, t_err_str);
796+
else
797+
CB_DocumentFrameFailed(m_owner->GetInst(), t_url_str, t_err_str);
798+
799+
if (t_err_str != nil)
800+
MCCStringFree(t_err_str);
801+
}
782802
else
783-
CB_DocumentFrameComplete(m_owner->GetInst(), t_url_str);
784-
803+
{
804+
if (p_frame->IsMain())
805+
CB_DocumentComplete(m_owner->GetInst(), t_url_str);
806+
else
807+
CB_DocumentFrameComplete(m_owner->GetInst(), t_url_str);
808+
}
809+
785810
if (t_url_str != nil)
786811
MCCStringFree(t_url_str);
787812
}
@@ -791,7 +816,7 @@ class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandl
791816
if (IgnoreUrl(p_failed_url))
792817
return;
793818

794-
AddLoadErrorFrame(p_frame->GetIdentifier(), p_failed_url);
819+
AddLoadErrorFrame(p_frame->GetIdentifier(), p_failed_url, p_error_text);
795820
}
796821

797822
// ContextMenuHandler interface

0 commit comments

Comments
 (0)