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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 const FilePath& full_path) { | 287 const FilePath& full_path) { |
287 if (!success) { | 288 if (!success) { |
288 Respond(false); | 289 Respond(false); |
289 return; | 290 return; |
290 } | 291 } |
291 | 292 |
292 full_path_ = full_path; | 293 full_path_ = full_path; |
293 | 294 |
294 // We have to open file system in order to create a FileEntry object for the | 295 // We have to open file system in order to create a FileEntry object for the |
295 // selected file path. | 296 // selected file path. |
296 BrowserContext::GetFileSystemContext(profile_)->OpenFileSystem( | 297 BrowserContext::GetDefaultStoragePartition(profile_)-> |
297 source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false, | 298 GetFileSystemContext()->OpenFileSystem( |
298 base::Bind(&RunOpenFileSystemCallback, | 299 source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false, |
299 base::Bind(&FileHandlerSelectFileFunction::OnFileSystemOpened, | 300 base::Bind( |
300 this))); | 301 &RunOpenFileSystemCallback, |
| 302 base::Bind(&FileHandlerSelectFileFunction::OnFileSystemOpened, |
| 303 this))); |
301 }; | 304 }; |
302 | 305 |
303 void FileHandlerSelectFileFunction::OnFileSystemOpened( | 306 void FileHandlerSelectFileFunction::OnFileSystemOpened( |
304 bool success, | 307 bool success, |
305 const std::string& file_system_name, | 308 const std::string& file_system_name, |
306 const GURL& file_system_root) { | 309 const GURL& file_system_root) { |
307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
308 | 311 |
309 if (!success) { | 312 if (!success) { |
310 Respond(false); | 313 Respond(false); |
311 return; | 314 return; |
312 } | 315 } |
313 | 316 |
314 // Remember opened file system's parameters. | 317 // Remember opened file system's parameters. |
315 file_system_name_ = file_system_name; | 318 file_system_name_ = file_system_name; |
316 file_system_root_ = file_system_root; | 319 file_system_root_ = file_system_root; |
317 | 320 |
318 GrantPermissions(); | 321 GrantPermissions(); |
319 } | 322 } |
320 | 323 |
321 void FileHandlerSelectFileFunction::GrantPermissions() { | 324 void FileHandlerSelectFileFunction::GrantPermissions() { |
322 fileapi::ExternalFileSystemMountPointProvider* external_provider = | 325 fileapi::ExternalFileSystemMountPointProvider* external_provider = |
323 BrowserContext::GetFileSystemContext(profile_)->external_provider(); | 326 BrowserContext::GetDefaultStoragePartition(profile_)-> |
| 327 GetFileSystemContext()->external_provider(); |
324 DCHECK(external_provider); | 328 DCHECK(external_provider); |
325 | 329 |
326 external_provider->GetVirtualPath(full_path_, &virtual_path_); | 330 external_provider->GetVirtualPath(full_path_, &virtual_path_); |
327 DCHECK(!virtual_path_.empty()); | 331 DCHECK(!virtual_path_.empty()); |
328 | 332 |
329 // Grant access to this particular file to target extension. This will | 333 // Grant access to this particular file to target extension. This will |
330 // ensure that the target extension can access only this FS entry and | 334 // ensure that the target extension can access only this FS entry and |
331 // prevent from traversing FS hierarchy upward. | 335 // prevent from traversing FS hierarchy upward. |
332 external_provider->GrantFileAccessToExtension(extension_id(), virtual_path_); | 336 external_provider->GrantFileAccessToExtension(extension_id(), virtual_path_); |
333 | 337 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 result->entry.reset(new FileEntryInfo()); | 385 result->entry.reset(new FileEntryInfo()); |
382 result->entry->file_system_name = file_system_name_; | 386 result->entry->file_system_name = file_system_name_; |
383 result->entry->file_system_root = file_system_root_.spec(); | 387 result->entry->file_system_root = file_system_root_.spec(); |
384 result->entry->file_full_path = "/" + virtual_path_.value(); | 388 result->entry->file_full_path = "/" + virtual_path_.value(); |
385 result->entry->file_is_directory = false; | 389 result->entry->file_is_directory = false; |
386 } | 390 } |
387 | 391 |
388 results_ = SelectFile::Results::Create(*result); | 392 results_ = SelectFile::Results::Create(*result); |
389 SendResponse(true); | 393 SendResponse(true); |
390 } | 394 } |
OLD | NEW |