summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/ui/webui')
-rw-r--r--chrome/browser/ui/webui/downloads_ui_browsertest.cc9
-rw-r--r--chrome/browser/ui/webui/downloads_ui_browsertest.h6
-rw-r--r--chrome/browser/ui/webui/downloads_ui_browsertest.js153
-rw-r--r--chrome/browser/ui/webui/downloads_ui_browsertest_base.js134
-rw-r--r--chrome/browser/ui/webui/downloads_ui_supervised_browsertest.cc15
-rw-r--r--chrome/browser/ui/webui/downloads_ui_supervised_browsertest.h16
-rw-r--r--chrome/browser/ui/webui/downloads_ui_supervised_browsertest.js27
-rw-r--r--chrome/browser/ui/webui/extensions/extension_settings_handler.cc2
-rw-r--r--chrome/browser/ui/webui/options/create_profile_handler.cc361
-rw-r--r--chrome/browser/ui/webui/options/create_profile_handler.h88
-rw-r--r--chrome/browser/ui/webui/options/options_ui.cc8
11 files changed, 450 insertions, 369 deletions
diff --git a/chrome/browser/ui/webui/downloads_ui_browsertest.cc b/chrome/browser/ui/webui/downloads_ui_browsertest.cc
index eafa460..025d54a 100644
--- a/chrome/browser/ui/webui/downloads_ui_browsertest.cc
+++ b/chrome/browser/ui/webui/downloads_ui_browsertest.cc
@@ -4,13 +4,9 @@
#include "chrome/browser/ui/webui/downloads_ui_browsertest.h"
-#include "base/command_line.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/supervised_user/supervised_user_service.h"
-#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/ui/browser.h"
-#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "content/public/test/test_utils.h"
@@ -22,8 +18,3 @@ void DownloadsUIBrowserTest::SetDeleteAllowed(bool allowed) {
browser()->profile()->GetPrefs()->
SetBoolean(prefs::kAllowDeletingBrowserHistory, allowed);
}
-
-void DownloadsWebUIForSupervisedUsersTest::SetUpCommandLine(
- CommandLine* command_line) {
- command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf");
-}
diff --git a/chrome/browser/ui/webui/downloads_ui_browsertest.h b/chrome/browser/ui/webui/downloads_ui_browsertest.h
index 4d35321..7b02787 100644
--- a/chrome/browser/ui/webui/downloads_ui_browsertest.h
+++ b/chrome/browser/ui/webui/downloads_ui_browsertest.h
@@ -21,10 +21,4 @@ class DownloadsUIBrowserTest : public WebUIBrowserTest {
DISALLOW_COPY_AND_ASSIGN(DownloadsUIBrowserTest);
};
-class DownloadsWebUIForSupervisedUsersTest : public DownloadsUIBrowserTest {
- public:
- // InProcessBrowserTest overrides:
- virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
-};
-
#endif // CHROME_BROWSER_UI_WEBUI_DOWNLOADS_UI_BROWSERTEST_H_
diff --git a/chrome/browser/ui/webui/downloads_ui_browsertest.js b/chrome/browser/ui/webui/downloads_ui_browsertest.js
index 4eb5bc1d..4329f4f 100644
--- a/chrome/browser/ui/webui/downloads_ui_browsertest.js
+++ b/chrome/browser/ui/webui/downloads_ui_browsertest.js
@@ -2,139 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+GEN_INCLUDE(['downloads_ui_browsertest_base.js']);
GEN('#include "chrome/browser/ui/webui/downloads_ui_browsertest.h"');
-/** @const */ var TOTAL_RESULT_COUNT = 25;
-
-/**
- * Test C++ fixture for downloads WebUI testing.
- * @constructor
- * @extends {testing.Test}
- */
-function DownloadsUIBrowserTest() {}
-
-/**
- * Base fixture for Downloads WebUI testing.
- * @extends {testing.Test}
- * @constructor
- */
-function BaseDownloadsWebUITest() {}
-
-BaseDownloadsWebUITest.prototype = {
- __proto__: testing.Test.prototype,
-
- /**
- * Browse to the downloads page & call our preLoad().
- */
- browsePreload: 'chrome://downloads/',
-
- /** @override */
- typedefCppFixture: 'DownloadsUIBrowserTest',
-
- /** @override */
- testGenPreamble: function() {
- GEN(' SetDeleteAllowed(true);');
- },
-
- /** @override */
- runAccessibilityChecks: true,
-
- /** @override */
- accessibilityIssuesAreErrors: true,
-
- /**
- * Sends TOTAL_RESULT_COUNT fake downloads to the page. This can't be called
- * in the preLoad, because it requires the global Download object to have
- * been created by the page.
- * @override
- */
- setUp: function() {
- // The entries will begin at 1:00 AM on Sept 2, 2008, and will be spaced
- // two minutes apart.
- var timestamp = new Date(2008, 9, 2, 1, 0).getTime();
- for (var i = 0; i < TOTAL_RESULT_COUNT; ++i) {
- downloads.updated(this.createDownload_(i, timestamp));
- timestamp += 2 * 60 * 1000; // Next visit is two minutes later.
- }
- expectEquals(downloads.size(), TOTAL_RESULT_COUNT);
- },
-
- /**
- * Creates a download object to be passed to the page, following the expected
- * backend format (see downloads_dom_handler.cc).
- * @param {number} A unique ID for the download.
- * @param {number} The time the download purportedly started.
- * @return {!Object} A fake download object.
- * @private
- */
- createDownload_: function(id, timestamp) {
- return {
- id: id,
- started: timestamp,
- otr: false,
- state: Download.States.COMPLETE,
- retry: false,
- file_path: '/path/to/file',
- file_url: 'http://google.com/' + timestamp,
- file_name: 'download_' + timestamp,
- url: 'http://google.com/' + timestamp,
- file_externally_removed: false,
- danger_type: Download.DangerType.NOT_DANGEROUS,
- last_reason_text: '',
- since_string: 'today',
- date_string: 'today',
- percent: 100,
- progress_status_text: 'done',
- received: 128,
- };
- },
-
- /**
- * Asserts the correctness of the state of the UI elements
- * that delete the download history.
- * @param {boolean} allowDelete True if download history deletion is
- * allowed and false otherwise.
- * @param {boolean} expectControlsHidden True if the controls to delete
- * download history are expected to be hidden and false otherwise.
- */
- testHelper: function(allowDelete, expectControlsHidden) {
- var clearAllElements = document.getElementsByClassName('clear-all-link');
- var disabledElements = document.getElementsByClassName('disabled-link');
- var removeLinkElements =
- document.getElementsByClassName('control-remove-link');
-
- // "Clear all" should be a link only when deletions are allowed.
- expectEquals(allowDelete ? 1 : 0, clearAllElements.length);
-
- // There should be no disabled links when deletions are allowed.
- // On the other hand, when deletions are not allowed, "Clear All"
- // and all "Remove from list" links should be disabled.
- expectEquals(allowDelete ? 0 : TOTAL_RESULT_COUNT + 1,
- disabledElements.length);
-
- // All "Remove from list" items should be links when deletions are allowed.
- // On the other hand, when deletions are not allowed, all
- // "Remove from list" items should be text.
- expectEquals(allowDelete ? TOTAL_RESULT_COUNT : 0,
- removeLinkElements.length);
-
- if (allowDelete) {
- // "Clear all" should not be hidden.
- expectFalse(clearAllElements[0].hidden);
-
- // No "Remove from list" items should be hidden.
- expectFalse(removeLinkElements[0].hidden);
- } else {
- expectEquals(expectControlsHidden, disabledElements[0].hidden);
- }
-
- // The model is updated synchronously, even though the actual
- // back-end removal (tested elsewhere) is asynchronous.
- clearAll();
- expectEquals(allowDelete ? 0 : TOTAL_RESULT_COUNT, downloads.size());
- },
-};
-
// Test UI when removing entries is allowed.
TEST_F('BaseDownloadsWebUITest', 'DeleteAllowed', function() {
this.testHelper(true, false);
@@ -174,24 +44,3 @@ TEST_F('DownloadsWebUIDeleteProhibitedTest', 'DeleteProhibited', function() {
// single item.
testDone();
});
-
-/**
- * Fixture for Downloads WebUI testing for a supervised user.
- * @extends {BaseDownloadsWebUITest}
- * @constructor
- */
-function DownloadsWebUIForSupervisedUsersTest() {}
-
-DownloadsWebUIForSupervisedUsersTest.prototype = {
- __proto__: BaseDownloadsWebUITest.prototype,
-
- /** @override */
- typedefCppFixture: 'DownloadsWebUIForSupervisedUsersTest',
-};
-
-// Test UI for supervised users, removing entries should be disabled
-// and removal controls should be hidden.
-TEST_F('DownloadsWebUIForSupervisedUsersTest', 'SupervisedUsers', function() {
- this.testHelper(false, true);
- testDone();
-});
diff --git a/chrome/browser/ui/webui/downloads_ui_browsertest_base.js b/chrome/browser/ui/webui/downloads_ui_browsertest_base.js
new file mode 100644
index 0000000..c6d0db0
--- /dev/null
+++ b/chrome/browser/ui/webui/downloads_ui_browsertest_base.js
@@ -0,0 +1,134 @@
+// Copyright 2014 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.
+
+/** @const */ var TOTAL_RESULT_COUNT = 25;
+
+/**
+ * Test C++ fixture for downloads WebUI testing.
+ * @constructor
+ * @extends {testing.Test}
+ */
+function DownloadsUIBrowserTest() {}
+
+/**
+ * Base fixture for Downloads WebUI testing.
+ * @extends {testing.Test}
+ * @constructor
+ */
+function BaseDownloadsWebUITest() {}
+
+BaseDownloadsWebUITest.prototype = {
+ __proto__: testing.Test.prototype,
+
+ /**
+ * Browse to the downloads page & call our preLoad().
+ */
+ browsePreload: 'chrome://downloads/',
+
+ /** @override */
+ typedefCppFixture: 'DownloadsUIBrowserTest',
+
+ /** @override */
+ testGenPreamble: function() {
+ GEN(' SetDeleteAllowed(true);');
+ },
+
+ /** @override */
+ runAccessibilityChecks: true,
+
+ /** @override */
+ accessibilityIssuesAreErrors: true,
+
+ /**
+ * Sends TOTAL_RESULT_COUNT fake downloads to the page. This can't be called
+ * in the preLoad, because it requires the global Download object to have
+ * been created by the page.
+ * @override
+ */
+ setUp: function() {
+ // The entries will begin at 1:00 AM on Sept 2, 2008, and will be spaced
+ // two minutes apart.
+ var timestamp = new Date(2008, 9, 2, 1, 0).getTime();
+ for (var i = 0; i < TOTAL_RESULT_COUNT; ++i) {
+ downloads.updated(this.createDownload_(i, timestamp));
+ timestamp += 2 * 60 * 1000; // Next visit is two minutes later.
+ }
+ expectEquals(downloads.size(), TOTAL_RESULT_COUNT);
+ },
+
+ /**
+ * Creates a download object to be passed to the page, following the expected
+ * backend format (see downloads_dom_handler.cc).
+ * @param {number} A unique ID for the download.
+ * @param {number} The time the download purportedly started.
+ * @return {!Object} A fake download object.
+ * @private
+ */
+ createDownload_: function(id, timestamp) {
+ return {
+ id: id,
+ started: timestamp,
+ otr: false,
+ state: Download.States.COMPLETE,
+ retry: false,
+ file_path: '/path/to/file',
+ file_url: 'http://google.com/' + timestamp,
+ file_name: 'download_' + timestamp,
+ url: 'http://google.com/' + timestamp,
+ file_externally_removed: false,
+ danger_type: Download.DangerType.NOT_DANGEROUS,
+ last_reason_text: '',
+ since_string: 'today',
+ date_string: 'today',
+ percent: 100,
+ progress_status_text: 'done',
+ received: 128,
+ };
+ },
+
+ /**
+ * Asserts the correctness of the state of the UI elements
+ * that delete the download history.
+ * @param {boolean} allowDelete True if download history deletion is
+ * allowed and false otherwise.
+ * @param {boolean} expectControlsHidden True if the controls to delete
+ * download history are expected to be hidden and false otherwise.
+ */
+ testHelper: function(allowDelete, expectControlsHidden) {
+ var clearAllElements = document.getElementsByClassName('clear-all-link');
+ var disabledElements = document.getElementsByClassName('disabled-link');
+ var removeLinkElements =
+ document.getElementsByClassName('control-remove-link');
+
+ // "Clear all" should be a link only when deletions are allowed.
+ expectEquals(allowDelete ? 1 : 0, clearAllElements.length);
+
+ // There should be no disabled links when deletions are allowed.
+ // On the other hand, when deletions are not allowed, "Clear All"
+ // and all "Remove from list" links should be disabled.
+ expectEquals(allowDelete ? 0 : TOTAL_RESULT_COUNT + 1,
+ disabledElements.length);
+
+ // All "Remove from list" items should be links when deletions are allowed.
+ // On the other hand, when deletions are not allowed, all
+ // "Remove from list" items should be text.
+ expectEquals(allowDelete ? TOTAL_RESULT_COUNT : 0,
+ removeLinkElements.length);
+
+ if (allowDelete) {
+ // "Clear all" should not be hidden.
+ expectFalse(clearAllElements[0].hidden);
+
+ // No "Remove from list" items should be hidden.
+ expectFalse(removeLinkElements[0].hidden);
+ } else {
+ expectEquals(expectControlsHidden, disabledElements[0].hidden);
+ }
+
+ // The model is updated synchronously, even though the actual
+ // back-end removal (tested elsewhere) is asynchronous.
+ clearAll();
+ expectEquals(allowDelete ? 0 : TOTAL_RESULT_COUNT, downloads.size());
+ },
+};
diff --git a/chrome/browser/ui/webui/downloads_ui_supervised_browsertest.cc b/chrome/browser/ui/webui/downloads_ui_supervised_browsertest.cc
new file mode 100644
index 0000000..52d7f27
--- /dev/null
+++ b/chrome/browser/ui/webui/downloads_ui_supervised_browsertest.cc
@@ -0,0 +1,15 @@
+// Copyright 2014 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.
+
+#include "chrome/browser/ui/webui/downloads_ui_supervised_browsertest.h"
+
+#include "base/command_line.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/common/chrome_switches.h"
+#include "content/public/test/test_utils.h"
+
+void DownloadsWebUIForSupervisedUsersTest::SetUpCommandLine(
+ CommandLine* command_line) {
+ command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf");
+}
diff --git a/chrome/browser/ui/webui/downloads_ui_supervised_browsertest.h b/chrome/browser/ui/webui/downloads_ui_supervised_browsertest.h
new file mode 100644
index 0000000..bf4d869
--- /dev/null
+++ b/chrome/browser/ui/webui/downloads_ui_supervised_browsertest.h
@@ -0,0 +1,16 @@
+// Copyright 2014 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.
+
+#ifndef CHROME_BROWSER_UI_WEBUI_DOWNLOADS_UI_SUPERVISED_BROWSERTEST_H_
+#define CHROME_BROWSER_UI_WEBUI_DOWNLOADS_UI_SUPERVISED_BROWSERTEST_H_
+
+#include "chrome/browser/ui/webui/downloads_ui_browsertest.h"
+
+class DownloadsWebUIForSupervisedUsersTest : public DownloadsUIBrowserTest {
+ public:
+ // InProcessBrowserTest implementation.
+ virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
+};
+
+#endif // CHROME_BROWSER_UI_WEBUI_DOWNLOADS_UI_SUPERVISED_BROWSERTEST_H_
diff --git a/chrome/browser/ui/webui/downloads_ui_supervised_browsertest.js b/chrome/browser/ui/webui/downloads_ui_supervised_browsertest.js
new file mode 100644
index 0000000..23b70d1
--- /dev/null
+++ b/chrome/browser/ui/webui/downloads_ui_supervised_browsertest.js
@@ -0,0 +1,27 @@
+// Copyright 2014 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.
+
+GEN_INCLUDE(['downloads_ui_browsertest_base.js']);
+GEN('#include "chrome/browser/ui/webui/downloads_ui_supervised_browsertest.h"');
+
+/**
+ * Fixture for Downloads WebUI testing for a supervised user.
+ * @extends {BaseDownloadsWebUITest}
+ * @constructor
+ */
+function DownloadsWebUIForSupervisedUsersTest() {}
+
+DownloadsWebUIForSupervisedUsersTest.prototype = {
+ __proto__: BaseDownloadsWebUITest.prototype,
+
+ /** @override */
+ typedefCppFixture: 'DownloadsWebUIForSupervisedUsersTest',
+};
+
+// Test UI for supervised users, removing entries should be disabled
+// and removal controls should be hidden.
+TEST_F('DownloadsWebUIForSupervisedUsersTest', 'SupervisedUsers', function() {
+ this.testHelper(false, true);
+ testDone();
+});
diff --git a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc
index 305d975..b2317ca 100644
--- a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc
+++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc
@@ -44,8 +44,6 @@
#include "chrome/browser/platform_util.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/supervised_user/supervised_user_service.h"
-#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/tab_contents/background_contents.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
diff --git a/chrome/browser/ui/webui/options/create_profile_handler.cc b/chrome/browser/ui/webui/options/create_profile_handler.cc
index 135c876..b357dbf 100644
--- a/chrome/browser/ui/webui/options/create_profile_handler.cc
+++ b/chrome/browser/ui/webui/options/create_profile_handler.cc
@@ -15,18 +15,22 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/profiles/profiles_state.h"
-#include "chrome/browser/supervised_user/supervised_user_registration_utility.h"
-#include "chrome/browser/supervised_user/supervised_user_service.h"
-#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
-#include "chrome/browser/supervised_user/supervised_user_sync_service.h"
-#include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/webui/options/options_handlers_helper.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
+#include "content/public/browser/web_ui.h"
#include "ui/base/l10n/l10n_util.h"
+#if defined(ENABLE_MANAGED_USERS)
+#include "chrome/browser/supervised_user/supervised_user_registration_utility.h"
+#include "chrome/browser/supervised_user/supervised_user_service.h"
+#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
+#include "chrome/browser/supervised_user/supervised_user_sync_service.h"
+#include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h"
+#endif
+
namespace options {
CreateProfileHandler::CreateProfileHandler()
@@ -35,7 +39,10 @@ CreateProfileHandler::CreateProfileHandler()
}
CreateProfileHandler::~CreateProfileHandler() {
+#if defined(ENABLE_MANAGED_USERS)
+ // Cancellation is only supported for supervised users.
CancelProfileRegistration(false);
+#endif
}
void CreateProfileHandler::GetLocalizedValues(
@@ -43,10 +50,13 @@ void CreateProfileHandler::GetLocalizedValues(
}
void CreateProfileHandler::RegisterMessages() {
+#if defined(ENABLE_MANAGED_USERS)
+ // Cancellation is only supported for supervised users.
web_ui()->RegisterMessageCallback(
"cancelCreateProfile",
base::Bind(&CreateProfileHandler::HandleCancelProfileCreation,
base::Unretained(this)));
+#endif
web_ui()->RegisterMessageCallback(
"createProfile",
base::Bind(&CreateProfileHandler::CreateProfile,
@@ -54,12 +64,12 @@ void CreateProfileHandler::RegisterMessages() {
}
void CreateProfileHandler::CreateProfile(const base::ListValue* args) {
+#if defined(ENABLE_MANAGED_USERS)
// This handler could have been called for a supervised user, for example
- // because the user fiddled with the web inspector. Silently return in this
- // case.
- Profile* current_profile = Profile::FromWebUI(web_ui());
- if (current_profile->IsSupervised())
+ // because the user fiddled with the web inspector. Silently return.
+ if (Profile::FromWebUI(web_ui())->IsSupervised())
return;
+#endif
if (!profiles::IsMultipleProfilesEnabled())
return;
@@ -77,44 +87,17 @@ void CreateProfileHandler::CreateProfile(const base::ListValue* args) {
base::string16 name;
base::string16 icon;
- std::string supervised_user_id;
bool create_shortcut = false;
- bool supervised_user = false;
if (args->GetString(0, &name) && args->GetString(1, &icon)) {
base::TrimWhitespace(name, base::TRIM_ALL, &name);
CHECK(!name.empty());
- if (args->GetBoolean(2, &create_shortcut)) {
- bool success = args->GetBoolean(3, &supervised_user);
- DCHECK(success);
- success = args->GetString(4, &supervised_user_id);
- DCHECK(success);
- }
- }
-
- if (supervised_user) {
- if (!IsValidExistingSupervisedUserId(supervised_user_id))
- return;
-
- profile_creation_type_ = SUPERVISED_PROFILE_IMPORT;
- if (supervised_user_id.empty()) {
- profile_creation_type_ = SUPERVISED_PROFILE_CREATION;
- supervised_user_id =
- SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId();
-
- // If sync is not yet fully initialized, the creation may take extra time,
- // so show a message. Import doesn't wait for an acknowledgement, so it
- // won't have the same potential delay.
- ProfileSyncService* sync_service =
- ProfileSyncServiceFactory::GetInstance()->GetForProfile(
- current_profile);
- ProfileSyncService::SyncStatusSummary status =
- sync_service->QuerySyncStatusSummary();
- if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) {
- ShowProfileCreationWarning(l10n_util::GetStringUTF16(
- IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN));
- }
- }
+ args->GetBoolean(2, &create_shortcut);
}
+ std::string supervised_user_id;
+#if defined(ENABLE_MANAGED_USERS)
+ if (!ProcessSupervisedCreateProfileArgs(args, &supervised_user_id))
+ return;
+#endif
ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG);
@@ -139,8 +122,7 @@ void CreateProfileHandler::OnProfileCreated(
switch (status) {
case Profile::CREATE_STATUS_LOCAL_FAIL: {
- ShowProfileCreationError(profile,
- GetProfileCreationErrorMessage(LOCAL_ERROR));
+ ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal());
break;
}
case Profile::CREATE_STATUS_CREATED: {
@@ -176,66 +158,19 @@ void CreateProfileHandler::HandleProfileCreationSuccess(
CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile);
break;
}
+#if defined(ENABLE_MANAGED_USERS)
case SUPERVISED_PROFILE_CREATION:
case SUPERVISED_PROFILE_IMPORT:
RegisterSupervisedUser(create_shortcut, desktop_type,
supervised_user_id, profile);
break;
+#endif
case NO_CREATION_IN_PROGRESS:
NOTREACHED();
break;
}
}
-void CreateProfileHandler::RegisterSupervisedUser(
- bool create_shortcut,
- chrome::HostDesktopType desktop_type,
- const std::string& supervised_user_id,
- Profile* new_profile) {
- DCHECK_EQ(profile_path_being_created_.value(),
- new_profile->GetPath().value());
-
- SupervisedUserService* supervised_user_service =
- SupervisedUserServiceFactory::GetForProfile(new_profile);
-
- // Register the supervised user using the profile of the custodian.
- supervised_user_registration_utility_ =
- SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui()));
- supervised_user_service->RegisterAndInitSync(
- supervised_user_registration_utility_.get(),
- Profile::FromWebUI(web_ui()),
- supervised_user_id,
- base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered,
- weak_ptr_factory_.GetWeakPtr(),
- create_shortcut,
- desktop_type,
- new_profile));
-}
-
-void CreateProfileHandler::OnSupervisedUserRegistered(
- bool create_shortcut,
- chrome::HostDesktopType desktop_type,
- Profile* profile,
- const GoogleServiceAuthError& error) {
- GoogleServiceAuthError::State state = error.state();
- RecordSupervisedProfileCreationMetrics(state);
- if (state == GoogleServiceAuthError::NONE) {
- CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile);
- return;
- }
-
- base::string16 error_msg;
- if (state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS ||
- state == GoogleServiceAuthError::USER_NOT_SIGNED_UP ||
- state == GoogleServiceAuthError::ACCOUNT_DELETED ||
- state == GoogleServiceAuthError::ACCOUNT_DISABLED) {
- error_msg = GetProfileCreationErrorMessage(SIGNIN_ERROR);
- } else {
- error_msg = GetProfileCreationErrorMessage(REMOTE_ERROR);
- }
- ShowProfileCreationError(profile, error_msg);
-}
-
void CreateProfileHandler::CreateShortcutAndShowSuccess(
bool create_shortcut,
chrome::HostDesktopType desktop_type,
@@ -255,10 +190,12 @@ void CreateProfileHandler::CreateShortcutAndShowSuccess(
dict.SetString("name",
profile->GetPrefs()->GetString(prefs::kProfileName));
dict.Set("filePath", base::CreateFilePathValue(profile->GetPath()));
+#if defined(ENABLE_MANAGED_USERS)
bool is_supervised =
profile_creation_type_ == SUPERVISED_PROFILE_CREATION ||
profile_creation_type_ == SUPERVISED_PROFILE_IMPORT;
dict.SetBoolean("isSupervised", is_supervised);
+#endif
web_ui()->CallJavascriptFunction(
GetJavascriptMethodName(PROFILE_CREATION_SUCCESS), dict);
@@ -267,7 +204,13 @@ void CreateProfileHandler::CreateShortcutAndShowSuccess(
// dialog. If we are importing an existing supervised profile or creating a
// new non-supervised user profile we don't show any confirmation, so open
// the new window now.
- if (profile_creation_type_ != SUPERVISED_PROFILE_CREATION) {
+ bool should_open_new_window = true;
+#if defined(ENABLE_MANAGED_USERS)
+ if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION)
+ should_open_new_window = false;
+#endif
+
+ if (should_open_new_window) {
// Opening the new window must be the last action, after all callbacks
// have been run, to give them a chance to initialize the profile.
helper::OpenNewWindowForProfile(desktop_type,
@@ -291,11 +234,109 @@ void CreateProfileHandler::ShowProfileCreationError(
helper::DeleteProfileAtPath(profile->GetPath(), web_ui());
}
-void CreateProfileHandler::ShowProfileCreationWarning(
- const base::string16& warning) {
- DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_);
- web_ui()->CallJavascriptFunction("BrowserOptions.showCreateProfileWarning",
- base::StringValue(warning));
+void CreateProfileHandler::RecordProfileCreationMetrics(
+ Profile::CreateStatus status) {
+ UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult",
+ status,
+ Profile::MAX_CREATE_STATUS);
+ UMA_HISTOGRAM_MEDIUM_TIMES(
+ "Profile.CreateTimeNoTimeout",
+ base::TimeTicks::Now() - profile_creation_start_time_);
+}
+
+base::string16 CreateProfileHandler::GetProfileCreationErrorMessageLocal()
+ const {
+ int message_id = IDS_PROFILES_CREATE_LOCAL_ERROR;
+#if defined(ENABLE_MANAGED_USERS)
+ // Local errors can occur during supervised profile import.
+ if (profile_creation_type_ == SUPERVISED_PROFILE_IMPORT)
+ message_id = IDS_SUPERVISED_USER_IMPORT_LOCAL_ERROR;
+#endif
+ return l10n_util::GetStringUTF16(message_id);
+}
+
+#if defined(ENABLE_MANAGED_USERS)
+base::string16 CreateProfileHandler::GetProfileCreationErrorMessageRemote()
+ const {
+ return l10n_util::GetStringUTF16(
+ profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
+ IDS_SUPERVISED_USER_IMPORT_REMOTE_ERROR :
+ IDS_PROFILES_CREATE_REMOTE_ERROR);
+}
+
+base::string16 CreateProfileHandler::GetProfileCreationErrorMessageSignin()
+ const {
+ return l10n_util::GetStringUTF16(
+ profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
+ IDS_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR :
+ IDS_PROFILES_CREATE_SIGN_IN_ERROR);
+}
+#endif
+
+std::string CreateProfileHandler::GetJavascriptMethodName(
+ ProfileCreationStatus status) const {
+ switch (profile_creation_type_) {
+#if defined(ENABLE_MANAGED_USERS)
+ case SUPERVISED_PROFILE_IMPORT:
+ switch (status) {
+ case PROFILE_CREATION_SUCCESS:
+ return "BrowserOptions.showSupervisedUserImportSuccess";
+ case PROFILE_CREATION_ERROR:
+ return "BrowserOptions.showSupervisedUserImportError";
+ }
+ break;
+#endif
+ default:
+ switch (status) {
+ case PROFILE_CREATION_SUCCESS:
+ return "BrowserOptions.showCreateProfileSuccess";
+ case PROFILE_CREATION_ERROR:
+ return "BrowserOptions.showCreateProfileError";
+ }
+ break;
+ }
+
+ NOTREACHED();
+ return std::string();
+}
+
+#if defined(ENABLE_MANAGED_USERS)
+bool CreateProfileHandler::ProcessSupervisedCreateProfileArgs(
+ const base::ListValue* args, std::string* supervised_user_id) {
+ bool supervised_user = false;
+ if (args->GetSize() == 4) {
+ bool success = args->GetBoolean(3, &supervised_user);
+ DCHECK(success);
+
+ success = args->GetString(4, supervised_user_id);
+ DCHECK(success);
+ }
+
+ if (supervised_user) {
+ if (!IsValidExistingSupervisedUserId(*supervised_user_id))
+ return false;
+
+ profile_creation_type_ = SUPERVISED_PROFILE_IMPORT;
+ if (supervised_user_id->empty()) {
+ profile_creation_type_ = SUPERVISED_PROFILE_CREATION;
+ *supervised_user_id =
+ SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId();
+
+ // If sync is not yet fully initialized, the creation may take extra time,
+ // so show a message. Import doesn't wait for an acknowledgment, so it
+ // won't have the same potential delay.
+ ProfileSyncService* sync_service =
+ ProfileSyncServiceFactory::GetInstance()->GetForProfile(
+ Profile::FromWebUI(web_ui()));
+ ProfileSyncService::SyncStatusSummary status =
+ sync_service->QuerySyncStatusSummary();
+ if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) {
+ ShowProfileCreationWarning(l10n_util::GetStringUTF16(
+ IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN));
+ }
+ }
+ }
+ return true;
}
void CreateProfileHandler::HandleCancelProfileCreation(
@@ -303,20 +344,20 @@ void CreateProfileHandler::HandleCancelProfileCreation(
CancelProfileRegistration(true);
}
+// Non-supervised user creation cannot be canceled. (Creating a non-supervised
+// profile shouldn't take significant time, and it can easily be deleted
+// afterward.)
void CreateProfileHandler::CancelProfileRegistration(bool user_initiated) {
if (profile_path_being_created_.empty())
return;
ProfileManager* manager = g_browser_process->profile_manager();
Profile* new_profile = manager->GetProfileByPath(profile_path_being_created_);
- if (!new_profile)
+ if (!new_profile || !new_profile->IsSupervised())
return;
- // Non-supervised user creation cannot be canceled. (Creating a non-supervised
- // profile shouldn't take significant time, and it can easily be deleted
- // afterward.)
- if (!new_profile->IsSupervised())
- return;
+ DCHECK(supervised_user_registration_utility_.get());
+ supervised_user_registration_utility_.reset();
if (user_initiated) {
UMA_HISTOGRAM_MEDIUM_TIMES(
@@ -325,9 +366,6 @@ void CreateProfileHandler::CancelProfileRegistration(bool user_initiated) {
RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED);
}
- DCHECK(supervised_user_registration_utility_.get());
- supervised_user_registration_utility_.reset();
-
DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_);
profile_creation_type_ = NO_CREATION_IN_PROGRESS;
@@ -337,14 +375,60 @@ void CreateProfileHandler::CancelProfileRegistration(bool user_initiated) {
helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui());
}
-void CreateProfileHandler::RecordProfileCreationMetrics(
- Profile::CreateStatus status) {
- UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult",
- status,
- Profile::MAX_CREATE_STATUS);
- UMA_HISTOGRAM_MEDIUM_TIMES(
- "Profile.CreateTimeNoTimeout",
- base::TimeTicks::Now() - profile_creation_start_time_);
+void CreateProfileHandler::RegisterSupervisedUser(
+ bool create_shortcut,
+ chrome::HostDesktopType desktop_type,
+ const std::string& supervised_user_id,
+ Profile* new_profile) {
+ DCHECK_EQ(profile_path_being_created_.value(),
+ new_profile->GetPath().value());
+
+ SupervisedUserService* supervised_user_service =
+ SupervisedUserServiceFactory::GetForProfile(new_profile);
+
+ // Register the supervised user using the profile of the custodian.
+ supervised_user_registration_utility_ =
+ SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui()));
+ supervised_user_service->RegisterAndInitSync(
+ supervised_user_registration_utility_.get(),
+ Profile::FromWebUI(web_ui()),
+ supervised_user_id,
+ base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered,
+ weak_ptr_factory_.GetWeakPtr(),
+ create_shortcut,
+ desktop_type,
+ new_profile));
+}
+
+void CreateProfileHandler::OnSupervisedUserRegistered(
+ bool create_shortcut,
+ chrome::HostDesktopType desktop_type,
+ Profile* profile,
+ const GoogleServiceAuthError& error) {
+ GoogleServiceAuthError::State state = error.state();
+ RecordSupervisedProfileCreationMetrics(state);
+ if (state == GoogleServiceAuthError::NONE) {
+ CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile);
+ return;
+ }
+
+ base::string16 error_msg;
+ if (state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS ||
+ state == GoogleServiceAuthError::USER_NOT_SIGNED_UP ||
+ state == GoogleServiceAuthError::ACCOUNT_DELETED ||
+ state == GoogleServiceAuthError::ACCOUNT_DISABLED) {
+ error_msg = GetProfileCreationErrorMessageSignin();
+ } else {
+ error_msg = GetProfileCreationErrorMessageRemote();
+ }
+ ShowProfileCreationError(profile, error_msg);
+}
+
+void CreateProfileHandler::ShowProfileCreationWarning(
+ const base::string16& warning) {
+ DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_);
+ web_ui()->CallJavascriptFunction("BrowserOptions.showCreateProfileWarning",
+ base::StringValue(warning));
}
void CreateProfileHandler::RecordSupervisedProfileCreationMetrics(
@@ -367,50 +451,6 @@ void CreateProfileHandler::RecordSupervisedProfileCreationMetrics(
}
}
-base::string16 CreateProfileHandler::GetProfileCreationErrorMessage(
- ProfileCreationErrorType error) const {
- int message_id = -1;
- switch (error) {
- case SIGNIN_ERROR:
- message_id =
- profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
- IDS_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR :
- IDS_PROFILES_CREATE_SIGN_IN_ERROR;
- break;
- case REMOTE_ERROR:
- message_id =
- profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
- IDS_SUPERVISED_USER_IMPORT_REMOTE_ERROR :
- IDS_PROFILES_CREATE_REMOTE_ERROR;
- break;
- case LOCAL_ERROR:
- message_id =
- profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
- IDS_SUPERVISED_USER_IMPORT_LOCAL_ERROR :
- IDS_PROFILES_CREATE_LOCAL_ERROR;
- break;
- }
-
- return l10n_util::GetStringUTF16(message_id);
-}
-
-std::string CreateProfileHandler::GetJavascriptMethodName(
- ProfileCreationStatus status) const {
- switch (status) {
- case PROFILE_CREATION_SUCCESS:
- return profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
- "BrowserOptions.showSupervisedUserImportSuccess" :
- "BrowserOptions.showCreateProfileSuccess";
- case PROFILE_CREATION_ERROR:
- return profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
- "BrowserOptions.showSupervisedUserImportError" :
- "BrowserOptions.showCreateProfileError";
- }
-
- NOTREACHED();
- return std::string();
-}
-
bool CreateProfileHandler::IsValidExistingSupervisedUserId(
const std::string& existing_supervised_user_id) const {
if (existing_supervised_user_id.empty())
@@ -433,5 +473,6 @@ bool CreateProfileHandler::IsValidExistingSupervisedUserId(
}
return true;
}
+#endif
} // namespace options
diff --git a/chrome/browser/ui/webui/options/create_profile_handler.h b/chrome/browser/ui/webui/options/create_profile_handler.h
index d6e3ea7..d299c10 100644
--- a/chrome/browser/ui/webui/options/create_profile_handler.h
+++ b/chrome/browser/ui/webui/options/create_profile_handler.h
@@ -19,7 +19,9 @@ class DictionaryValue;
class ListValue;
}
+#if defined(ENABLE_MANAGED_USERS)
class SupervisedUserRegistrationUtility;
+#endif
namespace options {
@@ -44,21 +46,14 @@ class CreateProfileHandler: public OptionsPageUIHandler {
PROFILE_CREATION_ERROR,
};
- // Represents errors that could occur during a profile creation.
- // It is used to map error types to messages that will be displayed
- // to the user.
- enum ProfileCreationErrorType {
- REMOTE_ERROR,
- LOCAL_ERROR,
- SIGNIN_ERROR
- };
-
// Represents the type of the in progress profile creation operation.
// It is used to map the type of the profile creation operation to the
// correct UMA metric name.
enum ProfileCreationOperationType {
+#if defined(ENABLE_MANAGED_USERS)
SUPERVISED_PROFILE_CREATION,
SUPERVISED_PROFILE_IMPORT,
+#endif
NON_SUPERVISED_PROFILE_CREATION,
NO_CREATION_IN_PROGRESS
};
@@ -90,19 +85,6 @@ class CreateProfileHandler: public OptionsPageUIHandler {
const std::string& supervised_user_id,
Profile* profile);
- // After a new supervised-user profile has been created, registers the user
- // with the management server.
- void RegisterSupervisedUser(bool create_shortcut,
- chrome::HostDesktopType desktop_type,
- const std::string& supervised_user_id,
- Profile* new_profile);
-
- // Called back with the result of the supervised user registration.
- void OnSupervisedUserRegistered(bool create_shortcut,
- chrome::HostDesktopType desktop_type,
- Profile* profile,
- const GoogleServiceAuthError& error);
-
// Creates desktop shortcut and updates the UI to indicate success
// when creating a profile.
void CreateShortcutAndShowSuccess(bool create_shortcut,
@@ -115,6 +97,37 @@ class CreateProfileHandler: public OptionsPageUIHandler {
// Updates the UI to show a non-fatal warning when creating a profile.
void ShowProfileCreationWarning(const base::string16& warning);
+ // Records UMA histograms relevant to profile creation.
+ void RecordProfileCreationMetrics(Profile::CreateStatus status);
+
+ base::string16 GetProfileCreationErrorMessageLocal() const;
+#if defined(ENABLE_MANAGED_USERS)
+ // The following error messages only apply to supervised profiles.
+ base::string16 GetProfileCreationErrorMessageRemote() const;
+ base::string16 GetProfileCreationErrorMessageSignin() const;
+#endif
+
+ std::string GetJavascriptMethodName(ProfileCreationStatus status) const;
+
+ // Used to allow cancelling a profile creation (particularly a supervised-user
+ // registration) in progress. Set when profile creation is begun, and
+ // cleared when all the callbacks have been run and creation is complete.
+ base::FilePath profile_path_being_created_;
+
+ // Used to track how long profile creation takes.
+ base::TimeTicks profile_creation_start_time_;
+
+ // Indicates the type of the in progress profile creation operation.
+ // The value is only relevant while we are creating/importing a profile.
+ ProfileCreationOperationType profile_creation_type_;
+
+#if defined(ENABLE_MANAGED_USERS)
+ // Extracts the supervised user ID from the args passed into CreateProfile,
+ // sets |profile_creation_type_| if necessary, and returns true if the
+ // supervised user id specified in |args| are valid.
+ bool ProcessSupervisedCreateProfileArgs(const base::ListValue* args,
+ std::string* supervised_user_id);
+
// Cancels creation of a supervised-user profile currently in progress, as
// indicated by profile_path_being_created_, removing the object and files
// and canceling supervised-user registration. This is the handler for the
@@ -127,35 +140,30 @@ class CreateProfileHandler: public OptionsPageUIHandler {
// was caused implicitly, e.g. by shutting down the browser.
void CancelProfileRegistration(bool user_initiated);
- // Records UMA histograms relevant to profile creation.
- void RecordProfileCreationMetrics(Profile::CreateStatus status);
+ // After a new supervised-user profile has been created, registers the user
+ // with the management server.
+ void RegisterSupervisedUser(bool create_shortcut,
+ chrome::HostDesktopType desktop_type,
+ const std::string& managed_user_id,
+ Profile* new_profile);
+
+ // Called back with the result of the supervised user registration.
+ void OnSupervisedUserRegistered(bool create_shortcut,
+ chrome::HostDesktopType desktop_type,
+ Profile* profile,
+ const GoogleServiceAuthError& error);
// Records UMA histograms relevant to supervised user profiles
// creation and registration.
void RecordSupervisedProfileCreationMetrics(
GoogleServiceAuthError::State error_state);
- base::string16 GetProfileCreationErrorMessage(
- ProfileCreationErrorType error) const;
- std::string GetJavascriptMethodName(ProfileCreationStatus status) const;
-
bool IsValidExistingSupervisedUserId(
const std::string& existing_supervised_user_id) const;
- // Used to allow cancelling a profile creation (particularly a supervised-user
- // registration) in progress. Set when profile creation is begun, and
- // cleared when all the callbacks have been run and creation is complete.
- base::FilePath profile_path_being_created_;
-
- // Used to track how long profile creation takes.
- base::TimeTicks profile_creation_start_time_;
-
scoped_ptr<SupervisedUserRegistrationUtility>
supervised_user_registration_utility_;
-
- // Indicates the type of the in progress profile creation operation.
- // The value is only relevant while we are creating/importing a profile.
- ProfileCreationOperationType profile_creation_type_;
+#endif
base::WeakPtrFactory<CreateProfileHandler> weak_ptr_factory_;
diff --git a/chrome/browser/ui/webui/options/options_ui.cc b/chrome/browser/ui/webui/options/options_ui.cc
index 76a997f..7581e87 100644
--- a/chrome/browser/ui/webui/options/options_ui.cc
+++ b/chrome/browser/ui/webui/options/options_ui.cc
@@ -70,6 +70,12 @@
#include "ui/base/webui/web_ui_util.h"
#include "url/gurl.h"
+#if defined(ENABLE_MANAGED_USERS)
+#include "chrome/browser/ui/webui/options/supervised_user_create_confirm_handler.h"
+#include "chrome/browser/ui/webui/options/supervised_user_import_handler.h"
+#include "chrome/browser/ui/webui/options/supervised_user_learn_more_handler.h"
+#endif
+
#if defined(OS_CHROMEOS)
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
@@ -295,11 +301,13 @@ OptionsUI::OptionsUI(content::WebUI* web_ui)
AddOptionsPageUIHandler(localized_strings, new SearchEngineManagerHandler());
AddOptionsPageUIHandler(localized_strings, new ImportDataHandler());
AddOptionsPageUIHandler(localized_strings, new StartupPagesHandler());
+#if defined(ENABLE_MANAGED_USERS)
AddOptionsPageUIHandler(localized_strings,
new SupervisedUserCreateConfirmHandler());
AddOptionsPageUIHandler(localized_strings, new SupervisedUserImportHandler());
AddOptionsPageUIHandler(localized_strings,
new SupervisedUserLearnMoreHandler());
+#endif
AddOptionsPageUIHandler(localized_strings, new SyncSetupHandler(
g_browser_process->profile_manager()));
AddOptionsPageUIHandler(localized_strings, new WebsiteSettingsHandler());