| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/shell_dialogs.h" | 5 #include "chrome/browser/ui/shell_dialogs.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "views/window/non_client_view.h" | 26 #include "views/window/non_client_view.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 const char kKeyNamePath[] = "path"; | 30 const char kKeyNamePath[] = "path"; |
| 31 const int kSaveCompletePageIndex = 2; | 31 const int kSaveCompletePageIndex = 2; |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 // Implementation of SelectFileDialog that shows an UI for choosing a file | 35 // Implementation of SelectFileDialog that shows an UI for choosing a file |
| 36 // or folder using FileBrowseUI. | 36 // or folder. |
| 37 class SelectFileDialogImpl : public SelectFileDialog { | 37 class SelectFileDialogImpl : public SelectFileDialog { |
| 38 public: | 38 public: |
| 39 explicit SelectFileDialogImpl(Listener* listener); | 39 explicit SelectFileDialogImpl(Listener* listener); |
| 40 | 40 |
| 41 // BaseShellDialog implementation. | 41 // BaseShellDialog implementation. |
| 42 virtual bool IsRunning(gfx::NativeWindow parent_window) const; | 42 virtual bool IsRunning(gfx::NativeWindow parent_window) const; |
| 43 virtual void ListenerDestroyed(); | 43 virtual void ListenerDestroyed(); |
| 44 | 44 |
| 45 protected: | 45 protected: |
| 46 // SelectFileDialog implementation. | 46 // SelectFileDialog implementation. |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 318 |
| 319 bool SelectFileDialogImpl::FileBrowseDelegate::IsDialogModal() const { | 319 bool SelectFileDialogImpl::FileBrowseDelegate::IsDialogModal() const { |
| 320 return true; | 320 return true; |
| 321 } | 321 } |
| 322 | 322 |
| 323 string16 SelectFileDialogImpl::FileBrowseDelegate::GetDialogTitle() const { | 323 string16 SelectFileDialogImpl::FileBrowseDelegate::GetDialogTitle() const { |
| 324 return title_; | 324 return title_; |
| 325 } | 325 } |
| 326 | 326 |
| 327 GURL SelectFileDialogImpl::FileBrowseDelegate::GetDialogContentURL() const { | 327 GURL SelectFileDialogImpl::FileBrowseDelegate::GetDialogContentURL() const { |
| 328 #if defined(USE_AURA) |
| 329 // TODO(saintlou): The current SelectFileDialogImpl assumes chromeos==1 |
| 330 std::string url_string; |
| 331 #else |
| 328 std::string url_string(chrome::kChromeUIFileBrowseURL); | 332 std::string url_string(chrome::kChromeUIFileBrowseURL); |
| 329 | 333 #endif |
| 330 return GURL(url_string); | 334 return GURL(url_string); |
| 331 } | 335 } |
| 332 | 336 |
| 333 void SelectFileDialogImpl::FileBrowseDelegate::GetWebUIMessageHandlers( | 337 void SelectFileDialogImpl::FileBrowseDelegate::GetWebUIMessageHandlers( |
| 334 std::vector<WebUIMessageHandler*>* handlers) const { | 338 std::vector<WebUIMessageHandler*>* handlers) const { |
| 335 handlers->push_back(new FileBrowseDelegateHandler( | 339 handlers->push_back(new FileBrowseDelegateHandler( |
| 336 const_cast<FileBrowseDelegate*>(this))); | 340 const_cast<FileBrowseDelegate*>(this))); |
| 337 return; | 341 return; |
| 338 } | 342 } |
| 339 | 343 |
| 340 void SelectFileDialogImpl::FileBrowseDelegate::GetDialogSize( | 344 void SelectFileDialogImpl::FileBrowseDelegate::GetDialogSize( |
| 341 gfx::Size* size) const { | 345 gfx::Size* size) const { |
| 342 size->SetSize(320, 240); | 346 size->SetSize(320, 240); |
| 343 } | 347 } |
| 344 | 348 |
| 345 std::string SelectFileDialogImpl::FileBrowseDelegate::GetDialogArgs() const { | 349 std::string SelectFileDialogImpl::FileBrowseDelegate::GetDialogArgs() const { |
| 350 #if defined(USE_AURA) |
| 351 // TODO(saintlou): The current SelectFileDialogImpl does not seem to work |
| 352 // when chromeos==0. |
| 353 return std::string(); |
| 354 #else |
| 346 // SelectFile inputs as json. | 355 // SelectFile inputs as json. |
| 347 // { | 356 // { |
| 348 // "type" : "open", // (or "open_multiple", "save", "folder" | 357 // "type" : "open", // (or "open_multiple", "save", "folder" |
| 349 // "all_files" : true, | 358 // "all_files" : true, |
| 350 // "file_types" : { | 359 // "file_types" : { |
| 351 // "exts" : [ ["htm", "html"], ["txt"] ], | 360 // "exts" : [ ["htm", "html"], ["txt"] ], |
| 352 // "desc" : [ "HTML files", "Text files" ], | 361 // "desc" : [ "HTML files", "Text files" ], |
| 353 // }, | 362 // }, |
| 354 // "file_type_index" : 1, // 1-based file type index. | 363 // "file_type_index" : 1, // 1-based file type index. |
| 355 // } | 364 // } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 "\"current_file\":\"%s\"," | 426 "\"current_file\":\"%s\"," |
| 418 "\"file_types\":{\"exts\":[%s],\"desc\":[%s]}," | 427 "\"file_types\":{\"exts\":[%s],\"desc\":[%s]}," |
| 419 "\"file_type_index\":%d" | 428 "\"file_type_index\":%d" |
| 420 "}", | 429 "}", |
| 421 type_string.c_str(), | 430 type_string.c_str(), |
| 422 file_types_.include_all_files ? "true" : "false", | 431 file_types_.include_all_files ? "true" : "false", |
| 423 filename.c_str(), | 432 filename.c_str(), |
| 424 exts_list.c_str(), | 433 exts_list.c_str(), |
| 425 desc_list.c_str(), | 434 desc_list.c_str(), |
| 426 file_type_index_); | 435 file_type_index_); |
| 436 #endif |
| 427 } | 437 } |
| 428 | 438 |
| 429 void SelectFileDialogImpl::FileBrowseDelegate::OnDialogClosed( | 439 void SelectFileDialogImpl::FileBrowseDelegate::OnDialogClosed( |
| 430 const std::string& json_retval) { | 440 const std::string& json_retval) { |
| 431 owner_->OnDialogClosed(this, json_retval); | 441 owner_->OnDialogClosed(this, json_retval); |
| 432 delete this; | 442 delete this; |
| 433 return; | 443 return; |
| 434 } | 444 } |
| 435 | 445 |
| 436 SelectFileDialogImpl::FileBrowseDelegateHandler::FileBrowseDelegateHandler( | 446 SelectFileDialogImpl::FileBrowseDelegateHandler::FileBrowseDelegateHandler( |
| 437 FileBrowseDelegate* delegate) | 447 FileBrowseDelegate* delegate) |
| 438 : delegate_(delegate) { | 448 : delegate_(delegate) { |
| 439 } | 449 } |
| 440 | 450 |
| 441 void SelectFileDialogImpl::FileBrowseDelegateHandler::RegisterMessages() { | 451 void SelectFileDialogImpl::FileBrowseDelegateHandler::RegisterMessages() { |
| 442 web_ui_->RegisterMessageCallback("setDialogTitle", | 452 web_ui_->RegisterMessageCallback("setDialogTitle", |
| 443 NewCallback(this, &FileBrowseDelegateHandler::HandleSetDialogTitle)); | 453 NewCallback(this, &FileBrowseDelegateHandler::HandleSetDialogTitle)); |
| 444 } | 454 } |
| 445 | 455 |
| 446 void SelectFileDialogImpl::FileBrowseDelegateHandler::HandleSetDialogTitle( | 456 void SelectFileDialogImpl::FileBrowseDelegateHandler::HandleSetDialogTitle( |
| 447 const ListValue* args) { | 457 const ListValue* args) { |
| 458 #if !defined(USE_AURA) |
| 459 // TODO(saintlou): The current SelectFileDialogImpl does not seem to work |
| 460 // when chromeos==0. |
| 448 std::wstring new_title = UTF16ToWideHack(ExtractStringValue(args)); | 461 std::wstring new_title = UTF16ToWideHack(ExtractStringValue(args)); |
| 449 if (new_title != delegate_->title_) { | 462 if (new_title != delegate_->title_) { |
| 450 delegate_->title_ = new_title; | 463 delegate_->title_ = new_title; |
| 451 | 464 |
| 452 // Notify the containing view about the title change. | 465 // Notify the containing view about the title change. |
| 453 // The current HtmlDialogUIDelegate and HtmlDialogView does not support | 466 // The current HtmlDialogUIDelegate and HtmlDialogView does not support |
| 454 // dynamic title change. We hijacked the mechanism between HTMLDialogUI | 467 // dynamic title change. We hijacked the mechanism between HTMLDialogUI |
| 455 // and HtmlDialogView to get the HtmlDialogView and forced it to update | 468 // and HtmlDialogView to get the HtmlDialogView and forced it to update |
| 456 // its title. | 469 // its title. |
| 457 // TODO(xiyuan): Change this when the infrastructure is improved. | 470 // TODO(xiyuan): Change this when the infrastructure is improved. |
| 458 HtmlDialogUIDelegate** delegate = HtmlDialogUI::GetPropertyAccessor(). | 471 HtmlDialogUIDelegate** delegate = HtmlDialogUI::GetPropertyAccessor(). |
| 459 GetProperty(web_ui_->tab_contents()->property_bag()); | 472 GetProperty(web_ui_->tab_contents()->property_bag()); |
| 460 HtmlDialogView* containing_view = static_cast<HtmlDialogView*>(*delegate); | 473 HtmlDialogView* containing_view = static_cast<HtmlDialogView*>(*delegate); |
| 461 DCHECK(containing_view); | 474 DCHECK(containing_view); |
| 462 | 475 |
| 463 containing_view->GetWindow()->UpdateWindowTitle(); | 476 containing_view->GetWindow()->UpdateWindowTitle(); |
| 464 containing_view->GetWindow()->non_client_view()->SchedulePaint(); | 477 containing_view->GetWindow()->non_client_view()->SchedulePaint(); |
| 465 } | 478 } |
| 479 #endif |
| 466 } | 480 } |
| OLD | NEW |