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_frame/test/ie_configurator.h" | 5 #include "chrome_frame/test/ie_configurator.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <objbase.h> | 8 #include <objbase.h> |
9 | 9 |
10 #include <ios> | 10 #include <ios> |
(...skipping 18 matching lines...) Expand all Loading... |
29 const wchar_t kKeyIEInformationBar[] = | 29 const wchar_t kKeyIEInformationBar[] = |
30 L"Software\\Microsoft\\Internet Explorer\\InformationBar"; | 30 L"Software\\Microsoft\\Internet Explorer\\InformationBar"; |
31 const wchar_t kKeyIEMain[] = | 31 const wchar_t kKeyIEMain[] = |
32 L"Software\\Microsoft\\Internet Explorer\\Main"; | 32 L"Software\\Microsoft\\Internet Explorer\\Main"; |
33 const wchar_t kKeyIEPhishingFilter[] = | 33 const wchar_t kKeyIEPhishingFilter[] = |
34 L"Software\\Microsoft\\Internet Explorer\\PhishingFilter"; | 34 L"Software\\Microsoft\\Internet Explorer\\PhishingFilter"; |
35 const wchar_t kKeyIEBrowserEmulation[] = | 35 const wchar_t kKeyIEBrowserEmulation[] = |
36 L"Software\\Microsoft\\Internet Explorer\\BrowserEmulation"; | 36 L"Software\\Microsoft\\Internet Explorer\\BrowserEmulation"; |
37 const wchar_t kKeyPoliciesExt[] = | 37 const wchar_t kKeyPoliciesExt[] = |
38 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Ext"; | 38 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Ext"; |
| 39 const wchar_t kValueEnabledV8[] = L"EnabledV8"; |
39 const wchar_t kValueEnabledV9[] = L"EnabledV9"; | 40 const wchar_t kValueEnabledV9[] = L"EnabledV9"; |
40 const wchar_t kValueFirstTime[] = L"FirstTime"; | 41 const wchar_t kValueFirstTime[] = L"FirstTime"; |
| 42 const wchar_t kValueIE8Completed[] = L"IE8RunOncePerInstallCompleted"; |
| 43 const wchar_t kValueIE8CompletionTime[] = L"IE8RunOnceCompletionTime"; |
| 44 const wchar_t kValueIE8RunOnceLastShown[] = L"IE8RunOnceLastShown"; |
| 45 const wchar_t kValueIE8RunOnceLastShownTimestamp[] = |
| 46 L"IE8RunOnceLastShown_TIMESTAMP"; |
| 47 const wchar_t kValueIE8TourNoShow[] = L"IE8TourNoShow"; |
41 const wchar_t kValueIE9Completed[] = L"IE9RunOncePerInstallCompleted"; | 48 const wchar_t kValueIE9Completed[] = L"IE9RunOncePerInstallCompleted"; |
42 const wchar_t kValueIE9CompletionTime[] = L"IE9RunOnceCompletionTime"; | 49 const wchar_t kValueIE9CompletionTime[] = L"IE9RunOnceCompletionTime"; |
43 const wchar_t kValueIE9LastShown[] = L"IE9RunOnceLastShown"; | 50 const wchar_t kValueIE9RunOnceLastShown[] = L"IE9RunOnceLastShown"; |
| 51 const wchar_t kValueIE9RunOnceLastShownTimestamp[] = |
| 52 L"IE9RunOnceLastShown_TIMESTAMP"; |
44 const wchar_t kValueIE9TourNoShow[] = L"IE9TourNoShow"; | 53 const wchar_t kValueIE9TourNoShow[] = L"IE9TourNoShow"; |
45 const wchar_t kValueIE10Completed[] = L"IE10RunOncePerInstallCompleted"; | 54 const wchar_t kValueIE10Completed[] = L"IE10RunOncePerInstallCompleted"; |
46 const wchar_t kValueIE10CompletionTime[] = L"IE10RunOnceCompletionTime"; | 55 const wchar_t kValueIE10CompletionTime[] = L"IE10RunOnceCompletionTime"; |
| 56 const wchar_t kValueIE10RunOnceLastShown[] = L"IE10RunOnceLastShown"; |
| 57 const wchar_t kValueIE10RunOnceLastShownTimestamp[] = |
| 58 L"IE10RunOnceLastShown_TIMESTAMP"; |
47 const wchar_t kValueIgnoreFrameApprovalCheck[] = L"IgnoreFrameApprovalCheck"; | 59 const wchar_t kValueIgnoreFrameApprovalCheck[] = L"IgnoreFrameApprovalCheck"; |
48 const wchar_t kValueMSCompatibilityMode[] = L"MSCompatibilityMode"; | 60 const wchar_t kValueMSCompatibilityMode[] = L"MSCompatibilityMode"; |
49 | 61 |
50 // A helper class that accumulate a set of registry mutations and corresponding | 62 // A helper class that accumulate a set of registry mutations and corresponding |
51 // undo data via calls to its Add*() methods. The mutations can be applied to | 63 // undo data via calls to its Add*() methods. The mutations can be applied to |
52 // the registry (repeatedly, if desired) via a call to Apply(). Revert() can be | 64 // the registry (repeatedly, if desired) via a call to Apply(). Revert() can be |
53 // called to apply the accumulated undo data. | 65 // called to apply the accumulated undo data. |
54 class RegistrySetter { | 66 class RegistrySetter { |
55 public: | 67 public: |
56 RegistrySetter(); | 68 RegistrySetter(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 virtual void Initialize() OVERRIDE; | 147 virtual void Initialize() OVERRIDE; |
136 virtual void ApplySettings() OVERRIDE; | 148 virtual void ApplySettings() OVERRIDE; |
137 virtual void RevertSettings() OVERRIDE; | 149 virtual void RevertSettings() OVERRIDE; |
138 | 150 |
139 private: | 151 private: |
140 RegistrySetter setter_; | 152 RegistrySetter setter_; |
141 | 153 |
142 DISALLOW_COPY_AND_ASSIGN(IE7Configurator); | 154 DISALLOW_COPY_AND_ASSIGN(IE7Configurator); |
143 }; | 155 }; |
144 | 156 |
145 // A configurator for Internet Explorer 9 and 10. | 157 // A configurator for Internet Explorer 8, 9, and 10. |
146 class ModernIEConfigurator : public IEConfigurator { | 158 class ModernIEConfigurator : public IEConfigurator { |
147 public: | 159 public: |
148 explicit ModernIEConfigurator(IEVersion ie_version); | 160 explicit ModernIEConfigurator(IEVersion ie_version); |
149 virtual ~ModernIEConfigurator(); | 161 virtual ~ModernIEConfigurator(); |
150 | 162 |
151 virtual void Initialize() OVERRIDE; | 163 virtual void Initialize() OVERRIDE; |
152 virtual void ApplySettings() OVERRIDE; | 164 virtual void ApplySettings() OVERRIDE; |
153 virtual void RevertSettings() OVERRIDE; | 165 virtual void RevertSettings() OVERRIDE; |
154 | 166 |
155 private: | 167 private: |
156 // The names of the registry values used to determine if IE's one-time | 168 // The names of the registry values used to determine if IE's one-time |
157 // initialization has been completed. | 169 // initialization has been completed. |
158 struct RunOnceValueNames { | 170 struct RunOnceValueNames { |
159 // This DWORD value is non-zero once initialization has been completed. | 171 // This DWORD value is non-zero once initialization has been completed. |
160 const wchar_t* completed; | 172 const wchar_t* completed; |
161 // This 8-byte binary value is the FILETIME of completion. | 173 // This 8-byte binary value is the FILETIME of completion. |
162 const wchar_t* completion_time; | 174 const wchar_t* completion_time; |
| 175 // This DWORD value is non-zero if run-once was previously deferred. |
| 176 const wchar_t* last_shown; |
| 177 // This 8-byte binary value is the FILETIME of run-once deferral. |
| 178 const wchar_t* last_shown_timestamp; |
163 }; | 179 }; |
164 | 180 |
| 181 static const RunOnceValueNames kIE8ValueNames; |
165 static const RunOnceValueNames kIE9ValueNames; | 182 static const RunOnceValueNames kIE9ValueNames; |
166 static const RunOnceValueNames kIE10ValueNames; | 183 static const RunOnceValueNames kIE10ValueNames; |
167 | 184 |
168 static const RunOnceValueNames* RunOnceNamesForVersion(IEVersion ie_version); | 185 static const RunOnceValueNames* RunOnceNamesForVersion(IEVersion ie_version); |
169 bool IsPerUserSetupComplete(); | 186 bool IsPerUserSetupComplete(); |
170 static string16 GetChromeFrameBHOCLSID(); | 187 static string16 GetChromeFrameBHOCLSID(); |
171 static bool IsAddonPromptDisabledForChromeFrame(); | 188 static bool IsAddonPromptDisabledForChromeFrame(); |
172 | 189 |
173 const IEVersion ie_version_; | 190 const IEVersion ie_version_; |
174 const RunOnceValueNames* run_once_value_names_; | 191 const RunOnceValueNames* run_once_value_names_; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 setter_.Apply(); | 364 setter_.Apply(); |
348 } | 365 } |
349 | 366 |
350 void IE7Configurator::RevertSettings() { | 367 void IE7Configurator::RevertSettings() { |
351 setter_.Revert(); | 368 setter_.Revert(); |
352 } | 369 } |
353 | 370 |
354 // ModernIEConfigurator implementation | 371 // ModernIEConfigurator implementation |
355 | 372 |
356 const ModernIEConfigurator::RunOnceValueNames | 373 const ModernIEConfigurator::RunOnceValueNames |
| 374 ModernIEConfigurator::kIE8ValueNames = { |
| 375 kValueIE8Completed, |
| 376 kValueIE8CompletionTime, |
| 377 kValueIE8RunOnceLastShown, |
| 378 kValueIE8RunOnceLastShownTimestamp, |
| 379 }; |
| 380 |
| 381 const ModernIEConfigurator::RunOnceValueNames |
357 ModernIEConfigurator::kIE9ValueNames = { | 382 ModernIEConfigurator::kIE9ValueNames = { |
358 kValueIE9Completed, | 383 kValueIE9Completed, |
359 kValueIE9CompletionTime, | 384 kValueIE9CompletionTime, |
| 385 kValueIE9RunOnceLastShown, |
| 386 kValueIE9RunOnceLastShownTimestamp, |
360 }; | 387 }; |
361 | 388 |
362 const ModernIEConfigurator::RunOnceValueNames | 389 const ModernIEConfigurator::RunOnceValueNames |
363 ModernIEConfigurator::kIE10ValueNames = { | 390 ModernIEConfigurator::kIE10ValueNames = { |
364 kValueIE10Completed, | 391 kValueIE10Completed, |
365 kValueIE10CompletionTime, | 392 kValueIE10CompletionTime, |
| 393 kValueIE10RunOnceLastShown, |
| 394 kValueIE10RunOnceLastShownTimestamp, |
366 }; | 395 }; |
367 | 396 |
368 ModernIEConfigurator::ModernIEConfigurator(IEVersion ie_version) | 397 ModernIEConfigurator::ModernIEConfigurator(IEVersion ie_version) |
369 : ie_version_(ie_version), | 398 : ie_version_(ie_version), |
370 run_once_value_names_(RunOnceNamesForVersion(ie_version)) { | 399 run_once_value_names_(RunOnceNamesForVersion(ie_version)) { |
371 } | 400 } |
372 | 401 |
373 ModernIEConfigurator::~ModernIEConfigurator() { | 402 ModernIEConfigurator::~ModernIEConfigurator() { |
374 } | 403 } |
375 | 404 |
376 // static | 405 // static |
377 const ModernIEConfigurator::RunOnceValueNames* | 406 const ModernIEConfigurator::RunOnceValueNames* |
378 ModernIEConfigurator::RunOnceNamesForVersion( | 407 ModernIEConfigurator::RunOnceNamesForVersion( |
379 IEVersion ie_version) { | 408 IEVersion ie_version) { |
380 switch (ie_version) { | 409 switch (ie_version) { |
| 410 case IE_8: |
| 411 return &kIE8ValueNames; |
| 412 break; |
381 case IE_9: | 413 case IE_9: |
382 return &kIE9ValueNames; | 414 return &kIE9ValueNames; |
383 break; | 415 break; |
384 case IE_10: | 416 case IE_10: |
385 return &kIE10ValueNames; | 417 return &kIE10ValueNames; |
386 break; | 418 break; |
387 default: | 419 default: |
388 NOTREACHED(); | 420 NOTREACHED(); |
389 } | 421 } |
390 return NULL; | 422 return NULL; |
391 } | 423 } |
392 | 424 |
393 // Returns true if the per-user setup is complete. | 425 // Returns true if the per-user setup is complete. |
394 bool ModernIEConfigurator::IsPerUserSetupComplete() { | 426 bool ModernIEConfigurator::IsPerUserSetupComplete() { |
395 bool is_complete = false; | 427 bool is_complete = false; |
396 base::win::RegKey key_main; | 428 base::win::RegKey key_main; |
397 | 429 |
398 if (key_main.Open(HKEY_CURRENT_USER, kKeyIEMain, | 430 if (key_main.Open(HKEY_CURRENT_USER, kKeyIEMain, |
399 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | 431 KEY_QUERY_VALUE) != ERROR_SUCCESS) { |
400 DWORD completed = 0; | 432 return false; |
401 FILETIME completion_time = {}; | |
402 DWORD size = sizeof(completion_time); | |
403 | |
404 if (key_main.ReadValueDW(run_once_value_names_->completed, | |
405 &completed) == ERROR_SUCCESS && | |
406 completed != 0 && | |
407 key_main.ReadValue(run_once_value_names_->completion_time, | |
408 &completion_time, &size, NULL) == ERROR_SUCCESS && | |
409 size == sizeof(completion_time)) { | |
410 is_complete = true; | |
411 } | |
412 } | 433 } |
413 | 434 |
414 return is_complete; | 435 DWORD dword_value = 0; |
| 436 FILETIME shown_time = {}; |
| 437 FILETIME completion_time = {}; |
| 438 DWORD size = sizeof(completion_time); |
| 439 |
| 440 // See if the user has seen the first-run prompt. |
| 441 if (key_main.ReadValue(run_once_value_names_->last_shown_timestamp, |
| 442 &shown_time, &size, NULL) != ERROR_SUCCESS || |
| 443 size != sizeof(shown_time)) { |
| 444 return false; |
| 445 } |
| 446 |
| 447 // See if setup was completed. |
| 448 if (key_main.ReadValue(run_once_value_names_->completion_time, |
| 449 &completion_time, &size, NULL) != ERROR_SUCCESS || |
| 450 size != sizeof(completion_time)) { |
| 451 return false; |
| 452 } |
| 453 |
| 454 // See if setup was completed after the last time the prompt was shown. |
| 455 base::Time time_shown = base::Time::FromFileTime(shown_time); |
| 456 base::Time time_completed = base::Time::FromFileTime(completion_time); |
| 457 if (time_shown >= time_completed) |
| 458 return false; |
| 459 |
| 460 return true; |
415 } | 461 } |
416 | 462 |
417 // Returns the path to the IE9 Approved Extensions key for Chrome Frame. | 463 // Returns the path to the IE9 Approved Extensions key for Chrome Frame. |
418 // static | 464 // static |
419 string16 ModernIEConfigurator::GetChromeFrameBHOCLSID() { | 465 string16 ModernIEConfigurator::GetChromeFrameBHOCLSID() { |
420 string16 bho_guid(39, L'\0'); | 466 string16 bho_guid(39, L'\0'); |
421 int guid_len = StringFromGUID2(CLSID_ChromeFrameBHO, &bho_guid[0], | 467 int guid_len = StringFromGUID2(CLSID_ChromeFrameBHO, &bho_guid[0], |
422 bho_guid.size()); | 468 bho_guid.size()); |
423 DCHECK_EQ(guid_len, static_cast<int>(bho_guid.size())); | 469 DCHECK_EQ(guid_len, static_cast<int>(bho_guid.size())); |
424 bho_guid.resize(guid_len - 1); | 470 bho_guid.resize(guid_len - 1); |
(...skipping 29 matching lines...) Expand all Loading... |
454 is_disabled = true; | 500 is_disabled = true; |
455 } | 501 } |
456 } | 502 } |
457 | 503 |
458 return is_disabled; | 504 return is_disabled; |
459 } | 505 } |
460 | 506 |
461 void ModernIEConfigurator::Initialize() { | 507 void ModernIEConfigurator::Initialize() { |
462 // Check for per-user IE setup. | 508 // Check for per-user IE setup. |
463 if (!IsPerUserSetupComplete()) { | 509 if (!IsPerUserSetupComplete()) { |
| 510 base::Time time(base::Time::Now()); |
464 const HKEY root = HKEY_CURRENT_USER; | 511 const HKEY root = HKEY_CURRENT_USER; |
465 // Suppress the "Set up Internet Explorer" dialog. | 512 // Suppress the "Set up Internet Explorer" dialog. |
| 513 setter_.AddDWORDValue(root, kKeyIEMain, run_once_value_names_->last_shown, |
| 514 1); |
466 setter_.AddDWORDValue(root, kKeyIEMain, run_once_value_names_->completed, | 515 setter_.AddDWORDValue(root, kKeyIEMain, run_once_value_names_->completed, |
467 1); | 516 1); |
468 setter_.AddFILETIMEValue(root, kKeyIEMain, | 517 setter_.AddFILETIMEValue(root, kKeyIEMain, |
| 518 run_once_value_names_->last_shown_timestamp, |
| 519 time.ToFileTime()); |
| 520 time += base::TimeDelta::FromMilliseconds(10); |
| 521 setter_.AddFILETIMEValue(root, kKeyIEMain, |
469 run_once_value_names_->completion_time, | 522 run_once_value_names_->completion_time, |
470 base::Time::Now().ToFileTime()); | 523 time.ToFileTime()); |
471 if (ie_version_ == IE_9) { | 524 if (ie_version_ < IE_10) { |
472 setter_.AddDWORDValue(root, kKeyIEMain, kValueIE9LastShown, 1); | 525 // Don't show a tour of IE 8 and 9. |
473 // Don't show a tour of IE 9. | 526 setter_.AddDWORDValue( |
474 setter_.AddDWORDValue(root, kKeyIEMain, kValueIE9TourNoShow, 1); | 527 root, |
| 528 kKeyIEMain, |
| 529 (ie_version_ == IE_8 ? kValueIE8TourNoShow : kValueIE9TourNoShow), |
| 530 1); |
475 } | 531 } |
476 // Turn off the phishing filter. | 532 // Turn off the phishing filter. |
477 setter_.AddDWORDValue(root, kKeyIEPhishingFilter, kValueEnabledV9, 0); | 533 setter_.AddDWORDValue( |
| 534 root, |
| 535 kKeyIEPhishingFilter, |
| 536 (ie_version_ == IE_8 ? kValueEnabledV8 : kValueEnabledV9), |
| 537 0); |
478 // Don't download compatibility view lists. | 538 // Don't download compatibility view lists. |
479 setter_.AddDWORDValue(root, kKeyIEBrowserEmulation, | 539 setter_.AddDWORDValue(root, kKeyIEBrowserEmulation, |
480 kValueMSCompatibilityMode, 0); | 540 kValueMSCompatibilityMode, 0); |
481 } | 541 } |
482 | 542 |
483 // Turn off the "'Foo' add-on from 'Bar' is ready for use." prompt via Group | 543 // Turn off the "'Foo' add-on from 'Bar' is ready for use." prompt via Group |
484 // Policy. | 544 // Policy. |
485 if (!IsAddonPromptDisabledForChromeFrame()) { | 545 if (!IsAddonPromptDisabledForChromeFrame()) { |
486 setter_.AddDWORDValue(HKEY_LOCAL_MACHINE, kKeyPoliciesExt, | 546 setter_.AddDWORDValue(HKEY_LOCAL_MACHINE, kKeyPoliciesExt, |
487 kValueIgnoreFrameApprovalCheck, 1); | 547 kValueIgnoreFrameApprovalCheck, 1); |
(...skipping 19 matching lines...) Expand all Loading... |
507 } | 567 } |
508 | 568 |
509 IEConfigurator* CreateConfigurator() { | 569 IEConfigurator* CreateConfigurator() { |
510 IEConfigurator* configurator = NULL; | 570 IEConfigurator* configurator = NULL; |
511 | 571 |
512 IEVersion ie_version = GetInstalledIEVersion(); | 572 IEVersion ie_version = GetInstalledIEVersion(); |
513 switch (ie_version) { | 573 switch (ie_version) { |
514 case IE_7: | 574 case IE_7: |
515 configurator = new IE7Configurator(); | 575 configurator = new IE7Configurator(); |
516 break; | 576 break; |
| 577 case IE_8: |
517 case IE_9: | 578 case IE_9: |
518 case IE_10: | 579 case IE_10: |
519 configurator = new ModernIEConfigurator(ie_version); | 580 configurator = new ModernIEConfigurator(ie_version); |
520 break; | 581 break; |
521 default: | 582 default: |
522 break; | 583 break; |
523 } | 584 } |
524 | 585 |
525 return configurator; | 586 return configurator; |
526 } | 587 } |
527 | 588 |
528 void InstallIEConfigurator() { | 589 void InstallIEConfigurator() { |
529 IEConfigurator* configurator = CreateConfigurator(); | 590 IEConfigurator* configurator = CreateConfigurator(); |
530 | 591 |
531 if (configurator != NULL) { | 592 if (configurator != NULL) { |
532 testing::UnitTest::GetInstance()->listeners().Append( | 593 testing::UnitTest::GetInstance()->listeners().Append( |
533 new ConfiguratorDriver(configurator)); | 594 new ConfiguratorDriver(configurator)); |
534 } | 595 } |
535 } | 596 } |
536 | 597 |
537 } // namespace chrome_frame_test | 598 } // namespace chrome_frame_test |
OLD | NEW |