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 RunOnceValueNames RunOnceNamesForVersion(IEVersion ie_version); | |
166 bool IsPerUserSetupComplete(); | |
155 static string16 GetChromeFrameBHOCLSID(); | 167 static string16 GetChromeFrameBHOCLSID(); |
156 static bool IsAddonPromptDisabledForChromeFrame(); | 168 static bool IsAddonPromptDisabledForChromeFrame(); |
157 | 169 |
170 const IEVersion ie_version_; | |
171 RunOnceValueNames run_once_value_names_; | |
158 RegistrySetter setter_; | 172 RegistrySetter setter_; |
159 | 173 |
160 DISALLOW_COPY_AND_ASSIGN(IE9Configurator); | 174 DISALLOW_COPY_AND_ASSIGN(ModernIEConfigurator); |
161 }; | 175 }; |
162 | 176 |
163 // RegistrySetter implementation. | 177 // RegistrySetter implementation. |
164 | 178 |
165 RegistrySetter::RegistrySetter() { | 179 RegistrySetter::RegistrySetter() { |
166 } | 180 } |
167 | 181 |
168 RegistrySetter::~RegistrySetter() { | 182 RegistrySetter::~RegistrySetter() { |
169 } | 183 } |
170 | 184 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 } | 341 } |
328 | 342 |
329 void IE7Configurator::ApplySettings() { | 343 void IE7Configurator::ApplySettings() { |
330 setter_.Apply(); | 344 setter_.Apply(); |
331 } | 345 } |
332 | 346 |
333 void IE7Configurator::RevertSettings() { | 347 void IE7Configurator::RevertSettings() { |
334 setter_.Revert(); | 348 setter_.Revert(); |
335 } | 349 } |
336 | 350 |
337 // IE9Configurator implementation | 351 // ModernIEConfigurator implementation |
338 | 352 |
339 IE9Configurator::IE9Configurator() { | 353 ModernIEConfigurator::ModernIEConfigurator(IEVersion ie_version) |
354 : ie_version_(ie_version), | |
355 run_once_value_names_(RunOnceNamesForVersion(ie_version)) { | |
340 } | 356 } |
341 | 357 |
342 IE9Configurator::~IE9Configurator() { | 358 ModernIEConfigurator::~ModernIEConfigurator() { |
359 } | |
360 | |
361 // static | |
362 ModernIEConfigurator::RunOnceValueNames | |
robertshield
2012/10/14 01:30:34
how do you feel about sticking this in a construct
grt (UTC plus 2)
2012/10/15 14:16:17
Not so great. The names struct is a super-lightwe
| |
363 ModernIEConfigurator::RunOnceNamesForVersion( | |
364 IEVersion ie_version) { | |
365 RunOnceValueNames names = {}; | |
366 switch (ie_version) { | |
367 case IE_9: | |
368 names.completed = kValueIE9Completed; | |
369 names.completion_time = kValueIE9CompletionTime; | |
370 break; | |
371 case IE_10: | |
372 names.completed = kValueIE10Completed; | |
373 names.completion_time = kValueIE10CompletionTime; | |
374 break; | |
375 default: | |
376 NOTREACHED(); | |
377 } | |
378 return names; | |
343 } | 379 } |
344 | 380 |
345 // Returns true if the per-user setup is complete. | 381 // Returns true if the per-user setup is complete. |
346 // static | 382 bool ModernIEConfigurator::IsPerUserSetupComplete() { |
347 bool IE9Configurator::IsPerUserSetupComplete() { | |
348 bool is_complete = false; | 383 bool is_complete = false; |
349 base::win::RegKey key_main; | 384 base::win::RegKey key_main; |
350 | 385 |
351 if (key_main.Open(HKEY_CURRENT_USER, kKeyIEMain, | 386 if (key_main.Open(HKEY_CURRENT_USER, kKeyIEMain, |
352 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | 387 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
353 DWORD completed = 0; | 388 DWORD completed = 0; |
354 FILETIME completion_time = {}; | 389 FILETIME completion_time = {}; |
355 DWORD size = sizeof(completion_time); | 390 DWORD size = sizeof(completion_time); |
356 | 391 |
357 if (key_main.ReadValueDW(kValueIE9Completed, | 392 if (key_main.ReadValueDW(run_once_value_names_.completed, |
358 &completed) == ERROR_SUCCESS && | 393 &completed) == ERROR_SUCCESS && |
359 completed != 0 && | 394 completed != 0 && |
360 key_main.ReadValue(kValueIE9CompletionTime, &completion_time, | 395 key_main.ReadValue(run_once_value_names_.completion_time, |
361 &size, NULL) == ERROR_SUCCESS && | 396 &completion_time, &size, NULL) == ERROR_SUCCESS && |
362 size == sizeof(completion_time)) { | 397 size == sizeof(completion_time)) { |
363 is_complete = true; | 398 is_complete = true; |
364 } | 399 } |
365 } | 400 } |
366 | 401 |
367 return is_complete; | 402 return is_complete; |
368 } | 403 } |
369 | 404 |
370 // Returns the path to the IE9 Approved Extensions key for Chrome Frame. | 405 // Returns the path to the IE9 Approved Extensions key for Chrome Frame. |
371 // static | 406 // static |
372 string16 IE9Configurator::GetChromeFrameBHOCLSID() { | 407 string16 ModernIEConfigurator::GetChromeFrameBHOCLSID() { |
373 string16 bho_guid(39, L'\0'); | 408 string16 bho_guid(39, L'\0'); |
374 int guid_len = StringFromGUID2(CLSID_ChromeFrameBHO, &bho_guid[0], | 409 int guid_len = StringFromGUID2(CLSID_ChromeFrameBHO, &bho_guid[0], |
375 bho_guid.size()); | 410 bho_guid.size()); |
376 DCHECK_EQ(guid_len, static_cast<int>(bho_guid.size())); | 411 DCHECK_EQ(guid_len, static_cast<int>(bho_guid.size())); |
377 bho_guid.resize(guid_len - 1); | 412 bho_guid.resize(guid_len - 1); |
378 return bho_guid; | 413 return bho_guid; |
379 } | 414 } |
380 | 415 |
381 // Returns true if the add-on enablement prompt is disabled by Group Policy. | 416 // Returns true if the add-on enablement prompt is disabled by Group Policy. |
382 // static | 417 // static |
383 bool IE9Configurator::IsAddonPromptDisabledForChromeFrame() { | 418 bool ModernIEConfigurator::IsAddonPromptDisabledForChromeFrame() { |
384 bool is_disabled = false; | 419 bool is_disabled = false; |
385 base::win::RegKey key; | 420 base::win::RegKey key; |
386 | 421 |
387 // See if the prompt is disabled for this user of IE. | 422 // See if the prompt is disabled for this user of IE. |
388 if (key.Open(HKEY_CURRENT_USER, kKeyIEApprovedExtensions, | 423 if (key.Open(HKEY_CURRENT_USER, kKeyIEApprovedExtensions, |
389 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | 424 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
390 DWORD type = REG_NONE; | 425 DWORD type = REG_NONE; |
391 DWORD size = 0; | 426 DWORD size = 0; |
392 if (key.ReadValue(GetChromeFrameBHOCLSID().c_str(), NULL, &size, | 427 if (key.ReadValue(GetChromeFrameBHOCLSID().c_str(), NULL, &size, |
393 &type) == ERROR_SUCCESS && | 428 &type) == ERROR_SUCCESS && |
(...skipping 10 matching lines...) Expand all Loading... | |
404 if (key.ReadValueDW(kValueIgnoreFrameApprovalCheck, | 439 if (key.ReadValueDW(kValueIgnoreFrameApprovalCheck, |
405 &ignore) == ERROR_SUCCESS && | 440 &ignore) == ERROR_SUCCESS && |
406 ignore != 0) { | 441 ignore != 0) { |
407 is_disabled = true; | 442 is_disabled = true; |
408 } | 443 } |
409 } | 444 } |
410 | 445 |
411 return is_disabled; | 446 return is_disabled; |
412 } | 447 } |
413 | 448 |
414 void IE9Configurator::Initialize() { | 449 void ModernIEConfigurator::Initialize() { |
415 // Check for per-user IE setup. | 450 // Check for per-user IE setup. |
416 if (!IsPerUserSetupComplete()) { | 451 if (!IsPerUserSetupComplete()) { |
417 const HKEY root = HKEY_CURRENT_USER; | 452 const HKEY root = HKEY_CURRENT_USER; |
418 // Suppress the "Set up Internet Explorer 9" dialog. | 453 // Suppress the "Set up Internet Explorer 9" dialog. |
robertshield
2012/10/14 01:30:34
nit: no 9
grt (UTC plus 2)
2012/10/15 14:16:17
Done.
| |
419 setter_.AddDWORDValue(root, kKeyIEMain, kValueIE9Completed, 1); | 454 setter_.AddDWORDValue(root, kKeyIEMain, run_once_value_names_.completed, 1); |
420 setter_.AddFILETIMEValue(root, kKeyIEMain, kValueIE9CompletionTime, | 455 setter_.AddFILETIMEValue(root, kKeyIEMain, |
456 run_once_value_names_.completion_time, | |
421 base::Time::Now().ToFileTime()); | 457 base::Time::Now().ToFileTime()); |
422 setter_.AddDWORDValue(root, kKeyIEMain, kValueIE9LastShown, 1); | 458 if (ie_version_ == IE_9) { |
423 // Don't show a tour of IE 9. | 459 setter_.AddDWORDValue(root, kKeyIEMain, kValueIE9LastShown, 1); |
424 setter_.AddDWORDValue(root, kKeyIEMain, kValueIE9TourNoShow, 1); | 460 // Don't show a tour of IE 9. |
461 setter_.AddDWORDValue(root, kKeyIEMain, kValueIE9TourNoShow, 1); | |
462 } | |
425 // Turn off the phishing filter. | 463 // Turn off the phishing filter. |
426 setter_.AddDWORDValue(root, kKeyIEPhishingFilter, kValueEnabledV9, 0); | 464 setter_.AddDWORDValue(root, kKeyIEPhishingFilter, kValueEnabledV9, 0); |
427 // Don't download compatibility view lists. | 465 // Don't download compatibility view lists. |
428 setter_.AddDWORDValue(root, kKeyIEBrowserEmulation, | 466 setter_.AddDWORDValue(root, kKeyIEBrowserEmulation, |
429 kValueMSCompatibilityMode, 0); | 467 kValueMSCompatibilityMode, 0); |
430 } | 468 } |
431 | 469 |
432 // Turn off the "'Foo' add-on from 'Bar' is ready for use." prompt via Group | 470 // Turn off the "'Foo' add-on from 'Bar' is ready for use." prompt via Group |
433 // Policy. | 471 // Policy. |
434 if (!IsAddonPromptDisabledForChromeFrame()) { | 472 if (!IsAddonPromptDisabledForChromeFrame()) { |
435 setter_.AddDWORDValue(HKEY_LOCAL_MACHINE, kKeyPoliciesExt, | 473 setter_.AddDWORDValue(HKEY_LOCAL_MACHINE, kKeyPoliciesExt, |
436 kValueIgnoreFrameApprovalCheck, 1); | 474 kValueIgnoreFrameApprovalCheck, 1); |
437 } | 475 } |
438 } | 476 } |
439 | 477 |
440 void IE9Configurator::ApplySettings() { | 478 void ModernIEConfigurator::ApplySettings() { |
441 setter_.Apply(); | 479 setter_.Apply(); |
442 } | 480 } |
443 | 481 |
444 void IE9Configurator::RevertSettings() { | 482 void ModernIEConfigurator::RevertSettings() { |
445 setter_.Revert(); | 483 setter_.Revert(); |
446 } | 484 } |
447 | 485 |
448 } // namespace | 486 } // namespace |
449 | 487 |
450 // Configurator implementation. | 488 // Configurator implementation. |
451 | 489 |
452 IEConfigurator::IEConfigurator() { | 490 IEConfigurator::IEConfigurator() { |
453 } | 491 } |
454 | 492 |
455 IEConfigurator::~IEConfigurator() { | 493 IEConfigurator::~IEConfigurator() { |
456 } | 494 } |
457 | 495 |
458 IEConfigurator* CreateConfigurator() { | 496 IEConfigurator* CreateConfigurator() { |
459 IEConfigurator* configurator = NULL; | 497 IEConfigurator* configurator = NULL; |
460 | 498 |
461 switch (GetInstalledIEVersion()) { | 499 IEVersion ie_version = GetInstalledIEVersion(); |
500 switch (ie_version) { | |
462 case IE_7: | 501 case IE_7: |
463 configurator = new IE7Configurator(); | 502 configurator = new IE7Configurator(); |
464 break; | 503 break; |
465 case IE_9: | 504 case IE_9: |
466 configurator = new IE9Configurator(); | 505 case IE_10: |
506 configurator = new ModernIEConfigurator(ie_version); | |
467 break; | 507 break; |
468 default: | 508 default: |
469 break; | 509 break; |
470 } | 510 } |
471 | 511 |
472 return configurator; | 512 return configurator; |
473 } | 513 } |
474 | 514 |
475 void InstallIEConfigurator() { | 515 void InstallIEConfigurator() { |
476 IEConfigurator* configurator = CreateConfigurator(); | 516 IEConfigurator* configurator = CreateConfigurator(); |
477 | 517 |
478 if (configurator != NULL) { | 518 if (configurator != NULL) { |
479 testing::UnitTest::GetInstance()->listeners().Append( | 519 testing::UnitTest::GetInstance()->listeners().Append( |
480 new ConfiguratorDriver(configurator)); | 520 new ConfiguratorDriver(configurator)); |
481 } | 521 } |
482 } | 522 } |
483 | 523 |
484 } // namespace chrome_frame_test | 524 } // namespace chrome_frame_test |
OLD | NEW |