| 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 #include "chrome/browser/devtools/devtools_file_helper.h" | 5 #include "chrome/browser/devtools/devtools_file_helper.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 std::string root_url = fileapi::GetIsolatedFileSystemRootURIString( | 178 std::string root_url = fileapi::GetIsolatedFileSystemRootURIString( |
| 179 origin, | 179 origin, |
| 180 file_system_id, | 180 file_system_id, |
| 181 registered_name); | 181 registered_name); |
| 182 return DevToolsFileHelper::FileSystem(file_system_name, | 182 return DevToolsFileHelper::FileSystem(file_system_name, |
| 183 root_url, | 183 root_url, |
| 184 file_system_path); | 184 file_system_path); |
| 185 } | 185 } |
| 186 | 186 |
| 187 set<std::string> GetAddedFileSystemPaths(Profile* profile) { | 187 set<std::string> GetAddedFileSystemPaths(Profile* profile) { |
| 188 const DictionaryValue* file_systems_paths_value = | 188 const base::DictionaryValue* file_systems_paths_value = |
| 189 profile->GetPrefs()->GetDictionary(prefs::kDevToolsFileSystemPaths); | 189 profile->GetPrefs()->GetDictionary(prefs::kDevToolsFileSystemPaths); |
| 190 set<std::string> result; | 190 set<std::string> result; |
| 191 for (DictionaryValue::Iterator it(*file_systems_paths_value); !it.IsAtEnd(); | 191 for (base::DictionaryValue::Iterator it(*file_systems_paths_value); |
| 192 it.Advance()) { | 192 !it.IsAtEnd(); it.Advance()) { |
| 193 result.insert(it.key()); | 193 result.insert(it.key()); |
| 194 } | 194 } |
| 195 return result; | 195 return result; |
| 196 } | 196 } |
| 197 | 197 |
| 198 } // namespace | 198 } // namespace |
| 199 | 199 |
| 200 DevToolsFileHelper::FileSystem::FileSystem() { | 200 DevToolsFileHelper::FileSystem::FileSystem() { |
| 201 } | 201 } |
| 202 | 202 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 222 const std::string& content, | 222 const std::string& content, |
| 223 bool save_as, | 223 bool save_as, |
| 224 const SaveCallback& saveCallback, | 224 const SaveCallback& saveCallback, |
| 225 const SaveCallback& cancelCallback) { | 225 const SaveCallback& cancelCallback) { |
| 226 PathsMap::iterator it = saved_files_.find(url); | 226 PathsMap::iterator it = saved_files_.find(url); |
| 227 if (it != saved_files_.end() && !save_as) { | 227 if (it != saved_files_.end() && !save_as) { |
| 228 SaveAsFileSelected(url, content, saveCallback, it->second); | 228 SaveAsFileSelected(url, content, saveCallback, it->second); |
| 229 return; | 229 return; |
| 230 } | 230 } |
| 231 | 231 |
| 232 const DictionaryValue* file_map = | 232 const base::DictionaryValue* file_map = |
| 233 profile_->GetPrefs()->GetDictionary(prefs::kDevToolsEditedFiles); | 233 profile_->GetPrefs()->GetDictionary(prefs::kDevToolsEditedFiles); |
| 234 base::FilePath initial_path; | 234 base::FilePath initial_path; |
| 235 | 235 |
| 236 const Value* path_value; | 236 const base::Value* path_value; |
| 237 if (file_map->Get(base::MD5String(url), &path_value)) | 237 if (file_map->Get(base::MD5String(url), &path_value)) |
| 238 base::GetValueAsFilePath(*path_value, &initial_path); | 238 base::GetValueAsFilePath(*path_value, &initial_path); |
| 239 | 239 |
| 240 if (initial_path.empty()) { | 240 if (initial_path.empty()) { |
| 241 GURL gurl(url); | 241 GURL gurl(url); |
| 242 std::string suggested_file_name = gurl.is_valid() ? | 242 std::string suggested_file_name = gurl.is_valid() ? |
| 243 gurl.ExtractFileName() : url; | 243 gurl.ExtractFileName() : url; |
| 244 | 244 |
| 245 if (suggested_file_name.length() > 64) | 245 if (suggested_file_name.length() > 64) |
| 246 suggested_file_name = suggested_file_name.substr(0, 64); | 246 suggested_file_name = suggested_file_name.substr(0, 64); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 282 |
| 283 void DevToolsFileHelper::SaveAsFileSelected(const std::string& url, | 283 void DevToolsFileHelper::SaveAsFileSelected(const std::string& url, |
| 284 const std::string& content, | 284 const std::string& content, |
| 285 const SaveCallback& callback, | 285 const SaveCallback& callback, |
| 286 const base::FilePath& path) { | 286 const base::FilePath& path) { |
| 287 *g_last_save_path.Pointer() = path; | 287 *g_last_save_path.Pointer() = path; |
| 288 saved_files_[url] = path; | 288 saved_files_[url] = path; |
| 289 | 289 |
| 290 DictionaryPrefUpdate update(profile_->GetPrefs(), | 290 DictionaryPrefUpdate update(profile_->GetPrefs(), |
| 291 prefs::kDevToolsEditedFiles); | 291 prefs::kDevToolsEditedFiles); |
| 292 DictionaryValue* files_map = update.Get(); | 292 base::DictionaryValue* files_map = update.Get(); |
| 293 files_map->SetWithoutPathExpansion(base::MD5String(url), | 293 files_map->SetWithoutPathExpansion(base::MD5String(url), |
| 294 base::CreateFilePathValue(path)); | 294 base::CreateFilePathValue(path)); |
| 295 callback.Run(); | 295 callback.Run(); |
| 296 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 296 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 297 Bind(&WriteToFile, path, content)); | 297 Bind(&WriteToFile, path, content)); |
| 298 } | 298 } |
| 299 | 299 |
| 300 void DevToolsFileHelper::SaveAsFileSelectionCanceled( | 300 void DevToolsFileHelper::SaveAsFileSelectionCanceled( |
| 301 const SaveCallback& callback) { | 301 const SaveCallback& callback) { |
| 302 callback.Run(); | 302 callback.Run(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 for (; it != mount_points.end(); ++it) | 336 for (; it != mount_points.end(); ++it) |
| 337 InnerAddFileSystem(callback, show_info_bar_callback, it->path); | 337 InnerAddFileSystem(callback, show_info_bar_callback, it->path); |
| 338 } | 338 } |
| 339 | 339 |
| 340 void DevToolsFileHelper::InnerAddFileSystem( | 340 void DevToolsFileHelper::InnerAddFileSystem( |
| 341 const AddFileSystemCallback& callback, | 341 const AddFileSystemCallback& callback, |
| 342 const ShowInfoBarCallback& show_info_bar_callback, | 342 const ShowInfoBarCallback& show_info_bar_callback, |
| 343 const base::FilePath& path) { | 343 const base::FilePath& path) { |
| 344 std::string file_system_path = path.AsUTF8Unsafe(); | 344 std::string file_system_path = path.AsUTF8Unsafe(); |
| 345 | 345 |
| 346 const DictionaryValue* file_systems_paths_value = | 346 const base::DictionaryValue* file_systems_paths_value = |
| 347 profile_->GetPrefs()->GetDictionary(prefs::kDevToolsFileSystemPaths); | 347 profile_->GetPrefs()->GetDictionary(prefs::kDevToolsFileSystemPaths); |
| 348 if (file_systems_paths_value->HasKey(file_system_path)) { | 348 if (file_systems_paths_value->HasKey(file_system_path)) { |
| 349 callback.Run(FileSystem()); | 349 callback.Run(FileSystem()); |
| 350 return; | 350 return; |
| 351 } | 351 } |
| 352 | 352 |
| 353 std::string path_display_name = path.AsEndingWithSeparator().AsUTF8Unsafe(); | 353 std::string path_display_name = path.AsEndingWithSeparator().AsUTF8Unsafe(); |
| 354 base::string16 message = l10n_util::GetStringFUTF16( | 354 base::string16 message = l10n_util::GetStringFUTF16( |
| 355 IDS_DEV_TOOLS_CONFIRM_ADD_FILE_SYSTEM_MESSAGE, | 355 IDS_DEV_TOOLS_CONFIRM_ADD_FILE_SYSTEM_MESSAGE, |
| 356 UTF8ToUTF16(path_display_name)); | 356 UTF8ToUTF16(path_display_name)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 370 return; | 370 return; |
| 371 } | 371 } |
| 372 std::string registered_name; | 372 std::string registered_name; |
| 373 std::string file_system_id = RegisterFileSystem(web_contents_, | 373 std::string file_system_id = RegisterFileSystem(web_contents_, |
| 374 path, | 374 path, |
| 375 ®istered_name); | 375 ®istered_name); |
| 376 std::string file_system_path = path.AsUTF8Unsafe(); | 376 std::string file_system_path = path.AsUTF8Unsafe(); |
| 377 | 377 |
| 378 DictionaryPrefUpdate update(profile_->GetPrefs(), | 378 DictionaryPrefUpdate update(profile_->GetPrefs(), |
| 379 prefs::kDevToolsFileSystemPaths); | 379 prefs::kDevToolsFileSystemPaths); |
| 380 DictionaryValue* file_systems_paths_value = update.Get(); | 380 base::DictionaryValue* file_systems_paths_value = update.Get(); |
| 381 file_systems_paths_value->SetWithoutPathExpansion(file_system_path, | 381 file_systems_paths_value->SetWithoutPathExpansion( |
| 382 Value::CreateNullValue()); | 382 file_system_path, base::Value::CreateNullValue()); |
| 383 | 383 |
| 384 FileSystem filesystem = CreateFileSystemStruct(web_contents_, | 384 FileSystem filesystem = CreateFileSystemStruct(web_contents_, |
| 385 file_system_id, | 385 file_system_id, |
| 386 registered_name, | 386 registered_name, |
| 387 file_system_path); | 387 file_system_path); |
| 388 callback.Run(filesystem); | 388 callback.Run(filesystem); |
| 389 } | 389 } |
| 390 | 390 |
| 391 void DevToolsFileHelper::RequestFileSystems( | 391 void DevToolsFileHelper::RequestFileSystems( |
| 392 const RequestFileSystemsCallback& callback) { | 392 const RequestFileSystemsCallback& callback) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 410 callback.Run(file_systems); | 410 callback.Run(file_systems); |
| 411 } | 411 } |
| 412 | 412 |
| 413 void DevToolsFileHelper::RemoveFileSystem(const std::string& file_system_path) { | 413 void DevToolsFileHelper::RemoveFileSystem(const std::string& file_system_path) { |
| 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 415 base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path); | 415 base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path); |
| 416 isolated_context()->RevokeFileSystemByPath(path); | 416 isolated_context()->RevokeFileSystemByPath(path); |
| 417 | 417 |
| 418 DictionaryPrefUpdate update(profile_->GetPrefs(), | 418 DictionaryPrefUpdate update(profile_->GetPrefs(), |
| 419 prefs::kDevToolsFileSystemPaths); | 419 prefs::kDevToolsFileSystemPaths); |
| 420 DictionaryValue* file_systems_paths_value = update.Get(); | 420 base::DictionaryValue* file_systems_paths_value = update.Get(); |
| 421 file_systems_paths_value->RemoveWithoutPathExpansion(file_system_path, NULL); | 421 file_systems_paths_value->RemoveWithoutPathExpansion(file_system_path, NULL); |
| 422 } | 422 } |
| 423 | 423 |
| 424 bool DevToolsFileHelper::IsFileSystemAdded( | 424 bool DevToolsFileHelper::IsFileSystemAdded( |
| 425 const std::string& file_system_path) { | 425 const std::string& file_system_path) { |
| 426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 427 set<std::string> file_system_paths = GetAddedFileSystemPaths(profile_); | 427 set<std::string> file_system_paths = GetAddedFileSystemPaths(profile_); |
| 428 return file_system_paths.find(file_system_path) != file_system_paths.end(); | 428 return file_system_paths.find(file_system_path) != file_system_paths.end(); |
| 429 } | 429 } |
| OLD | NEW |