Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: chrome/browser/ui/views/file_manager_dialog.cc

Issue 8523006: Don't show FileManagerDialog if another FileManagerDialog is shown in the same tab. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: space Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // static
176 bool FileManagerDialog::PendingExists(int32 tab_id) {
177 return PendingDialog::GetInstance()->Find(tab_id) != NULL;
178 }
179
175 bool FileManagerDialog::HasMultipleFileTypeChoicesImpl() { 180 bool FileManagerDialog::HasMultipleFileTypeChoicesImpl() {
176 return hasMultipleFileTypeChoices_; 181 return hasMultipleFileTypeChoices_;
177 } 182 }
178 183
179 void FileManagerDialog::SelectFileImpl( 184 void FileManagerDialog::SelectFileImpl(
180 Type type, 185 Type type,
181 const string16& title, 186 const string16& title,
182 const FilePath& default_path, 187 const FilePath& default_path,
183 const FileTypeInfo* file_types, 188 const FileTypeInfo* file_types,
184 int file_type_index, 189 int file_type_index,
185 const FilePath::StringType& default_extension, 190 const FilePath::StringType& default_extension,
186 gfx::NativeWindow owner_window, 191 gfx::NativeWindow owner_window,
187 void* params) { 192 void* params) {
188 if (owner_window_) { 193 if (owner_window_) {
189 LOG(ERROR) << "File dialog already in use!"; 194 LOG(ERROR) << "File dialog already in use!";
190 return; 195 return;
191 } 196 }
192 // Extension background pages may not supply an owner_window. 197 // Extension background pages may not supply an owner_window.
193 Browser* owner_browser = (owner_window ? 198 Browser* owner_browser = (owner_window ?
194 BrowserList::FindBrowserWithWindow(owner_window) : 199 BrowserList::FindBrowserWithWindow(owner_window) :
195 BrowserList::GetLastActive()); 200 BrowserList::GetLastActive());
196 if (!owner_browser) { 201 if (!owner_browser) {
197 NOTREACHED() << "Can't find owning browser"; 202 NOTREACHED() << "Can't find owning browser";
198 return; 203 return;
199 } 204 }
200 205
206 TabContentsWrapper* tab = owner_browser->GetSelectedTabContentsWrapper();
207
208 // Check if we have another dialog opened in the tab. It's unlikely, but
209 // possible.
210 int32 tab_id = tab ? tab->restore_tab_helper()->session_id().id() : 0;
211 if (PendingExists(tab_id))
212 return;
213
201 FilePath virtual_path; 214 FilePath virtual_path;
202 if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath( 215 if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath(
203 owner_browser->profile(), default_path, &virtual_path)) { 216 owner_browser->profile(), default_path, &virtual_path)) {
204 virtual_path = default_path.BaseName(); 217 virtual_path = default_path.BaseName();
205 } 218 }
206 219
207 hasMultipleFileTypeChoices_ = 220 hasMultipleFileTypeChoices_ =
208 file_types ? file_types->extensions.size() > 1 : true; 221 file_types ? file_types->extensions.size() > 1 : true;
209 222
210 GURL file_browser_url = FileManagerUtil::GetFileBrowserUrlWithParams( 223 GURL file_browser_url = FileManagerUtil::GetFileBrowserUrlWithParams(
211 type, title, virtual_path, file_types, file_type_index, 224 type, title, virtual_path, file_types, file_type_index,
212 default_extension); 225 default_extension);
213 TabContentsWrapper* tab = owner_browser->GetSelectedTabContentsWrapper(); 226
214 ExtensionDialog* dialog = ExtensionDialog::Show(file_browser_url, 227 ExtensionDialog* dialog = ExtensionDialog::Show(file_browser_url,
215 owner_browser, tab->tab_contents(), 228 owner_browser, tab->tab_contents(),
216 kFileManagerWidth, kFileManagerHeight, 229 kFileManagerWidth, kFileManagerHeight,
217 this /* ExtensionDialog::Observer */); 230 this /* ExtensionDialog::Observer */);
218 if (!dialog) { 231 if (!dialog) {
219 LOG(ERROR) << "Unable to create extension dialog"; 232 LOG(ERROR) << "Unable to create extension dialog";
220 return; 233 return;
221 } 234 }
222 235
223 // Connect our listener to FileDialogFunction's per-tab callbacks. 236 // 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); 237 AddPending(tab_id);
226 238
227 extension_dialog_ = dialog; 239 extension_dialog_ = dialog;
228 params_ = params; 240 params_ = params;
229 tab_id_ = tab_id; 241 tab_id_ = tab_id;
230 owner_window_ = owner_window; 242 owner_window_ = owner_window;
231 } 243 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/file_manager_dialog.h ('k') | chrome/browser/ui/views/file_manager_dialog_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698