Index: modules/overlay/overlay.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/overlay/overlay.module,v
retrieving revision 1.31
diff -u -p -r1.31 overlay.module
--- modules/overlay/overlay.module	31 Aug 2010 15:04:09 -0000	1.31
+++ modules/overlay/overlay.module	7 Oct 2010 07:27:23 -0000
@@ -77,6 +77,7 @@ function overlay_form_user_profile_form_
         '#description' => t('Show administrative pages on top of the page you started from.'),
         '#default_value' => isset($account->data['overlay']) ? $account->data['overlay'] : 1,
       );
+      $form['#submit'][] = 'overlay_control_submit';
     }
   }
 }
@@ -91,6 +92,19 @@ function overlay_user_presave(&$edit, $a
 }
 
 /**
+ * Submit handler for the overlay toggle on the user account page.
+ */
+function overlay_control_submit($form, &$form_state) {
+  // If the current user just enabled the overlay for themselves, set a session
+  // variable which causes overlay_init() to redirect into the overlay
+  // immediately on the next page request.
+  global $user;
+  if ($user->uid == $form_state['user']->uid && !empty($form_state['values']['overlay']) && empty($form_state['user']->data['overlay'])) {
+    $_SESSION['overlay_enable_redirect'] = 1;
+  }
+}
+
+/**
  * Implements hook_init().
  *
  * Determine whether the current page request is destined to appear in the
@@ -108,11 +122,17 @@ function overlay_init() {
   $use_overlay = !isset($user->data['overlay']) || $user->data['overlay'];
   if (empty($mode) && user_access('access overlay') && $use_overlay) {
     $current_path = current_path();
-    // After overlay is enabled on the modules page, redirect to
-    // <front>#overlay=admin/modules to actually enable the overlay.
+    // If the overlay has just been enabled on the current page (for example,
+    // the modules page at admin/modules), redirect to the same page in the
+    // overlay (for example, <front>#overlay=admin/modules) to actually enable
+    // the overlay.
     if (isset($_SESSION['overlay_enable_redirect']) && $_SESSION['overlay_enable_redirect']) {
       unset($_SESSION['overlay_enable_redirect']);
-      drupal_goto('<front>', array('fragment' => 'overlay=' . $current_path));
+	  if ($current_path == 'user/' . $user->uid . '/edit') {
+	 	drupal_goto('user/' . $user->uid, array('fragment' => 'overlay=' . $current_path));
+	  } else {
+	 	drupal_goto('<front>', array('fragment' => 'overlay=' . $current_path));
+	  }
     }
 
     if (isset($_GET['render']) && $_GET['render'] == 'overlay') {
