| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/select_file_dialog_extension.h" | 5 #include "chrome/browser/ui/views/select_file_dialog_extension.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 Map map_; | 58 Map map_; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // static | 61 // static |
| 62 PendingDialog* PendingDialog::GetInstance() { | 62 PendingDialog* PendingDialog::GetInstance() { |
| 63 return Singleton<PendingDialog>::get(); | 63 return Singleton<PendingDialog>::get(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void PendingDialog::Add(int32 tab_id, | 66 void PendingDialog::Add(int32 tab_id, |
| 67 scoped_refptr<SelectFileDialogExtension> dialog) { | 67 scoped_refptr<SelectFileDialogExtension> dialog) { |
| 68 DCHECK(dialog); | 68 DCHECK(dialog.get()); |
| 69 if (map_.find(tab_id) == map_.end()) | 69 if (map_.find(tab_id) == map_.end()) |
| 70 map_.insert(std::make_pair(tab_id, dialog)); | 70 map_.insert(std::make_pair(tab_id, dialog)); |
| 71 else | 71 else |
| 72 DLOG(WARNING) << "Duplicate pending dialog " << tab_id; | 72 DLOG(WARNING) << "Duplicate pending dialog " << tab_id; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void PendingDialog::Remove(int32 tab_id) { | 75 void PendingDialog::Remove(int32 tab_id) { |
| 76 map_.erase(tab_id); | 76 map_.erase(tab_id); |
| 77 } | 77 } |
| 78 | 78 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 102 has_multiple_file_type_choices_(false), | 102 has_multiple_file_type_choices_(false), |
| 103 tab_id_(0), | 103 tab_id_(0), |
| 104 profile_(NULL), | 104 profile_(NULL), |
| 105 owner_window_(NULL), | 105 owner_window_(NULL), |
| 106 selection_type_(CANCEL), | 106 selection_type_(CANCEL), |
| 107 selection_index_(0), | 107 selection_index_(0), |
| 108 params_(NULL) { | 108 params_(NULL) { |
| 109 } | 109 } |
| 110 | 110 |
| 111 SelectFileDialogExtension::~SelectFileDialogExtension() { | 111 SelectFileDialogExtension::~SelectFileDialogExtension() { |
| 112 if (extension_dialog_) | 112 if (extension_dialog_.get()) |
| 113 extension_dialog_->ObserverDestroyed(); | 113 extension_dialog_->ObserverDestroyed(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool SelectFileDialogExtension::IsRunning( | 116 bool SelectFileDialogExtension::IsRunning( |
| 117 gfx::NativeWindow owner_window) const { | 117 gfx::NativeWindow owner_window) const { |
| 118 return owner_window_ == owner_window; | 118 return owner_window_ == owner_window; |
| 119 } | 119 } |
| 120 | 120 |
| 121 void SelectFileDialogExtension::ListenerDestroyed() { | 121 void SelectFileDialogExtension::ListenerDestroyed() { |
| 122 listener_ = NULL; | 122 listener_ = NULL; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 dialog->Close(); | 161 dialog->Close(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // static | 164 // static |
| 165 void SelectFileDialogExtension::OnFileSelected( | 165 void SelectFileDialogExtension::OnFileSelected( |
| 166 int32 tab_id, | 166 int32 tab_id, |
| 167 const ui::SelectedFileInfo& file, | 167 const ui::SelectedFileInfo& file, |
| 168 int index) { | 168 int index) { |
| 169 scoped_refptr<SelectFileDialogExtension> dialog = | 169 scoped_refptr<SelectFileDialogExtension> dialog = |
| 170 PendingDialog::GetInstance()->Find(tab_id); | 170 PendingDialog::GetInstance()->Find(tab_id); |
| 171 if (!dialog) | 171 if (!dialog.get()) |
| 172 return; | 172 return; |
| 173 dialog->selection_type_ = SINGLE_FILE; | 173 dialog->selection_type_ = SINGLE_FILE; |
| 174 dialog->selection_files_.clear(); | 174 dialog->selection_files_.clear(); |
| 175 dialog->selection_files_.push_back(file); | 175 dialog->selection_files_.push_back(file); |
| 176 dialog->selection_index_ = index; | 176 dialog->selection_index_ = index; |
| 177 } | 177 } |
| 178 | 178 |
| 179 // static | 179 // static |
| 180 void SelectFileDialogExtension::OnMultiFilesSelected( | 180 void SelectFileDialogExtension::OnMultiFilesSelected( |
| 181 int32 tab_id, | 181 int32 tab_id, |
| 182 const std::vector<ui::SelectedFileInfo>& files) { | 182 const std::vector<ui::SelectedFileInfo>& files) { |
| 183 scoped_refptr<SelectFileDialogExtension> dialog = | 183 scoped_refptr<SelectFileDialogExtension> dialog = |
| 184 PendingDialog::GetInstance()->Find(tab_id); | 184 PendingDialog::GetInstance()->Find(tab_id); |
| 185 if (!dialog) | 185 if (!dialog.get()) |
| 186 return; | 186 return; |
| 187 dialog->selection_type_ = MULTIPLE_FILES; | 187 dialog->selection_type_ = MULTIPLE_FILES; |
| 188 dialog->selection_files_ = files; | 188 dialog->selection_files_ = files; |
| 189 dialog->selection_index_ = 0; | 189 dialog->selection_index_ = 0; |
| 190 } | 190 } |
| 191 | 191 |
| 192 // static | 192 // static |
| 193 void SelectFileDialogExtension::OnFileSelectionCanceled(int32 tab_id) { | 193 void SelectFileDialogExtension::OnFileSelectionCanceled(int32 tab_id) { |
| 194 scoped_refptr<SelectFileDialogExtension> dialog = | 194 scoped_refptr<SelectFileDialogExtension> dialog = |
| 195 PendingDialog::GetInstance()->Find(tab_id); | 195 PendingDialog::GetInstance()->Find(tab_id); |
| 196 if (!dialog) | 196 if (!dialog.get()) |
| 197 return; | 197 return; |
| 198 dialog->selection_type_ = CANCEL; | 198 dialog->selection_type_ = CANCEL; |
| 199 dialog->selection_files_.clear(); | 199 dialog->selection_files_.clear(); |
| 200 dialog->selection_index_ = 0; | 200 dialog->selection_index_ = 0; |
| 201 } | 201 } |
| 202 | 202 |
| 203 content::RenderViewHost* SelectFileDialogExtension::GetRenderViewHost() { | 203 content::RenderViewHost* SelectFileDialogExtension::GetRenderViewHost() { |
| 204 if (extension_dialog_) | 204 if (extension_dialog_.get()) |
| 205 return extension_dialog_->host()->render_view_host(); | 205 return extension_dialog_->host()->render_view_host(); |
| 206 return NULL; | 206 return NULL; |
| 207 } | 207 } |
| 208 | 208 |
| 209 void SelectFileDialogExtension::NotifyListener() { | 209 void SelectFileDialogExtension::NotifyListener() { |
| 210 if (!listener_) | 210 if (!listener_) |
| 211 return; | 211 return; |
| 212 switch (selection_type_) { | 212 switch (selection_type_) { |
| 213 case CANCEL: | 213 case CANCEL: |
| 214 listener_->FileSelectionCanceled(params_); | 214 listener_->FileSelectionCanceled(params_); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 369 } |
| 370 | 370 |
| 371 // Connect our listener to FileDialogFunction's per-tab callbacks. | 371 // Connect our listener to FileDialogFunction's per-tab callbacks. |
| 372 AddPending(tab_id); | 372 AddPending(tab_id); |
| 373 | 373 |
| 374 extension_dialog_ = dialog; | 374 extension_dialog_ = dialog; |
| 375 params_ = params; | 375 params_ = params; |
| 376 tab_id_ = tab_id; | 376 tab_id_ = tab_id; |
| 377 owner_window_ = owner_window; | 377 owner_window_ = owner_window; |
| 378 } | 378 } |
| OLD | NEW |