| 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 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // Messages. | 69 // Messages. |
| 70 void OnGetExportNetLogInfo(const base::ListValue* list); | 70 void OnGetExportNetLogInfo(const base::ListValue* list); |
| 71 void OnStartNetLog(const base::ListValue* list); | 71 void OnStartNetLog(const base::ListValue* list); |
| 72 void OnStopNetLog(const base::ListValue* list); | 72 void OnStopNetLog(const base::ListValue* list); |
| 73 void OnSendNetLog(const base::ListValue* list); | 73 void OnSendNetLog(const base::ListValue* list); |
| 74 | 74 |
| 75 // ui::SelectFileDialog::Listener: | 75 // ui::SelectFileDialog::Listener: |
| 76 void FileSelected(const base::FilePath& path, | 76 void FileSelected(const base::FilePath& path, |
| 77 int index, | 77 int index, |
| 78 void* params) override; | 78 void* params) override; |
| 79 void FileSelectionCanceled(void* params) override; |
| 79 | 80 |
| 80 private: | 81 private: |
| 81 // Calls NetLogFileWriter's ProcessCommand with DO_START and DO_STOP commands. | 82 // Calls NetLogFileWriter's ProcessCommand with DO_START and DO_STOP commands. |
| 82 static void ProcessNetLogCommand( | 83 static void ProcessNetLogCommand( |
| 83 base::WeakPtr<NetExportMessageHandler> net_export_message_handler, | 84 base::WeakPtr<NetExportMessageHandler> net_export_message_handler, |
| 84 net_log::NetLogFileWriter* net_log_file_writer, | 85 net_log::NetLogFileWriter* net_log_file_writer, |
| 85 net_log::NetLogFileWriter::Command command); | 86 net_log::NetLogFileWriter::Command command); |
| 86 | 87 |
| 87 // Returns the path to the file which has NetLog data. | 88 // Returns the path to the file which has NetLog data. |
| 88 static base::FilePath GetNetLogFileName( | 89 static base::FilePath GetNetLogFileName( |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 305 |
| 305 void NetExportMessageHandler::OnExportNetLogInfoChanged(base::Value* arg) { | 306 void NetExportMessageHandler::OnExportNetLogInfoChanged(base::Value* arg) { |
| 306 std::unique_ptr<base::Value> value(arg); | 307 std::unique_ptr<base::Value> value(arg); |
| 307 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 308 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 308 web_ui()->CallJavascriptFunctionUnsafe(net_log::kOnExportNetLogInfoChanged, | 309 web_ui()->CallJavascriptFunctionUnsafe(net_log::kOnExportNetLogInfoChanged, |
| 309 *arg); | 310 *arg); |
| 310 } | 311 } |
| 311 | 312 |
| 312 void NetExportMessageHandler::ShowSelectFileDialog( | 313 void NetExportMessageHandler::ShowSelectFileDialog( |
| 313 const base::FilePath& default_path) { | 314 const base::FilePath& default_path) { |
| 314 DCHECK(!select_file_dialog_); | 315 // User may have clicked more than once before the save dialog appears. |
| 316 // This prevents creating more than one save dialog. |
| 317 if (select_file_dialog_) |
| 318 return; |
| 315 | 319 |
| 316 WebContents* webcontents = nullptr; | 320 WebContents* webcontents = web_ui()->GetWebContents(); |
| 317 | 321 |
| 318 select_file_dialog_ = ui::SelectFileDialog::Create( | 322 select_file_dialog_ = ui::SelectFileDialog::Create( |
| 319 this, new ChromeSelectFilePolicy(webcontents)); | 323 this, new ChromeSelectFilePolicy(webcontents)); |
| 320 ui::SelectFileDialog::FileTypeInfo file_type_info; | 324 ui::SelectFileDialog::FileTypeInfo file_type_info; |
| 321 file_type_info.extensions = {{FILE_PATH_LITERAL("json")}}; | 325 file_type_info.extensions = {{FILE_PATH_LITERAL("json")}}; |
| 322 gfx::NativeWindow owning_window = | 326 gfx::NativeWindow owning_window = webcontents->GetTopLevelNativeWindow(); |
| 323 webcontents ? platform_util::GetTopLevel(webcontents->GetNativeView()) | |
| 324 : nullptr; | |
| 325 | |
| 326 select_file_dialog_->SelectFile( | 327 select_file_dialog_->SelectFile( |
| 327 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), default_path, | 328 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), default_path, |
| 328 &file_type_info, 0, base::FilePath::StringType(), owning_window, nullptr); | 329 &file_type_info, 0, base::FilePath::StringType(), owning_window, nullptr); |
| 329 } | 330 } |
| 330 | 331 |
| 331 void NetExportMessageHandler::FileSelected(const base::FilePath& path, | 332 void NetExportMessageHandler::FileSelected(const base::FilePath& path, |
| 332 int index, | 333 int index, |
| 333 void* params) { | 334 void* params) { |
| 335 DCHECK(select_file_dialog_); |
| 336 select_file_dialog_ = nullptr; |
| 337 |
| 334 BrowserThread::PostTaskAndReply( | 338 BrowserThread::PostTaskAndReply( |
| 335 BrowserThread::FILE_USER_BLOCKING, FROM_HERE, | 339 BrowserThread::FILE_USER_BLOCKING, FROM_HERE, |
| 336 base::Bind(&net_log::NetLogFileWriter::SetUpNetExportLogPath, | 340 base::Bind(&net_log::NetLogFileWriter::SetUpNetExportLogPath, |
| 337 base::Unretained(net_log_file_writer_), path), | 341 base::Unretained(net_log_file_writer_), path), |
| 338 // NetExportMessageHandler is tied to the lifetime of the tab | 342 // NetExportMessageHandler is tied to the lifetime of the tab |
| 339 // so it cannot be assured that it will be valid when this | 343 // so it cannot be assured that it will be valid when this |
| 340 // StartNetLog is called. Instead of using base::Unretained a | 344 // StartNetLog is called. Instead of using base::Unretained a |
| 341 // weak pointer is used to adjust for this. | 345 // weak pointer is used to adjust for this. |
| 342 base::Bind(&NetExportMessageHandler::StartNetLog, | 346 base::Bind(&NetExportMessageHandler::StartNetLog, |
| 343 weak_ptr_factory_.GetWeakPtr())); | 347 weak_ptr_factory_.GetWeakPtr())); |
| 344 } | 348 } |
| 345 | 349 |
| 350 void NetExportMessageHandler::FileSelectionCanceled(void* params) { |
| 351 DCHECK(select_file_dialog_); |
| 352 select_file_dialog_ = nullptr; |
| 353 } |
| 354 |
| 346 } // namespace | 355 } // namespace |
| 347 | 356 |
| 348 NetExportUI::NetExportUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 357 NetExportUI::NetExportUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 349 web_ui->AddMessageHandler(new NetExportMessageHandler()); | 358 web_ui->AddMessageHandler(new NetExportMessageHandler()); |
| 350 | 359 |
| 351 // Set up the chrome://net-export/ source. | 360 // Set up the chrome://net-export/ source. |
| 352 Profile* profile = Profile::FromWebUI(web_ui); | 361 Profile* profile = Profile::FromWebUI(web_ui); |
| 353 content::WebUIDataSource::Add(profile, CreateNetExportHTMLSource()); | 362 content::WebUIDataSource::Add(profile, CreateNetExportHTMLSource()); |
| 354 } | 363 } |
| OLD | NEW |