@@ -34,6 +34,11 @@ BrowserWidget::BrowserWidget(const Cef& cef,
3434 forward_button_->setDisabled (true );
3535 connect (forward_button_, &QToolButton::clicked, [=](bool ) { Forward (); });
3636
37+ ssl_button_ = new QToolButton;
38+ ssl_button_->setAutoRaise (true );
39+ ssl_button_->setDisabled (true );
40+ connect (ssl_button_, &QToolButton::clicked, [=](bool ) { ShowSslInfo (); });
41+
3742 url_edit_ = new UrlEdit (this );
3843 connect (url_edit_, &UrlEdit::returnPressed, [=]() {
3944 cef_widg_->LoadUrl (url_edit_->text ());
@@ -60,6 +65,7 @@ BrowserWidget::BrowserWidget(const Cef& cef,
6065 top_layout->setMargin (0 );
6166 top_layout->addWidget (back_button_);
6267 top_layout->addWidget (forward_button_);
68+ top_layout->addWidget (ssl_button_);
6369 top_layout->addWidget (url_edit_, 1 );
6470 top_layout->addWidget (stop_button_);
6571 top_layout->addWidget (refresh_button_);
@@ -356,13 +362,13 @@ void BrowserWidget::RecreateCefWidget(const QString& url) {
356362 PageIndex::MarkVisit (CurrentUrl (), current_title_,
357363 current_favicon_url_, current_favicon_);
358364 }
359- // Reset the URL edit stylesheet if we're not in error mode
360- if (loading_) {
361- if (next_load_is_error_ ) {
362- next_load_is_error_ = false ;
363- } else {
364- url_edit_-> setStyleSheet ( " " );
365- }
365+
366+ // Reset the stylesheet and update SSL status when not errored
367+ if (number_of_load_completes_are_error_ <= 0 ) {
368+ UpdateSslStatus ( false ) ;
369+ url_edit_-> setStyleSheet ( " " );
370+ } else if (!loading_) {
371+ number_of_load_completes_are_error_--;
366372 }
367373 });
368374 connect (cef_widg_, &CefWidget::LoadError,
@@ -371,19 +377,20 @@ void BrowserWidget::RecreateCefWidget(const QString& url) {
371377 const QString& error_text,
372378 const QString& failed_url) {
373379 // Some error codes we are ok with
374- if (error_code == ERR_NONE || error_code == ERR_ABORTED) {
375- return ;
376- }
377- if (frame->IsMain ()) {
378- url_edit_->setStyleSheet (" QLineEdit { background-color: pink; }" );
379- next_load_is_error_ = true ;
380+ if (error_code != ERR_NONE && error_code != ERR_ABORTED) {
381+ ShowError (failed_url, error_text, frame);
380382 }
381- auto new_html =
382- QString (" <html><body style=\" background-color: pink;\" >"
383- " Error loading page: <strong>%1</strong>"
384- " </body></html>" ).arg (error_text);
385- frame->LoadString (CefString (new_html.toStdString ()),
386- CefString (failed_url.toStdString ()));
383+ });
384+ connect (cef_widg_, &CefWidget::CertificateError,
385+ [=](cef_errorcode_t ,
386+ const QString& request_url,
387+ CefRefPtr<CefSSLInfo> ssl_info,
388+ CefRefPtr<CefRequestCallback> callback) {
389+ // TODO(cretz): Check if this is the main frame please
390+ errored_ssl_info_ = ssl_info;
391+ errored_ssl_callback_ = callback;
392+ ShowError (request_url, " Invalid Certificate" );
393+ UpdateSslStatus (true );
387394 });
388395 connect (cef_widg_, &CefWidget::PageOpen,
389396 [=](CefHandler::WindowOpenType type,
@@ -536,6 +543,8 @@ void BrowserWidget::RebuildNavMenu() {
536543void BrowserWidget::ShowAsSuspendedScreenshot () {
537544 auto grid_layout = qobject_cast<QGridLayout*>(layout ());
538545 if (Suspended ()) {
546+ // Have to disable the SSL button
547+ ssl_button_->setDisabled (true );
539548 // Remove the cef widg and add screenshot
540549 grid_layout->removeWidget (cef_widg_);
541550 cef_widg_->hide ();
@@ -642,4 +651,65 @@ void BrowserWidget::HandleContextMenuCommand(
642651 }
643652}
644653
654+ void BrowserWidget::ShowError (const QString& failed_url,
655+ const QString& error_text,
656+ CefRefPtr<CefFrame> frame) {
657+ if (!frame || frame->IsMain ()) {
658+ url_edit_->setStyleSheet (" QLineEdit { background-color: pink; }" );
659+ number_of_load_completes_are_error_ = 2 ;
660+ }
661+ auto new_html =
662+ QString (" <html><body style=\" background-color: pink;\" >"
663+ " Error loading page: <strong>%1</strong>"
664+ " </body></html>" ).arg (error_text);
665+ cef_widg_->ShowStringPage (failed_url, new_html, frame);
666+ }
667+
668+ void BrowserWidget::UpdateSslStatus (bool check_errored) {
669+ if (check_errored && errored_ssl_info_) {
670+ ssl_button_->setDisabled (false );
671+ ssl_button_->setIcon (QIcon (*Util::CachedPixmapColorOverlay (
672+ " :/res/images/fontawesome/unlock.png" , " red" )));
673+ ssl_button_->setToolTip (" Invalid Certificate" );
674+ } else if (loading_) {
675+ ssl_button_->setDisabled (true );
676+ ssl_button_->setIcon (QIcon ());
677+ ssl_button_->setToolTip (" " );
678+ } else {
679+ errored_ssl_info_ = nullptr ;
680+ errored_ssl_callback_ = nullptr ;
681+ ssl_status_ = cef_widg_->CurrentSSLStatus ();
682+ // If the SSL status is not there or there is no SSL, we mark
683+ // it as unlocked and disable the button
684+ if (!ssl_status_ || !ssl_status_->IsSecureConnection ()) {
685+ ssl_button_->setIcon (Util::CachedIconLighterDisabled (
686+ " :/res/images/fontawesome/unlock-alt.png" ));
687+ ssl_button_->setDisabled (true );
688+ ssl_button_->setToolTip (" Not secure" );
689+ } else {
690+ ssl_button_->setDisabled (false );
691+ // Red when there is a cert error, orange for content error,
692+ // green otherwise
693+ if (ssl_status_->GetCertStatus () != CERT_STATUS_NONE) {
694+ ssl_button_->setIcon (QIcon (*Util::CachedPixmapColorOverlay (
695+ " :/res/images/fontawesome/unlock.png" , " red" )));
696+ ssl_button_->setToolTip (" Invalid Certificate" );
697+ } else if (ssl_status_->GetContentStatus () !=
698+ SSL_CONTENT_NORMAL_CONTENT) {
699+ ssl_button_->setIcon (QIcon (*Util::CachedPixmapColorOverlay (
700+ " :/res/images/fontawesome/unlock.png" , " orange" )));
701+ ssl_button_->setToolTip (" Insecure Page Contents" );
702+ } else {
703+ ssl_button_->setIcon (QIcon (*Util::CachedPixmapColorOverlay (
704+ " :/res/images/fontawesome/lock.png" , " green" )));
705+ ssl_button_->setToolTip (" Secure" );
706+ }
707+ }
708+ }
709+ }
710+
711+ void BrowserWidget::ShowSslInfo () const {
712+ // TODO
713+ }
714+
645715} // namespace doogie
0 commit comments