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

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

Issue 144783002: Simplify directory initialization in Files app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months 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) 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.";
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;
349
350 base::FilePath fallback_path = !profile_->last_selected_directory().empty() ?
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;
353 if (default_dialog_path.IsAbsolute() && 356 if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
354 (file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath( 357 profile_,
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.
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);
375
376 if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
377 profile_,
378 kFileManagerAppId,
379 current_directory_path,
380 &current_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 &current_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;
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698