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

Side by Side Diff: chrome/browser/enumerate_modules_model_win.cc

Issue 12314090: Add utf_string_conversions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
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/enumerate_modules_model_win.h" 5 #include "chrome/browser/enumerate_modules_model_win.h"
6 6
7 #include <Tlhelp32.h> 7 #include <Tlhelp32.h>
8 #include <wintrust.h> 8 #include <wintrust.h>
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 const ModuleEnumerator::Module& module, 328 const ModuleEnumerator::Module& module,
329 const ModuleEnumerator::BlacklistEntry& blacklisted) { 329 const ModuleEnumerator::BlacklistEntry& blacklisted) {
330 // All modules must be normalized before matching against blacklist. 330 // All modules must be normalized before matching against blacklist.
331 DCHECK(module.normalized); 331 DCHECK(module.normalized);
332 // Filename is mandatory and version should not contain spaces. 332 // Filename is mandatory and version should not contain spaces.
333 DCHECK(strlen(blacklisted.filename) > 0); 333 DCHECK(strlen(blacklisted.filename) > 0);
334 DCHECK(!strstr(blacklisted.version_from, " ")); 334 DCHECK(!strstr(blacklisted.version_from, " "));
335 DCHECK(!strstr(blacklisted.version_to, " ")); 335 DCHECK(!strstr(blacklisted.version_to, " "));
336 336
337 std::string filename_hash, location_hash; 337 std::string filename_hash, location_hash;
338 GenerateHash(WideToUTF8(module.name), &filename_hash); 338 GenerateHash(base::WideToUTF8(module.name), &filename_hash);
339 GenerateHash(WideToUTF8(module.location), &location_hash); 339 GenerateHash(base::WideToUTF8(module.location), &location_hash);
340 340
341 // Filenames are mandatory. Location is mandatory if given. 341 // Filenames are mandatory. Location is mandatory if given.
342 if (filename_hash == blacklisted.filename && 342 if (filename_hash == blacklisted.filename &&
343 (std::string(blacklisted.location).empty() || 343 (std::string(blacklisted.location).empty() ||
344 location_hash == blacklisted.location)) { 344 location_hash == blacklisted.location)) {
345 // We have a name match against the blacklist (and possibly location match 345 // We have a name match against the blacklist (and possibly location match
346 // also), so check version. 346 // also), so check version.
347 Version module_version(UTF16ToASCII(module.version)); 347 Version module_version(UTF16ToASCII(module.version));
348 Version version_min(blacklisted.version_from); 348 Version version_min(blacklisted.version_from);
349 Version version_max(blacklisted.version_to); 349 Version version_max(blacklisted.version_to);
350 bool version_ok = !version_min.IsValid() && !version_max.IsValid(); 350 bool version_ok = !version_min.IsValid() && !version_max.IsValid();
351 if (!version_ok) { 351 if (!version_ok) {
352 bool too_low = version_min.IsValid() && 352 bool too_low = version_min.IsValid() &&
353 (!module_version.IsValid() || 353 (!module_version.IsValid() ||
354 module_version.CompareTo(version_min) < 0); 354 module_version.CompareTo(version_min) < 0);
355 bool too_high = version_max.IsValid() && 355 bool too_high = version_max.IsValid() &&
356 (!module_version.IsValid() || 356 (!module_version.IsValid() ||
357 module_version.CompareTo(version_max) >= 0); 357 module_version.CompareTo(version_max) >= 0);
358 version_ok = !too_low && !too_high; 358 version_ok = !too_low && !too_high;
359 } 359 }
360 360
361 if (version_ok) { 361 if (version_ok) {
362 // At this point, the names match and there is no version specified 362 // At this point, the names match and there is no version specified
363 // or the versions also match. 363 // or the versions also match.
364 364
365 std::string desc_or_signer(blacklisted.desc_or_signer); 365 std::string desc_or_signer(blacklisted.desc_or_signer);
366 std::string signer_hash, description_hash; 366 std::string signer_hash, description_hash;
367 GenerateHash(WideToUTF8(module.digital_signer), &signer_hash); 367 GenerateHash(base::WideToUTF8(module.digital_signer), &signer_hash);
368 GenerateHash(WideToUTF8(module.description), &description_hash); 368 GenerateHash(base::WideToUTF8(module.description), &description_hash);
369 369
370 // If signatures match (or both are empty), then we have a winner. 370 // If signatures match (or both are empty), then we have a winner.
371 if (signer_hash == desc_or_signer) 371 if (signer_hash == desc_or_signer)
372 return CONFIRMED_BAD; 372 return CONFIRMED_BAD;
373 373
374 // If descriptions match (or both are empty) and the locations match, then 374 // If descriptions match (or both are empty) and the locations match, then
375 // we also have a confirmed match. 375 // we also have a confirmed match.
376 if (description_hash == desc_or_signer && 376 if (description_hash == desc_or_signer &&
377 !location_hash.empty() && location_hash == blacklisted.location) { 377 !location_hash.empty() && location_hash == blacklisted.location) {
378 return CONFIRMED_BAD; 378 return CONFIRMED_BAD;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 env_vars.push_back(L"ProgramFiles"); 599 env_vars.push_back(L"ProgramFiles");
600 env_vars.push_back(L"ProgramData"); 600 env_vars.push_back(L"ProgramData");
601 env_vars.push_back(L"USERPROFILE"); 601 env_vars.push_back(L"USERPROFILE");
602 env_vars.push_back(L"SystemRoot"); 602 env_vars.push_back(L"SystemRoot");
603 env_vars.push_back(L"TEMP"); 603 env_vars.push_back(L"TEMP");
604 env_vars.push_back(L"TMP"); 604 env_vars.push_back(L"TMP");
605 env_vars.push_back(L"CommonProgramFiles"); 605 env_vars.push_back(L"CommonProgramFiles");
606 for (std::vector<string16>::const_iterator variable = env_vars.begin(); 606 for (std::vector<string16>::const_iterator variable = env_vars.begin();
607 variable != env_vars.end(); ++variable) { 607 variable != env_vars.end(); ++variable) {
608 std::string path; 608 std::string path;
609 if (environment->GetVar(WideToASCII(*variable).c_str(), &path)) { 609 if (environment->GetVar(base::WideToASCII(*variable).c_str(), &path)) {
610 path_mapping_.push_back( 610 path_mapping_.push_back(
611 std::make_pair(base::i18n::ToLower(UTF8ToUTF16(path)) + L"\\", 611 std::make_pair(base::i18n::ToLower(UTF8ToUTF16(path)) + L"\\",
612 L"%" + base::i18n::ToLower(*variable) + L"%")); 612 L"%" + base::i18n::ToLower(*variable) + L"%"));
613 } 613 }
614 } 614 }
615 } 615 }
616 616
617 void ModuleEnumerator::CollapsePath(Module* entry) { 617 void ModuleEnumerator::CollapsePath(Module* entry) {
618 // Take the path and see if we can use any of the substitution values 618 // Take the path and see if we can use any of the substitution values
619 // from the vector constructed above to replace c:\windows with, for 619 // from the vector constructed above to replace c:\windows with, for
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 827
828 for (ModuleEnumerator::ModulesVector::const_iterator module = 828 for (ModuleEnumerator::ModulesVector::const_iterator module =
829 enumerated_modules_.begin(); 829 enumerated_modules_.begin();
830 module != enumerated_modules_.end(); ++module) { 830 module != enumerated_modules_.end(); ++module) {
831 DictionaryValue* data = new DictionaryValue(); 831 DictionaryValue* data = new DictionaryValue();
832 data->SetInteger("type", module->type); 832 data->SetInteger("type", module->type);
833 string16 type_string; 833 string16 type_string;
834 if ((module->type & ModuleEnumerator::LOADED_MODULE) == 0) { 834 if ((module->type & ModuleEnumerator::LOADED_MODULE) == 0) {
835 // Module is not loaded, denote type of module. 835 // Module is not loaded, denote type of module.
836 if (module->type & ModuleEnumerator::SHELL_EXTENSION) 836 if (module->type & ModuleEnumerator::SHELL_EXTENSION)
837 type_string = ASCIIToWide("Shell Extension"); 837 type_string = base::ASCIIToWide("Shell Extension");
838 if (module->type & ModuleEnumerator::WINSOCK_MODULE_REGISTRATION) { 838 if (module->type & ModuleEnumerator::WINSOCK_MODULE_REGISTRATION) {
839 if (!type_string.empty()) 839 if (!type_string.empty())
840 type_string += ASCIIToWide(", "); 840 type_string += base::ASCIIToWide(", ");
841 type_string += ASCIIToWide("Winsock"); 841 type_string += base::ASCIIToWide("Winsock");
842 } 842 }
843 // Must be one of the above type. 843 // Must be one of the above type.
844 DCHECK(!type_string.empty()); 844 DCHECK(!type_string.empty());
845 if (!limited_mode_) { 845 if (!limited_mode_) {
846 type_string += ASCIIToWide(" -- "); 846 type_string += base::ASCIIToWide(" -- ");
847 type_string += l10n_util::GetStringUTF16(IDS_CONFLICTS_NOT_LOADED_YET); 847 type_string += l10n_util::GetStringUTF16(IDS_CONFLICTS_NOT_LOADED_YET);
848 } 848 }
849 } 849 }
850 data->SetString("type_description", type_string); 850 data->SetString("type_description", type_string);
851 data->SetInteger("status", module->status); 851 data->SetInteger("status", module->status);
852 data->SetString("location", module->location); 852 data->SetString("location", module->location);
853 data->SetString("name", module->name); 853 data->SetString("name", module->name);
854 data->SetString("product_name", module->product_name); 854 data->SetString("product_name", module->product_name);
855 data->SetString("description", module->description); 855 data->SetString("description", module->description);
856 data->SetString("version", module->version); 856 data->SetString("version", module->version);
857 data->SetString("digital_signer", module->digital_signer); 857 data->SetString("digital_signer", module->digital_signer);
858 858
859 if (!limited_mode_) { 859 if (!limited_mode_) {
860 // Figure out the possible resolution help string. 860 // Figure out the possible resolution help string.
861 string16 actions; 861 string16 actions;
862 string16 separator = ASCIIToWide(" ") + l10n_util::GetStringUTF16( 862 string16 separator = base::ASCIIToWide(" ") + l10n_util::GetStringUTF16(
863 IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_SEPERATOR) + 863 IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_SEPERATOR) +
864 ASCIIToWide(" "); 864 base::ASCIIToWide(" ");
865 865
866 if (module->recommended_action & ModuleEnumerator::NONE) { 866 if (module->recommended_action & ModuleEnumerator::NONE) {
867 actions = l10n_util::GetStringUTF16( 867 actions = l10n_util::GetStringUTF16(
868 IDS_CONFLICTS_CHECK_INVESTIGATING); 868 IDS_CONFLICTS_CHECK_INVESTIGATING);
869 } 869 }
870 if (module->recommended_action & ModuleEnumerator::UNINSTALL) { 870 if (module->recommended_action & ModuleEnumerator::UNINSTALL) {
871 if (!actions.empty()) 871 if (!actions.empty())
872 actions += separator; 872 actions += separator;
873 actions = l10n_util::GetStringUTF16( 873 actions = l10n_util::GetStringUTF16(
874 IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_UNINSTALL); 874 IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_UNINSTALL);
875 } 875 }
876 if (module->recommended_action & ModuleEnumerator::UPDATE) { 876 if (module->recommended_action & ModuleEnumerator::UPDATE) {
877 if (!actions.empty()) 877 if (!actions.empty())
878 actions += separator; 878 actions += separator;
879 actions += l10n_util::GetStringUTF16( 879 actions += l10n_util::GetStringUTF16(
880 IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_UPDATE); 880 IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_UPDATE);
881 } 881 }
882 if (module->recommended_action & ModuleEnumerator::DISABLE) { 882 if (module->recommended_action & ModuleEnumerator::DISABLE) {
883 if (!actions.empty()) 883 if (!actions.empty())
884 actions += separator; 884 actions += separator;
885 actions += l10n_util::GetStringUTF16( 885 actions += l10n_util::GetStringUTF16(
886 IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_DISABLE); 886 IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_DISABLE);
887 } 887 }
888 string16 possible_resolution = actions.empty() ? ASCIIToWide("") : 888 string16 possible_resolution = actions.empty() ? base::ASCIIToWide("") :
889 l10n_util::GetStringUTF16(IDS_CONFLICTS_CHECK_POSSIBLE_ACTIONS) + 889 l10n_util::GetStringUTF16(IDS_CONFLICTS_CHECK_POSSIBLE_ACTIONS) +
890 ASCIIToWide(" ") + 890 base::ASCIIToWide(" ") +
891 actions; 891 actions;
892 data->SetString("possibleResolution", possible_resolution); 892 data->SetString("possibleResolution", possible_resolution);
893 data->SetString("help_url", 893 data->SetString("help_url",
894 ConstructHelpCenterUrl(*module).spec().c_str()); 894 ConstructHelpCenterUrl(*module).spec().c_str());
895 } 895 }
896 896
897 list->Append(data); 897 list->Append(data);
898 } 898 }
899 899
900 lock->Release(); 900 lock->Release();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 content::NotificationService::NoDetails()); 963 content::NotificationService::NoDetails());
964 } 964 }
965 965
966 GURL EnumerateModulesModel::ConstructHelpCenterUrl( 966 GURL EnumerateModulesModel::ConstructHelpCenterUrl(
967 const ModuleEnumerator::Module& module) const { 967 const ModuleEnumerator::Module& module) const {
968 if (!(module.recommended_action & ModuleEnumerator::SEE_LINK)) 968 if (!(module.recommended_action & ModuleEnumerator::SEE_LINK))
969 return GURL(); 969 return GURL();
970 970
971 // Construct the needed hashes. 971 // Construct the needed hashes.
972 std::string filename, location, description, signer; 972 std::string filename, location, description, signer;
973 GenerateHash(WideToUTF8(module.name), &filename); 973 GenerateHash(base::WideToUTF8(module.name), &filename);
974 GenerateHash(WideToUTF8(module.location), &location); 974 GenerateHash(base::WideToUTF8(module.location), &location);
975 GenerateHash(WideToUTF8(module.description), &description); 975 GenerateHash(base::WideToUTF8(module.description), &description);
976 GenerateHash(WideToUTF8(module.digital_signer), &signer); 976 GenerateHash(base::WideToUTF8(module.digital_signer), &signer);
977 977
978 string16 url = l10n_util::GetStringFUTF16(IDS_HELP_CENTER_VIEW_CONFLICTS, 978 string16 url = l10n_util::GetStringFUTF16(IDS_HELP_CENTER_VIEW_CONFLICTS,
979 ASCIIToUTF16(filename), ASCIIToUTF16(location), 979 ASCIIToUTF16(filename), ASCIIToUTF16(location),
980 ASCIIToUTF16(description), ASCIIToUTF16(signer)); 980 ASCIIToUTF16(description), ASCIIToUTF16(signer));
981 return GURL(UTF16ToUTF8(url)); 981 return GURL(UTF16ToUTF8(url));
982 } 982 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698