Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Unified Diff: chrome/browser/ui/cocoa/profiles/user_manager_mac.mm

Issue 1261433013: Implement online reauth UI for Locked Profiles on Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix views code Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/profiles/user_manager_mac.mm
diff --git a/chrome/browser/ui/cocoa/profiles/user_manager_mac.mm b/chrome/browser/ui/cocoa/profiles/user_manager_mac.mm
index 5c8b1ae7c3db6f0d4fb83d4fff9db488fd38ed7f..159ccb5baf60da743c14f98995cfa2fa19472393 100644
--- a/chrome/browser/ui/cocoa/profiles/user_manager_mac.mm
+++ b/chrome/browser/ui/cocoa/profiles/user_manager_mac.mm
@@ -12,6 +12,7 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/profiles/profiles_state.h"
+#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/ui/browser_dialogs.h"
#import "chrome/browser/ui/cocoa/browser_window_utils.h"
#include "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
@@ -25,7 +26,6 @@
#include "ui/events/keycodes/keyboard_codes.h"
namespace {
-
// Update the App Controller with a new Profile. Used when a Profile is locked
// to set the Controller to the Guest profile so the old Profile's bookmarks,
// etc... cannot be accessed.
@@ -45,6 +45,11 @@ void ChangeAppControllerForProfile(Profile* profile,
UserManagerMac* instance_ = NULL; // Weak.
BOOL instance_under_construction_ = NO;
+void CloseInstanceReauthDialog() {
+ DCHECK(instance_);
+ instance_->CloseReauthDialog();
+}
+
// Custom WebContentsDelegate that allows handling of hotkeys.
class UserManagerWebContentsDelegate : public content::WebContentsDelegate {
public:
@@ -75,6 +80,103 @@ class UserManagerWebContentsDelegate : public content::WebContentsDelegate {
}
};
+class ReauthDialogDelegate : public profiles::ReauthDialogObserver,
+ public UserManagerWebContentsDelegate {
+ public:
+ ReauthDialogDelegate(content::WebContents* web_contents, std::string email)
+ : profiles::ReauthDialogObserver(web_contents, email),
+ web_contents_(web_contents),
+ email_address_(email) {
+ Observe(web_contents);
Roger Tawa OOO till Jul 10th 2015/08/05 13:36:05 Can you put this Observe() call into the ctor of R
anthonyvd 2015/08/05 18:20:44 Done.
+ }
+
+ // profiles::ReauthDialogObserver:
+ void CloseReauthDialog() override {
+ CloseInstanceReauthDialog();
+ }
+
+ private:
+ content::WebContents* web_contents_;
+ std::string email_address_;
+
+ DISALLOW_COPY_AND_ASSIGN(ReauthDialogDelegate);
+};
+
+@interface ReauthDialogWindowController
+ : NSWindowController <NSWindowDelegate> {
+ @private
+ std::string emailAddress_;
+ scoped_ptr<content::WebContents> webContents_;
+ scoped_ptr<ReauthDialogDelegate> webContentsDelegate_;
+ NSModalSession modalSession_;
+}
+- (void)windowWillClose:(NSNotification*)notification;
+- (id)initWithProfile:(Profile*)profile email:(std::string)email;
+@end
+
+@implementation ReauthDialogWindowController
+- (void)windowWillClose:(NSNotification*)notification {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [NSApp endModalSession:modalSession_];
+}
+
+- (id)initWithProfile:(Profile*)profile email:(std::string)email {
+ emailAddress_ = email;
+ // Center the window on the screen that currently has focus.
+ NSScreen* mainScreen = [NSScreen mainScreen];
+ CGFloat screenHeight = [mainScreen frame].size.height;
+ CGFloat screenWidth = [mainScreen frame].size.width;
+ NSRect contentRect =
+ NSMakeRect((screenWidth - UserManager::kReauthDialogWidth) / 2,
+ (screenHeight - UserManager::kReauthDialogHeight) / 2,
+ UserManager::kReauthDialogWidth,
+ UserManager::kReauthDialogHeight);
+ ChromeEventProcessingWindow* window = [[ChromeEventProcessingWindow alloc]
+ initWithContentRect:contentRect
+ styleMask:NSTitledWindowMask |
+ NSClosableWindowMask |
+ NSResizableWindowMask
+ backing:NSBackingStoreBuffered
+ defer:NO
+ screen:mainScreen];
+ [window setTitle:l10n_util::GetNSString(IDS_PRODUCT_NAME)];
+ [window setMinSize:NSMakeSize(UserManager::kReauthDialogWidth,
+ UserManager::kReauthDialogHeight)];
+
+ if ((self = [super initWithWindow:window])) {
+ // Initialize the web view.
+ webContents_.reset(content::WebContents::Create(
+ content::WebContents::CreateParams(profile)));
+ window.contentView = webContents_->GetNativeView();
+ webContentsDelegate_.reset(
+ new ReauthDialogDelegate(webContents_.get(), emailAddress_));
+ webContents_->SetDelegate(webContentsDelegate_.get());
+ DCHECK(window.contentView);
+
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(windowWillClose:)
+ name:NSWindowWillCloseNotification
+ object:self.window];
+ [self show];
+ }
+ return self;
+}
+
+- (void)show {
+ GURL url = signin::GetReauthURLWithEmail(emailAddress_);
+ webContents_->GetController().LoadURL(url, content::Referrer(),
+ ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
+ std::string());
+ modalSession_ = [NSApp beginModalSessionForWindow:[self window]];
+ [NSApp runModalSession:modalSession_];
+}
+
+- (void)close {
+ [[self window] close];
+}
+@end
+
// Window controller for the User Manager view.
@interface UserManagerWindowController : NSWindowController <NSWindowDelegate> {
@private
@@ -238,7 +340,25 @@ void UserManager::OnUserManagerShown() {
// static
void UserManager::ShowReauthDialog(content::BrowserContext* browser_context,
const std::string& email) {
- // TODO(rogerta): See equivalent views implementation in user_manager_view.cc.
+ DCHECK(instance_);
+ instance_->ShowReauthDialog(browser_context, email);
+}
+
+void UserManagerMac::ShowReauthDialog(content::BrowserContext* browser_context,
+ const std::string& email) {
+ if (reauthWindow_) {
+ [reauthWindow_ close];
+ }
+
+ reauthWindow_.reset(
+ [[ReauthDialogWindowController alloc]
+ initWithProfile:Profile::FromBrowserContext(browser_context)
+ email:email]);
+}
+
+void UserManagerMac::CloseReauthDialog() {
+ [reauthWindow_ close];
+ reauthWindow_.reset();
}
UserManagerMac::UserManagerMac(Profile* profile) {
@@ -270,6 +390,9 @@ void UserManagerMac::LogTimeToOpen() {
}
void UserManagerMac::WindowWasClosed() {
+ if (reauthWindow_) {
+ CloseReauthDialog();
+ }
instance_ = NULL;
delete this;
}

Powered by Google App Engine
This is Rietveld 408576698