summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/page_info_window_controller.mm
blob: fc98b028b4d0d13adb8363cb6b54488548b1acbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2010 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.

#import "chrome/browser/cocoa/page_info_window_controller.h"

#include "app/l10n_util_mac.h"
#include "base/mac_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/cocoa/page_info_window_mac.h"
#include "chrome/browser/cocoa/window_size_autosaver.h"
#include "chrome/browser/pref_service.h"
#include "chrome/common/pref_names.h"
#include "grit/generated_resources.h"

namespace {

// The width of the window. The height will be determined by the content.
const NSInteger kWindowWidth = 460;

}  // namespace

@implementation PageInfoWindowController

- (id)init {
  NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask |
                         NSMiniaturizableWindowMask;
  scoped_nsobject<NSWindow> window(
      // Use an arbitrary height because it will be changed by the bridge.
      [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, kWindowWidth, 100)
                                  styleMask:styleMask
                                    backing:NSBackingStoreBuffered
                                      defer:NO]);
  if ((self = [super initWithWindow:window.get()])) {
    [window setTitle:
        l10n_util::GetNSStringWithFixup(IDS_PAGEINFO_WINDOW_TITLE)];
    [window setDelegate:self];

    if (g_browser_process && g_browser_process->local_state()) {
      sizeSaver_.reset([[WindowSizeAutosaver alloc]
          initWithWindow:[self window]
             prefService:g_browser_process->local_state()
                    path:prefs::kPageInfoWindowPlacement
                   state:kSaveWindowPos]);
    }
  }
  return self;
}

- (void)setPageInfo:(PageInfoWindowMac*)pageInfo {
  pageInfo_.reset(pageInfo);
}

- (IBAction)showCertWindow:(id)sender {
  pageInfo_->ShowCertDialog(0);  // Pass it any int because it's ignored.
}

// If the page info window gets closed, we have nothing left to manage and we
// can clean ourselves up.
- (void)windowWillClose:(NSNotification*)notif {
  [self autorelease];
}

@end