| 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/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.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 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 if (contents) | 902 if (contents) |
| 903 tab_id = ExtensionTabUtil::GetTabId(contents); | 903 tab_id = ExtensionTabUtil::GetTabId(contents); |
| 904 } | 904 } |
| 905 return tab_id; | 905 return tab_id; |
| 906 } | 906 } |
| 907 | 907 |
| 908 const FileDialogFunction::Callback& FileDialogFunction::GetCallback() const { | 908 const FileDialogFunction::Callback& FileDialogFunction::GetCallback() const { |
| 909 return Callback::Find(GetTabId()); | 909 return Callback::Find(GetTabId()); |
| 910 } | 910 } |
| 911 | 911 |
| 912 void FileDialogFunction::RemoveCallback() { |
| 913 // Listeners expect to be invoked exactly once, so we need to remove our |
| 914 // callback objects afterwards. |
| 915 Callback::Remove(GetTabId()); |
| 916 } |
| 917 |
| 912 // GetFileSystemRootPathOnFileThread can only be called from the file thread, | 918 // GetFileSystemRootPathOnFileThread can only be called from the file thread, |
| 913 // so here we are. This function takes a vector of virtual paths, converts | 919 // so here we are. This function takes a vector of virtual paths, converts |
| 914 // them to local paths and calls GetLocalPathsResponseOnUIThread with the | 920 // them to local paths and calls GetLocalPathsResponseOnUIThread with the |
| 915 // result vector, on the UI thread. | 921 // result vector, on the UI thread. |
| 916 void FileDialogFunction::GetLocalPathsOnFileThread(const UrlList& file_urls, | 922 void FileDialogFunction::GetLocalPathsOnFileThread(const UrlList& file_urls, |
| 917 const std::string& task_id) { | 923 const std::string& task_id) { |
| 918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 924 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 919 FilePathList selected_files; | 925 FilePathList selected_files; |
| 920 | 926 |
| 921 // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS. | 927 // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 return; | 994 return; |
| 989 } | 995 } |
| 990 int index; | 996 int index; |
| 991 args_->GetInteger(1, &index); | 997 args_->GetInteger(1, &index); |
| 992 const Callback& callback = GetCallback(); | 998 const Callback& callback = GetCallback(); |
| 993 DCHECK(!callback.IsNull()); | 999 DCHECK(!callback.IsNull()); |
| 994 if (!callback.IsNull()) { | 1000 if (!callback.IsNull()) { |
| 995 callback.listener()->FileSelected(files[0], | 1001 callback.listener()->FileSelected(files[0], |
| 996 index, | 1002 index, |
| 997 callback.params()); | 1003 callback.params()); |
| 1004 RemoveCallback(); // Listeners expect to be invoked exactly once. |
| 998 } | 1005 } |
| 999 SendResponse(true); | 1006 SendResponse(true); |
| 1000 } | 1007 } |
| 1001 | 1008 |
| 1002 | 1009 |
| 1003 ViewFilesFunction::ViewFilesFunction() { | 1010 ViewFilesFunction::ViewFilesFunction() { |
| 1004 } | 1011 } |
| 1005 | 1012 |
| 1006 ViewFilesFunction::~ViewFilesFunction() { | 1013 ViewFilesFunction::~ViewFilesFunction() { |
| 1007 } | 1014 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 } | 1089 } |
| 1083 | 1090 |
| 1084 void SelectFilesFunction::GetLocalPathsResponseOnUIThread( | 1091 void SelectFilesFunction::GetLocalPathsResponseOnUIThread( |
| 1085 const FilePathList& files, const std::string& internal_task_id) { | 1092 const FilePathList& files, const std::string& internal_task_id) { |
| 1086 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1093 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1087 | 1094 |
| 1088 const Callback& callback = GetCallback(); | 1095 const Callback& callback = GetCallback(); |
| 1089 DCHECK(!callback.IsNull()); | 1096 DCHECK(!callback.IsNull()); |
| 1090 if (!callback.IsNull()) { | 1097 if (!callback.IsNull()) { |
| 1091 callback.listener()->MultiFilesSelected(files, callback.params()); | 1098 callback.listener()->MultiFilesSelected(files, callback.params()); |
| 1099 RemoveCallback(); // Listeners expect to be invoked exactly once. |
| 1092 } | 1100 } |
| 1093 SendResponse(true); | 1101 SendResponse(true); |
| 1094 } | 1102 } |
| 1095 | 1103 |
| 1096 bool CancelFileDialogFunction::RunImpl() { | 1104 bool CancelFileDialogFunction::RunImpl() { |
| 1097 const Callback& callback = GetCallback(); | 1105 const Callback& callback = GetCallback(); |
| 1098 DCHECK(!callback.IsNull()); | 1106 DCHECK(!callback.IsNull()); |
| 1099 if (!callback.IsNull()) { | 1107 if (!callback.IsNull()) { |
| 1100 callback.listener()->FileSelectionCanceled(callback.params()); | 1108 callback.listener()->FileSelectionCanceled(callback.params()); |
| 1109 RemoveCallback(); // Listeners expect to be invoked exactly once. |
| 1101 } | 1110 } |
| 1102 SendResponse(true); | 1111 SendResponse(true); |
| 1103 return true; | 1112 return true; |
| 1104 } | 1113 } |
| 1105 | 1114 |
| 1106 bool FileDialogStringsFunction::RunImpl() { | 1115 bool FileDialogStringsFunction::RunImpl() { |
| 1107 result_.reset(new DictionaryValue()); | 1116 result_.reset(new DictionaryValue()); |
| 1108 DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get()); | 1117 DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get()); |
| 1109 | 1118 |
| 1110 #define SET_STRING(ns, id) \ | 1119 #define SET_STRING(ns, id) \ |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 #undef SET_STRING | 1191 #undef SET_STRING |
| 1183 | 1192 |
| 1184 // TODO(serya): Create a new string in .grd file for this one in M13. | 1193 // TODO(serya): Create a new string in .grd file for this one in M13. |
| 1185 dict->SetString("PREVIEW_IMAGE", | 1194 dict->SetString("PREVIEW_IMAGE", |
| 1186 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_VIEW_CERT_BUTTON)); | 1195 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_VIEW_CERT_BUTTON)); |
| 1187 dict->SetString("PLAY_MEDIA", | 1196 dict->SetString("PLAY_MEDIA", |
| 1188 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); | 1197 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); |
| 1189 | 1198 |
| 1190 return true; | 1199 return true; |
| 1191 } | 1200 } |
| OLD | NEW |