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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 Browser* browser = browser::FindOrCreateTabbedBrowser(profile); | 221 Browser* browser = browser::FindOrCreateTabbedBrowser(profile); |
222 chrome::ShowMessageBox( | 222 chrome::ShowMessageBox( |
223 browser->window()->GetNativeWindow(), | 223 browser->window()->GetNativeWindow(), |
224 l10n_util::GetStringFUTF16( | 224 l10n_util::GetStringFUTF16( |
225 IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE, | 225 IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE, |
226 UTF8ToUTF16(path.BaseName().value())), | 226 UTF8ToUTF16(path.BaseName().value())), |
227 l10n_util::GetStringUTF16(IDS_FILE_BROWSER_ERROR_VIEWING_FILE), | 227 l10n_util::GetStringUTF16(IDS_FILE_BROWSER_ERROR_VIEWING_FILE), |
228 chrome::MESSAGE_BOX_TYPE_WARNING); | 228 chrome::MESSAGE_BOX_TYPE_WARNING); |
229 } | 229 } |
230 | 230 |
231 // Called when a file on GData was found. Opens the file found at |file_path| | 231 // Called when a file on Drive was found. Opens the file found at |file_path| |
232 // in a new tab with a URL computed based on the |file_type| | 232 // in a new tab with a URL computed based on the |file_type| |
233 void OnGDataFileFound(Profile* profile, | 233 void OnGDataFileFound(Profile* profile, |
234 const FilePath& file_path, | 234 const FilePath& file_path, |
235 gdata::DriveFileType file_type, | 235 gdata::DriveFileType file_type, |
236 gdata::DriveFileError error, | 236 gdata::DriveFileError error, |
237 scoped_ptr<gdata::DriveEntryProto> entry_proto) { | 237 scoped_ptr<gdata::DriveEntryProto> entry_proto) { |
238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
239 | 239 |
240 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 240 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
241 error = gdata::DRIVE_FILE_ERROR_NOT_FOUND; | 241 error = gdata::DRIVE_FILE_ERROR_NOT_FOUND; |
242 | 242 |
243 if (error == gdata::DRIVE_FILE_OK) { | 243 if (error == gdata::DRIVE_FILE_OK) { |
244 GURL page_url; | 244 GURL page_url; |
245 if (file_type == gdata::REGULAR_FILE) { | 245 if (file_type == gdata::REGULAR_FILE) { |
246 page_url = gdata::util::GetFileResourceUrl( | 246 page_url = gdata::util::GetFileResourceUrl( |
247 entry_proto->resource_id(), | 247 entry_proto->resource_id(), |
248 entry_proto->base_name()); | 248 entry_proto->base_name()); |
249 } else if (file_type == gdata::HOSTED_DOCUMENT) { | 249 } else if (file_type == gdata::HOSTED_DOCUMENT) { |
250 page_url = GURL(entry_proto->file_specific_info().alternate_url()); | 250 page_url = GURL(entry_proto->file_specific_info().alternate_url()); |
251 } else { | 251 } else { |
252 NOTREACHED(); | 252 NOTREACHED(); |
253 } | 253 } |
254 OpenNewTab(page_url, profile); | 254 OpenNewTab(page_url, profile); |
255 } else { | 255 } else { |
256 ShowWarningMessageBox(profile, file_path); | 256 ShowWarningMessageBox(profile, file_path); |
257 } | 257 } |
258 } | 258 } |
259 | 259 |
260 // Called when a crx file on GData was downloaded. | 260 // Called when a crx file on Drive was downloaded. |
261 void OnCRXDownloadCallback(Browser* browser, | 261 void OnCRXDownloadCallback(Browser* browser, |
262 gdata::DriveFileError error, | 262 gdata::DriveFileError error, |
263 const FilePath& file, | 263 const FilePath& file, |
264 const std::string& unused_mime_type, | 264 const std::string& unused_mime_type, |
265 gdata::DriveFileType file_type) { | 265 gdata::DriveFileType file_type) { |
266 if (error != gdata::DRIVE_FILE_OK || file_type != gdata::REGULAR_FILE) | 266 if (error != gdata::DRIVE_FILE_OK || file_type != gdata::REGULAR_FILE) |
267 return; | 267 return; |
268 InstallCRX(browser, file); | 268 InstallCRX(browser, file); |
269 } | 269 } |
270 | 270 |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 // Override gdata resource to point to internal handler instead of file: | 636 // Override gdata resource to point to internal handler instead of file: |
637 // URL. | 637 // URL. |
638 if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) { | 638 if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) { |
639 gdata::DriveSystemService* system_service = | 639 gdata::DriveSystemService* system_service = |
640 gdata::DriveSystemServiceFactory::GetForProfile(profile); | 640 gdata::DriveSystemServiceFactory::GetForProfile(profile); |
641 if (!system_service) | 641 if (!system_service) |
642 return false; | 642 return false; |
643 | 643 |
644 // Open the file once the file is found. | 644 // Open the file once the file is found. |
645 system_service->file_system()->GetEntryInfoByPath( | 645 system_service->file_system()->GetEntryInfoByPath( |
646 gdata::util::ExtractGDataPath(path), | 646 gdata::util::ExtractDrivePath(path), |
647 base::Bind(&OnGDataFileFound, profile, path, gdata::REGULAR_FILE)); | 647 base::Bind(&OnGDataFileFound, profile, path, gdata::REGULAR_FILE)); |
648 return true; | 648 return true; |
649 } | 649 } |
650 OpenNewTab(page_url, NULL); | 650 OpenNewTab(page_url, NULL); |
651 return true; | 651 return true; |
652 } | 652 } |
653 | 653 |
654 if (IsSupportedGDocsExtension(file_extension.data())) { | 654 if (IsSupportedGDocsExtension(file_extension.data())) { |
655 if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) { | 655 if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) { |
656 // The file is on Google Docs. Get the Docs from the GData service. | 656 // The file is on Google Docs. Get the Docs from the Drive service. |
657 gdata::DriveSystemService* system_service = | 657 gdata::DriveSystemService* system_service = |
658 gdata::DriveSystemServiceFactory::GetForProfile(profile); | 658 gdata::DriveSystemServiceFactory::GetForProfile(profile); |
659 if (!system_service) | 659 if (!system_service) |
660 return false; | 660 return false; |
661 | 661 |
662 system_service->file_system()->GetEntryInfoByPath( | 662 system_service->file_system()->GetEntryInfoByPath( |
663 gdata::util::ExtractGDataPath(path), | 663 gdata::util::ExtractDrivePath(path), |
664 base::Bind(&OnGDataFileFound, profile, path, | 664 base::Bind(&OnGDataFileFound, profile, path, |
665 gdata::HOSTED_DOCUMENT)); | 665 gdata::HOSTED_DOCUMENT)); |
666 } else { | 666 } else { |
667 // The file is local (downloaded from an attachment or otherwise copied). | 667 // The file is local (downloaded from an attachment or otherwise copied). |
668 // Parse the file to extract the Docs url and open this url. | 668 // Parse the file to extract the Docs url and open this url. |
669 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 669 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
670 base::Bind(&ReadUrlFromGDocOnFileThread, path)); | 670 base::Bind(&ReadUrlFromGDocOnFileThread, path)); |
671 } | 671 } |
672 return true; | 672 return true; |
673 } | 673 } |
(...skipping 25 matching lines...) Expand all Loading... |
699 | 699 |
700 application_launch::LaunchParams params(profile, extension, | 700 application_launch::LaunchParams params(profile, extension, |
701 extension_misc::LAUNCH_WINDOW, | 701 extension_misc::LAUNCH_WINDOW, |
702 NEW_FOREGROUND_TAB); | 702 NEW_FOREGROUND_TAB); |
703 params.override_url = GetVideoPlayerUrl(url); | 703 params.override_url = GetVideoPlayerUrl(url); |
704 application_launch::OpenApplication(params); | 704 application_launch::OpenApplication(params); |
705 return true; | 705 return true; |
706 } | 706 } |
707 | 707 |
708 if (IsCRXFile(file_extension.data())) { | 708 if (IsCRXFile(file_extension.data())) { |
709 if (gdata::util::IsUnderGDataMountPoint(path)) { | 709 if (gdata::util::IsUnderDriveMountPoint(path)) { |
710 gdata::DriveSystemService* system_service = | 710 gdata::DriveSystemService* system_service = |
711 gdata::DriveSystemServiceFactory::GetForProfile(profile); | 711 gdata::DriveSystemServiceFactory::GetForProfile(profile); |
712 if (!system_service) | 712 if (!system_service) |
713 return false; | 713 return false; |
714 system_service->file_system()->GetFileByPath( | 714 system_service->file_system()->GetFileByPath( |
715 gdata::util::ExtractGDataPath(path), | 715 gdata::util::ExtractDrivePath(path), |
716 base::Bind(&OnCRXDownloadCallback, browser), | 716 base::Bind(&OnCRXDownloadCallback, browser), |
717 gdata::GetContentCallback()); | 717 gdata::GetContentCallback()); |
718 } else { | 718 } else { |
719 InstallCRX(browser, path); | 719 InstallCRX(browser, path); |
720 } | 720 } |
721 return true; | 721 return true; |
722 } | 722 } |
723 | 723 |
724 // Unknown file type. Record UMA and show an error message. | 724 // Unknown file type. Record UMA and show an error message. |
725 size_t extension_index = UMAExtensionIndex(file_extension.data(), | 725 size_t extension_index = UMAExtensionIndex(file_extension.data(), |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 OperationRegistry::ProgressStatus>::const_iterator iter = | 771 OperationRegistry::ProgressStatus>::const_iterator iter = |
772 list.begin(); | 772 list.begin(); |
773 iter != list.end(); ++iter) { | 773 iter != list.end(); ++iter) { |
774 result_list->Append( | 774 result_list->Append( |
775 ProgessStatusToDictionaryValue(profile, origin_url, *iter)); | 775 ProgessStatusToDictionaryValue(profile, origin_url, *iter)); |
776 } | 776 } |
777 return result_list.release(); | 777 return result_list.release(); |
778 } | 778 } |
779 | 779 |
780 } // namespace file_manager_util | 780 } // namespace file_manager_util |
OLD | NEW |