Chromium Code Reviews| 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/views/file_manager_dialog.h" | 5 #include "chrome/browser/ui/views/file_manager_dialog.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "chrome/browser/extensions/extension_file_browser_private_api.h" | 10 #include "chrome/browser/extensions/extension_file_browser_private_api.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 RenderViewHost* FileManagerDialog::GetRenderViewHost() { | 165 RenderViewHost* FileManagerDialog::GetRenderViewHost() { |
| 166 if (extension_dialog_) | 166 if (extension_dialog_) |
| 167 return extension_dialog_->host()->render_view_host(); | 167 return extension_dialog_->host()->render_view_host(); |
| 168 return NULL; | 168 return NULL; |
| 169 } | 169 } |
| 170 | 170 |
| 171 void FileManagerDialog::AddPending(int32 tab_id) { | 171 void FileManagerDialog::AddPending(int32 tab_id) { |
| 172 PendingDialog::GetInstance()->Add(tab_id, this); | 172 PendingDialog::GetInstance()->Add(tab_id, this); |
| 173 } | 173 } |
| 174 | 174 |
| 175 bool FileManagerDialog::PendingExists(int32 tab_id) { | |
| 176 return PendingDialog::GetInstance()->Find(tab_id) != NULL; | |
| 177 } | |
| 178 | |
| 175 bool FileManagerDialog::HasMultipleFileTypeChoicesImpl() { | 179 bool FileManagerDialog::HasMultipleFileTypeChoicesImpl() { |
| 176 return hasMultipleFileTypeChoices_; | 180 return hasMultipleFileTypeChoices_; |
| 177 } | 181 } |
| 178 | 182 |
| 179 void FileManagerDialog::SelectFileImpl( | 183 void FileManagerDialog::SelectFileImpl( |
| 180 Type type, | 184 Type type, |
| 181 const string16& title, | 185 const string16& title, |
| 182 const FilePath& default_path, | 186 const FilePath& default_path, |
| 183 const FileTypeInfo* file_types, | 187 const FileTypeInfo* file_types, |
| 184 int file_type_index, | 188 int file_type_index, |
| 185 const FilePath::StringType& default_extension, | 189 const FilePath::StringType& default_extension, |
| 186 gfx::NativeWindow owner_window, | 190 gfx::NativeWindow owner_window, |
| 187 void* params) { | 191 void* params) { |
| 188 if (owner_window_) { | 192 if (owner_window_) { |
| 189 LOG(ERROR) << "File dialog already in use!"; | 193 LOG(ERROR) << "File dialog already in use!"; |
| 190 return; | 194 return; |
| 191 } | 195 } |
| 192 // Extension background pages may not supply an owner_window. | 196 // Extension background pages may not supply an owner_window. |
| 193 Browser* owner_browser = (owner_window ? | 197 Browser* owner_browser = (owner_window ? |
| 194 BrowserList::FindBrowserWithWindow(owner_window) : | 198 BrowserList::FindBrowserWithWindow(owner_window) : |
| 195 BrowserList::GetLastActive()); | 199 BrowserList::GetLastActive()); |
| 196 if (!owner_browser) { | 200 if (!owner_browser) { |
| 197 NOTREACHED() << "Can't find owning browser"; | 201 NOTREACHED() << "Can't find owning browser"; |
| 198 return; | 202 return; |
| 199 } | 203 } |
| 200 | 204 |
| 205 TabContentsWrapper* tab = owner_browser->GetSelectedTabContentsWrapper(); | |
| 206 | |
| 207 // Check if we have another dialog opened in the tab. It's unlikely, but | |
| 208 // possible. | |
| 209 int32 tab_id = (tab ? tab->restore_tab_helper()->session_id().id() : 0); | |
|
achuithb
2011/11/10 20:58:40
parens are not required.
tbarzic
2011/11/10 22:00:48
removed
| |
| 210 if (PendingExists(tab_id)) | |
| 211 return; | |
| 212 | |
| 201 FilePath virtual_path; | 213 FilePath virtual_path; |
| 202 if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath( | 214 if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath( |
| 203 owner_browser->profile(), default_path, &virtual_path)) { | 215 owner_browser->profile(), default_path, &virtual_path)) { |
| 204 virtual_path = default_path.BaseName(); | 216 virtual_path = default_path.BaseName(); |
| 205 } | 217 } |
| 206 | 218 |
| 207 hasMultipleFileTypeChoices_ = | 219 hasMultipleFileTypeChoices_ = |
| 208 file_types ? file_types->extensions.size() > 1 : true; | 220 file_types ? file_types->extensions.size() > 1 : true; |
| 209 | 221 |
| 210 GURL file_browser_url = FileManagerUtil::GetFileBrowserUrlWithParams( | 222 GURL file_browser_url = FileManagerUtil::GetFileBrowserUrlWithParams( |
| 211 type, title, virtual_path, file_types, file_type_index, | 223 type, title, virtual_path, file_types, file_type_index, |
| 212 default_extension); | 224 default_extension); |
| 213 TabContentsWrapper* tab = owner_browser->GetSelectedTabContentsWrapper(); | 225 |
| 214 ExtensionDialog* dialog = ExtensionDialog::Show(file_browser_url, | 226 ExtensionDialog* dialog = ExtensionDialog::Show(file_browser_url, |
| 215 owner_browser, tab->tab_contents(), | 227 owner_browser, tab->tab_contents(), |
| 216 kFileManagerWidth, kFileManagerHeight, | 228 kFileManagerWidth, kFileManagerHeight, |
| 217 this /* ExtensionDialog::Observer */); | 229 this /* ExtensionDialog::Observer */); |
| 218 if (!dialog) { | 230 if (!dialog) { |
| 219 LOG(ERROR) << "Unable to create extension dialog"; | 231 LOG(ERROR) << "Unable to create extension dialog"; |
| 220 return; | 232 return; |
| 221 } | 233 } |
| 222 | 234 |
| 223 // Connect our listener to FileDialogFunction's per-tab callbacks. | 235 // Connect our listener to FileDialogFunction's per-tab callbacks. |
| 224 int32 tab_id = (tab ? tab->restore_tab_helper()->session_id().id() : 0); | |
| 225 AddPending(tab_id); | 236 AddPending(tab_id); |
| 226 | 237 |
| 227 extension_dialog_ = dialog; | 238 extension_dialog_ = dialog; |
| 228 params_ = params; | 239 params_ = params; |
| 229 tab_id_ = tab_id; | 240 tab_id_ = tab_id; |
| 230 owner_window_ = owner_window; | 241 owner_window_ = owner_window; |
| 231 } | 242 } |
| OLD | NEW |