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 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 4 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
5 | 5 |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 return type_str; | 181 return type_str; |
182 } | 182 } |
183 | 183 |
184 DictionaryValue* ProgessStatusToDictionaryValue( | 184 DictionaryValue* ProgessStatusToDictionaryValue( |
185 Profile* profile, | 185 Profile* profile, |
186 const GURL& origin_url, | 186 const GURL& origin_url, |
187 const gdata::OperationProgressStatus& status) { | 187 const gdata::OperationProgressStatus& status) { |
188 scoped_ptr<DictionaryValue> result(new DictionaryValue()); | 188 scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
189 GURL file_url; | 189 GURL file_url; |
190 if (file_manager_util::ConvertFileToFileSystemUrl(profile, | 190 if (file_manager_util::ConvertFileToFileSystemUrl(profile, |
191 gdata::util::GetSpecialRemoteRootPath().Append( | 191 drive::util::GetSpecialRemoteRootPath().Append( |
192 FilePath(status.file_path)), | 192 FilePath(status.file_path)), |
193 origin_url, | 193 origin_url, |
194 &file_url)) { | 194 &file_url)) { |
195 result->SetString("fileUrl", file_url.spec()); | 195 result->SetString("fileUrl", file_url.spec()); |
196 } | 196 } |
197 | 197 |
198 result->SetString("transferState", | 198 result->SetString("transferState", |
199 OperationTransferStateToString(status.transfer_state)); | 199 OperationTransferStateToString(status.transfer_state)); |
200 result->SetString("transferType", | 200 result->SetString("transferType", |
201 OperationTypeToString(status.operation_type)); | 201 OperationTypeToString(status.operation_type)); |
(...skipping 26 matching lines...) Expand all Loading... |
228 IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE, | 228 IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE, |
229 UTF8ToUTF16(path.BaseName().value())), | 229 UTF8ToUTF16(path.BaseName().value())), |
230 l10n_util::GetStringUTF16(IDS_FILE_BROWSER_ERROR_VIEWING_FILE), | 230 l10n_util::GetStringUTF16(IDS_FILE_BROWSER_ERROR_VIEWING_FILE), |
231 chrome::MESSAGE_BOX_TYPE_WARNING); | 231 chrome::MESSAGE_BOX_TYPE_WARNING); |
232 } | 232 } |
233 | 233 |
234 // Called when a file on Drive was found. Opens the file found at |file_path| | 234 // Called when a file on Drive was found. Opens the file found at |file_path| |
235 // in a new tab with a URL computed based on the |file_type| | 235 // in a new tab with a URL computed based on the |file_type| |
236 void OnDriveFileFound(Profile* profile, | 236 void OnDriveFileFound(Profile* profile, |
237 const FilePath& file_path, | 237 const FilePath& file_path, |
238 gdata::DriveFileType file_type, | 238 drive::DriveFileType file_type, |
239 gdata::DriveFileError error, | 239 drive::DriveFileError error, |
240 scoped_ptr<gdata::DriveEntryProto> entry_proto) { | 240 scoped_ptr<drive::DriveEntryProto> entry_proto) { |
241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
242 | 242 |
243 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 243 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
244 error = gdata::DRIVE_FILE_ERROR_NOT_FOUND; | 244 error = drive::DRIVE_FILE_ERROR_NOT_FOUND; |
245 | 245 |
246 if (error == gdata::DRIVE_FILE_OK) { | 246 if (error == drive::DRIVE_FILE_OK) { |
247 GURL page_url; | 247 GURL page_url; |
248 if (file_type == gdata::REGULAR_FILE) { | 248 if (file_type == drive::REGULAR_FILE) { |
249 page_url = gdata::util::GetFileResourceUrl( | 249 page_url = drive::util::GetFileResourceUrl( |
250 entry_proto->resource_id(), | 250 entry_proto->resource_id(), |
251 entry_proto->base_name()); | 251 entry_proto->base_name()); |
252 } else if (file_type == gdata::HOSTED_DOCUMENT) { | 252 } else if (file_type == drive::HOSTED_DOCUMENT) { |
253 page_url = GURL(entry_proto->file_specific_info().alternate_url()); | 253 page_url = GURL(entry_proto->file_specific_info().alternate_url()); |
254 } else { | 254 } else { |
255 NOTREACHED(); | 255 NOTREACHED(); |
256 } | 256 } |
257 OpenNewTab(page_url, profile); | 257 OpenNewTab(page_url, profile); |
258 } else { | 258 } else { |
259 ShowWarningMessageBox(profile, file_path); | 259 ShowWarningMessageBox(profile, file_path); |
260 } | 260 } |
261 } | 261 } |
262 | 262 |
263 // Called when a crx file on Drive was downloaded. | 263 // Called when a crx file on Drive was downloaded. |
264 void OnCRXDownloadCallback(Browser* browser, | 264 void OnCRXDownloadCallback(Browser* browser, |
265 gdata::DriveFileError error, | 265 drive::DriveFileError error, |
266 const FilePath& file, | 266 const FilePath& file, |
267 const std::string& unused_mime_type, | 267 const std::string& unused_mime_type, |
268 gdata::DriveFileType file_type) { | 268 drive::DriveFileType file_type) { |
269 if (error != gdata::DRIVE_FILE_OK || file_type != gdata::REGULAR_FILE) | 269 if (error != drive::DRIVE_FILE_OK || file_type != drive::REGULAR_FILE) |
270 return; | 270 return; |
271 InstallCRX(browser, file); | 271 InstallCRX(browser, file); |
272 } | 272 } |
273 | 273 |
274 } // namespace | 274 } // namespace |
275 | 275 |
276 GURL GetFileBrowserExtensionUrl() { | 276 GURL GetFileBrowserExtensionUrl() { |
277 return GURL(kFileBrowserExtensionUrl); | 277 return GURL(kFileBrowserExtensionUrl); |
278 } | 278 } |
279 | 279 |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 | 667 |
668 Profile* profile = browser->profile(); | 668 Profile* profile = browser->profile(); |
669 std::string file_extension = path.Extension(); | 669 std::string file_extension = path.Extension(); |
670 // For things supported natively by the browser, we should open it | 670 // For things supported natively by the browser, we should open it |
671 // in a tab. | 671 // in a tab. |
672 if (IsSupportedBrowserExtension(file_extension.data()) || | 672 if (IsSupportedBrowserExtension(file_extension.data()) || |
673 ShouldBeOpenedWithPdfPlugin(profile, file_extension.data())) { | 673 ShouldBeOpenedWithPdfPlugin(profile, file_extension.data())) { |
674 GURL page_url = net::FilePathToFileURL(path); | 674 GURL page_url = net::FilePathToFileURL(path); |
675 // Override gdata resource to point to internal handler instead of file: | 675 // Override gdata resource to point to internal handler instead of file: |
676 // URL. | 676 // URL. |
677 if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) { | 677 if (drive::util::GetSpecialRemoteRootPath().IsParent(path)) { |
678 gdata::DriveSystemService* system_service = | 678 drive::DriveSystemService* system_service = |
679 gdata::DriveSystemServiceFactory::GetForProfile(profile); | 679 drive::DriveSystemServiceFactory::GetForProfile(profile); |
680 if (!system_service) | 680 if (!system_service) |
681 return false; | 681 return false; |
682 | 682 |
683 // Open the file once the file is found. | 683 // Open the file once the file is found. |
684 system_service->file_system()->GetEntryInfoByPath( | 684 system_service->file_system()->GetEntryInfoByPath( |
685 gdata::util::ExtractDrivePath(path), | 685 drive::util::ExtractDrivePath(path), |
686 base::Bind(&OnDriveFileFound, profile, path, gdata::REGULAR_FILE)); | 686 base::Bind(&OnDriveFileFound, profile, path, drive::REGULAR_FILE)); |
687 return true; | 687 return true; |
688 } | 688 } |
689 OpenNewTab(page_url, NULL); | 689 OpenNewTab(page_url, NULL); |
690 return true; | 690 return true; |
691 } | 691 } |
692 | 692 |
693 if (IsSupportedGDocsExtension(file_extension.data())) { | 693 if (IsSupportedGDocsExtension(file_extension.data())) { |
694 if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) { | 694 if (drive::util::GetSpecialRemoteRootPath().IsParent(path)) { |
695 // The file is on Google Docs. Get the Docs from the Drive service. | 695 // The file is on Google Docs. Get the Docs from the Drive service. |
696 gdata::DriveSystemService* system_service = | 696 drive::DriveSystemService* system_service = |
697 gdata::DriveSystemServiceFactory::GetForProfile(profile); | 697 drive::DriveSystemServiceFactory::GetForProfile(profile); |
698 if (!system_service) | 698 if (!system_service) |
699 return false; | 699 return false; |
700 | 700 |
701 system_service->file_system()->GetEntryInfoByPath( | 701 system_service->file_system()->GetEntryInfoByPath( |
702 gdata::util::ExtractDrivePath(path), | 702 drive::util::ExtractDrivePath(path), |
703 base::Bind(&OnDriveFileFound, profile, path, | 703 base::Bind(&OnDriveFileFound, profile, path, |
704 gdata::HOSTED_DOCUMENT)); | 704 drive::HOSTED_DOCUMENT)); |
705 } else { | 705 } else { |
706 // The file is local (downloaded from an attachment or otherwise copied). | 706 // The file is local (downloaded from an attachment or otherwise copied). |
707 // Parse the file to extract the Docs url and open this url. | 707 // Parse the file to extract the Docs url and open this url. |
708 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 708 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
709 base::Bind(&ReadUrlFromGDocOnFileThread, path)); | 709 base::Bind(&ReadUrlFromGDocOnFileThread, path)); |
710 } | 710 } |
711 return true; | 711 return true; |
712 } | 712 } |
713 | 713 |
714 if (internal_task_id == kFileBrowserPlayTaskId) { | 714 if (internal_task_id == kFileBrowserPlayTaskId) { |
(...skipping 23 matching lines...) Expand all Loading... |
738 | 738 |
739 application_launch::LaunchParams params(profile, extension, | 739 application_launch::LaunchParams params(profile, extension, |
740 extension_misc::LAUNCH_WINDOW, | 740 extension_misc::LAUNCH_WINDOW, |
741 NEW_FOREGROUND_TAB); | 741 NEW_FOREGROUND_TAB); |
742 params.override_url = GetVideoPlayerUrl(url); | 742 params.override_url = GetVideoPlayerUrl(url); |
743 application_launch::OpenApplication(params); | 743 application_launch::OpenApplication(params); |
744 return true; | 744 return true; |
745 } | 745 } |
746 | 746 |
747 if (IsCRXFile(file_extension.data())) { | 747 if (IsCRXFile(file_extension.data())) { |
748 if (gdata::util::IsUnderDriveMountPoint(path)) { | 748 if (drive::util::IsUnderDriveMountPoint(path)) { |
749 gdata::DriveSystemService* system_service = | 749 drive::DriveSystemService* system_service = |
750 gdata::DriveSystemServiceFactory::GetForProfile(profile); | 750 drive::DriveSystemServiceFactory::GetForProfile(profile); |
751 if (!system_service) | 751 if (!system_service) |
752 return false; | 752 return false; |
753 system_service->file_system()->GetFileByPath( | 753 system_service->file_system()->GetFileByPath( |
754 gdata::util::ExtractDrivePath(path), | 754 drive::util::ExtractDrivePath(path), |
755 base::Bind(&OnCRXDownloadCallback, browser), | 755 base::Bind(&OnCRXDownloadCallback, browser), |
756 gdata::GetContentCallback()); | 756 gdata::GetContentCallback()); |
757 } else { | 757 } else { |
758 InstallCRX(browser, path); | 758 InstallCRX(browser, path); |
759 } | 759 } |
760 return true; | 760 return true; |
761 } | 761 } |
762 | 762 |
763 // Unknown file type. Record UMA and show an error message. | 763 // Unknown file type. Record UMA and show an error message. |
764 size_t extension_index = UMAExtensionIndex(file_extension.data(), | 764 size_t extension_index = UMAExtensionIndex(file_extension.data(), |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 scoped_ptr<ListValue> result_list(new ListValue()); | 810 scoped_ptr<ListValue> result_list(new ListValue()); |
811 for (gdata::OperationProgressStatusList::const_iterator iter = list.begin(); | 811 for (gdata::OperationProgressStatusList::const_iterator iter = list.begin(); |
812 iter != list.end(); ++iter) { | 812 iter != list.end(); ++iter) { |
813 result_list->Append( | 813 result_list->Append( |
814 ProgessStatusToDictionaryValue(profile, origin_url, *iter)); | 814 ProgessStatusToDictionaryValue(profile, origin_url, *iter)); |
815 } | 815 } |
816 return result_list.release(); | 816 return result_list.release(); |
817 } | 817 } |
818 | 818 |
819 } // namespace file_manager_util | 819 } // namespace file_manager_util |
OLD | NEW |