Chromium Code Reviews| 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 "apps/shell_window.h" | 7 #include "apps/shell_window.h" |
| 8 #include "apps/shell_window_registry.h" | 8 #include "apps/shell_window_registry.h" |
| 9 #include "apps/ui/native_app_window.h" | 9 #include "apps/ui/native_app_window.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 if (!owner_browser) { | 289 if (!owner_browser) { |
| 290 // If an owner_window was supplied but we couldn't find a browser, this | 290 // If an owner_window was supplied but we couldn't find a browser, this |
| 291 // could be for a shell window. | 291 // could be for a shell window. |
| 292 shell_window = apps::ShellWindowRegistry:: | 292 shell_window = apps::ShellWindowRegistry:: |
| 293 GetShellWindowForNativeWindowAnyProfile(owner_window); | 293 GetShellWindowForNativeWindowAnyProfile(owner_window); |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 | 296 |
| 297 if (shell_window) { | 297 if (shell_window) { |
| 298 if (shell_window->window_type_is_panel()) { | 298 if (shell_window->window_type_is_panel()) { |
| 299 NOTREACHED() << "File dialog opened by panel."; | 299 NOTREACHED() << "File dialog opened by panel."; |
|
Peter Kasting
2014/01/24 19:17:25
Nit: While here, can you fix this style guide viol
mtomasz
2014/01/27 02:38:44
Done.
| |
| 300 return; | 300 return; |
| 301 } | 301 } |
| 302 base_window = shell_window->GetBaseWindow(); | 302 base_window = shell_window->GetBaseWindow(); |
| 303 web_contents = shell_window->web_contents(); | 303 web_contents = shell_window->web_contents(); |
| 304 } else { | 304 } else { |
| 305 // If the owning window is still unknown, this could be a background page or | 305 // If the owning window is still unknown, this could be a background page or |
| 306 // and extension popup. Use the last active browser. | 306 // and extension popup. Use the last active browser. |
| 307 if (!owner_browser) { | 307 if (!owner_browser) { |
| 308 owner_browser = | 308 owner_browser = |
| 309 chrome::FindLastActiveWithHostDesktopType(chrome::GetActiveDesktop()); | 309 chrome::FindLastActiveWithHostDesktopType(chrome::GetActiveDesktop()); |
| 310 } | 310 } |
| 311 DCHECK(owner_browser); | 311 DCHECK(owner_browser); |
| 312 if (!owner_browser) { | 312 if (!owner_browser) { |
|
Peter Kasting
2014/01/24 19:17:25
Nit: Similarly, can you remove this whole conditio
mtomasz
2014/01/27 02:38:44
Done.
| |
| 313 LOG(ERROR) << "Could not find browser or shell window for popup."; | 313 LOG(ERROR) << "Could not find browser or shell window for popup."; |
| 314 return; | 314 return; |
| 315 } | 315 } |
| 316 base_window = owner_browser->window(); | 316 base_window = owner_browser->window(); |
| 317 web_contents = owner_browser->tab_strip_model()->GetActiveWebContents(); | 317 web_contents = owner_browser->tab_strip_model()->GetActiveWebContents(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 DCHECK(base_window); | 320 DCHECK(base_window); |
| 321 DCHECK(web_contents); | 321 DCHECK(web_contents); |
| 322 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 322 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 323 DCHECK(profile_); | 323 DCHECK(profile_); |
| 324 | 324 |
| 325 // Check if we have another dialog opened for the contents. It's unlikely, but | 325 // Check if we have another dialog opened for the contents. It's unlikely, but |
| 326 // possible. | 326 // possible. |
| 327 RoutingID routing_id = GetRoutingIDFromWebContents(web_contents); | 327 RoutingID routing_id = GetRoutingIDFromWebContents(web_contents); |
| 328 if (PendingExists(routing_id)) { | 328 if (PendingExists(routing_id)) { |
| 329 DLOG(WARNING) << "Pending dialog exists with id " << routing_id; | 329 DLOG(WARNING) << "Pending dialog exists with id " << routing_id; |
| 330 return; | 330 return; |
| 331 } | 331 } |
| 332 | 332 |
| 333 base::FilePath default_dialog_path; | |
| 334 | |
| 335 const PrefService* pref_service = profile_->GetPrefs(); | 333 const PrefService* pref_service = profile_->GetPrefs(); |
| 336 | 334 if (!pref_service) { |
| 337 if (default_path.empty() && pref_service) { | 335 LOG(ERROR) << "Could not find the pref service."; |
|
Peter Kasting
2014/01/24 19:17:25
In general, don't use logging statements. They bl
mtomasz
2014/01/27 02:38:44
Done.
| |
| 338 default_dialog_path = | 336 return; |
| 339 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory); | |
| 340 } else { | |
| 341 default_dialog_path = default_path; | |
| 342 } | 337 } |
| 343 | 338 |
| 344 base::FilePath virtual_path; | 339 // All of the paths below are absolute. |
| 345 base::FilePath fallback_path = profile_->last_selected_directory().Append( | 340 base::FilePath download_default_path( |
| 346 default_dialog_path.BaseName()); | 341 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory)); |
| 347 // If an absolute path is specified as the default path, convert it to the | 342 |
| 348 // virtual path in the file browser extension. Due to the current design, | 343 base::FilePath selection_path = default_path.IsAbsolute() ? |
| 349 // an invalid temporal cache file path may passed as |default_dialog_path| | 344 default_path : download_default_path.Append(default_path.BaseName()); |
| 350 // (crbug.com/178013 #9-#11). In such a case, we use the last selected | 345 base::FilePath current_directory_path = selection_path.DirName(); |
| 351 // directory as a workaround. Real fix is tracked at crbug.com/110119. | 346 |
| 347 base::FilePath current_directory_virtual_path; | |
| 348 base::FilePath selection_virtual_path; | |
|
Peter Kasting
2014/01/24 19:17:25
Nit: Declare these as close to their initializatio
mtomasz
2014/01/27 02:38:44
Done.
| |
| 349 | |
| 350 base::FilePath fallback_path = !profile_->last_selected_directory().empty() ? | |
|
Peter Kasting
2014/01/24 19:17:25
Nit: Remove "!" and reverse arms
mtomasz
2014/01/27 02:38:44
Done, but is it better? I usually do this:
conditi
Peter Kasting
2014/01/28 03:22:04
I find it easier to read conditionals when they're
| |
| 351 profile_->last_selected_directory() : download_default_path; | |
| 352 | |
| 353 // Convert the above absolute paths to virtual paths. | |
| 354 // TODO(mtomasz): Use URLs instead of paths. | |
| 352 using file_manager::kFileManagerAppId; | 355 using file_manager::kFileManagerAppId; |
|
Peter Kasting
2014/01/24 19:17:25
Nit: This using statement doesn't buy us much; all
mtomasz
2014/01/27 02:38:44
Done.
| |
| 353 if (default_dialog_path.IsAbsolute() && | 356 if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath( |
| 354 (file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath( | 357 profile_, |
|
Peter Kasting
2014/01/24 19:17:25
Nit: Indent 4, not 8
You're welcome to put more t
mtomasz
2014/01/27 02:38:44
Over and over again I receive contrasting comments
Peter Kasting
2014/01/28 03:22:04
The Google style guide is ambiguous. My memory of
| |
| 355 profile_, kFileManagerAppId, default_dialog_path, &virtual_path) || | 358 kFileManagerAppId, |
| 356 file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath( | 359 selection_path, |
| 357 profile_, kFileManagerAppId, fallback_path, &virtual_path))) { | 360 &selection_virtual_path)) { |
| 358 virtual_path = base::FilePath("/").Append(virtual_path); | 361 // Due to the current design, an invalid temporal cache file path may passed |
| 359 } else { | 362 // as |default_path| (crbug.com/178013 #9-#11). In such a case, we use the |
| 360 // If the path was relative, or failed to convert, just use the base name, | 363 // last selected directory as a workaround. Real fix is tracked at |
| 361 virtual_path = default_dialog_path.BaseName(); | 364 // crbug.com/110119. |
|
Peter Kasting
2014/01/24 19:17:25
Nit: Normally I discourage bug references in comme
mtomasz
2014/01/27 02:38:44
I'm not sure if I understand. I think the context
Peter Kasting
2014/01/28 03:22:04
I mostly meant, if "an invalid temporal cache file
| |
| 365 if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath( | |
| 366 profile_, | |
| 367 kFileManagerAppId, | |
| 368 fallback_path.Append(selection_path.BaseName()), | |
| 369 &selection_virtual_path)) { | |
| 370 LOG(ERROR) << "Unable to resolve the selection path."; | |
| 371 return; | |
| 372 } | |
| 362 } | 373 } |
| 374 selection_virtual_path = base::FilePath("/").Append(selection_virtual_path); | |
|
Peter Kasting
2014/01/24 19:17:25
I don't work with FilePaths enough to know the ans
mtomasz
2014/01/27 02:38:44
This works, because select_file_dialog_extension.c
| |
| 375 | |
| 376 if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath( | |
| 377 profile_, | |
| 378 kFileManagerAppId, | |
| 379 current_directory_path, | |
| 380 ¤t_directory_virtual_path)) { | |
| 381 // Fallback if necessary, see the comment above. | |
| 382 if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath( | |
| 383 profile_, | |
| 384 kFileManagerAppId, | |
| 385 fallback_path, | |
| 386 ¤t_directory_virtual_path)) { | |
| 387 LOG(ERROR) << "Unable to resolve the current directory path: " | |
| 388 << fallback_path.value(); | |
| 389 return; | |
| 390 } | |
| 391 } | |
| 392 current_directory_virtual_path = base::FilePath("/").Append( | |
| 393 current_directory_virtual_path); | |
| 363 | 394 |
| 364 has_multiple_file_type_choices_ = | 395 has_multiple_file_type_choices_ = |
| 365 file_types ? file_types->extensions.size() > 1 : true; | 396 file_types ? file_types->extensions.size() > 1 : true; |
|
Peter Kasting
2014/01/24 19:17:25
Nit: Slightly simpler:
!file_types || (file
mtomasz
2014/01/27 02:38:44
Done.
| |
| 366 | 397 |
| 367 GURL file_manager_url = | 398 GURL file_manager_url = |
| 368 file_manager::util::GetFileManagerMainPageUrlWithParams( | 399 file_manager::util::GetFileManagerMainPageUrlWithParams( |
| 369 type, title, virtual_path, file_types, file_type_index, | 400 type, |
| 401 title, | |
| 402 current_directory_virtual_path, | |
| 403 selection_virtual_path, | |
| 404 file_types, | |
| 405 file_type_index, | |
| 370 default_extension); | 406 default_extension); |
| 371 | 407 |
| 372 ExtensionDialog* dialog = ExtensionDialog::Show(file_manager_url, | 408 ExtensionDialog* dialog = ExtensionDialog::Show(file_manager_url, |
| 373 base_window, profile_, web_contents, | 409 base_window, profile_, web_contents, |
| 374 kFileManagerWidth, kFileManagerHeight, | 410 kFileManagerWidth, kFileManagerHeight, |
| 375 kFileManagerMinimumWidth, | 411 kFileManagerMinimumWidth, |
| 376 kFileManagerMinimumHeight, | 412 kFileManagerMinimumHeight, |
| 377 #if defined(USE_AURA) | 413 #if defined(USE_AURA) |
| 378 file_manager::util::GetSelectFileDialogTitle(type), | 414 file_manager::util::GetSelectFileDialogTitle(type), |
| 379 #else | 415 #else |
| 380 // HTML-based header used. | 416 // HTML-based header used. |
| 381 base::string16(), | 417 base::string16(), |
| 382 #endif | 418 #endif |
| 383 this /* ExtensionDialog::Observer */); | 419 this /* ExtensionDialog::Observer */); |
| 384 if (!dialog) { | 420 if (!dialog) { |
| 385 LOG(ERROR) << "Unable to create extension dialog"; | 421 LOG(ERROR) << "Unable to create extension dialog"; |
| 386 return; | 422 return; |
| 387 } | 423 } |
| 388 | 424 |
| 389 // Connect our listener to FileDialogFunction's per-tab callbacks. | 425 // Connect our listener to FileDialogFunction's per-tab callbacks. |
| 390 AddPending(routing_id); | 426 AddPending(routing_id); |
| 391 | 427 |
| 392 extension_dialog_ = dialog; | 428 extension_dialog_ = dialog; |
| 393 params_ = params; | 429 params_ = params; |
| 394 routing_id_ = routing_id; | 430 routing_id_ = routing_id; |
| 395 owner_window_ = owner_window; | 431 owner_window_ = owner_window; |
| 396 } | 432 } |
| OLD | NEW |