| 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 // The file contains the implementation of | 5 // The file contains the implementation of |
| 6 // fileBrowserHandlerInternal.selectFile extension function. | 6 // fileBrowserHandlerInternal.selectFile extension function. |
| 7 // When invoked, the function does the following: | 7 // When invoked, the function does the following: |
| 8 // - Verifies that the extension function was invoked as a result of user | 8 // - Verifies that the extension function was invoked as a result of user |
| 9 // gesture. | 9 // gesture. |
| 10 // - Display 'save as' dialog using FileSelectorImpl which waits for the user | 10 // - Display 'save as' dialog using FileSelectorImpl which waits for the user |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // process ID has to be granted read, write and create permissions for the | 25 // process ID has to be granted read, write and create permissions for the |
| 26 // selected file's full filesystem path (e.g. | 26 // selected file's full filesystem path (e.g. |
| 27 // /home/chronos/user/Downloads/foo) in ChildProcessSecurityPolicy. | 27 // /home/chronos/user/Downloads/foo) in ChildProcessSecurityPolicy. |
| 28 // - After the required file access permissions are granted, result object is | 28 // - After the required file access permissions are granted, result object is |
| 29 // created and returned back. | 29 // created and returned back. |
| 30 | 30 |
| 31 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_handler_a
pi.h" | 31 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_handler_a
pi.h" |
| 32 | 32 |
| 33 #include <stddef.h> | 33 #include <stddef.h> |
| 34 | 34 |
| 35 #include <memory> |
| 36 |
| 35 #include "base/bind.h" | 37 #include "base/bind.h" |
| 36 #include "base/files/file_path.h" | 38 #include "base/files/file_path.h" |
| 37 #include "base/macros.h" | 39 #include "base/macros.h" |
| 38 #include "base/memory/scoped_ptr.h" | |
| 39 #include "base/thread_task_runner_handle.h" | 40 #include "base/thread_task_runner_handle.h" |
| 40 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 41 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
| 41 #include "chrome/browser/ui/browser.h" | 42 #include "chrome/browser/ui/browser.h" |
| 42 #include "chrome/browser/ui/browser_window.h" | 43 #include "chrome/browser/ui/browser_window.h" |
| 43 #include "chrome/browser/ui/chrome_select_file_policy.h" | 44 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 44 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 45 #include "chrome/common/extensions/api/file_browser_handler_internal.h" | 46 #include "chrome/common/extensions/api/file_browser_handler_internal.h" |
| 46 #include "content/public/browser/browser_thread.h" | 47 #include "content/public/browser/browser_thread.h" |
| 47 #include "content/public/browser/child_process_security_policy.h" | 48 #include "content/public/browser/child_process_security_policy.h" |
| 48 #include "content/public/browser/render_frame_host.h" | 49 #include "content/public/browser/render_frame_host.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 bool enable_user_gesture_check) | 284 bool enable_user_gesture_check) |
| 284 : file_selector_factory_(file_selector_factory), | 285 : file_selector_factory_(file_selector_factory), |
| 285 user_gesture_check_enabled_(enable_user_gesture_check) { | 286 user_gesture_check_enabled_(enable_user_gesture_check) { |
| 286 DCHECK(file_selector_factory); | 287 DCHECK(file_selector_factory); |
| 287 } | 288 } |
| 288 | 289 |
| 289 FileBrowserHandlerInternalSelectFileFunction:: | 290 FileBrowserHandlerInternalSelectFileFunction:: |
| 290 ~FileBrowserHandlerInternalSelectFileFunction() {} | 291 ~FileBrowserHandlerInternalSelectFileFunction() {} |
| 291 | 292 |
| 292 bool FileBrowserHandlerInternalSelectFileFunction::RunAsync() { | 293 bool FileBrowserHandlerInternalSelectFileFunction::RunAsync() { |
| 293 scoped_ptr<SelectFile::Params> params(SelectFile::Params::Create(*args_)); | 294 std::unique_ptr<SelectFile::Params> params( |
| 295 SelectFile::Params::Create(*args_)); |
| 294 | 296 |
| 295 base::FilePath suggested_name(params->selection_params.suggested_name); | 297 base::FilePath suggested_name(params->selection_params.suggested_name); |
| 296 std::vector<std::string> allowed_extensions; | 298 std::vector<std::string> allowed_extensions; |
| 297 if (params->selection_params.allowed_file_extensions.get()) | 299 if (params->selection_params.allowed_file_extensions.get()) |
| 298 allowed_extensions = *params->selection_params.allowed_file_extensions; | 300 allowed_extensions = *params->selection_params.allowed_file_extensions; |
| 299 | 301 |
| 300 if (!user_gesture() && user_gesture_check_enabled_) { | 302 if (!user_gesture() && user_gesture_check_enabled_) { |
| 301 SetError(kNoUserGestureError); | 303 SetError(kNoUserGestureError); |
| 302 return false; | 304 return false; |
| 303 } | 305 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 } | 353 } |
| 352 | 354 |
| 353 void FileBrowserHandlerInternalSelectFileFunction::RespondEntryDefinition( | 355 void FileBrowserHandlerInternalSelectFileFunction::RespondEntryDefinition( |
| 354 const EntryDefinition& entry_definition) { | 356 const EntryDefinition& entry_definition) { |
| 355 Respond(entry_definition, true); | 357 Respond(entry_definition, true); |
| 356 } | 358 } |
| 357 | 359 |
| 358 void FileBrowserHandlerInternalSelectFileFunction::Respond( | 360 void FileBrowserHandlerInternalSelectFileFunction::Respond( |
| 359 const EntryDefinition& entry_definition, | 361 const EntryDefinition& entry_definition, |
| 360 bool success) { | 362 bool success) { |
| 361 scoped_ptr<SelectFile::Results::Result> result( | 363 std::unique_ptr<SelectFile::Results::Result> result( |
| 362 new SelectFile::Results::Result()); | 364 new SelectFile::Results::Result()); |
| 363 result->success = success; | 365 result->success = success; |
| 364 | 366 |
| 365 // If the file was selected, add 'entry' object which will be later used to | 367 // If the file was selected, add 'entry' object which will be later used to |
| 366 // create a FileEntry instance for the selected file. | 368 // create a FileEntry instance for the selected file. |
| 367 if (success && entry_definition.error == base::File::FILE_OK) { | 369 if (success && entry_definition.error == base::File::FILE_OK) { |
| 368 result->entry.reset(new FileEntryInfo()); | 370 result->entry.reset(new FileEntryInfo()); |
| 369 // TODO(mtomasz): Make the response fields consistent with other files. | 371 // TODO(mtomasz): Make the response fields consistent with other files. |
| 370 result->entry->file_system_name = entry_definition.file_system_name; | 372 result->entry->file_system_name = entry_definition.file_system_name; |
| 371 result->entry->file_system_root = entry_definition.file_system_root_url; | 373 result->entry->file_system_root = entry_definition.file_system_root_url; |
| 372 result->entry->file_full_path = | 374 result->entry->file_full_path = |
| 373 "/" + entry_definition.full_path.AsUTF8Unsafe(); | 375 "/" + entry_definition.full_path.AsUTF8Unsafe(); |
| 374 result->entry->file_is_directory = entry_definition.is_directory; | 376 result->entry->file_is_directory = entry_definition.is_directory; |
| 375 } | 377 } |
| 376 | 378 |
| 377 results_ = SelectFile::Results::Create(*result); | 379 results_ = SelectFile::Results::Create(*result); |
| 378 SendResponse(true); | 380 SendResponse(true); |
| 379 } | 381 } |
| OLD | NEW |