| 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/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/download/download_prefs.h" | 21 #include "chrome/browser/download/download_prefs.h" |
| 22 #include "chrome/browser/io_thread.h" | 22 #include "chrome/browser/io_thread.h" |
| 23 #include "chrome/browser/net/net_export_helper.h" | 23 #include "chrome/browser/net/net_export_helper.h" |
| 24 #include "chrome/browser/platform_util.h" | 24 #include "chrome/browser/platform_util.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/ui/chrome_select_file_policy.h" | 26 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 27 #include "chrome/common/channel_info.h" |
| 27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 28 #include "components/grit/components_resources.h" | 29 #include "components/grit/components_resources.h" |
| 29 #include "components/net_log/chrome_net_log.h" | 30 #include "components/net_log/chrome_net_log.h" |
| 30 #include "components/net_log/net_export_ui_constants.h" | 31 #include "components/net_log/net_export_ui_constants.h" |
| 31 #include "components/net_log/net_log_file_writer.h" | 32 #include "components/net_log/net_log_file_writer.h" |
| 32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/storage_partition.h" | 34 #include "content/public/browser/storage_partition.h" |
| 34 #include "content/public/browser/url_data_source.h" | 35 #include "content/public/browser/url_data_source.h" |
| 35 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/browser/web_ui.h" | 37 #include "content/public/browser/web_ui.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // net_log::NetLogFileWriter::StateObserver implementation. | 105 // net_log::NetLogFileWriter::StateObserver implementation. |
| 105 void OnNewState(const base::DictionaryValue& state) override; | 106 void OnNewState(const base::DictionaryValue& state) override; |
| 106 | 107 |
| 107 private: | 108 private: |
| 108 using URLRequestContextGetterList = | 109 using URLRequestContextGetterList = |
| 109 std::vector<scoped_refptr<net::URLRequestContextGetter>>; | 110 std::vector<scoped_refptr<net::URLRequestContextGetter>>; |
| 110 | 111 |
| 111 // Send NetLog data via email. | 112 // Send NetLog data via email. |
| 112 static void SendEmail(const base::FilePath& file_to_send); | 113 static void SendEmail(const base::FilePath& file_to_send); |
| 113 | 114 |
| 115 void StartNetLog(const base::FilePath& path); |
| 116 |
| 114 // Reveal |path| in the shell on desktop platforms. | 117 // Reveal |path| in the shell on desktop platforms. |
| 115 void ShowFileInShell(const base::FilePath& path); | 118 void ShowFileInShell(const base::FilePath& path); |
| 116 | 119 |
| 117 // chrome://net-export can be used on both mobile and desktop platforms. | 120 // chrome://net-export can be used on both mobile and desktop platforms. |
| 118 // On mobile a user cannot pick where their NetLog file is saved to. | 121 // On mobile a user cannot pick where their NetLog file is saved to. |
| 119 // Instead, everything is saved on the user's temp directory. Thus the | 122 // Instead, everything is saved on the user's temp directory. Thus the |
| 120 // mobile user has the UI available to send their NetLog file as an | 123 // mobile user has the UI available to send their NetLog file as an |
| 121 // email while the desktop user, who gets to choose their NetLog file's | 124 // email while the desktop user, who gets to choose their NetLog file's |
| 122 // location, does not. Furthermore, since every time a user starts logging | 125 // location, does not. Furthermore, since every time a user starts logging |
| 123 // to a new NetLog file on mobile platforms it overwrites the previous | 126 // to a new NetLog file on mobile platforms it overwrites the previous |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) { | 218 void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) { |
| 216 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 219 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 217 std::string capture_mode_string; | 220 std::string capture_mode_string; |
| 218 bool result = list->GetString(0, &capture_mode_string); | 221 bool result = list->GetString(0, &capture_mode_string); |
| 219 DCHECK(result); | 222 DCHECK(result); |
| 220 | 223 |
| 221 capture_mode_ = | 224 capture_mode_ = |
| 222 net_log::NetLogFileWriter::CaptureModeFromString(capture_mode_string); | 225 net_log::NetLogFileWriter::CaptureModeFromString(capture_mode_string); |
| 223 | 226 |
| 224 if (UsingMobileUI()) { | 227 if (UsingMobileUI()) { |
| 225 file_writer_->StartNetLog(base::FilePath(), capture_mode_, | 228 StartNetLog(base::FilePath()); |
| 226 GetURLRequestContexts()); | |
| 227 } else { | 229 } else { |
| 228 base::FilePath initial_dir = last_save_dir.Pointer()->empty() ? | 230 base::FilePath initial_dir = last_save_dir.Pointer()->empty() ? |
| 229 DownloadPrefs::FromBrowserContext( | 231 DownloadPrefs::FromBrowserContext( |
| 230 web_ui()->GetWebContents()->GetBrowserContext())->DownloadPath() : | 232 web_ui()->GetWebContents()->GetBrowserContext())->DownloadPath() : |
| 231 *last_save_dir.Pointer(); | 233 *last_save_dir.Pointer(); |
| 232 base::FilePath initial_path = | 234 base::FilePath initial_path = |
| 233 initial_dir.Append(FILE_PATH_LITERAL("chrome-net-export-log.json")); | 235 initial_dir.Append(FILE_PATH_LITERAL("chrome-net-export-log.json")); |
| 234 ShowSelectFileDialog(initial_path); | 236 ShowSelectFileDialog(initial_path); |
| 235 } | 237 } |
| 236 } | 238 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 base::Bind(&NetExportMessageHandler::ShowFileInShell, AsWeakPtr())); | 275 base::Bind(&NetExportMessageHandler::ShowFileInShell, AsWeakPtr())); |
| 274 } | 276 } |
| 275 | 277 |
| 276 void NetExportMessageHandler::FileSelected(const base::FilePath& path, | 278 void NetExportMessageHandler::FileSelected(const base::FilePath& path, |
| 277 int index, | 279 int index, |
| 278 void* params) { | 280 void* params) { |
| 279 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 281 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 280 DCHECK(select_file_dialog_); | 282 DCHECK(select_file_dialog_); |
| 281 *last_save_dir.Pointer() = path.DirName(); | 283 *last_save_dir.Pointer() = path.DirName(); |
| 282 | 284 |
| 283 file_writer_->StartNetLog(path, capture_mode_, GetURLRequestContexts()); | 285 StartNetLog(path); |
| 284 | 286 |
| 285 // IMPORTANT: resetting the dialog may lead to the deletion of |path|, so keep | 287 // IMPORTANT: resetting the dialog may lead to the deletion of |path|, so keep |
| 286 // this line last. | 288 // this line last. |
| 287 select_file_dialog_ = nullptr; | 289 select_file_dialog_ = nullptr; |
| 288 } | 290 } |
| 289 | 291 |
| 290 void NetExportMessageHandler::FileSelectionCanceled(void* params) { | 292 void NetExportMessageHandler::FileSelectionCanceled(void* params) { |
| 291 DCHECK(select_file_dialog_); | 293 DCHECK(select_file_dialog_); |
| 292 select_file_dialog_ = nullptr; | 294 select_file_dialog_ = nullptr; |
| 293 } | 295 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 308 std::string body = | 310 std::string body = |
| 309 "Please add some informative text about the network issues."; | 311 "Please add some informative text about the network issues."; |
| 310 base::FilePath::StringType file_to_attach(file_to_send.value()); | 312 base::FilePath::StringType file_to_attach(file_to_send.value()); |
| 311 chrome::android::SendEmail( | 313 chrome::android::SendEmail( |
| 312 base::UTF8ToUTF16(email), base::UTF8ToUTF16(subject), | 314 base::UTF8ToUTF16(email), base::UTF8ToUTF16(subject), |
| 313 base::UTF8ToUTF16(body), base::UTF8ToUTF16(title), | 315 base::UTF8ToUTF16(body), base::UTF8ToUTF16(title), |
| 314 base::UTF8ToUTF16(file_to_attach)); | 316 base::UTF8ToUTF16(file_to_attach)); |
| 315 #endif | 317 #endif |
| 316 } | 318 } |
| 317 | 319 |
| 320 void NetExportMessageHandler::StartNetLog(const base::FilePath& path) { |
| 321 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 322 |
| 323 file_writer_->StartNetLog( |
| 324 base::FilePath(), capture_mode_, |
| 325 base::CommandLine::ForCurrentProcess()->GetCommandLineString(), |
| 326 chrome::GetChannelString(), GetURLRequestContexts()); |
| 327 } |
| 328 |
| 318 void NetExportMessageHandler::ShowFileInShell(const base::FilePath& path) { | 329 void NetExportMessageHandler::ShowFileInShell(const base::FilePath& path) { |
| 319 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 330 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 320 if (path.empty()) | 331 if (path.empty()) |
| 321 return; | 332 return; |
| 322 | 333 |
| 323 // (The |profile| parameter is relevant for Chrome OS) | 334 // (The |profile| parameter is relevant for Chrome OS) |
| 324 Profile* profile = Profile::FromWebUI(web_ui()); | 335 Profile* profile = Profile::FromWebUI(web_ui()); |
| 325 | 336 |
| 326 platform_util::ShowItemInFolder(profile, path); | 337 platform_util::ShowItemInFolder(profile, path); |
| 327 } | 338 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 393 |
| 383 } // namespace | 394 } // namespace |
| 384 | 395 |
| 385 NetExportUI::NetExportUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 396 NetExportUI::NetExportUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 386 web_ui->AddMessageHandler(base::MakeUnique<NetExportMessageHandler>()); | 397 web_ui->AddMessageHandler(base::MakeUnique<NetExportMessageHandler>()); |
| 387 | 398 |
| 388 // Set up the chrome://net-export/ source. | 399 // Set up the chrome://net-export/ source. |
| 389 Profile* profile = Profile::FromWebUI(web_ui); | 400 Profile* profile = Profile::FromWebUI(web_ui); |
| 390 content::WebUIDataSource::Add(profile, CreateNetExportHTMLSource()); | 401 content::WebUIDataSource::Add(profile, CreateNetExportHTMLSource()); |
| 391 } | 402 } |
| OLD | NEW |