Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: chrome/browser/ui/webui/certificate_viewer_webui.cc

Issue 10554010: Remove BrowserList::GetLastActive usage from WebUI pages. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/certificate_viewer_webui.h" 5 #include "chrome/browser/ui/webui/certificate_viewer_webui.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/i18n/time_formatting.h" 9 #include "base/i18n/time_formatting.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/certificate_viewer.h" 13 #include "chrome/browser/certificate_viewer.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_dialogs.h" 14 #include "chrome/browser/ui/browser_dialogs.h"
16 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/certificate_dialogs.h" 15 #include "chrome/browser/ui/certificate_dialogs.h"
18 #include "chrome/browser/ui/constrained_window.h" 16 #include "chrome/browser/ui/constrained_window.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents.h" 17 #include "chrome/browser/ui/tab_contents/tab_contents.h"
20 #include "chrome/common/net/x509_certificate_model.h" 18 #include "chrome/common/net/x509_certificate_model.h"
21 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
22 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
23 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/gfx/size.h"
25 #include "ui/web_dialogs/constrained_web_dialog_ui.h" 24 #include "ui/web_dialogs/constrained_web_dialog_ui.h"
26 #include "ui/web_dialogs/web_dialog_observer.h" 25 #include "ui/web_dialogs/web_dialog_observer.h"
27 26
28 using content::WebContents; 27 using content::WebContents;
29 using content::WebUIMessageHandler; 28 using content::WebUIMessageHandler;
30 using ui::WebDialogObserver; 29 using ui::WebDialogObserver;
31 30
32 namespace { 31 namespace {
33 32
34 // Default width/height of the dialog. 33 // Default width/height of the dialog.
35 const int kDefaultWidth = 580; 34 const int kDefaultWidth = 580;
36 const int kDefaultHeight = 600; 35 const int kDefaultHeight = 600;
37 36
38 } // namespace 37 } // namespace
39 38
40 // Shows a certificate using the WebUI certificate viewer. 39 // Shows a certificate using the WebUI certificate viewer.
41 void ShowCertificateViewer(gfx::NativeWindow parent, 40 void ShowCertificateViewer(WebContents* web_contents,
41 gfx::NativeWindow parent,
42 net::X509Certificate* cert) { 42 net::X509Certificate* cert) {
43 CertificateViewerDialog* dialog = new CertificateViewerDialog(cert); 43 CertificateViewerDialog* dialog = new CertificateViewerDialog(cert);
44 dialog->Show(parent); 44 dialog->Show(web_contents, parent);
45 } 45 }
46 46
47 //////////////////////////////////////////////////////////////////////////////// 47 ////////////////////////////////////////////////////////////////////////////////
48 // CertificateViewerDialog 48 // CertificateViewerDialog
49 49
50 void CertificateViewerDialog::AddObserver(WebDialogObserver* observer) { 50 void CertificateViewerDialog::AddObserver(WebDialogObserver* observer) {
51 observers_.AddObserver(observer); 51 observers_.AddObserver(observer);
52 } 52 }
53 53
54 void CertificateViewerDialog::RemoveObserver(WebDialogObserver* observer) { 54 void CertificateViewerDialog::RemoveObserver(WebDialogObserver* observer) {
55 observers_.RemoveObserver(observer); 55 observers_.RemoveObserver(observer);
56 } 56 }
57 57
58 CertificateViewerDialog::CertificateViewerDialog(net::X509Certificate* cert) 58 CertificateViewerDialog::CertificateViewerDialog(net::X509Certificate* cert)
59 : cert_(cert), window_(NULL) { 59 : cert_(cert), window_(NULL) {
60 // Construct the dialog title from the certificate. 60 // Construct the dialog title from the certificate.
61 net::X509Certificate::OSCertHandles cert_chain; 61 net::X509Certificate::OSCertHandles cert_chain;
62 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(), 62 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(),
63 &cert_chain); 63 &cert_chain);
64 title_ = l10n_util::GetStringFUTF16(IDS_CERT_INFO_DIALOG_TITLE, 64 title_ = l10n_util::GetStringFUTF16(IDS_CERT_INFO_DIALOG_TITLE,
65 UTF8ToUTF16(x509_certificate_model::GetTitle(cert_chain.front()))); 65 UTF8ToUTF16(x509_certificate_model::GetTitle(cert_chain.front())));
66 } 66 }
67 67
68 CertificateViewerDialog::~CertificateViewerDialog() { 68 CertificateViewerDialog::~CertificateViewerDialog() {
69 } 69 }
70 70
71 void CertificateViewerDialog::Show(gfx::NativeWindow parent) { 71 void CertificateViewerDialog::Show(WebContents* web_contents,
72 // TODO(oshima): Should get browser from parent. 72 gfx::NativeWindow parent) {
73 Browser* browser = BrowserList::GetLastActive();
74 DCHECK(browser);
75 TabContents* current_tab_contents = browser->GetActiveTabContents();
76 // TODO(bshe): UI tweaks needed for AURA html Dialog, such as add padding on 73 // TODO(bshe): UI tweaks needed for AURA html Dialog, such as add padding on
77 // title for AURA ConstrainedWebDialogUI. 74 // title for AURA ConstrainedWebDialogUI.
75 TabContents* tab = TabContents::FromWebContents(web_contents);
78 window_ = ui::CreateConstrainedWebDialog( 76 window_ = ui::CreateConstrainedWebDialog(
79 current_tab_contents->profile(), 77 tab->profile(),
80 this, 78 this,
81 NULL, 79 NULL,
82 current_tab_contents)->window()->GetNativeWindow(); 80 tab)->window()->GetNativeWindow();
83 } 81 }
84 82
85 ui::ModalType CertificateViewerDialog::GetDialogModalType() const { 83 ui::ModalType CertificateViewerDialog::GetDialogModalType() const {
86 return ui::MODAL_TYPE_NONE; 84 return ui::MODAL_TYPE_NONE;
87 } 85 }
88 86
89 string16 CertificateViewerDialog::GetDialogTitle() const { 87 string16 CertificateViewerDialog::GetDialogTitle() const {
90 return title_; 88 return title_;
91 } 89 }
92 90
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 const base::ListValue* args) const { 409 const base::ListValue* args) const {
412 int cert_index; 410 int cert_index;
413 double val; 411 double val;
414 if (!(args->GetDouble(0, &val))) 412 if (!(args->GetDouble(0, &val)))
415 return -1; 413 return -1;
416 cert_index = static_cast<int>(val); 414 cert_index = static_cast<int>(val);
417 if (cert_index < 0 || cert_index >= static_cast<int>(cert_chain_.size())) 415 if (cert_index < 0 || cert_index >= static_cast<int>(cert_chain_.size()))
418 return -1; 416 return -1;
419 return cert_index; 417 return cert_index;
420 } 418 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/certificate_viewer_webui.h ('k') | chrome/browser/ui/webui/feedback_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698