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.
5 #include "chrome/browser/extensions/scoped_gaia_auth_extension.h"
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"
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"
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();
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);
41 int manifest_resource_id = IDR_GAIA_AUTH_MANIFEST;
43 #if defined(OS_CHROMEOS)
44 if (chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation())
45 manifest_resource_id = IDR_GAIA_AUTH_KEYBOARD_MANIFEST;
46 else if (command_line->HasSwitch(chromeos::switches::kEnableSamlSignin))
47 manifest_resource_id = IDR_GAIA_AUTH_SAML_MANIFEST;
48 #elif !defined(OS_ANDROID)
49 if (command_line->HasSwitch(switches::kEnableInlineSignin))
50 manifest_resource_id = IDR_GAIA_AUTH_INLINE_MANIFEST;
53 component_loader->Add(manifest_resource_id,
54 base::FilePath(FILE_PATH_LITERAL("gaia_auth")));
57 void UnloadGaiaAuthExtension(Profile* profile) {
58 const char kGaiaAuthId[] = "mfffpogegjflfpflabcdkioaeobkgjik";
59 GetComponentLoader(profile)->Remove(kGaiaAuthId);
64 ScopedGaiaAuthExtension::ScopedGaiaAuthExtension(Profile* profile)
66 LoadGaiaAuthExtension(profile_);
69 ScopedGaiaAuthExtension::~ScopedGaiaAuthExtension() {
70 UnloadGaiaAuthExtension(profile_);