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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/file_browser_handler_api.cc

Issue 18344013: fileapi: Rename FileSystemMountProvider to FileSystemBackend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 5 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 // 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
11 // feedback. 11 // feedback.
12 // - Once the user selects the file path (or cancels the selection), 12 // - Once the user selects the file path (or cancels the selection),
13 // FileSelectorImpl notifies FileBrowserHandlerInternalSelectFileFunction of 13 // FileSelectorImpl notifies FileBrowserHandlerInternalSelectFileFunction of
14 // the selection result by calling FileHandlerSelectFile::OnFilePathSelected. 14 // the selection result by calling FileHandlerSelectFile::OnFilePathSelected.
15 // - If the selection was canceled, 15 // - If the selection was canceled,
16 // FileBrowserHandlerInternalSelectFileFunction returns reporting failure. 16 // FileBrowserHandlerInternalSelectFileFunction returns reporting failure.
17 // - If the file path was selected, the function opens external file system 17 // - If the file path was selected, the function opens external file system
18 // needed to create FileEntry object for the selected path 18 // needed to create FileEntry object for the selected path
19 // (opening file system will create file system name and root url for the 19 // (opening file system will create file system name and root url for the
20 // caller's external file system). 20 // caller's external file system).
21 // - The function grants permissions needed to read/write/create file under the 21 // - The function grants permissions needed to read/write/create file under the
22 // selected path. To grant permissions to the caller, caller's extension ID 22 // selected path. To grant permissions to the caller, caller's extension ID
23 // has to be allowed to access the files virtual path (e.g. /Downloads/foo) 23 // has to be allowed to access the files virtual path (e.g. /Downloads/foo)
24 // in ExternalFileSystemMountPointProvider. Additionally, the callers render 24 // in ExternalFileSystemBackend. Additionally, the callers render
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 "base/bind.h" 33 #include "base/bind.h"
34 #include "base/files/file_path.h" 34 #include "base/files/file_path.h"
35 #include "base/memory/scoped_ptr.h" 35 #include "base/memory/scoped_ptr.h"
36 #include "base/message_loop/message_loop_proxy.h" 36 #include "base/message_loop/message_loop_proxy.h"
37 #include "base/platform_file.h" 37 #include "base/platform_file.h"
38 #include "chrome/browser/chromeos/extensions/file_manager/file_handler_util.h" 38 #include "chrome/browser/chromeos/extensions/file_manager/file_handler_util.h"
39 #include "chrome/browser/profiles/profile.h" 39 #include "chrome/browser/profiles/profile.h"
40 #include "chrome/browser/ui/browser.h" 40 #include "chrome/browser/ui/browser.h"
41 #include "chrome/browser/ui/browser_window.h" 41 #include "chrome/browser/ui/browser_window.h"
42 #include "chrome/browser/ui/chrome_select_file_policy.h" 42 #include "chrome/browser/ui/chrome_select_file_policy.h"
43 #include "chrome/browser/ui/tabs/tab_strip_model.h" 43 #include "chrome/browser/ui/tabs/tab_strip_model.h"
44 #include "chrome/common/extensions/api/file_browser_handler_internal.h" 44 #include "chrome/common/extensions/api/file_browser_handler_internal.h"
45 #include "content/public/browser/browser_thread.h" 45 #include "content/public/browser/browser_thread.h"
46 #include "content/public/browser/child_process_security_policy.h" 46 #include "content/public/browser/child_process_security_policy.h"
47 #include "content/public/browser/render_process_host.h" 47 #include "content/public/browser/render_process_host.h"
48 #include "content/public/browser/render_view_host.h" 48 #include "content/public/browser/render_view_host.h"
49 #include "content/public/browser/storage_partition.h" 49 #include "content/public/browser/storage_partition.h"
50 #include "ui/shell_dialogs/select_file_dialog.h" 50 #include "ui/shell_dialogs/select_file_dialog.h"
51 #include "webkit/browser/fileapi/file_system_backend.h"
51 #include "webkit/browser/fileapi/file_system_context.h" 52 #include "webkit/browser/fileapi/file_system_context.h"
52 #include "webkit/browser/fileapi/file_system_mount_point_provider.h"
53 53
54 using content::BrowserContext; 54 using content::BrowserContext;
55 using content::BrowserThread; 55 using content::BrowserThread;
56 using extensions::api::file_browser_handler_internal::FileEntryInfo; 56 using extensions::api::file_browser_handler_internal::FileEntryInfo;
57 using file_handler::FileSelector; 57 using file_handler::FileSelector;
58 using file_handler::FileSelectorFactory; 58 using file_handler::FileSelectorFactory;
59 59
60 namespace SelectFile = 60 namespace SelectFile =
61 extensions::api::file_browser_handler_internal::SelectFile; 61 extensions::api::file_browser_handler_internal::SelectFile;
62 62
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 file_system_name_ = file_system_name; 360 file_system_name_ = file_system_name;
361 file_system_root_ = file_system_root; 361 file_system_root_ = file_system_root;
362 362
363 GrantPermissions(); 363 GrantPermissions();
364 364
365 Respond(true); 365 Respond(true);
366 } 366 }
367 367
368 void FileBrowserHandlerInternalSelectFileFunction::GrantPermissions() { 368 void FileBrowserHandlerInternalSelectFileFunction::GrantPermissions() {
369 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); 369 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance();
370 fileapi::ExternalFileSystemMountPointProvider* external_provider = 370 fileapi::ExternalFileSystemBackend* external_backend =
371 BrowserContext::GetStoragePartition(profile_, site_instance)-> 371 BrowserContext::GetStoragePartition(profile_, site_instance)->
372 GetFileSystemContext()->external_provider(); 372 GetFileSystemContext()->external_backend();
373 DCHECK(external_provider); 373 DCHECK(external_backend);
374 374
375 external_provider->GetVirtualPath(full_path_, &virtual_path_); 375 external_backend->GetVirtualPath(full_path_, &virtual_path_);
376 DCHECK(!virtual_path_.empty()); 376 DCHECK(!virtual_path_.empty());
377 377
378 // Grant access to this particular file to target extension. This will 378 // Grant access to this particular file to target extension. This will
379 // ensure that the target extension can access only this FS entry and 379 // ensure that the target extension can access only this FS entry and
380 // prevent from traversing FS hierarchy upward. 380 // prevent from traversing FS hierarchy upward.
381 external_provider->GrantFileAccessToExtension(extension_id(), virtual_path_); 381 external_backend->GrantFileAccessToExtension(extension_id(), virtual_path_);
382 382
383 // Grant access to the selected file to target extensions render view process. 383 // Grant access to the selected file to target extensions render view process.
384 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( 384 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
385 render_view_host()->GetProcess()->GetID(), 385 render_view_host()->GetProcess()->GetID(),
386 full_path_, 386 full_path_,
387 file_handler_util::GetReadWritePermissions()); 387 file_handler_util::GetReadWritePermissions());
388 } 388 }
389 389
390 void FileBrowserHandlerInternalSelectFileFunction::Respond(bool success) { 390 void FileBrowserHandlerInternalSelectFileFunction::Respond(bool success) {
391 scoped_ptr<SelectFile::Results::Result> result( 391 scoped_ptr<SelectFile::Results::Result> result(
392 new SelectFile::Results::Result()); 392 new SelectFile::Results::Result());
393 result->success = success; 393 result->success = success;
394 394
395 // If the file was selected, add 'entry' object which will be later used to 395 // If the file was selected, add 'entry' object which will be later used to
396 // create a FileEntry instance for the selected file. 396 // create a FileEntry instance for the selected file.
397 if (success) { 397 if (success) {
398 result->entry.reset(new FileEntryInfo()); 398 result->entry.reset(new FileEntryInfo());
399 result->entry->file_system_name = file_system_name_; 399 result->entry->file_system_name = file_system_name_;
400 result->entry->file_system_root = file_system_root_.spec(); 400 result->entry->file_system_root = file_system_root_.spec();
401 result->entry->file_full_path = "/" + virtual_path_.AsUTF8Unsafe(); 401 result->entry->file_full_path = "/" + virtual_path_.AsUTF8Unsafe();
402 result->entry->file_is_directory = false; 402 result->entry->file_is_directory = false;
403 } 403 }
404 404
405 results_ = SelectFile::Results::Create(*result); 405 results_ = SelectFile::Results::Create(*result);
406 SendResponse(true); 406 SendResponse(true);
407 } 407 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698