1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/extensions/scoped_gaia_auth_extension.h" 6 7 #include "base/command_line.h" 8 #include "chrome/browser/extensions/component_loader.h" 9 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_system.h" 11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/common/chrome_constants.h" 13 #include "chrome/common/chrome_switches.h" 14 #include "grit/browser_resources.h" 15 16 #if defined(OS_CHROMEOS) 17 #include "chrome/browser/chromeos/system/input_device_settings.h" 18 #include "chromeos/chromeos_constants.h" 19 #include "chromeos/chromeos_switches.h" 20 #endif 21 22 namespace { 23 24 extensions::ComponentLoader* GetComponentLoader(Profile* profile) { 25 extensions::ExtensionSystem* extension_system = 26 extensions::ExtensionSystem::Get(profile); 27 ExtensionService* extension_service = extension_system->extension_service(); 28 return extension_service->component_loader(); 29 } 30 31 void LoadGaiaAuthExtension(Profile* profile) { 32 extensions::ComponentLoader* component_loader = GetComponentLoader(profile); 33 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 34 if (command_line->HasSwitch(switches::kAuthExtensionPath)) { 35 base::FilePath auth_extension_path = 36 command_line->GetSwitchValuePath(switches::kAuthExtensionPath); 37 component_loader->Add(IDR_GAIA_AUTH_MANIFEST, auth_extension_path); 38 return; 39 } 40 41 bool force_keyboard_oobe = false; 42 #if defined(OS_CHROMEOS) 43 force_keyboard_oobe = 44 chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation(); 45 #endif // OS_CHROMEOS 46 if (force_keyboard_oobe) { 47 component_loader->Add(IDR_GAIA_AUTH_KEYBOARD_MANIFEST, 48 base::FilePath(FILE_PATH_LITERAL("gaia_auth"))); 49 } else { 50 component_loader->Add(IDR_GAIA_AUTH_MANIFEST, 51 base::FilePath(FILE_PATH_LITERAL("gaia_auth"))); 52 } 53 } 54 55 void UnloadGaiaAuthExtension(Profile* profile) { 56 const char kGaiaAuthId[] = "mfffpogegjflfpflabcdkioaeobkgjik"; 57 GetComponentLoader(profile)->Remove(kGaiaAuthId); 58 } 59 60 } // namespace 61 62 ScopedGaiaAuthExtension::ScopedGaiaAuthExtension(Profile* profile) 63 : profile_(profile) { 64 LoadGaiaAuthExtension(profile_); 65 } 66 67 ScopedGaiaAuthExtension::~ScopedGaiaAuthExtension() { 68 UnloadGaiaAuthExtension(profile_); 69 } 70