OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_file_browser_private_api.h" | 5 #include "chrome/browser/extensions/extension_file_browser_private_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/task.h" | 9 #include "base/task.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
13 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
14 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" |
| 15 #include "googleurl/src/gurl.h" |
15 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
16 #include "webkit/fileapi/file_system_context.h" | 17 #include "webkit/fileapi/file_system_context.h" |
17 #include "webkit/fileapi/file_system_operation.h" | 18 #include "webkit/fileapi/file_system_operation.h" |
18 #include "webkit/fileapi/file_system_path_manager.h" | 19 #include "webkit/fileapi/file_system_path_manager.h" |
19 #include "webkit/fileapi/file_system_types.h" | 20 #include "webkit/fileapi/file_system_types.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 | 22 |
22 | 23 |
23 class LocalFileSystemCallbackDispatcher | 24 class LocalFileSystemCallbackDispatcher |
24 : public fileapi::FileSystemCallbackDispatcher { | 25 : public fileapi::FileSystemCallbackDispatcher { |
(...skipping 12 matching lines...) Expand all Loading... |
37 } | 38 } |
38 virtual void DidReadDirectory( | 39 virtual void DidReadDirectory( |
39 const std::vector<base::FileUtilProxy::Entry>& entries, | 40 const std::vector<base::FileUtilProxy::Entry>& entries, |
40 bool has_more) OVERRIDE { | 41 bool has_more) OVERRIDE { |
41 NOTREACHED(); | 42 NOTREACHED(); |
42 } | 43 } |
43 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE { | 44 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE { |
44 NOTREACHED(); | 45 NOTREACHED(); |
45 } | 46 } |
46 virtual void DidOpenFileSystem(const std::string& name, | 47 virtual void DidOpenFileSystem(const std::string& name, |
47 const FilePath& path) OVERRIDE { | 48 const GURL& root) OVERRIDE { |
48 BrowserThread::PostTask( | 49 BrowserThread::PostTask( |
49 BrowserThread::UI, FROM_HERE, | 50 BrowserThread::UI, FROM_HERE, |
50 NewRunnableMethod(function_, | 51 NewRunnableMethod(function_, |
51 &RequestLocalFileSystemFunction::RespondSuccessOnUIThread, | 52 &RequestLocalFileSystemFunction::RespondSuccessOnUIThread, |
52 name, | 53 name, |
53 path)); | 54 root)); |
54 } | 55 } |
55 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { | 56 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { |
56 BrowserThread::PostTask( | 57 BrowserThread::PostTask( |
57 BrowserThread::UI, FROM_HERE, | 58 BrowserThread::UI, FROM_HERE, |
58 NewRunnableMethod(function_, | 59 NewRunnableMethod(function_, |
59 &RequestLocalFileSystemFunction::RespondFailedOnUIThread, | 60 &RequestLocalFileSystemFunction::RespondFailedOnUIThread, |
60 error_code)); | 61 error_code)); |
61 } | 62 } |
62 private: | 63 private: |
63 RequestLocalFileSystemFunction* function_; | 64 RequestLocalFileSystemFunction* function_; |
(...skipping 14 matching lines...) Expand all Loading... |
78 profile()->GetFileSystemContext(), | 79 profile()->GetFileSystemContext(), |
79 NULL); | 80 NULL); |
80 GURL origin_url = source_url().GetOrigin(); | 81 GURL origin_url = source_url().GetOrigin(); |
81 operation->OpenFileSystem(origin_url, fileapi::kFileSystemTypeLocal, | 82 operation->OpenFileSystem(origin_url, fileapi::kFileSystemTypeLocal, |
82 false); // create | 83 false); // create |
83 // Will finish asynchronously. | 84 // Will finish asynchronously. |
84 return true; | 85 return true; |
85 } | 86 } |
86 | 87 |
87 void RequestLocalFileSystemFunction::RespondSuccessOnUIThread( | 88 void RequestLocalFileSystemFunction::RespondSuccessOnUIThread( |
88 const std::string& name, const FilePath& path) { | 89 const std::string& name, const GURL& root) { |
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
90 result_.reset(new DictionaryValue()); | 91 result_.reset(new DictionaryValue()); |
91 DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get()); | 92 DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get()); |
92 dict->SetString("name", name); | 93 dict->SetString("name", name); |
93 dict->SetString("path", path.value()); | 94 dict->SetString("path", root.spec()); |
94 dict->SetInteger("error", base::PLATFORM_FILE_OK); | 95 dict->SetInteger("error", base::PLATFORM_FILE_OK); |
95 SendResponse(true); | 96 SendResponse(true); |
96 } | 97 } |
97 | 98 |
98 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( | 99 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( |
99 base::PlatformFileError error_code) { | 100 base::PlatformFileError error_code) { |
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
101 result_.reset(new DictionaryValue()); | 102 result_.reset(new DictionaryValue()); |
102 DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get()); | 103 DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get()); |
103 dict->SetInteger("error", static_cast<int>(error_code)); | 104 dict->SetInteger("error", static_cast<int>(error_code)); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 SET_STRING(IDS_FILE_BROWSER, COMPUTING_SELECTION); | 292 SET_STRING(IDS_FILE_BROWSER, COMPUTING_SELECTION); |
292 SET_STRING(IDS_FILE_BROWSER, NOTHING_SELECTED); | 293 SET_STRING(IDS_FILE_BROWSER, NOTHING_SELECTED); |
293 SET_STRING(IDS_FILE_BROWSER, ONE_FILE_SELECTED); | 294 SET_STRING(IDS_FILE_BROWSER, ONE_FILE_SELECTED); |
294 SET_STRING(IDS_FILE_BROWSER, MANY_FILES_SELECTED); | 295 SET_STRING(IDS_FILE_BROWSER, MANY_FILES_SELECTED); |
295 | 296 |
296 #undef SET_STRING | 297 #undef SET_STRING |
297 | 298 |
298 SendResponse(true); | 299 SendResponse(true); |
299 return true; | 300 return true; |
300 } | 301 } |
OLD | NEW |