Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
View Certificate on Mac & Windows
Browse files Browse the repository at this point in the history
Defer view certificate support on linux

fix brave/browser-laptop#2611

Auditors: @bridiver, @bbondy
  • Loading branch information
darkdh committed Feb 20, 2017
1 parent 5b98422 commit 4baf267
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 0 deletions.
12 changes: 12 additions & 0 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include "content/public/browser/security_style_explanations.h"
#include "content/public/browser/service_worker_context.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/ssl_status.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/context_menu_params.h"
Expand Down Expand Up @@ -1529,6 +1530,15 @@ void WebContents::StopFindInPage(content::StopFindAction action) {
web_contents()->StopFinding(action);
}

void WebContents::ShowCertificate() {
scoped_refptr<net::X509Certificate> certificate =
web_contents()->GetController().GetVisibleEntry()->GetSSL().certificate;
if (!certificate)
return;
web_contents()->GetDelegate()->ShowCertificateViewerInDevTools(
web_contents(), certificate);
}

void WebContents::ShowDefinitionForSelection() {
#if defined(OS_MACOSX)
const auto view = web_contents()->GetRenderWidgetHostView();
Expand Down Expand Up @@ -1992,6 +2002,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
.SetMethod("showCertificate",
&WebContents::ShowCertificate)
.SetMethod("showDefinitionForSelection",
&WebContents::ShowDefinitionForSelection)
.SetMethod("copyImageAt", &WebContents::CopyImageAt)
Expand Down
1 change: 1 addition & 0 deletions atom/browser/api/atom_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
void ReplaceMisspelling(const base::string16& word);
uint32_t FindInPage(mate::Arguments* args);
void StopFindInPage(content::StopFindAction action);
void ShowCertificate();
void ShowDefinitionForSelection();
void CopyImageAt(int x, int y);

Expand Down
12 changes: 12 additions & 0 deletions atom/browser/common_web_contents_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "base/files/file_util.h"
#include "base/strings/utf_string_conversions.h"
#include "brave/browser/brave_javascript_dialog_manager.h"
#include "chrome/browser/certificate_viewer.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
#include "chrome/browser/printing/print_preview_message_handler.h"
Expand Down Expand Up @@ -394,6 +395,17 @@ bool CommonWebContentsDelegate::IsFullscreenForTabOrPending(
return html_fullscreen_;
}

void CommonWebContentsDelegate::ShowCertificateViewerInDevTools(
content::WebContents* web_contents,
scoped_refptr<net::X509Certificate> certificate) {
// TODO(Anthony): Support linux certificate viewing modal
#if !defined(OS_LINUX)
::ShowCertificateViewer(web_contents_->GetWebContents(),
owner_window_->GetNativeWindow(),
certificate.get());
#endif
}

blink::WebSecurityStyle CommonWebContentsDelegate::GetSecurityStyle(
content::WebContents* web_contents,
content::SecurityStyleExplanations* security_style_explanations) {
Expand Down
3 changes: 3 additions & 0 deletions atom/browser/common_web_contents_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class CommonWebContentsDelegate
void ExitFullscreenModeForTab(content::WebContents* source) override;
bool IsFullscreenForTabOrPending(
const content::WebContents* source) const override;
void ShowCertificateViewerInDevTools(
content::WebContents* web_contents,
scoped_refptr<net::X509Certificate> certificate) override;
blink::WebSecurityStyle GetSecurityStyle(
content::WebContents* web_contents,
content::SecurityStyleExplanations* explanations) override;
Expand Down
1 change: 1 addition & 0 deletions atom/common/api/resources/web_view_api_bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const asyncMethods = [
'inspectServiceWorker',
'print',
'printToPDF',
'showCertificate',
'showDefinitionForSelection',
'capturePage',
'setActive',
Expand Down
1 change: 1 addition & 0 deletions brave/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ source_set("browser") {
"brave_javascript_dialog_manager.cc",
"brave_permission_manager.h",
"brave_permission_manager.cc",
"certificate_viewer_mac.mm",
"renderer_preferences_helper.h",
"renderer_preferences_helper.cc",
]
Expand Down
13 changes: 13 additions & 0 deletions brave/browser/certificate_viewer_mac.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "chrome/browser/certificate_viewer.h"

#import "chrome/browser/ui/certificate_viewer_mac.h"

void ShowCertificateViewer(content::WebContents* web_contents,
gfx::NativeWindow parent,
net::X509Certificate* cert) {
SSLCertificateViewerMac* viewer = ([[SSLCertificateViewerMac alloc]
initWithCertificate:cert
forWebContents:web_contents]);
[viewer showCertificateSheet:parent];
[viewer releaseSheetWindow];
}
14 changes: 14 additions & 0 deletions chromium_src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,15 @@ source_set("browser") {
"chrome/browser/ui/views/color_chooser_win.cc",
"//chrome/browser/printing/pdf_to_emf_converter.cc",
"//chrome/browser/printing/pdf_to_emf_converter.h",
"//chrome/browser/ui/views/certificate_viewer_win.cc",
]

deps += [
"//ui/shell_dialogs",
]
libs = [
"cryptui.lib",
]
}

if (is_linux) {
Expand All @@ -249,6 +253,16 @@ source_set("browser") {
]
}

if (is_mac) {
sources += [
"//chrome/browser/ui/certificate_viewer_mac.h",
"//chrome/browser/ui/certificate_viewer_mac.mm",
]
libs = [
"SecurityInterface.framework",
]
}

if (use_nss_certs) {
sources += [
"chrome/browser/certificate_manager_model.cc",
Expand Down
3 changes: 3 additions & 0 deletions lib/browser/api/browser-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ Object.assign(BrowserWindow.prototype, {
inspectServiceWorker () {
return this.webContents.inspectServiceWorker()
},
showCertificate () {
return this.webContents.showCertificate()
},
showDefinitionForSelection () {
return this.webContents.showDefinitionForSelection()
},
Expand Down

0 comments on commit 4baf267

Please sign in to comment.