| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/shell_dialogs.h" | 5 #include "chrome/browser/shell_dialogs.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/browser.h" | 15 #include "chrome/browser/browser.h" |
| 16 #include "chrome/browser/browser_list.h" | 16 #include "chrome/browser/browser_list.h" |
| 17 #include "chrome/browser/chrome_thread.h" | 17 #include "chrome/browser/chrome_thread.h" |
| 18 #include "chrome/browser/dom_ui/html_dialog_ui.h" | 18 #include "chrome/browser/dom_ui/html_dialog_ui.h" |
| 19 #include "chrome/browser/profile_manager.h" |
| 19 #include "chrome/browser/shell_dialogs.h" | 20 #include "chrome/browser/shell_dialogs.h" |
| 20 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
| 21 #include "chrome/browser/views/browser_dialogs.h" | 22 #include "chrome/browser/views/browser_dialogs.h" |
| 22 #include "chrome/browser/views/html_dialog_view.h" | 23 #include "chrome/browser/views/html_dialog_view.h" |
| 23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 25 #include "views/window/non_client_view.h" | 26 #include "views/window/non_client_view.h" |
| 26 #include "views/window/window.h" | 27 #include "views/window/window.h" |
| 27 | 28 |
| 28 #include "chrome/browser/profile_manager.h" | |
| 29 | |
| 30 namespace { | 29 namespace { |
| 31 | 30 |
| 32 static const wchar_t* kKeyNamePath = L"path"; | 31 const char kKeyNamePath[] = "path"; |
| 33 static const int kSaveCompletePageIndex = 2; | 32 const int kSaveCompletePageIndex = 2; |
| 34 | 33 |
| 35 }; // namespace | 34 } // namespace |
| 36 | 35 |
| 37 // Implementation of SelectFileDialog that shows an UI for choosing a file | 36 // Implementation of SelectFileDialog that shows an UI for choosing a file |
| 38 // or folder using FileBrowseUI. | 37 // or folder using FileBrowseUI. |
| 39 class SelectFileDialogImpl : public SelectFileDialog { | 38 class SelectFileDialogImpl : public SelectFileDialog { |
| 40 public: | 39 public: |
| 41 explicit SelectFileDialogImpl(Listener* listener); | 40 explicit SelectFileDialogImpl(Listener* listener); |
| 42 | 41 |
| 43 // BaseShellDialog implementation. | 42 // BaseShellDialog implementation. |
| 44 virtual bool IsRunning(gfx::NativeWindow parent_window) const; | 43 virtual bool IsRunning(gfx::NativeWindow parent_window) const; |
| 45 virtual void ListenerDestroyed(); | 44 virtual void ListenerDestroyed(); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 if (!json.empty()) { | 249 if (!json.empty()) { |
| 251 scoped_ptr<Value> value(base::JSONReader::Read(json, false)); | 250 scoped_ptr<Value> value(base::JSONReader::Read(json, false)); |
| 252 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) { | 251 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) { |
| 253 // Bad json value returned. | 252 // Bad json value returned. |
| 254 NOTREACHED(); | 253 NOTREACHED(); |
| 255 } else { | 254 } else { |
| 256 const DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 255 const DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
| 257 if (delegate->type_ == SELECT_OPEN_FILE || | 256 if (delegate->type_ == SELECT_OPEN_FILE || |
| 258 delegate->type_ == SELECT_SAVEAS_FILE || | 257 delegate->type_ == SELECT_SAVEAS_FILE || |
| 259 delegate->type_ == SELECT_FOLDER) { | 258 delegate->type_ == SELECT_FOLDER) { |
| 260 std::wstring path_string; | 259 std::string path_string; |
| 261 if (dict->HasKey(kKeyNamePath) && | 260 if (dict->HasKey(kKeyNamePath) && |
| 262 dict->GetString(kKeyNamePath, &path_string)) { | 261 dict->GetString(kKeyNamePath, &path_string)) { |
| 263 FilePath path = FilePath::FromWStringHack(path_string); | 262 FilePath path = FilePath::FromWStringHack(UTF8ToWide(path_string)); |
| 264 | 263 |
| 265 listener_->FileSelected(path, kSaveCompletePageIndex, | 264 listener_->FileSelected(path, kSaveCompletePageIndex, |
| 266 delegate->params_); | 265 delegate->params_); |
| 267 notification_fired = true; | 266 notification_fired = true; |
| 268 } | 267 } |
| 269 } else if (delegate->type_ == SELECT_OPEN_MULTI_FILE) { | 268 } else if (delegate->type_ == SELECT_OPEN_MULTI_FILE) { |
| 270 ListValue* paths_value = NULL; | 269 ListValue* paths_value = NULL; |
| 271 if (dict->HasKey(kKeyNamePath) && | 270 if (dict->HasKey(kKeyNamePath) && |
| 272 dict->GetList(kKeyNamePath, &paths_value) && | 271 dict->GetList(kKeyNamePath, &paths_value) && |
| 273 paths_value) { | 272 paths_value) { |
| 274 std::vector<FilePath> paths; | 273 std::vector<FilePath> paths; |
| 275 paths.reserve(paths_value->GetSize()); | 274 paths.reserve(paths_value->GetSize()); |
| 276 for (size_t i = 0; i < paths_value->GetSize(); ++i) { | 275 for (size_t i = 0; i < paths_value->GetSize(); ++i) { |
| 277 std::wstring path_string; | 276 std::string path_string; |
| 278 if (paths_value->GetString(i, &path_string) && | 277 if (paths_value->GetString(i, &path_string) && |
| 279 !path_string.empty()) { | 278 !path_string.empty()) { |
| 280 paths.push_back(FilePath::FromWStringHack(path_string)); | 279 paths.push_back(FilePath::FromWStringHack( |
| 280 UTF8ToWide(path_string))); |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 listener_->MultiFilesSelected(paths, delegate->params_); | 284 listener_->MultiFilesSelected(paths, delegate->params_); |
| 285 notification_fired = true; | 285 notification_fired = true; |
| 286 } | 286 } |
| 287 } else { | 287 } else { |
| 288 NOTREACHED(); | 288 NOTREACHED(); |
| 289 } | 289 } |
| 290 } | 290 } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 // TODO(xiyuan): Change this when the infrastructure is improved. | 473 // TODO(xiyuan): Change this when the infrastructure is improved. |
| 474 HtmlDialogUIDelegate** delegate = HtmlDialogUI::GetPropertyAccessor(). | 474 HtmlDialogUIDelegate** delegate = HtmlDialogUI::GetPropertyAccessor(). |
| 475 GetProperty(dom_ui_->tab_contents()->property_bag()); | 475 GetProperty(dom_ui_->tab_contents()->property_bag()); |
| 476 HtmlDialogView* containing_view = static_cast<HtmlDialogView*>(*delegate); | 476 HtmlDialogView* containing_view = static_cast<HtmlDialogView*>(*delegate); |
| 477 DCHECK(containing_view); | 477 DCHECK(containing_view); |
| 478 | 478 |
| 479 containing_view->GetWindow()->UpdateWindowTitle(); | 479 containing_view->GetWindow()->UpdateWindowTitle(); |
| 480 containing_view->GetWindow()->GetNonClientView()->SchedulePaint(); | 480 containing_view->GetWindow()->GetNonClientView()->SchedulePaint(); |
| 481 } | 481 } |
| 482 } | 482 } |
| OLD | NEW |