Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: chrome/browser/dom_ui/filebrowse_ui.cc

Issue 3037052: Convert browser/dom_ui/f*.cc to not use wstrings/wchar_t*s. (Closed)
Patch Set: changed per thestig Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/dom_ui/font_settings_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/dom_ui/filebrowse_ui.h" 5 #include "chrome/browser/dom_ui/filebrowse_ui.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 #if defined(OS_CHROMEOS) 49 #if defined(OS_CHROMEOS)
50 #include "chrome/browser/chromeos/cros/cros_library.h" 50 #include "chrome/browser/chromeos/cros/cros_library.h"
51 #include "chrome/browser/chromeos/cros/mount_library.h" 51 #include "chrome/browser/chromeos/cros/mount_library.h"
52 #include "chrome/browser/chromeos/login/user_manager.h" 52 #include "chrome/browser/chromeos/login/user_manager.h"
53 #endif 53 #endif
54 54
55 // Maximum number of search results to return in a given search. We should 55 // Maximum number of search results to return in a given search. We should
56 // eventually remove this. 56 // eventually remove this.
57 static const int kMaxSearchResults = 100; 57 static const int kMaxSearchResults = 100;
58 static const std::wstring kPropertyPath = L"path"; 58 static const char kPropertyPath[] = "path";
59 static const std::wstring kPropertyTitle = L"title"; 59 static const char kPropertyTitle[] = "title";
60 static const std::wstring kPropertyDirectory = L"isDirectory"; 60 static const char kPropertyDirectory[] = "isDirectory";
61 static const std::string kPicasawebUserPrefix = 61 static const char kPicasawebUserPrefix[] =
62 "http://picasaweb.google.com/data/feed/api/user/"; 62 "http://picasaweb.google.com/data/feed/api/user/";
63 static const std::string kPicasawebDefault = "/albumid/default"; 63 static const char kPicasawebDefault[] = "/albumid/default";
64 static const std::string kPicasawebDropBox = "/home"; 64 static const char kPicasawebDropBox[] = "/home";
65 static const std::string kPicasawebBaseUrl = "http://picasaweb.google.com/"; 65 static const char kPicasawebBaseUrl[] = "http://picasaweb.google.com/";
66 static const std::string kMediaPath = "/media"; 66 static const char kMediaPath[] = "/media";
67 static const char* kFilebrowseURLHash = "chrome://filebrowse#"; 67 static const char kFilebrowseURLHash[] = "chrome://filebrowse#";
68 static const int kPopupLeft = 0; 68 static const int kPopupLeft = 0;
69 static const int kPopupTop = 0; 69 static const int kPopupTop = 0;
70 70
71 class FileBrowseUIHTMLSource : public ChromeURLDataManager::DataSource { 71 class FileBrowseUIHTMLSource : public ChromeURLDataManager::DataSource {
72 public: 72 public:
73 FileBrowseUIHTMLSource(); 73 FileBrowseUIHTMLSource();
74 74
75 // Called when the network layer has requested a resource underneath 75 // Called when the network layer has requested a resource underneath
76 // the path we registered. 76 // the path we registered.
77 virtual void StartDataRequest(const std::string& path, 77 virtual void StartDataRequest(const std::string& path,
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 FileBrowseUIHTMLSource::FileBrowseUIHTMLSource() 262 FileBrowseUIHTMLSource::FileBrowseUIHTMLSource()
263 : DataSource(chrome::kChromeUIFileBrowseHost, MessageLoop::current()) { 263 : DataSource(chrome::kChromeUIFileBrowseHost, MessageLoop::current()) {
264 } 264 }
265 265
266 void FileBrowseUIHTMLSource::StartDataRequest(const std::string& path, 266 void FileBrowseUIHTMLSource::StartDataRequest(const std::string& path,
267 bool is_off_the_record, 267 bool is_off_the_record,
268 int request_id) { 268 int request_id) {
269 DictionaryValue localized_strings; 269 DictionaryValue localized_strings;
270 // TODO(dhg): Add stirings to localized strings, also add more strings 270 // TODO(dhg): Add stirings to localized strings, also add more strings
271 // that are currently hardcoded. 271 // that are currently hardcoded.
272 localized_strings.SetString(L"title", 272 localized_strings.SetString("title",
273 l10n_util::GetString(IDS_FILEBROWSER_TITLE)); 273 l10n_util::GetStringUTF16(IDS_FILEBROWSER_TITLE));
274 localized_strings.SetString(L"pause", 274 localized_strings.SetString("pause",
275 l10n_util::GetString(IDS_FILEBROWSER_PAUSE)); 275 l10n_util::GetStringUTF16(IDS_FILEBROWSER_PAUSE));
276 localized_strings.SetString(L"resume", 276 localized_strings.SetString("resume",
277 l10n_util::GetString(IDS_FILEBROWSER_RESUME)); 277 l10n_util::GetStringUTF16(IDS_FILEBROWSER_RESUME));
278 localized_strings.SetString(L"scanning", 278 localized_strings.SetString("scanning",
279 l10n_util::GetString(IDS_FILEBROWSER_SCANNING)); 279 l10n_util::GetStringUTF16(IDS_FILEBROWSER_SCANNING));
280 localized_strings.SetString(L"confirmdelete", 280 localized_strings.SetString("confirmdelete",
281 l10n_util::GetString(IDS_FILEBROWSER_CONFIRM_DELETE)); 281 l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_DELETE));
282 localized_strings.SetString(L"confirmyes", 282 localized_strings.SetString("confirmyes",
283 l10n_util::GetString(IDS_FILEBROWSER_CONFIRM_YES)); 283 l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_YES));
284 localized_strings.SetString(L"confirmcancel", 284 localized_strings.SetString("confirmcancel",
285 l10n_util::GetString(IDS_FILEBROWSER_CONFIRM_CANCEL)); 285 l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_CANCEL));
286 localized_strings.SetString(L"allowdownload", 286 localized_strings.SetString("allowdownload",
287 l10n_util::GetString(IDS_FILEBROWSER_CONFIRM_DOWNLOAD)); 287 l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_DOWNLOAD));
288 localized_strings.SetString(L"filenameprompt", 288 localized_strings.SetString("filenameprompt",
289 l10n_util::GetString(IDS_FILEBROWSER_PROMPT_FILENAME)); 289 l10n_util::GetStringUTF16(IDS_FILEBROWSER_PROMPT_FILENAME));
290 localized_strings.SetString(L"save", 290 localized_strings.SetString("save",
291 l10n_util::GetString(IDS_FILEBROWSER_SAVE)); 291 l10n_util::GetStringUTF16(IDS_FILEBROWSER_SAVE));
292 localized_strings.SetString(L"newfolder", 292 localized_strings.SetString("newfolder",
293 l10n_util::GetString(IDS_FILEBROWSER_NEW_FOLDER)); 293 l10n_util::GetStringUTF16(IDS_FILEBROWSER_NEW_FOLDER));
294 localized_strings.SetString(L"open", 294 localized_strings.SetString("open",
295 l10n_util::GetString(IDS_FILEBROWSER_OPEN)); 295 l10n_util::GetStringUTF16(IDS_FILEBROWSER_OPEN));
296 localized_strings.SetString(L"picasaweb", 296 localized_strings.SetString("picasaweb",
297 l10n_util::GetString(IDS_FILEBROWSER_UPLOAD_PICASAWEB)); 297 l10n_util::GetStringUTF16(IDS_FILEBROWSER_UPLOAD_PICASAWEB));
298 localized_strings.SetString(L"flickr", 298 localized_strings.SetString("flickr",
299 l10n_util::GetString(IDS_FILEBROWSER_UPLOAD_FLICKR)); 299 l10n_util::GetStringUTF16(IDS_FILEBROWSER_UPLOAD_FLICKR));
300 localized_strings.SetString(L"email", 300 localized_strings.SetString("email",
301 l10n_util::GetString(IDS_FILEBROWSER_UPLOAD_EMAIL)); 301 l10n_util::GetStringUTF16(IDS_FILEBROWSER_UPLOAD_EMAIL));
302 localized_strings.SetString(L"delete", 302 localized_strings.SetString("delete",
303 l10n_util::GetString(IDS_FILEBROWSER_DELETE)); 303 l10n_util::GetStringUTF16(IDS_FILEBROWSER_DELETE));
304 localized_strings.SetString(L"enqueue", 304 localized_strings.SetString("enqueue",
305 l10n_util::GetString(IDS_FILEBROWSER_ENQUEUE)); 305 l10n_util::GetStringUTF16(IDS_FILEBROWSER_ENQUEUE));
306 localized_strings.SetString(L"mediapath", kMediaPath); 306 localized_strings.SetString("mediapath", kMediaPath);
307 FilePath default_download_path; 307 FilePath default_download_path;
308 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, 308 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS,
309 &default_download_path)) { 309 &default_download_path)) {
310 NOTREACHED(); 310 NOTREACHED();
311 } 311 }
312 localized_strings.SetString(L"downloadpath", default_download_path.value()); 312 // TODO(viettrungluu): this is wrong -- FilePath's need not be Unicode.
313 localized_strings.SetString(L"error_unknown_file_type", 313 localized_strings.SetString("downloadpath", default_download_path.value());
314 l10n_util::GetString(IDS_FILEBROWSER_ERROR_UNKNOWN_FILE_TYPE)); 314 localized_strings.SetString("error_unknown_file_type",
315 l10n_util::GetStringUTF16(IDS_FILEBROWSER_ERROR_UNKNOWN_FILE_TYPE));
315 SetFontAndTextDirection(&localized_strings); 316 SetFontAndTextDirection(&localized_strings);
316 317
317 static const base::StringPiece filebrowse_html( 318 static const base::StringPiece filebrowse_html(
318 ResourceBundle::GetSharedInstance().GetRawDataResource( 319 ResourceBundle::GetSharedInstance().GetRawDataResource(
319 IDR_FILEBROWSE_HTML)); 320 IDR_FILEBROWSE_HTML));
320 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( 321 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
321 filebrowse_html, &localized_strings); 322 filebrowse_html, &localized_strings);
322 323
323 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 324 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
324 html_bytes->data.resize(full_html.size()); 325 html_bytes->data.resize(full_html.size());
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 441
441 void FilebrowseHandler::FireDeleteComplete(const FilePath& path) { 442 void FilebrowseHandler::FireDeleteComplete(const FilePath& path) {
442 // We notify the UI by telling it to refresh its contents. 443 // We notify the UI by telling it to refresh its contents.
443 FilePath dir_path = path.DirName(); 444 FilePath dir_path = path.DirName();
444 GetChildrenForPath(dir_path, true); 445 GetChildrenForPath(dir_path, true);
445 }; 446 };
446 447
447 void FilebrowseHandler::FireUploadComplete() { 448 void FilebrowseHandler::FireUploadComplete() {
448 #if defined(OS_CHROMEOS) 449 #if defined(OS_CHROMEOS)
449 DictionaryValue info_value; 450 DictionaryValue info_value;
450 info_value.SetString(L"path", current_file_uploaded_); 451 info_value.SetString("path", current_file_uploaded_);
451 452
452 std::string username; 453 std::string username;
453 chromeos::UserManager* user_man = chromeos::UserManager::Get(); 454 chromeos::UserManager* user_man = chromeos::UserManager::Get();
454 username = user_man->logged_in_user().email(); 455 username = user_man->logged_in_user().email();
455 456
456 if (username.empty()) { 457 if (username.empty()) {
457 LOG(ERROR) << "Unable to get username"; 458 LOG(ERROR) << "Unable to get username";
458 return; 459 return;
459 } 460 }
460 int location = username.find_first_of('@',0); 461 int location = username.find_first_of('@',0);
461 if (location <= 0) { 462 if (location <= 0) {
462 LOG(ERROR) << "Username not formatted correctly"; 463 LOG(ERROR) << "Username not formatted correctly";
463 return; 464 return;
464 } 465 }
465 username = username.erase(username.find_first_of('@',0)); 466 username = username.erase(username.find_first_of('@',0));
466 std::string picture_url; 467 std::string picture_url = kPicasawebBaseUrl;
467 picture_url = kPicasawebBaseUrl;
468 picture_url += username; 468 picture_url += username;
469 picture_url += kPicasawebDropBox; 469 picture_url += kPicasawebDropBox;
470 info_value.SetString(L"url", picture_url); 470 info_value.SetString("url", picture_url);
471 info_value.SetInteger(L"status_code", upload_response_code_); 471 info_value.SetInteger("status_code", upload_response_code_);
472 dom_ui_->CallJavascriptFunction(L"uploadComplete", info_value); 472 dom_ui_->CallJavascriptFunction(L"uploadComplete", info_value);
473 #endif 473 #endif
474 } 474 }
475 475
476 #if defined(OS_CHROMEOS) 476 #if defined(OS_CHROMEOS)
477 void FilebrowseHandler::MountChanged(chromeos::MountLibrary* obj, 477 void FilebrowseHandler::MountChanged(chromeos::MountLibrary* obj,
478 chromeos::MountEventType evt, 478 chromeos::MountEventType evt,
479 const std::string& path) { 479 const std::string& path) {
480 if (evt == chromeos::DISK_REMOVED || 480 if (evt == chromeos::DISK_REMOVED ||
481 evt == chromeos::DISK_CHANGED) { 481 evt == chromeos::DISK_CHANGED) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 NOTREACHED(); 537 NOTREACHED();
538 } 538 }
539 539
540 DictionaryValue* download_value = new DictionaryValue(); 540 DictionaryValue* download_value = new DictionaryValue();
541 download_value->SetString(kPropertyPath, default_download_path.value()); 541 download_value->SetString(kPropertyPath, default_download_path.value());
542 download_value->SetString(kPropertyTitle, "File Shelf"); 542 download_value->SetString(kPropertyTitle, "File Shelf");
543 download_value->SetBoolean(kPropertyDirectory, true); 543 download_value->SetBoolean(kPropertyDirectory, true);
544 544
545 results_value.Append(download_value); 545 results_value.Append(download_value);
546 546
547 info_value.SetString(L"functionCall", "getRoots"); 547 info_value.SetString("functionCall", "getRoots");
548 info_value.SetString(kPropertyPath, ""); 548 info_value.SetString(kPropertyPath, "");
549 dom_ui_->CallJavascriptFunction(L"browseFileResult", 549 dom_ui_->CallJavascriptFunction(L"browseFileResult",
550 info_value, results_value); 550 info_value, results_value);
551 } 551 }
552 552
553 void FilebrowseHandler::HandleCreateNewFolder(const Value* value) { 553 void FilebrowseHandler::HandleCreateNewFolder(const Value* value) {
554 #if defined(OS_CHROMEOS) 554 #if defined(OS_CHROMEOS)
555 if (value && value->GetType() == Value::TYPE_LIST) { 555 if (value && value->GetType() == Value::TYPE_LIST) {
556 const ListValue* list_value = static_cast<const ListValue*>(value); 556 const ListValue* list_value = static_cast<const ListValue*>(value);
557 std::string path; 557 std::string path;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 } 626 }
627 627
628 void FilebrowseHandler::HandleIsAdvancedEnabled(const Value* value) { 628 void FilebrowseHandler::HandleIsAdvancedEnabled(const Value* value) {
629 #if defined(OS_CHROMEOS) 629 #if defined(OS_CHROMEOS)
630 Profile* profile = BrowserList::GetLastActive()->profile(); 630 Profile* profile = BrowserList::GetLastActive()->profile();
631 PrefService* pref_service = profile->GetPrefs(); 631 PrefService* pref_service = profile->GetPrefs();
632 bool is_enabled = pref_service->GetBoolean( 632 bool is_enabled = pref_service->GetBoolean(
633 prefs::kLabsAdvancedFilesystemEnabled); 633 prefs::kLabsAdvancedFilesystemEnabled);
634 bool mp_enabled = pref_service->GetBoolean(prefs::kLabsMediaplayerEnabled); 634 bool mp_enabled = pref_service->GetBoolean(prefs::kLabsMediaplayerEnabled);
635 DictionaryValue info_value; 635 DictionaryValue info_value;
636 info_value.SetBoolean(L"enabled", is_enabled); 636 info_value.SetBoolean("enabled", is_enabled);
637 info_value.SetBoolean(L"mpEnabled", mp_enabled); 637 info_value.SetBoolean("mpEnabled", mp_enabled);
638 dom_ui_->CallJavascriptFunction(L"enabledResult", 638 dom_ui_->CallJavascriptFunction(L"enabledResult",
639 info_value); 639 info_value);
640 #endif 640 #endif
641 } 641 }
642 void FilebrowseHandler::HandleRefreshDirectory(const Value* value) { 642 void FilebrowseHandler::HandleRefreshDirectory(const Value* value) {
643 if (value && value->GetType() == Value::TYPE_LIST) { 643 if (value && value->GetType() == Value::TYPE_LIST) {
644 const ListValue* list_value = static_cast<const ListValue*>(value); 644 const ListValue* list_value = static_cast<const ListValue*>(value);
645 std::string path; 645 std::string path;
646 646
647 // Get path string. 647 // Get path string.
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 file_value->SetString(kPropertyPath, 940 file_value->SetString(kPropertyPath,
941 currentpath_.Append(data.filename).value()); 941 currentpath_.Append(data.filename).value());
942 file_value->SetBoolean(kPropertyDirectory, S_ISDIR(data.stat.st_mode)); 942 file_value->SetBoolean(kPropertyDirectory, S_ISDIR(data.stat.st_mode));
943 #endif 943 #endif
944 filelist_value_->Append(file_value); 944 filelist_value_->Append(file_value);
945 } 945 }
946 946
947 void FilebrowseHandler::OnListDone(int error) { 947 void FilebrowseHandler::OnListDone(int error) {
948 DictionaryValue info_value; 948 DictionaryValue info_value;
949 if (is_refresh_) { 949 if (is_refresh_) {
950 info_value.SetString(L"functionCall", "refresh"); 950 info_value.SetString("functionCall", "refresh");
951 } else { 951 } else {
952 info_value.SetString(L"functionCall", "getChildren"); 952 info_value.SetString("functionCall", "getChildren");
953 } 953 }
954 info_value.SetString(kPropertyPath, currentpath_.value()); 954 info_value.SetString(kPropertyPath, currentpath_.value());
955 dom_ui_->CallJavascriptFunction(L"browseFileResult", 955 dom_ui_->CallJavascriptFunction(L"browseFileResult",
956 info_value, *(filelist_value_.get())); 956 info_value, *(filelist_value_.get()));
957 SendCurrentDownloads(); 957 SendCurrentDownloads();
958 } 958 }
959 959
960 void FilebrowseHandler::HandleGetMetadata(const Value* value) { 960 void FilebrowseHandler::HandleGetMetadata(const Value* value) {
961 } 961 }
962 962
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 } 1150 }
1151 } 1151 }
1152 1152
1153 return NULL; 1153 return NULL;
1154 } 1154 }
1155 1155
1156 const int FileBrowseUI::kPopupWidth = 250; 1156 const int FileBrowseUI::kPopupWidth = 250;
1157 const int FileBrowseUI::kPopupHeight = 300; 1157 const int FileBrowseUI::kPopupHeight = 300;
1158 const int FileBrowseUI::kSmallPopupWidth = 250; 1158 const int FileBrowseUI::kSmallPopupWidth = 250;
1159 const int FileBrowseUI::kSmallPopupHeight = 50; 1159 const int FileBrowseUI::kSmallPopupHeight = 50;
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/dom_ui/font_settings_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698