OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/net_export_ui.h" | 5 #include "chrome/browser/ui/webui/net_export_ui.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/scoped_observer.h" | 15 #include "base/scoped_observer.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/download/download_prefs.h" | 20 #include "chrome/browser/download/download_prefs.h" |
21 #include "chrome/browser/io_thread.h" | 21 #include "chrome/browser/io_thread.h" |
22 #include "chrome/browser/net/net_export_helper.h" | 22 #include "chrome/browser/net/net_export_helper.h" |
| 23 #include "chrome/browser/platform_util.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/chrome_select_file_policy.h" | 25 #include "chrome/browser/ui/chrome_select_file_policy.h" |
25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
26 #include "components/grit/components_resources.h" | 27 #include "components/grit/components_resources.h" |
27 #include "components/net_log/chrome_net_log.h" | 28 #include "components/net_log/chrome_net_log.h" |
28 #include "components/net_log/net_export_ui_constants.h" | 29 #include "components/net_log/net_export_ui_constants.h" |
29 #include "components/net_log/net_log_file_writer.h" | 30 #include "components/net_log/net_log_file_writer.h" |
30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/storage_partition.h" | 32 #include "content/public/browser/storage_partition.h" |
32 #include "content/public/browser/url_data_source.h" | 33 #include "content/public/browser/url_data_source.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 ~NetExportMessageHandler() override; | 108 ~NetExportMessageHandler() override; |
108 | 109 |
109 // WebUIMessageHandler implementation. | 110 // WebUIMessageHandler implementation. |
110 void RegisterMessages() override; | 111 void RegisterMessages() override; |
111 | 112 |
112 // Messages | 113 // Messages |
113 void OnEnableNotifyUIWithState(const base::ListValue* list); | 114 void OnEnableNotifyUIWithState(const base::ListValue* list); |
114 void OnStartNetLog(const base::ListValue* list); | 115 void OnStartNetLog(const base::ListValue* list); |
115 void OnStopNetLog(const base::ListValue* list); | 116 void OnStopNetLog(const base::ListValue* list); |
116 void OnSendNetLog(const base::ListValue* list); | 117 void OnSendNetLog(const base::ListValue* list); |
| 118 void OnShowFile(const base::ListValue* list); |
117 | 119 |
118 // ui::SelectFileDialog::Listener implementation. | 120 // ui::SelectFileDialog::Listener implementation. |
119 void FileSelected(const base::FilePath& path, | 121 void FileSelected(const base::FilePath& path, |
120 int index, | 122 int index, |
121 void* params) override; | 123 void* params) override; |
122 void FileSelectionCanceled(void* params) override; | 124 void FileSelectionCanceled(void* params) override; |
123 | 125 |
124 // net_log::NetLogFileWriter::StateObserver implementation. | 126 // net_log::NetLogFileWriter::StateObserver implementation. |
125 void OnNewState(const base::DictionaryValue& state) override; | 127 void OnNewState(const base::DictionaryValue& state) override; |
126 | 128 |
127 private: | 129 private: |
128 using URLRequestContextGetterList = | 130 using URLRequestContextGetterList = |
129 std::vector<scoped_refptr<net::URLRequestContextGetter>>; | 131 std::vector<scoped_refptr<net::URLRequestContextGetter>>; |
130 | 132 |
131 // Send NetLog data via email. | 133 // Send NetLog data via email. |
132 static void SendEmail(const base::FilePath& file_to_send); | 134 static void SendEmail(const base::FilePath& file_to_send); |
133 | 135 |
| 136 // Reveal |path| in the shell on desktop platforms. |
| 137 void ShowFileInShell(const base::FilePath& path); |
| 138 |
134 // chrome://net-export can be used on both mobile and desktop platforms. | 139 // chrome://net-export can be used on both mobile and desktop platforms. |
135 // On mobile a user cannot pick where their NetLog file is saved to. | 140 // On mobile a user cannot pick where their NetLog file is saved to. |
136 // Instead, everything is saved on the user's temp directory. Thus the | 141 // Instead, everything is saved on the user's temp directory. Thus the |
137 // mobile user has the UI available to send their NetLog file as an | 142 // mobile user has the UI available to send their NetLog file as an |
138 // email while the desktop user, who gets to choose their NetLog file's | 143 // email while the desktop user, who gets to choose their NetLog file's |
139 // location, does not. Furthermore, since every time a user starts logging | 144 // location, does not. Furthermore, since every time a user starts logging |
140 // to a new NetLog file on mobile platforms it overwrites the previous | 145 // to a new NetLog file on mobile platforms it overwrites the previous |
141 // NetLog file, a warning message appears on the Start Logging button | 146 // NetLog file, a warning message appears on the Start Logging button |
142 // that informs the user of this. This does not exist on the desktop | 147 // that informs the user of this. This does not exist on the desktop |
143 // UI. | 148 // UI. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 base::Bind(&NetExportMessageHandler::OnStartNetLog, | 210 base::Bind(&NetExportMessageHandler::OnStartNetLog, |
206 base::Unretained(this))); | 211 base::Unretained(this))); |
207 web_ui()->RegisterMessageCallback( | 212 web_ui()->RegisterMessageCallback( |
208 net_log::kStopNetLogHandler, | 213 net_log::kStopNetLogHandler, |
209 base::Bind(&NetExportMessageHandler::OnStopNetLog, | 214 base::Bind(&NetExportMessageHandler::OnStopNetLog, |
210 base::Unretained(this))); | 215 base::Unretained(this))); |
211 web_ui()->RegisterMessageCallback( | 216 web_ui()->RegisterMessageCallback( |
212 net_log::kSendNetLogHandler, | 217 net_log::kSendNetLogHandler, |
213 base::Bind(&NetExportMessageHandler::OnSendNetLog, | 218 base::Bind(&NetExportMessageHandler::OnSendNetLog, |
214 base::Unretained(this))); | 219 base::Unretained(this))); |
| 220 web_ui()->RegisterMessageCallback( |
| 221 net_log::kShowFile, |
| 222 base::Bind(&NetExportMessageHandler::OnShowFile, base::Unretained(this))); |
215 } | 223 } |
216 | 224 |
217 // The net-export UI is not notified of state changes until this function runs. | 225 // The net-export UI is not notified of state changes until this function runs. |
218 // After this function, NotifyUIWithState() will be called on all |file_writer_| | 226 // After this function, NotifyUIWithState() will be called on all |file_writer_| |
219 // state changes. | 227 // state changes. |
220 void NetExportMessageHandler::OnEnableNotifyUIWithState( | 228 void NetExportMessageHandler::OnEnableNotifyUIWithState( |
221 const base::ListValue* list) { | 229 const base::ListValue* list) { |
222 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 230 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
223 if (!state_observer_manager_.IsObservingSources()) { | 231 if (!state_observer_manager_.IsObservingSources()) { |
224 state_observer_manager_.Add(file_writer_); | 232 state_observer_manager_.Add(file_writer_); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 file_writer_->StopNetLog(std::move(ui_thread_polled_data), | 282 file_writer_->StopNetLog(std::move(ui_thread_polled_data), |
275 Profile::FromWebUI(web_ui())->GetRequestContext()); | 283 Profile::FromWebUI(web_ui())->GetRequestContext()); |
276 } | 284 } |
277 | 285 |
278 void NetExportMessageHandler::OnSendNetLog(const base::ListValue* list) { | 286 void NetExportMessageHandler::OnSendNetLog(const base::ListValue* list) { |
279 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 287 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
280 file_writer_->GetFilePathToCompletedLog( | 288 file_writer_->GetFilePathToCompletedLog( |
281 base::Bind(&NetExportMessageHandler::SendEmail)); | 289 base::Bind(&NetExportMessageHandler::SendEmail)); |
282 } | 290 } |
283 | 291 |
| 292 void NetExportMessageHandler::OnShowFile(const base::ListValue* list) { |
| 293 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 294 file_writer_->GetFilePathToCompletedLog( |
| 295 base::Bind(&NetExportMessageHandler::ShowFileInShell, AsWeakPtr())); |
| 296 } |
| 297 |
284 void NetExportMessageHandler::FileSelected(const base::FilePath& path, | 298 void NetExportMessageHandler::FileSelected(const base::FilePath& path, |
285 int index, | 299 int index, |
286 void* params) { | 300 void* params) { |
287 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 301 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
288 DCHECK(select_file_dialog_); | 302 DCHECK(select_file_dialog_); |
289 select_file_dialog_ = nullptr; | 303 select_file_dialog_ = nullptr; |
290 *last_save_dir.Pointer() = path.DirName(); | 304 *last_save_dir.Pointer() = path.DirName(); |
291 | 305 |
292 file_writer_->StartNetLog(path, capture_mode_, GetURLRequestContexts()); | 306 file_writer_->StartNetLog(path, capture_mode_, GetURLRequestContexts()); |
293 } | 307 } |
(...skipping 19 matching lines...) Expand all Loading... |
313 std::string body = | 327 std::string body = |
314 "Please add some informative text about the network issues."; | 328 "Please add some informative text about the network issues."; |
315 base::FilePath::StringType file_to_attach(file_to_send.value()); | 329 base::FilePath::StringType file_to_attach(file_to_send.value()); |
316 chrome::android::SendEmail( | 330 chrome::android::SendEmail( |
317 base::UTF8ToUTF16(email), base::UTF8ToUTF16(subject), | 331 base::UTF8ToUTF16(email), base::UTF8ToUTF16(subject), |
318 base::UTF8ToUTF16(body), base::UTF8ToUTF16(title), | 332 base::UTF8ToUTF16(body), base::UTF8ToUTF16(title), |
319 base::UTF8ToUTF16(file_to_attach)); | 333 base::UTF8ToUTF16(file_to_attach)); |
320 #endif | 334 #endif |
321 } | 335 } |
322 | 336 |
| 337 void NetExportMessageHandler::ShowFileInShell(const base::FilePath& path) { |
| 338 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 339 if (path.empty()) |
| 340 return; |
| 341 |
| 342 // (The |profile| parameter is relevant for Chrome OS) |
| 343 Profile* profile = Profile::FromWebUI(web_ui()); |
| 344 |
| 345 platform_util::ShowItemInFolder(profile, path); |
| 346 } |
| 347 |
323 // static | 348 // static |
324 bool NetExportMessageHandler::UsingMobileUI() { | 349 bool NetExportMessageHandler::UsingMobileUI() { |
325 #if defined(OS_ANDROID) || defined(OS_IOS) | 350 #if defined(OS_ANDROID) || defined(OS_IOS) |
326 return true; | 351 return true; |
327 #else | 352 #else |
328 return false; | 353 return false; |
329 #endif | 354 #endif |
330 } | 355 } |
331 | 356 |
332 void NetExportMessageHandler::NotifyUIWithState( | 357 void NetExportMessageHandler::NotifyUIWithState( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 406 |
382 } // namespace | 407 } // namespace |
383 | 408 |
384 NetExportUI::NetExportUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 409 NetExportUI::NetExportUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
385 web_ui->AddMessageHandler(base::MakeUnique<NetExportMessageHandler>()); | 410 web_ui->AddMessageHandler(base::MakeUnique<NetExportMessageHandler>()); |
386 | 411 |
387 // Set up the chrome://net-export/ source. | 412 // Set up the chrome://net-export/ source. |
388 Profile* profile = Profile::FromWebUI(web_ui); | 413 Profile* profile = Profile::FromWebUI(web_ui); |
389 content::WebUIDataSource::Add(profile, CreateNetExportHTMLSource()); | 414 content::WebUIDataSource::Add(profile, CreateNetExportHTMLSource()); |
390 } | 415 } |
OLD | NEW |