Index: chrome/browser/extensions/extension_managed_mode_api.cc |
=================================================================== |
--- chrome/browser/extensions/extension_managed_mode_api.cc (revision 0) |
+++ chrome/browser/extensions/extension_managed_mode_api.cc (revision 0) |
@@ -0,0 +1,71 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Implementation of the Chrome Extensions Managed Mode API. |
+ |
+#include "chrome/browser/extensions/extension_managed_mode_api.h" |
+ |
+#include <string> |
+ |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/extensions/extension_preference_api_constants.h" |
+#include "chrome/browser/prefs/pref_service.h" |
Bernhard Bauer
2012/03/01 16:32:14
Nit: Remove one empty line here, but add empty lin
|
+ |
+ |
+namespace { |
+// Extension-pref key corresponding to the kInManagedMode browser pref. |
+const char kManagedModeEnabledKey[] = "managedModeEnabled"; |
+ |
+// Key to report whether the attempt to enable managed mode succeeded. |
+const char kEnableSuccessKey[] = "success"; |
+} // namespace |
+ |
+namespace keys = extension_preference_api_constants; |
+ |
+GetManagedModeFunction::~GetManagedModeFunction() { } |
+ |
+bool GetManagedModeFunction::RunImpl() { |
+ std::string browser_pref; |
+ if (!ValidateBrowserPref(kManagedModeEnabledKey, &browser_pref)) |
Bernhard Bauer
2012/03/01 16:32:14
What does it mean when this check fails? The key i
|
+ return false; |
+ PrefService* local_state = g_browser_process->local_state(); |
+ bool enabled = local_state->GetBoolean(browser_pref.c_str()); |
Bernhard Bauer
2012/03/01 16:32:14
Hm, thinking about it, we could directly use the p
|
+ |
+ // Since only one managed-mode extension can be active at a time, this |
+ // extension can control the value iff it is not currently enabled. |
+ // (This will need to be fixed if we ever have a policy or command-line |
+ // switch to prohibit managed mode.) |
+ std::string level_of_control = enabled ? keys::kNotControllable |
Bernhard Bauer
2012/03/01 16:32:14
I'm not sure if this makes anything clearer to the
Pam (message me for reviews)
2012/03/01 20:47:34
My goal was to keep the get() method as close to t
Bernhard Bauer
2012/03/02 09:23:58
OK. We still might to think about what controllabl
|
+ : keys::kControllableByThisExtension; |
+ |
+ scoped_ptr<DictionaryValue> result(new DictionaryValue); |
+ result->SetBoolean(keys::kValue, enabled); |
+ result->SetString(keys::kLevelOfControl, level_of_control); |
+ result_.reset(result.release()); |
+ return true; |
+} |
+ |
+EnableManagedModeFunction::~EnableManagedModeFunction() { } |
+ |
+bool EnableManagedModeFunction::RunImpl() { |
+ std::string browser_pref; |
+ if (!ValidateBrowserPref(kManagedModeEnabledKey, &browser_pref)) |
+ return false; |
+ PrefService* local_state = g_browser_process->local_state(); |
+ bool enabled = local_state->GetBoolean(browser_pref.c_str()); |
+ |
+ bool confirmed = true; |
+ if (!enabled) { |
+ // TODO(pamg): WIP. Show modal password dialog and save hashed password. Set |
+ // callback_result to false if user cancels dialog. |
+ |
+ if (confirmed) |
+ local_state->SetBoolean(browser_pref.c_str(), true); |
+ } |
+ |
+ scoped_ptr<DictionaryValue> result(new DictionaryValue); |
+ result->SetBoolean(kEnableSuccessKey, confirmed); |
+ result_.reset(result.release()); |
+ return true; |
+} |
Property changes on: chrome\browser\extensions\extension_managed_mode_api.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |