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/bookmarks/bookmark_extension_api.h" | 5 #include "chrome/browser/bookmarks/bookmark_extension_api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/i18n/file_util_icu.h" | 9 #include "base/i18n/file_util_icu.h" |
10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 | 841 |
842 BookmarksIOFunction::BookmarksIOFunction() {} | 842 BookmarksIOFunction::BookmarksIOFunction() {} |
843 | 843 |
844 BookmarksIOFunction::~BookmarksIOFunction() { | 844 BookmarksIOFunction::~BookmarksIOFunction() { |
845 // There may be pending file dialogs, we need to tell them that we've gone | 845 // There may be pending file dialogs, we need to tell them that we've gone |
846 // away so they don't try and call back to us. | 846 // away so they don't try and call back to us. |
847 if (select_file_dialog_.get()) | 847 if (select_file_dialog_.get()) |
848 select_file_dialog_->ListenerDestroyed(); | 848 select_file_dialog_->ListenerDestroyed(); |
849 } | 849 } |
850 | 850 |
851 void BookmarksIOFunction::SelectFile(SelectFileDialog::Type type) { | 851 void BookmarksIOFunction::SelectFile(ui::SelectFileDialog::Type type) { |
852 // GetDefaultFilepathForBookmarkExport() might have to touch the filesystem | 852 // GetDefaultFilepathForBookmarkExport() might have to touch the filesystem |
853 // (stat or access, for example), so this requires a thread with IO allowed. | 853 // (stat or access, for example), so this requires a thread with IO allowed. |
854 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | 854 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
855 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 855 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
856 base::Bind(&BookmarksIOFunction::SelectFile, this, type)); | 856 base::Bind(&BookmarksIOFunction::SelectFile, this, type)); |
857 return; | 857 return; |
858 } | 858 } |
859 | 859 |
860 // Pre-populating the filename field in case this is a SELECT_SAVEAS_FILE | 860 // Pre-populating the filename field in case this is a SELECT_SAVEAS_FILE |
861 // dialog. If not, there is no filename field in the dialog box. | 861 // dialog. If not, there is no filename field in the dialog box. |
862 FilePath default_path; | 862 FilePath default_path; |
863 if (type == SelectFileDialog::SELECT_SAVEAS_FILE) | 863 if (type == ui::SelectFileDialog::SELECT_SAVEAS_FILE) |
864 default_path = GetDefaultFilepathForBookmarkExport(); | 864 default_path = GetDefaultFilepathForBookmarkExport(); |
865 else | 865 else |
866 DCHECK(type == SelectFileDialog::SELECT_OPEN_FILE); | 866 DCHECK(type == ui::SelectFileDialog::SELECT_OPEN_FILE); |
867 | 867 |
868 // After getting the |default_path|, ask the UI to display the file dialog. | 868 // After getting the |default_path|, ask the UI to display the file dialog. |
869 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 869 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
870 base::Bind(&BookmarksIOFunction::ShowSelectFileDialog, this, | 870 base::Bind(&BookmarksIOFunction::ShowSelectFileDialog, this, |
871 type, default_path)); | 871 type, default_path)); |
872 } | 872 } |
873 | 873 |
874 void BookmarksIOFunction::ShowSelectFileDialog(SelectFileDialog::Type type, | 874 void BookmarksIOFunction::ShowSelectFileDialog(ui::SelectFileDialog::Type type, |
875 const FilePath& default_path) { | 875 const FilePath& default_path) { |
876 // Balanced in one of the three callbacks of SelectFileDialog: | 876 // Balanced in one of the three callbacks of SelectFileDialog: |
877 // either FileSelectionCanceled, MultiFilesSelected, or FileSelected | 877 // either FileSelectionCanceled, MultiFilesSelected, or FileSelected |
878 AddRef(); | 878 AddRef(); |
879 | 879 |
880 WebContents* web_contents = dispatcher()->delegate()-> | 880 WebContents* web_contents = dispatcher()->delegate()-> |
881 GetAssociatedWebContents(); | 881 GetAssociatedWebContents(); |
882 | 882 |
883 select_file_dialog_ = SelectFileDialog::Create( | 883 select_file_dialog_ = ui::SelectFileDialog::Create( |
884 this, new ChromeSelectFilePolicy(web_contents)); | 884 this, new ChromeSelectFilePolicy(web_contents)); |
885 SelectFileDialog::FileTypeInfo file_type_info; | 885 ui::SelectFileDialog::FileTypeInfo file_type_info; |
886 file_type_info.extensions.resize(1); | 886 file_type_info.extensions.resize(1); |
887 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html")); | 887 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html")); |
888 | 888 |
889 // |tab_contents| can be NULL (for background pages), which is fine. In such | 889 // |tab_contents| can be NULL (for background pages), which is fine. In such |
890 // a case if file-selection dialogs are forbidden by policy, we will not | 890 // a case if file-selection dialogs are forbidden by policy, we will not |
891 // show an InfoBar, which is better than letting one appear out of the blue. | 891 // show an InfoBar, which is better than letting one appear out of the blue. |
892 select_file_dialog_->SelectFile(type, | 892 select_file_dialog_->SelectFile(type, |
893 string16(), | 893 string16(), |
894 default_path, | 894 default_path, |
895 &file_type_info, | 895 &file_type_info, |
896 0, | 896 0, |
897 FILE_PATH_LITERAL(""), | 897 FILE_PATH_LITERAL(""), |
898 NULL, | 898 NULL, |
899 NULL); | 899 NULL); |
900 } | 900 } |
901 | 901 |
902 void BookmarksIOFunction::FileSelectionCanceled(void* params) { | 902 void BookmarksIOFunction::FileSelectionCanceled(void* params) { |
903 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 903 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
904 } | 904 } |
905 | 905 |
906 void BookmarksIOFunction::MultiFilesSelected( | 906 void BookmarksIOFunction::MultiFilesSelected( |
907 const std::vector<FilePath>& files, void* params) { | 907 const std::vector<FilePath>& files, void* params) { |
908 Release(); // Balanced in BookmarsIOFunction::SelectFile() | 908 Release(); // Balanced in BookmarsIOFunction::SelectFile() |
909 NOTREACHED() << "Should not be able to select multiple files"; | 909 NOTREACHED() << "Should not be able to select multiple files"; |
910 } | 910 } |
911 | 911 |
912 bool ImportBookmarksFunction::RunImpl() { | 912 bool ImportBookmarksFunction::RunImpl() { |
913 if (!EditBookmarksEnabled()) | 913 if (!EditBookmarksEnabled()) |
914 return false; | 914 return false; |
915 SelectFile(SelectFileDialog::SELECT_OPEN_FILE); | 915 SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE); |
916 return true; | 916 return true; |
917 } | 917 } |
918 | 918 |
919 void ImportBookmarksFunction::FileSelected(const FilePath& path, | 919 void ImportBookmarksFunction::FileSelected(const FilePath& path, |
920 int index, | 920 int index, |
921 void* params) { | 921 void* params) { |
922 #if !defined(OS_ANDROID) | 922 #if !defined(OS_ANDROID) |
923 // Android does not have support for the standard importers. | 923 // Android does not have support for the standard importers. |
924 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | 924 // TODO(jgreenwald): remove ifdef once extensions are no longer built on |
925 // Android. | 925 // Android. |
926 scoped_refptr<ImporterHost> importer_host(new ImporterHost); | 926 scoped_refptr<ImporterHost> importer_host(new ImporterHost); |
927 importer::SourceProfile source_profile; | 927 importer::SourceProfile source_profile; |
928 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; | 928 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; |
929 source_profile.source_path = path; | 929 source_profile.source_path = path; |
930 importer_host->StartImportSettings(source_profile, | 930 importer_host->StartImportSettings(source_profile, |
931 profile(), | 931 profile(), |
932 importer::FAVORITES, | 932 importer::FAVORITES, |
933 new ProfileWriter(profile()), | 933 new ProfileWriter(profile()), |
934 true); | 934 true); |
935 #endif | 935 #endif |
936 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 936 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
937 } | 937 } |
938 | 938 |
939 bool ExportBookmarksFunction::RunImpl() { | 939 bool ExportBookmarksFunction::RunImpl() { |
940 SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE); | 940 SelectFile(ui::SelectFileDialog::SELECT_SAVEAS_FILE); |
941 return true; | 941 return true; |
942 } | 942 } |
943 | 943 |
944 void ExportBookmarksFunction::FileSelected(const FilePath& path, | 944 void ExportBookmarksFunction::FileSelected(const FilePath& path, |
945 int index, | 945 int index, |
946 void* params) { | 946 void* params) { |
947 #if !defined(OS_ANDROID) | 947 #if !defined(OS_ANDROID) |
948 // Android does not have support for the standard exporter. | 948 // Android does not have support for the standard exporter. |
949 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | 949 // TODO(jgreenwald): remove ifdef once extensions are no longer built on |
950 // Android. | 950 // Android. |
951 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); | 951 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); |
952 #endif | 952 #endif |
953 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 953 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
954 } | 954 } |
OLD | NEW |