• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 #import <Cocoa/Cocoa.h>
6 
7 #import "base/mac/cocoa_protocols.h"
8 #include "base/memory/scoped_nsobject.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/cookies_tree_model.h"
11 #include "chrome/browser/ui/cocoa/constrained_window_mac.h"
12 #import "chrome/browser/ui/cocoa/content_settings/cookie_tree_node.h"
13 #include "content/common/notification_registrar.h"
14 
15 @class CollectedCookiesWindowController;
16 @class CookieDetailsViewController;
17 @class VerticalGradientView;
18 class TabContents;
19 
20 // The constrained window delegate reponsible for managing the collected
21 // cookies dialog.
22 class CollectedCookiesMac : public ConstrainedWindowMacDelegateCustomSheet,
23                             public NotificationObserver {
24  public:
25   CollectedCookiesMac(NSWindow* parent, TabContents* tab_contents);
26 
27   void OnSheetDidEnd(NSWindow* sheet);
28 
29   // ConstrainedWindowMacDelegateCustomSheet implementation.
30   virtual void DeleteDelegate();
31 
32  private:
33   virtual ~CollectedCookiesMac();
34 
35   // NotificationObserver implementation.
36   virtual void Observe(NotificationType type,
37                        const NotificationSource& source,
38                        const NotificationDetails& details);
39 
40   NotificationRegistrar registrar_;
41 
42   ConstrainedWindow* window_;
43 
44   TabContents* tab_contents_;
45 
46   CollectedCookiesWindowController* sheet_controller_;
47 
48   DISALLOW_COPY_AND_ASSIGN(CollectedCookiesMac);
49 };
50 
51 // Controller for the collected cookies dialog. This class stores an internal
52 // copy of the CookiesTreeModel but with Cocoa-converted values (NSStrings and
53 // NSImages instead of std::strings and SkBitmaps). Doing this allows us to use
54 // bindings for the interface. Changes are pushed to this internal model via a
55 // very thin bridge (see cookies_window_controller.h).
56 @interface CollectedCookiesWindowController : NSWindowController
57                                               <NSOutlineViewDelegate,
58                                                NSTabViewDelegate,
59                                                NSWindowDelegate> {
60  @private
61   // Platform-independent model.
62   scoped_ptr<CookiesTreeModel> allowedTreeModel_;
63   scoped_ptr<CookiesTreeModel> blockedTreeModel_;
64 
65   // Cached array of icons.
66   scoped_nsobject<NSMutableArray> icons_;
67 
68   // Our Cocoa copy of the model.
69   scoped_nsobject<CocoaCookieTreeNode> cocoaAllowedTreeModel_;
70   scoped_nsobject<CocoaCookieTreeNode> cocoaBlockedTreeModel_;
71 
72   BOOL allowedCookiesButtonsEnabled_;
73   BOOL blockedCookiesButtonsEnabled_;
74 
75   IBOutlet NSTreeController* allowedTreeController_;
76   IBOutlet NSTreeController* blockedTreeController_;
77   IBOutlet NSOutlineView* allowedOutlineView_;
78   IBOutlet NSOutlineView* blockedOutlineView_;
79   IBOutlet VerticalGradientView* infoBar_;
80   IBOutlet NSImageView* infoBarIcon_;
81   IBOutlet NSTextField* infoBarText_;
82   IBOutlet NSTabView* tabView_;
83   IBOutlet NSScrollView* blockedScrollView_;
84   IBOutlet NSTextField* blockedCookiesText_;
85   IBOutlet NSView* cookieDetailsViewPlaceholder_;
86 
87   scoped_nsobject<NSViewAnimation> animation_;
88 
89   scoped_nsobject<CookieDetailsViewController> detailsViewController_;
90 
91   TabContents* tabContents_;  // weak
92 
93   BOOL infoBarVisible_;
94 
95   BOOL contentSettingsChanged_;
96 }
97 @property(readonly, nonatomic) NSTreeController* allowedTreeController;
98 @property(readonly, nonatomic) NSTreeController* blockedTreeController;
99 
100 @property(assign, nonatomic) BOOL allowedCookiesButtonsEnabled;
101 @property(assign, nonatomic) BOOL blockedCookiesButtonsEnabled;
102 
103 // Designated initializer. TabContents cannot be NULL.
104 - (id)initWithTabContents:(TabContents*)tabContents;
105 
106 // Closes the sheet and ends the modal loop. This will also cleanup the memory.
107 - (IBAction)closeSheet:(id)sender;
108 
109 - (IBAction)allowOrigin:(id)sender;
110 - (IBAction)allowForSessionFromOrigin:(id)sender;
111 - (IBAction)blockOrigin:(id)sender;
112 
113 // Returns the |cocoaAllowedTreeModel_| and |cocoaBlockedTreeModel_|.
114 - (CocoaCookieTreeNode*)cocoaAllowedTreeModel;
115 - (CocoaCookieTreeNode*)cocoaBlockedTreeModel;
116 - (void)setCocoaAllowedTreeModel:(CocoaCookieTreeNode*)model;
117 - (void)setCocoaBlockedTreeModel:(CocoaCookieTreeNode*)model;
118 
119 // Returns the |allowedTreeModel_| and |blockedTreeModel_|.
120 - (CookiesTreeModel*)allowedTreeModel;
121 - (CookiesTreeModel*)blockedTreeModel;
122 
123 - (void)loadTreeModelFromTabContents;
124 @end
125