Chromium Code Reviews| 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 // In that case, we don't want more than one save dialog to appear. | |
|
mmenke
2016/10/24 16:58:58
nit: Don't use we in comments, as it's ambiguous
wangyix1
2016/10/24 19:57:12
Done.
| |
| 317 if (select_file_dialog_) { | |
| 318 return; | |
| 319 } | |
|
mmenke
2016/10/24 16:58:58
nit: No braces when the if condition and body tak
wangyix1
2016/10/24 19:57:12
Done.
| |
| 315 | 320 |
| 316 WebContents* webcontents = nullptr; | 321 WebContents* webcontents = web_ui()->GetWebContents(); |
| 317 | 322 |
| 318 select_file_dialog_ = ui::SelectFileDialog::Create( | 323 select_file_dialog_ = ui::SelectFileDialog::Create( |
| 319 this, new ChromeSelectFilePolicy(webcontents)); | 324 this, new ChromeSelectFilePolicy(webcontents)); |
| 320 ui::SelectFileDialog::FileTypeInfo file_type_info; | 325 ui::SelectFileDialog::FileTypeInfo file_type_info; |
| 321 file_type_info.extensions = {{FILE_PATH_LITERAL("json")}}; | 326 file_type_info.extensions = {{FILE_PATH_LITERAL("json")}}; |
| 322 gfx::NativeWindow owning_window = | 327 gfx::NativeWindow owning_window = |
| 323 webcontents ? platform_util::GetTopLevel(webcontents->GetNativeView()) | 328 webcontents ? webcontents->GetTopLevelNativeWindow() |
| 324 : nullptr; | 329 : nullptr; |
|
mmenke
2016/10/24 16:58:58
I don't think webcontents can actually ever be NUL
wangyix1
2016/10/24 19:57:12
Done.
| |
| 325 | |
| 326 select_file_dialog_->SelectFile( | 330 select_file_dialog_->SelectFile( |
| 327 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), default_path, | 331 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), default_path, |
| 328 &file_type_info, 0, base::FilePath::StringType(), owning_window, nullptr); | 332 &file_type_info, 0, base::FilePath::StringType(), owning_window, nullptr); |
| 329 } | 333 } |
| 330 | 334 |
| 331 void NetExportMessageHandler::FileSelected(const base::FilePath& path, | 335 void NetExportMessageHandler::FileSelected(const base::FilePath& path, |
| 332 int index, | 336 int index, |
| 333 void* params) { | 337 void* params) { |
|
mmenke
2016/10/24 16:58:58
Maybe put a DCHECK(select_file_dialog_); here and
wangyix1
2016/10/24 19:57:12
Done.
| |
| 338 select_file_dialog_ = nullptr; | |
| 334 BrowserThread::PostTaskAndReply( | 339 BrowserThread::PostTaskAndReply( |
| 335 BrowserThread::FILE_USER_BLOCKING, FROM_HERE, | 340 BrowserThread::FILE_USER_BLOCKING, FROM_HERE, |
| 336 base::Bind(&net_log::NetLogFileWriter::SetUpNetExportLogPath, | 341 base::Bind(&net_log::NetLogFileWriter::SetUpNetExportLogPath, |
| 337 base::Unretained(net_log_file_writer_), path), | 342 base::Unretained(net_log_file_writer_), path), |
| 338 // NetExportMessageHandler is tied to the lifetime of the tab | 343 // NetExportMessageHandler is tied to the lifetime of the tab |
| 339 // so it cannot be assured that it will be valid when this | 344 // so it cannot be assured that it will be valid when this |
| 340 // StartNetLog is called. Instead of using base::Unretained a | 345 // StartNetLog is called. Instead of using base::Unretained a |
| 341 // weak pointer is used to adjust for this. | 346 // weak pointer is used to adjust for this. |
| 342 base::Bind(&NetExportMessageHandler::StartNetLog, | 347 base::Bind(&NetExportMessageHandler::StartNetLog, |
| 343 weak_ptr_factory_.GetWeakPtr())); | 348 weak_ptr_factory_.GetWeakPtr())); |
| 344 } | 349 } |
| 345 | 350 |
| 351 void NetExportMessageHandler::FileSelectionCanceled(void* params) { | |
| 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 |