- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / scoped_gaia_auth_extension.cc
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   int manifest_resource_id = IDR_GAIA_AUTH_MANIFEST;
42
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;
51 #endif
52
53   component_loader->Add(manifest_resource_id,
54                         base::FilePath(FILE_PATH_LITERAL("gaia_auth")));
55 }
56
57 void UnloadGaiaAuthExtension(Profile* profile) {
58   const char kGaiaAuthId[] = "mfffpogegjflfpflabcdkioaeobkgjik";
59   GetComponentLoader(profile)->Remove(kGaiaAuthId);
60 }
61
62 }  // namespace
63
64 ScopedGaiaAuthExtension::ScopedGaiaAuthExtension(Profile* profile)
65     : profile_(profile) {
66   LoadGaiaAuthExtension(profile_);
67 }
68
69 ScopedGaiaAuthExtension::~ScopedGaiaAuthExtension() {
70   UnloadGaiaAuthExtension(profile_);
71 }