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

Side by Side Diff: chrome/browser/ui/certificate_dialogs.cc

Issue 10820034: Remove redirection header and add "ui::" before all SelectFileDialog usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reuploading for different try run. Created 8 years, 4 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/certificate_dialogs.h" 5 #include "chrome/browser/ui/certificate_dialogs.h"
6 6
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "chrome/browser/ui/chrome_select_file_policy.h" 15 #include "chrome/browser/ui/chrome_select_file_policy.h"
16 #include "chrome/common/net/x509_certificate_model.h" 16 #include "chrome/common/net/x509_certificate_model.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
19 #include "ui/base/dialogs/select_file_dialog.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
20 21
21 using content::BrowserThread; 22 using content::BrowserThread;
22 using content::WebContents; 23 using content::WebContents;
23 24
24 namespace { 25 namespace {
25 26
26 void WriterCallback(const FilePath& path, const std::string& data) { 27 void WriterCallback(const FilePath& path, const std::string& data) {
27 int bytes_written = file_util::WriteFile(path, data.data(), data.size()); 28 int bytes_written = file_util::WriteFile(path, data.data(), data.size());
28 if (bytes_written != static_cast<ssize_t>(data.size())) { 29 if (bytes_written != static_cast<ssize_t>(data.size())) {
(...skipping 24 matching lines...) Expand all
53 return ""; 54 return "";
54 } 55 }
55 return "-----BEGIN CERTIFICATE-----\r\n" + 56 return "-----BEGIN CERTIFICATE-----\r\n" +
56 WrapAt64(base64) + 57 WrapAt64(base64) +
57 "-----END CERTIFICATE-----\r\n"; 58 "-----END CERTIFICATE-----\r\n";
58 } 59 }
59 60
60 //////////////////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////////////////
61 // General utility functions. 62 // General utility functions.
62 63
63 class Exporter : public SelectFileDialog::Listener { 64 class Exporter : public ui::SelectFileDialog::Listener {
64 public: 65 public:
65 Exporter(WebContents* web_contents, gfx::NativeWindow parent, 66 Exporter(WebContents* web_contents, gfx::NativeWindow parent,
66 net::X509Certificate::OSCertHandle cert); 67 net::X509Certificate::OSCertHandle cert);
67 ~Exporter(); 68 ~Exporter();
68 69
69 // SelectFileDialog::Listener implemenation. 70 // SelectFileDialog::Listener implemenation.
70 virtual void FileSelected(const FilePath& path, 71 virtual void FileSelected(const FilePath& path,
71 int index, void* params); 72 int index, void* params);
72 virtual void FileSelectionCanceled(void* params); 73 virtual void FileSelectionCanceled(void* params);
73 private: 74 private:
74 scoped_refptr<SelectFileDialog> select_file_dialog_; 75 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
75 76
76 // The certificate hierarchy (leaf cert first). 77 // The certificate hierarchy (leaf cert first).
77 net::X509Certificate::OSCertHandles cert_chain_list_; 78 net::X509Certificate::OSCertHandles cert_chain_list_;
78 }; 79 };
79 80
80 Exporter::Exporter(WebContents* web_contents, 81 Exporter::Exporter(WebContents* web_contents,
81 gfx::NativeWindow parent, 82 gfx::NativeWindow parent,
82 net::X509Certificate::OSCertHandle cert) 83 net::X509Certificate::OSCertHandle cert)
83 : select_file_dialog_(SelectFileDialog::Create( 84 : select_file_dialog_(ui::SelectFileDialog::Create(
84 this, new ChromeSelectFilePolicy(web_contents))) { 85 this, new ChromeSelectFilePolicy(web_contents))) {
85 x509_certificate_model::GetCertChainFromCert(cert, &cert_chain_list_); 86 x509_certificate_model::GetCertChainFromCert(cert, &cert_chain_list_);
86 87
87 // TODO(mattm): should this default to some directory? 88 // TODO(mattm): should this default to some directory?
88 // Maybe SavePackage::GetSaveDirPreference? (Except that it's private.) 89 // Maybe SavePackage::GetSaveDirPreference? (Except that it's private.)
89 FilePath suggested_path("certificate"); 90 FilePath suggested_path("certificate");
90 std::string cert_title = x509_certificate_model::GetTitle(cert); 91 std::string cert_title = x509_certificate_model::GetTitle(cert);
91 if (!cert_title.empty()) 92 if (!cert_title.empty())
92 suggested_path = FilePath(cert_title); 93 suggested_path = FilePath(cert_title);
93 94
94 ShowCertSelectFileDialog(select_file_dialog_.get(), 95 ShowCertSelectFileDialog(select_file_dialog_.get(),
95 SelectFileDialog::SELECT_SAVEAS_FILE, 96 ui::SelectFileDialog::SELECT_SAVEAS_FILE,
96 suggested_path, 97 suggested_path,
97 parent, 98 parent,
98 NULL); 99 NULL);
99 } 100 }
100 101
101 Exporter::~Exporter() { 102 Exporter::~Exporter() {
102 // There may be pending file dialogs, we need to tell them that we've gone 103 // There may be pending file dialogs, we need to tell them that we've gone
103 // away so they don't try and call back to us. 104 // away so they don't try and call back to us.
104 if (select_file_dialog_.get()) 105 if (select_file_dialog_.get())
105 select_file_dialog_->ListenerDestroyed(); 106 select_file_dialog_->ListenerDestroyed();
(...skipping 29 matching lines...) Expand all
135 136
136 delete this; 137 delete this;
137 } 138 }
138 139
139 void Exporter::FileSelectionCanceled(void* params) { 140 void Exporter::FileSelectionCanceled(void* params) {
140 delete this; 141 delete this;
141 } 142 }
142 143
143 } // namespace 144 } // namespace
144 145
145 void ShowCertSelectFileDialog(SelectFileDialog* select_file_dialog, 146 void ShowCertSelectFileDialog(ui::SelectFileDialog* select_file_dialog,
146 SelectFileDialog::Type type, 147 ui::SelectFileDialog::Type type,
147 const FilePath& suggested_path, 148 const FilePath& suggested_path,
148 gfx::NativeWindow parent, 149 gfx::NativeWindow parent,
149 void* params) { 150 void* params) {
150 SelectFileDialog::FileTypeInfo file_type_info; 151 ui::SelectFileDialog::FileTypeInfo file_type_info;
151 file_type_info.extensions.resize(5); 152 file_type_info.extensions.resize(5);
152 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pem")); 153 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pem"));
153 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("crt")); 154 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("crt"));
154 file_type_info.extension_description_overrides.push_back( 155 file_type_info.extension_description_overrides.push_back(
155 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_BASE64)); 156 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_BASE64));
156 file_type_info.extensions[1].push_back(FILE_PATH_LITERAL("pem")); 157 file_type_info.extensions[1].push_back(FILE_PATH_LITERAL("pem"));
157 file_type_info.extensions[1].push_back(FILE_PATH_LITERAL("crt")); 158 file_type_info.extensions[1].push_back(FILE_PATH_LITERAL("crt"));
158 file_type_info.extension_description_overrides.push_back( 159 file_type_info.extension_description_overrides.push_back(
159 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_BASE64_CHAIN)); 160 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_BASE64_CHAIN));
160 file_type_info.extensions[2].push_back(FILE_PATH_LITERAL("der")); 161 file_type_info.extensions[2].push_back(FILE_PATH_LITERAL("der"));
(...skipping 11 matching lines...) Expand all
172 suggested_path, &file_type_info, 1, 173 suggested_path, &file_type_info, 1,
173 FILE_PATH_LITERAL("crt"), 174 FILE_PATH_LITERAL("crt"),
174 parent, params); 175 parent, params);
175 } 176 }
176 177
177 void ShowCertExportDialog(WebContents* web_contents, 178 void ShowCertExportDialog(WebContents* web_contents,
178 gfx::NativeWindow parent, 179 gfx::NativeWindow parent,
179 net::X509Certificate::OSCertHandle cert) { 180 net::X509Certificate::OSCertHandle cert) {
180 new Exporter(web_contents, parent, cert); 181 new Exporter(web_contents, parent, cert);
181 } 182 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/certificate_dialogs.h ('k') | chrome/browser/ui/chrome_select_file_policy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698