| 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 // NOTE: This code is a legacy utility API for partners to check whether | 5 // NOTE: This code is a legacy utility API for partners to check whether |
| 6 // Chrome can be installed and launched. Recent updates are being made | 6 // Chrome can be installed and launched. Recent updates are being made |
| 7 // to add new functionality. These updates use code from Chromium, the old | 7 // to add new functionality. These updates use code from Chromium, the old |
| 8 // coded against the win32 api directly. If you have an itch to shave a | 8 // coded against the win32 api directly. If you have an itch to shave a |
| 9 // yak, feel free to re-write the old code too. | 9 // yak, feel free to re-write the old code too. |
| 10 | 10 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 } | 312 } |
| 313 delete[] token_user; | 313 delete[] token_user; |
| 314 } | 314 } |
| 315 ::CloseHandle(process_token); | 315 ::CloseHandle(process_token); |
| 316 } | 316 } |
| 317 ::CloseHandle(process_handle); | 317 ::CloseHandle(process_handle); |
| 318 return result; | 318 return result; |
| 319 } | 319 } |
| 320 } // namespace | 320 } // namespace |
| 321 | 321 |
| 322 BOOL __stdcall GoogleChromeCompatibilityCheck(BOOL set_flag, DWORD* reasons) { | 322 BOOL __stdcall GoogleChromeCompatibilityCheck(BOOL set_flag, |
| 323 int shell_mode, |
| 324 DWORD* reasons) { |
| 323 DWORD local_reasons = 0; | 325 DWORD local_reasons = 0; |
| 324 | 326 |
| 325 WindowsVersion windows_version = GetWindowsVersion(); | 327 WindowsVersion windows_version = GetWindowsVersion(); |
| 326 // System requirements? | 328 // System requirements? |
| 327 if (windows_version == VERSION_BELOW_XP_SP2) | 329 if (windows_version == VERSION_BELOW_XP_SP2) |
| 328 local_reasons |= GCCC_ERROR_OSNOTSUPPORTED; | 330 local_reasons |= GCCC_ERROR_OSNOTSUPPORTED; |
| 329 | 331 |
| 330 if (IsChromeInstalled(HKEY_LOCAL_MACHINE)) | 332 if (IsChromeInstalled(HKEY_LOCAL_MACHINE)) |
| 331 local_reasons |= GCCC_ERROR_SYSTEMLEVELALREADYPRESENT; | 333 local_reasons |= GCCC_ERROR_SYSTEMLEVELALREADYPRESENT; |
| 332 | 334 |
| 333 if (IsChromeInstalled(HKEY_CURRENT_USER)) | 335 if (IsChromeInstalled(HKEY_CURRENT_USER)) |
| 334 local_reasons |= GCCC_ERROR_USERLEVELALREADYPRESENT; | 336 local_reasons |= GCCC_ERROR_USERLEVELALREADYPRESENT; |
| 335 | 337 |
| 336 if (!VerifyHKLMAccess()) { | 338 if (shell_mode == GCAPI_INVOKED_UAC_ELEVATION) { |
| 339 // Only check that we have HKLM write permissions if we specify that |
| 340 // GCAPI is being invoked from an elevated shell, or in admin mode |
| 341 if (!VerifyHKLMAccess()) { |
| 337 local_reasons |= GCCC_ERROR_ACCESSDENIED; | 342 local_reasons |= GCCC_ERROR_ACCESSDENIED; |
| 338 } else if ((windows_version == VERSION_VISTA_OR_HIGHER) && | 343 } else if ((windows_version == VERSION_VISTA_OR_HIGHER) && |
| 339 !VerifyAdminGroup()) { | 344 !VerifyAdminGroup()) { |
| 340 // For Vista or later check for elevation since even for admin user we could | 345 // For Vista or later check for elevation since even for admin user we could |
| 341 // be running in non-elevated mode. We require integrity level High. | 346 // be running in non-elevated mode. We require integrity level High. |
| 342 local_reasons |= GCCC_ERROR_INTEGRITYLEVEL; | 347 local_reasons |= GCCC_ERROR_INTEGRITYLEVEL; |
| 348 } |
| 343 } | 349 } |
| 344 | 350 |
| 345 // Then only check whether we can re-offer, if everything else is OK. | 351 // Then only check whether we can re-offer, if everything else is OK. |
| 346 if (local_reasons == 0 && !CanReOfferChrome(set_flag)) | 352 if (local_reasons == 0 && !CanReOfferChrome(set_flag)) |
| 347 local_reasons |= GCCC_ERROR_ALREADYOFFERED; | 353 local_reasons |= GCCC_ERROR_ALREADYOFFERED; |
| 348 | 354 |
| 349 // Done. Copy/return results. | 355 // Done. Copy/return results. |
| 350 if (reasons != NULL) | 356 if (reasons != NULL) |
| 351 *reasons = local_reasons; | 357 *reasons = local_reasons; |
| 352 | 358 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 if (days_since_last_run == std::numeric_limits<int>::max()) { | 543 if (days_since_last_run == std::numeric_limits<int>::max()) { |
| 538 days_since_last_run = -1; | 544 days_since_last_run = -1; |
| 539 } | 545 } |
| 540 | 546 |
| 541 return days_since_last_run; | 547 return days_since_last_run; |
| 542 } | 548 } |
| 543 | 549 |
| 544 BOOL __stdcall CanOfferReactivation(const wchar_t* brand_code, | 550 BOOL __stdcall CanOfferReactivation(const wchar_t* brand_code, |
| 545 int previous_brand_codes_length, | 551 int previous_brand_codes_length, |
| 546 const wchar_t** previous_brand_codes, | 552 const wchar_t** previous_brand_codes, |
| 553 int shell_mode, |
| 547 DWORD* error_code) { | 554 DWORD* error_code) { |
| 548 DCHECK(error_code); | 555 DCHECK(error_code); |
| 549 | 556 |
| 550 if (!brand_code || | 557 if (!brand_code || |
| 551 (previous_brand_codes_length > 0 && previous_brand_codes == NULL)) { | 558 (previous_brand_codes_length > 0 && previous_brand_codes == NULL)) { |
| 552 if (error_code) | 559 if (error_code) |
| 553 *error_code = REACTIVATE_ERROR_INVALID_INPUT; | 560 *error_code = REACTIVATE_ERROR_INVALID_INPUT; |
| 554 return FALSE; | 561 return FALSE; |
| 555 } | 562 } |
| 556 | 563 |
| 557 bool has_system_install = IsChromeInstalled(HKEY_LOCAL_MACHINE); | 564 bool has_system_install = IsChromeInstalled(HKEY_LOCAL_MACHINE); |
| 558 bool has_user_install = IsChromeInstalled(HKEY_CURRENT_USER); | 565 bool has_user_install = IsChromeInstalled(HKEY_CURRENT_USER); |
| 559 | 566 |
| 560 if (!has_system_install && !has_user_install) { | 567 if (!has_system_install && !has_user_install) { |
| 561 if (error_code) | 568 if (error_code) |
| 562 *error_code = REACTIVATE_ERROR_NOTINSTALLED; | 569 *error_code = REACTIVATE_ERROR_NOTINSTALLED; |
| 563 return FALSE; | 570 return FALSE; |
| 564 } | 571 } |
| 565 | 572 |
| 566 int days_since_last_run = GoogleChromeDaysSinceLastRun(); | 573 int days_since_last_run = GoogleChromeDaysSinceLastRun(); |
| 567 if (days_since_last_run >= 0 && | 574 if (days_since_last_run >= 0 && |
| 568 days_since_last_run < kReactivationMinDaysDormant) { | 575 days_since_last_run < kReactivationMinDaysDormant) { |
| 569 if (error_code) | 576 if (error_code) |
| 570 *error_code = REACTIVATE_ERROR_NOTDORMANT; | 577 *error_code = REACTIVATE_ERROR_NOTDORMANT; |
| 571 return FALSE; | 578 return FALSE; |
| 572 } | 579 } |
| 573 | 580 |
| 574 // Make sure we haven't previously been reactivated by this brand code | 581 // Make sure we haven't previously been reactivated by this brand code |
| 575 // or any of the previous brand codes from this partner. | 582 // or any of the previous brand codes from this partner. |
| 576 std::vector<std::wstring> reactivation_brands; | 583 // Since this function is invoked by ReactivateChrome, and since |
| 577 reactivation_brands.push_back(brand_code); | 584 // ReactivateChrome is called first in non-elevated shell and |
| 578 if (previous_brand_codes_length > 0 && previous_brand_codes != NULL) { | 585 // second in UAC-elevated shell, we only want to execute this block |
| 579 std::copy(previous_brand_codes, | 586 // of code the first time, in non-elevated mode. |
| 580 previous_brand_codes + previous_brand_codes_length, | 587 if (shell_mode == GCAPI_INVOKED_STANDARD_SHELL) { |
| 581 std::back_inserter(reactivation_brands)); | 588 std::vector<std::wstring> reactivation_brands; |
| 582 } | 589 reactivation_brands.push_back(brand_code); |
| 583 if (HasBeenReactivatedByBrandCodes(reactivation_brands)) { | 590 if (previous_brand_codes_length > 0 && previous_brand_codes != NULL) { |
| 584 if (error_code) | 591 std::copy(previous_brand_codes, |
| 585 *error_code = REACTIVATE_ERROR_ALREADY_REACTIVATED; | 592 previous_brand_codes + previous_brand_codes_length, |
| 586 return FALSE; | 593 std::back_inserter(reactivation_brands)); |
| 594 } |
| 595 if (HasBeenReactivatedByBrandCodes(reactivation_brands)) { |
| 596 if (error_code) |
| 597 *error_code = REACTIVATE_ERROR_ALREADY_REACTIVATED; |
| 598 return FALSE; |
| 599 } |
| 587 } | 600 } |
| 588 | 601 |
| 589 return TRUE; | 602 return TRUE; |
| 590 } | 603 } |
| 591 | 604 |
| 592 BOOL __stdcall ReactivateChrome(wchar_t* brand_code, | 605 BOOL __stdcall ReactivateChrome(wchar_t* brand_code, |
| 593 int previous_brand_codes_length, | 606 int previous_brand_codes_length, |
| 594 const wchar_t** previous_brand_codes, | 607 const wchar_t** previous_brand_codes, |
| 608 int shell_mode, |
| 595 DWORD* error_code) { | 609 DWORD* error_code) { |
| 596 BOOL result = FALSE; | 610 BOOL result = FALSE; |
| 597 if (CanOfferReactivation(brand_code, | 611 if (CanOfferReactivation(brand_code, |
| 598 previous_brand_codes_length, | 612 previous_brand_codes_length, |
| 599 previous_brand_codes, | 613 previous_brand_codes, |
| 614 shell_mode, |
| 600 error_code)) { | 615 error_code)) { |
| 601 if (SetReactivationBrandCode(brand_code)) { | 616 if (SetReactivationBrandCode(brand_code, shell_mode)) { |
| 602 // Currently set this as a best-effort thing. We return TRUE if | 617 // Currently set this as a best-effort thing. We return TRUE if |
| 603 // reactivation succeeded regardless of the experiment label result. | 618 // reactivation succeeded regardless of the experiment label result. |
| 604 SetOmahaExperimentLabel(brand_code); | 619 SetOmahaExperimentLabel(brand_code, shell_mode); |
| 605 | 620 |
| 606 result = TRUE; | 621 result = TRUE; |
| 607 } else { | 622 } else { |
| 608 if (error_code) | 623 if (error_code) |
| 609 *error_code = REACTIVATE_ERROR_REACTIVATION_FAILED; | 624 *error_code = REACTIVATE_ERROR_REACTIVATION_FAILED; |
| 610 } | 625 } |
| 611 } | 626 } |
| 612 | 627 |
| 613 return result; | 628 return result; |
| 614 } | 629 } |
| 615 | 630 |
| OLD | NEW |