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 24 matching lines...) Expand all Loading... |
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 kValueEnabledV9[] = L"EnabledV9"; | 39 const wchar_t kValueEnabledV9[] = L"EnabledV9"; |
40 const wchar_t kValueFirstTime[] = L"FirstTime"; | 40 const wchar_t kValueFirstTime[] = L"FirstTime"; |
41 const wchar_t kValueIE9Completed[] = L"IE9RunOncePerInstallCompleted"; | 41 const wchar_t kValueIE9Completed[] = L"IE9RunOncePerInstallCompleted"; |
42 const wchar_t kValueIE9CompletionTime[] = L"IE9RunOnceCompletionTime"; | 42 const wchar_t kValueIE9CompletionTime[] = L"IE9RunOnceCompletionTime"; |
43 const wchar_t kValueIE9LastShown[] = L"IE9RunOnceLastShown"; | 43 const wchar_t kValueIE9LastShown[] = L"IE9RunOnceLastShown"; |
44 const wchar_t kValueIE9TourNoShow[] = L"IE9TourNoShow"; | 44 const wchar_t kValueIE9TourNoShow[] = L"IE9TourNoShow"; |
| 45 const wchar_t kValueIE10Completed[] = L"IE10RunOncePerInstallCompleted"; |
| 46 const wchar_t kValueIE10CompletionTime[] = L"IE10RunOnceCompletionTime"; |
45 const wchar_t kValueIgnoreFrameApprovalCheck[] = L"IgnoreFrameApprovalCheck"; | 47 const wchar_t kValueIgnoreFrameApprovalCheck[] = L"IgnoreFrameApprovalCheck"; |
46 const wchar_t kValueMSCompatibilityMode[] = L"MSCompatibilityMode"; | 48 const wchar_t kValueMSCompatibilityMode[] = L"MSCompatibilityMode"; |
47 | 49 |
48 // A helper class that accumulate a set of registry mutations and corresponding | 50 // A helper class that accumulate a set of registry mutations and corresponding |
49 // undo data via calls to its Add*() methods. The mutations can be applied to | 51 // undo data via calls to its Add*() methods. The mutations can be applied to |
50 // the registry (repeatedly, if desired) via a call to Apply(). Revert() can be | 52 // the registry (repeatedly, if desired) via a call to Apply(). Revert() can be |
51 // called to apply the accumulated undo data. | 53 // called to apply the accumulated undo data. |
52 class RegistrySetter { | 54 class RegistrySetter { |
53 public: | 55 public: |
54 RegistrySetter(); | 56 RegistrySetter(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 virtual void Initialize() OVERRIDE; | 135 virtual void Initialize() OVERRIDE; |
134 virtual void ApplySettings() OVERRIDE; | 136 virtual void ApplySettings() OVERRIDE; |
135 virtual void RevertSettings() OVERRIDE; | 137 virtual void RevertSettings() OVERRIDE; |
136 | 138 |
137 private: | 139 private: |
138 RegistrySetter setter_; | 140 RegistrySetter setter_; |
139 | 141 |
140 DISALLOW_COPY_AND_ASSIGN(IE7Configurator); | 142 DISALLOW_COPY_AND_ASSIGN(IE7Configurator); |
141 }; | 143 }; |
142 | 144 |
143 // A configurator for Internet Explorer 9. | 145 // A configurator for Internet Explorer 9 and 10. |
144 class IE9Configurator : public IEConfigurator { | 146 class ModernIEConfigurator : public IEConfigurator { |
145 public: | 147 public: |
146 IE9Configurator(); | 148 explicit ModernIEConfigurator(IEVersion ie_version); |
147 virtual ~IE9Configurator(); | 149 virtual ~ModernIEConfigurator(); |
148 | 150 |
149 virtual void Initialize() OVERRIDE; | 151 virtual void Initialize() OVERRIDE; |
150 virtual void ApplySettings() OVERRIDE; | 152 virtual void ApplySettings() OVERRIDE; |
151 virtual void RevertSettings() OVERRIDE; | 153 virtual void RevertSettings() OVERRIDE; |
152 | 154 |
153 private: | 155 private: |
154 static bool IsPerUserSetupComplete(); | 156 // The names of the registry values used to determine if IE's one-time |
| 157 // initialization has been completed. |
| 158 struct RunOnceValueNames { |
| 159 // This DWORD value is non-zero once initialization has been completed. |
| 160 const wchar_t* completed; |
| 161 // This 8-byte binary value is the FILETIME of completion. |
| 162 const wchar_t* completion_time; |
| 163 }; |
| 164 |
| 165 static const RunOnceValueNames kIE9ValueNames; |
| 166 static const RunOnceValueNames kIE10ValueNames; |
| 167 |
| 168 static const RunOnceValueNames* RunOnceNamesForVersion(IEVersion ie_version); |
| 169 bool IsPerUserSetupComplete(); |
155 static string16 GetChromeFrameBHOCLSID(); | 170 static string16 GetChromeFrameBHOCLSID(); |
156 static bool IsAddonPromptDisabledForChromeFrame(); | 171 static bool IsAddonPromptDisabledForChromeFrame(); |
157 | 172 |
| 173 const IEVersion ie_version_; |
| 174 const RunOnceValueNames* run_once_value_names_; |
158 RegistrySetter setter_; | 175 RegistrySetter setter_; |
159 | 176 |
160 DISALLOW_COPY_AND_ASSIGN(IE9Configurator); | 177 DISALLOW_COPY_AND_ASSIGN(ModernIEConfigurator); |
161 }; | 178 }; |
162 | 179 |
163 // RegistrySetter implementation. | 180 // RegistrySetter implementation. |
164 | 181 |
165 RegistrySetter::RegistrySetter() { | 182 RegistrySetter::RegistrySetter() { |
166 } | 183 } |
167 | 184 |
168 RegistrySetter::~RegistrySetter() { | 185 RegistrySetter::~RegistrySetter() { |
169 } | 186 } |
170 | 187 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 } | 344 } |
328 | 345 |
329 void IE7Configurator::ApplySettings() { | 346 void IE7Configurator::ApplySettings() { |
330 setter_.Apply(); | 347 setter_.Apply(); |
331 } | 348 } |
332 | 349 |
333 void IE7Configurator::RevertSettings() { | 350 void IE7Configurator::RevertSettings() { |
334 setter_.Revert(); | 351 setter_.Revert(); |
335 } | 352 } |
336 | 353 |
337 // IE9Configurator implementation | 354 // ModernIEConfigurator implementation |
338 | 355 |
339 IE9Configurator::IE9Configurator() { | 356 const ModernIEConfigurator::RunOnceValueNames |
| 357 ModernIEConfigurator::kIE9ValueNames = { |
| 358 kValueIE9Completed, |
| 359 kValueIE9CompletionTime, |
| 360 }; |
| 361 |
| 362 const ModernIEConfigurator::RunOnceValueNames |
| 363 ModernIEConfigurator::kIE10ValueNames = { |
| 364 kValueIE10Completed, |
| 365 kValueIE10CompletionTime, |
| 366 }; |
| 367 |
| 368 ModernIEConfigurator::ModernIEConfigurator(IEVersion ie_version) |
| 369 : ie_version_(ie_version), |
| 370 run_once_value_names_(RunOnceNamesForVersion(ie_version)) { |
340 } | 371 } |
341 | 372 |
342 IE9Configurator::~IE9Configurator() { | 373 ModernIEConfigurator::~ModernIEConfigurator() { |
| 374 } |
| 375 |
| 376 // static |
| 377 const ModernIEConfigurator::RunOnceValueNames* |
| 378 ModernIEConfigurator::RunOnceNamesForVersion( |
| 379 IEVersion ie_version) { |
| 380 switch (ie_version) { |
| 381 case IE_9: |
| 382 return &kIE9ValueNames; |
| 383 break; |
| 384 case IE_10: |
| 385 return &kIE10ValueNames; |
| 386 break; |
| 387 default: |
| 388 NOTREACHED(); |
| 389 } |
| 390 return NULL; |
343 } | 391 } |
344 | 392 |
345 // Returns true if the per-user setup is complete. | 393 // Returns true if the per-user setup is complete. |
346 // static | 394 bool ModernIEConfigurator::IsPerUserSetupComplete() { |
347 bool IE9Configurator::IsPerUserSetupComplete() { | |
348 bool is_complete = false; | 395 bool is_complete = false; |
349 base::win::RegKey key_main; | 396 base::win::RegKey key_main; |
350 | 397 |
351 if (key_main.Open(HKEY_CURRENT_USER, kKeyIEMain, | 398 if (key_main.Open(HKEY_CURRENT_USER, kKeyIEMain, |
352 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | 399 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
353 DWORD completed = 0; | 400 DWORD completed = 0; |
354 FILETIME completion_time = {}; | 401 FILETIME completion_time = {}; |
355 DWORD size = sizeof(completion_time); | 402 DWORD size = sizeof(completion_time); |
356 | 403 |
357 if (key_main.ReadValueDW(kValueIE9Completed, | 404 if (key_main.ReadValueDW(run_once_value_names_->completed, |
358 &completed) == ERROR_SUCCESS && | 405 &completed) == ERROR_SUCCESS && |
359 completed != 0 && | 406 completed != 0 && |
360 key_main.ReadValue(kValueIE9CompletionTime, &completion_time, | 407 key_main.ReadValue(run_once_value_names_->completion_time, |
361 &size, NULL) == ERROR_SUCCESS && | 408 &completion_time, &size, NULL) == ERROR_SUCCESS && |
362 size == sizeof(completion_time)) { | 409 size == sizeof(completion_time)) { |
363 is_complete = true; | 410 is_complete = true; |
364 } | 411 } |
365 } | 412 } |
366 | 413 |
367 return is_complete; | 414 return is_complete; |
368 } | 415 } |
369 | 416 |
370 // Returns the path to the IE9 Approved Extensions key for Chrome Frame. | 417 // Returns the path to the IE9 Approved Extensions key for Chrome Frame. |
371 // static | 418 // static |
372 string16 IE9Configurator::GetChromeFrameBHOCLSID() { | 419 string16 ModernIEConfigurator::GetChromeFrameBHOCLSID() { |
373 string16 bho_guid(39, L'\0'); | 420 string16 bho_guid(39, L'\0'); |
374 int guid_len = StringFromGUID2(CLSID_ChromeFrameBHO, &bho_guid[0], | 421 int guid_len = StringFromGUID2(CLSID_ChromeFrameBHO, &bho_guid[0], |
375 bho_guid.size()); | 422 bho_guid.size()); |
376 DCHECK_EQ(guid_len, static_cast<int>(bho_guid.size())); | 423 DCHECK_EQ(guid_len, static_cast<int>(bho_guid.size())); |
377 bho_guid.resize(guid_len - 1); | 424 bho_guid.resize(guid_len - 1); |
378 return bho_guid; | 425 return bho_guid; |
379 } | 426 } |
380 | 427 |
381 // Returns true if the add-on enablement prompt is disabled by Group Policy. | 428 // Returns true if the add-on enablement prompt is disabled by Group Policy. |
382 // static | 429 // static |
383 bool IE9Configurator::IsAddonPromptDisabledForChromeFrame() { | 430 bool ModernIEConfigurator::IsAddonPromptDisabledForChromeFrame() { |
384 bool is_disabled = false; | 431 bool is_disabled = false; |
385 base::win::RegKey key; | 432 base::win::RegKey key; |
386 | 433 |
387 // See if the prompt is disabled for this user of IE. | 434 // See if the prompt is disabled for this user of IE. |
388 if (key.Open(HKEY_CURRENT_USER, kKeyIEApprovedExtensions, | 435 if (key.Open(HKEY_CURRENT_USER, kKeyIEApprovedExtensions, |
389 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | 436 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
390 DWORD type = REG_NONE; | 437 DWORD type = REG_NONE; |
391 DWORD size = 0; | 438 DWORD size = 0; |
392 if (key.ReadValue(GetChromeFrameBHOCLSID().c_str(), NULL, &size, | 439 if (key.ReadValue(GetChromeFrameBHOCLSID().c_str(), NULL, &size, |
393 &type) == ERROR_SUCCESS && | 440 &type) == ERROR_SUCCESS && |
(...skipping 10 matching lines...) Expand all Loading... |
404 if (key.ReadValueDW(kValueIgnoreFrameApprovalCheck, | 451 if (key.ReadValueDW(kValueIgnoreFrameApprovalCheck, |
405 &ignore) == ERROR_SUCCESS && | 452 &ignore) == ERROR_SUCCESS && |
406 ignore != 0) { | 453 ignore != 0) { |
407 is_disabled = true; | 454 is_disabled = true; |
408 } | 455 } |
409 } | 456 } |
410 | 457 |
411 return is_disabled; | 458 return is_disabled; |
412 } | 459 } |
413 | 460 |
414 void IE9Configurator::Initialize() { | 461 void ModernIEConfigurator::Initialize() { |
415 // Check for per-user IE setup. | 462 // Check for per-user IE setup. |
416 if (!IsPerUserSetupComplete()) { | 463 if (!IsPerUserSetupComplete()) { |
417 const HKEY root = HKEY_CURRENT_USER; | 464 const HKEY root = HKEY_CURRENT_USER; |
418 // Suppress the "Set up Internet Explorer 9" dialog. | 465 // Suppress the "Set up Internet Explorer" dialog. |
419 setter_.AddDWORDValue(root, kKeyIEMain, kValueIE9Completed, 1); | 466 setter_.AddDWORDValue(root, kKeyIEMain, run_once_value_names_->completed, |
420 setter_.AddFILETIMEValue(root, kKeyIEMain, kValueIE9CompletionTime, | 467 1); |
| 468 setter_.AddFILETIMEValue(root, kKeyIEMain, |
| 469 run_once_value_names_->completion_time, |
421 base::Time::Now().ToFileTime()); | 470 base::Time::Now().ToFileTime()); |
422 setter_.AddDWORDValue(root, kKeyIEMain, kValueIE9LastShown, 1); | 471 if (ie_version_ == IE_9) { |
423 // Don't show a tour of IE 9. | 472 setter_.AddDWORDValue(root, kKeyIEMain, kValueIE9LastShown, 1); |
424 setter_.AddDWORDValue(root, kKeyIEMain, kValueIE9TourNoShow, 1); | 473 // Don't show a tour of IE 9. |
| 474 setter_.AddDWORDValue(root, kKeyIEMain, kValueIE9TourNoShow, 1); |
| 475 } |
425 // Turn off the phishing filter. | 476 // Turn off the phishing filter. |
426 setter_.AddDWORDValue(root, kKeyIEPhishingFilter, kValueEnabledV9, 0); | 477 setter_.AddDWORDValue(root, kKeyIEPhishingFilter, kValueEnabledV9, 0); |
427 // Don't download compatibility view lists. | 478 // Don't download compatibility view lists. |
428 setter_.AddDWORDValue(root, kKeyIEBrowserEmulation, | 479 setter_.AddDWORDValue(root, kKeyIEBrowserEmulation, |
429 kValueMSCompatibilityMode, 0); | 480 kValueMSCompatibilityMode, 0); |
430 } | 481 } |
431 | 482 |
432 // Turn off the "'Foo' add-on from 'Bar' is ready for use." prompt via Group | 483 // Turn off the "'Foo' add-on from 'Bar' is ready for use." prompt via Group |
433 // Policy. | 484 // Policy. |
434 if (!IsAddonPromptDisabledForChromeFrame()) { | 485 if (!IsAddonPromptDisabledForChromeFrame()) { |
435 setter_.AddDWORDValue(HKEY_LOCAL_MACHINE, kKeyPoliciesExt, | 486 setter_.AddDWORDValue(HKEY_LOCAL_MACHINE, kKeyPoliciesExt, |
436 kValueIgnoreFrameApprovalCheck, 1); | 487 kValueIgnoreFrameApprovalCheck, 1); |
437 } | 488 } |
438 } | 489 } |
439 | 490 |
440 void IE9Configurator::ApplySettings() { | 491 void ModernIEConfigurator::ApplySettings() { |
441 setter_.Apply(); | 492 setter_.Apply(); |
442 } | 493 } |
443 | 494 |
444 void IE9Configurator::RevertSettings() { | 495 void ModernIEConfigurator::RevertSettings() { |
445 setter_.Revert(); | 496 setter_.Revert(); |
446 } | 497 } |
447 | 498 |
448 } // namespace | 499 } // namespace |
449 | 500 |
450 // Configurator implementation. | 501 // Configurator implementation. |
451 | 502 |
452 IEConfigurator::IEConfigurator() { | 503 IEConfigurator::IEConfigurator() { |
453 } | 504 } |
454 | 505 |
455 IEConfigurator::~IEConfigurator() { | 506 IEConfigurator::~IEConfigurator() { |
456 } | 507 } |
457 | 508 |
458 IEConfigurator* CreateConfigurator() { | 509 IEConfigurator* CreateConfigurator() { |
459 IEConfigurator* configurator = NULL; | 510 IEConfigurator* configurator = NULL; |
460 | 511 |
461 switch (GetInstalledIEVersion()) { | 512 IEVersion ie_version = GetInstalledIEVersion(); |
| 513 switch (ie_version) { |
462 case IE_7: | 514 case IE_7: |
463 configurator = new IE7Configurator(); | 515 configurator = new IE7Configurator(); |
464 break; | 516 break; |
465 case IE_9: | 517 case IE_9: |
466 configurator = new IE9Configurator(); | 518 case IE_10: |
| 519 configurator = new ModernIEConfigurator(ie_version); |
467 break; | 520 break; |
468 default: | 521 default: |
469 break; | 522 break; |
470 } | 523 } |
471 | 524 |
472 return configurator; | 525 return configurator; |
473 } | 526 } |
474 | 527 |
475 void InstallIEConfigurator() { | 528 void InstallIEConfigurator() { |
476 IEConfigurator* configurator = CreateConfigurator(); | 529 IEConfigurator* configurator = CreateConfigurator(); |
477 | 530 |
478 if (configurator != NULL) { | 531 if (configurator != NULL) { |
479 testing::UnitTest::GetInstance()->listeners().Append( | 532 testing::UnitTest::GetInstance()->listeners().Append( |
480 new ConfiguratorDriver(configurator)); | 533 new ConfiguratorDriver(configurator)); |
481 } | 534 } |
482 } | 535 } |
483 | 536 |
484 } // namespace chrome_frame_test | 537 } // namespace chrome_frame_test |
OLD | NEW |