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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "chrome/browser/ui/browser.h" | 47 #include "chrome/browser/ui/browser.h" |
48 #include "chrome/browser/ui/browser_tabstrip.h" | 48 #include "chrome/browser/ui/browser_tabstrip.h" |
49 #include "chrome/browser/ui/browser_window.h" | 49 #include "chrome/browser/ui/browser_window.h" |
50 #include "chrome/browser/ui/chrome_select_file_policy.h" | 50 #include "chrome/browser/ui/chrome_select_file_policy.h" |
51 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 51 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
52 #include "chrome/common/extensions/api/file_browser_handler_internal.h" | 52 #include "chrome/common/extensions/api/file_browser_handler_internal.h" |
53 #include "content/public/browser/browser_thread.h" | 53 #include "content/public/browser/browser_thread.h" |
54 #include "content/public/browser/child_process_security_policy.h" | 54 #include "content/public/browser/child_process_security_policy.h" |
55 #include "content/public/browser/render_process_host.h" | 55 #include "content/public/browser/render_process_host.h" |
56 #include "content/public/browser/render_view_host.h" | 56 #include "content/public/browser/render_view_host.h" |
| 57 #include "content/public/browser/storage_partition.h" |
57 #include "googleurl/src/gurl.h" | 58 #include "googleurl/src/gurl.h" |
58 #include "webkit/fileapi/file_system_context.h" | 59 #include "webkit/fileapi/file_system_context.h" |
59 #include "webkit/fileapi/file_system_mount_point_provider.h" | 60 #include "webkit/fileapi/file_system_mount_point_provider.h" |
60 #include "ui/base/dialogs/select_file_dialog.h" | 61 #include "ui/base/dialogs/select_file_dialog.h" |
61 | 62 |
62 using content::BrowserContext; | 63 using content::BrowserContext; |
63 using content::BrowserThread; | 64 using content::BrowserThread; |
64 using extensions::api::file_browser_handler_internal::FileEntryInfo; | 65 using extensions::api::file_browser_handler_internal::FileEntryInfo; |
65 using file_handler::FileSelector; | 66 using file_handler::FileSelector; |
66 using file_handler::FileSelectorFactory; | 67 using file_handler::FileSelectorFactory; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 const FilePath& full_path) { | 329 const FilePath& full_path) { |
329 if (!success) { | 330 if (!success) { |
330 Respond(false); | 331 Respond(false); |
331 return; | 332 return; |
332 } | 333 } |
333 | 334 |
334 full_path_ = full_path; | 335 full_path_ = full_path; |
335 | 336 |
336 // We have to open file system in order to create a FileEntry object for the | 337 // We have to open file system in order to create a FileEntry object for the |
337 // selected file path. | 338 // selected file path. |
338 BrowserContext::GetFileSystemContext(profile_)->OpenFileSystem( | 339 BrowserContext::GetDefaultStoragePartition(profile_)-> |
339 source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false, | 340 GetFileSystemContext()->OpenFileSystem( |
340 base::Bind(&RunOpenFileSystemCallback, | 341 source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false, |
341 base::Bind(&FileHandlerSelectFileFunction::OnFileSystemOpened, | 342 base::Bind( |
342 this))); | 343 &RunOpenFileSystemCallback, |
| 344 base::Bind(&FileHandlerSelectFileFunction::OnFileSystemOpened, |
| 345 this))); |
343 }; | 346 }; |
344 | 347 |
345 void FileHandlerSelectFileFunction::OnFileSystemOpened( | 348 void FileHandlerSelectFileFunction::OnFileSystemOpened( |
346 bool success, | 349 bool success, |
347 const std::string& file_system_name, | 350 const std::string& file_system_name, |
348 const GURL& file_system_root) { | 351 const GURL& file_system_root) { |
349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
350 | 353 |
351 if (!success) { | 354 if (!success) { |
352 Respond(false); | 355 Respond(false); |
353 return; | 356 return; |
354 } | 357 } |
355 | 358 |
356 // Remember opened file system's parameters. | 359 // Remember opened file system's parameters. |
357 file_system_name_ = file_system_name; | 360 file_system_name_ = file_system_name; |
358 file_system_root_ = file_system_root; | 361 file_system_root_ = file_system_root; |
359 | 362 |
360 GrantPermissions(); | 363 GrantPermissions(); |
361 } | 364 } |
362 | 365 |
363 void FileHandlerSelectFileFunction::GrantPermissions() { | 366 void FileHandlerSelectFileFunction::GrantPermissions() { |
364 fileapi::ExternalFileSystemMountPointProvider* external_provider = | 367 fileapi::ExternalFileSystemMountPointProvider* external_provider = |
365 BrowserContext::GetFileSystemContext(profile_)->external_provider(); | 368 BrowserContext::GetDefaultStoragePartition(profile_)-> |
| 369 GetFileSystemContext()->external_provider(); |
366 DCHECK(external_provider); | 370 DCHECK(external_provider); |
367 | 371 |
368 external_provider->GetVirtualPath(full_path_, &virtual_path_); | 372 external_provider->GetVirtualPath(full_path_, &virtual_path_); |
369 DCHECK(!virtual_path_.empty()); | 373 DCHECK(!virtual_path_.empty()); |
370 | 374 |
371 // Grant access to this particular file to target extension. This will | 375 // Grant access to this particular file to target extension. This will |
372 // ensure that the target extension can access only this FS entry and | 376 // ensure that the target extension can access only this FS entry and |
373 // prevent from traversing FS hierarchy upward. | 377 // prevent from traversing FS hierarchy upward. |
374 external_provider->GrantFileAccessToExtension(extension_id(), virtual_path_); | 378 external_provider->GrantFileAccessToExtension(extension_id(), virtual_path_); |
375 | 379 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 result->entry.reset(new FileEntryInfo()); | 427 result->entry.reset(new FileEntryInfo()); |
424 result->entry->file_system_name = file_system_name_; | 428 result->entry->file_system_name = file_system_name_; |
425 result->entry->file_system_root = file_system_root_.spec(); | 429 result->entry->file_system_root = file_system_root_.spec(); |
426 result->entry->file_full_path = "/" + virtual_path_.value(); | 430 result->entry->file_full_path = "/" + virtual_path_.value(); |
427 result->entry->file_is_directory = false; | 431 result->entry->file_is_directory = false; |
428 } | 432 } |
429 | 433 |
430 results_ = SelectFile::Results::Create(*result); | 434 results_ = SelectFile::Results::Create(*result); |
431 SendResponse(true); | 435 SendResponse(true); |
432 } | 436 } |
OLD | NEW |