OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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/ui/cocoa/extensions/web_auth_flow_window_cocoa.h" | |
6 | |
7 #include "base/sys_string_conversions.h" | |
8 #include "chrome/browser/ui/cocoa/browser_window_utils.h" | |
9 #include "content/public/browser/web_contents.h" | |
10 #include "content/public/browser/web_contents_view.h" | |
11 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" | |
12 | |
13 // A window controller for a minimal window to host a web app view. Passes | |
14 // Objective-C notifications to the C++ bridge. | |
15 @interface WebAuthFlowWindowController | |
16 : NSWindowController<NSWindowDelegate> { | |
17 @private | |
18 WebAuthFlowWindowCocoa* webAuthWindow_; // Weak; owns self. | |
19 } | |
20 | |
21 @property(assign, nonatomic) WebAuthFlowWindowCocoa* webAuthWindow; | |
22 | |
23 @end | |
24 | |
25 @implementation WebAuthFlowWindowController | |
26 | |
27 @synthesize webAuthWindow = webAuthWindow_; | |
28 | |
29 - (void)windowWillClose:(NSNotification*)notification { | |
30 if (webAuthWindow_) | |
31 webAuthWindow_->WindowWillClose(); | |
32 } | |
33 | |
34 @end | |
35 | |
36 WebAuthFlowWindowCocoa::WebAuthFlowWindowCocoa( | |
37 Delegate* delegate, | |
38 content::BrowserContext* browser_context, | |
39 content::WebContents* contents) | |
40 : WebAuthFlowWindow(delegate, browser_context, contents), | |
41 attention_request_id_(0) { | |
42 } | |
43 | |
44 void WebAuthFlowWindowCocoa::Show() { | |
45 NSRect rect = NSMakeRect(0, 0, kDefaultWidth, kDefaultHeight); | |
46 NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask | | |
47 NSMiniaturizableWindowMask | NSResizableWindowMask; | |
48 scoped_nsobject<NSWindow> window([[UnderlayOpenGLHostingWindow alloc] | |
49 initWithContentRect:rect | |
50 styleMask:styleMask | |
51 backing:NSBackingStoreBuffered | |
52 defer:NO]); | |
53 | |
54 NSView* view = contents()->GetView()->GetNativeView(); | |
55 [view setFrame:rect]; | |
56 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | |
57 [[window contentView] addSubview:view]; | |
58 | |
59 window_controller_.reset( | |
60 [[WebAuthFlowWindowController alloc] initWithWindow:window.release()]); | |
61 [[window_controller_ window] setDelegate:window_controller_]; | |
62 [window_controller_ setWebAuthWindow:this]; | |
63 | |
64 [[window_controller_ window] center]; | |
65 [window_controller_ showWindow:nil]; | |
66 } | |
67 | |
68 void WebAuthFlowWindowCocoa::WindowWillClose() { | |
69 if (delegate()) | |
70 delegate()->OnClose(); | |
71 } | |
72 | |
73 WebAuthFlowWindowCocoa::~WebAuthFlowWindowCocoa() { | |
74 [window_controller_ setWebAuthWindow:NULL]; | |
75 [window_controller_ close]; | |
76 } | |
77 | |
78 // static | |
79 WebAuthFlowWindow* WebAuthFlowWindow::Create( | |
80 Delegate* delegate, | |
81 content::BrowserContext* browser_context, | |
82 content::WebContents* contents) { | |
83 return new WebAuthFlowWindowCocoa(delegate, browser_context, contents); | |
84 } | |
OLD | NEW |