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.
5 #import <Cocoa/Cocoa.h>
7 #include "base/mac/scoped_nsobject.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/browsing_data/cookies_tree_model.h"
10 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
11 #import "chrome/browser/ui/cocoa/content_settings/cookie_tree_node.h"
12 #import "chrome/browser/ui/cocoa/content_settings/cookies_tree_controller_bridge.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
16 @
class CollectedCookiesWindowController
;
17 @
class CookieDetailsViewController
;
18 @
class VerticalGradientView
;
24 // The constrained window delegate reponsible for managing the collected
26 class CollectedCookiesMac
: public ConstrainedWindowMacDelegate
,
27 public content::NotificationObserver
{
29 CollectedCookiesMac(content::WebContents
* web_contents
);
30 ~CollectedCookiesMac() override
;
34 // ConstrainedWindowMacDelegate implementation.
35 void OnConstrainedWindowClosed(ConstrainedWindowMac
* window
) override
;
37 CollectedCookiesWindowController
* sheet_controller() const {
38 return sheet_controller_
.get();
42 // NotificationObserver implementation.
43 void Observe(int type
,
44 const content::NotificationSource
& source
,
45 const content::NotificationDetails
& details
) override
;
47 content::NotificationRegistrar registrar_
;
49 scoped_ptr
<ConstrainedWindowMac
> window_
;
51 base::scoped_nsobject
<CollectedCookiesWindowController
> sheet_controller_
;
53 DISALLOW_COPY_AND_ASSIGN(CollectedCookiesMac
);
56 // Controller for the collected cookies dialog. This class stores an internal
57 // copy of the CookiesTreeModel but with Cocoa-converted values (NSStrings and
58 // NSImages instead of std::strings and ImageSkias). Doing this allows us to use
59 // bindings for the interface. Changes are pushed to this internal model via a
60 // very thin bridge (see cookies_window_controller.h).
61 @interface CollectedCookiesWindowController
: NSWindowController
62 <NSOutlineViewDelegate
,
66 // Platform-independent model.
67 scoped_ptr
<CookiesTreeModel
> allowedTreeModel_
;
68 scoped_ptr
<CookiesTreeModel
> blockedTreeModel_
;
70 // Cached array of icons.
71 base::scoped_nsobject
<NSMutableArray
> icons_
;
73 // Our Cocoa copy of the model.
74 scoped_ptr
<CookiesTreeControllerBridge
> allowedControllerBridge_
;
75 scoped_ptr
<CookiesTreeControllerBridge
> blockedControllerBridge_
;
77 BOOL allowedCookiesButtonsEnabled_
;
78 BOOL blockedCookiesButtonsEnabled_
;
79 BOOL deleteCookiesButtonEnabled_
; // Only in the allowed pane.
81 IBOutlet NSTreeController
* allowedTreeController_
;
82 IBOutlet NSTreeController
* blockedTreeController_
;
83 IBOutlet NSOutlineView
* allowedOutlineView_
;
84 IBOutlet NSOutlineView
* blockedOutlineView_
;
85 IBOutlet VerticalGradientView
* infoBar_
;
86 IBOutlet NSImageView
* infoBarIcon_
;
87 IBOutlet NSTextField
* infoBarText_
;
88 IBOutlet NSTabView
* tabView_
;
89 IBOutlet NSScrollView
* blockedScrollView_
;
90 IBOutlet NSTextField
* blockedCookiesText_
;
91 IBOutlet NSView
* cookieDetailsViewPlaceholder_
;
93 base::scoped_nsobject
<NSViewAnimation
> animation_
;
95 base::scoped_nsobject
<CookieDetailsViewController
> detailsViewController_
;
97 content::WebContents
* webContents_
; // weak
99 CollectedCookiesMac
* collectedCookiesMac_
; // weak
101 BOOL infoBarVisible_
;
103 BOOL contentSettingsChanged_
;
106 @
property(readonly
, nonatomic
) IBOutlet NSTreeController
* allowedTreeController
;
107 @
property(readonly
, nonatomic
) IBOutlet NSTreeController
* blockedTreeController
;
108 @
property(readonly
, nonatomic
) IBOutlet NSOutlineView
* allowedOutlineView
;
109 @
property(readonly
, nonatomic
) IBOutlet NSOutlineView
* blockedOutlineView
;
110 @
property(readonly
, nonatomic
) IBOutlet VerticalGradientView
* infoBar
;
111 @
property(readonly
, nonatomic
) IBOutlet NSImageView
* infoBarIcon
;
112 @
property(readonly
, nonatomic
) IBOutlet NSTextField
* infoBarText
;
113 @
property(readonly
, nonatomic
) IBOutlet NSTabView
* tabView
;
114 @
property(readonly
, nonatomic
) IBOutlet NSScrollView
* blockedScrollView
;
115 @
property(readonly
, nonatomic
) IBOutlet NSTextField
* blockedCookiesText
;
116 @
property(readonly
, nonatomic
) IBOutlet NSView
* cookieDetailsViewPlaceholder
;
118 @
property(assign
, nonatomic
) BOOL allowedCookiesButtonsEnabled
;
119 @
property(assign
, nonatomic
) BOOL blockedCookiesButtonsEnabled
;
120 @
property(assign
, nonatomic
) BOOL deleteCookiesButtonEnabled
;
122 // Designated initializer. The WebContents cannot be NULL.
123 - (id
)initWithWebContents
:(content::WebContents
*)webContents
124 collectedCookiesMac
:(CollectedCookiesMac
*)collectedCookiesMac
;
126 // Closes the sheet and ends the modal loop. This will also clean up the memory.
127 - (IBAction
)closeSheet
:(id
)sender
;
129 - (IBAction
)allowOrigin
:(id
)sender
;
130 - (IBAction
)allowForSessionFromOrigin
:(id
)sender
;
131 - (IBAction
)blockOrigin
:(id
)sender
;
133 // Allows the deletion of set cookies (only visible in the Allowed pane).
134 - (IBAction
)deleteSelected
:(id
)sender
;
136 // Returns the |cocoaAllowedTreeModel_| and |cocoaBlockedTreeModel_|.
137 - (CocoaCookieTreeNode
*)cocoaAllowedTreeModel
;
138 - (CocoaCookieTreeNode
*)cocoaBlockedTreeModel
;
140 // Returns the |allowedTreeModel_| and |blockedTreeModel_|.
141 - (CookiesTreeModel
*)allowedTreeModel
;
142 - (CookiesTreeModel
*)blockedTreeModel
;
144 - (void)loadTreeModelFromWebContents
;
146 // Given an array of selected NSTreeNode objects, normalizes the selection so
147 // that it does not contain any children whose parents are also in the array.
148 + (NSArray
*)normalizeNodeSelection
:(NSArray
*)selection
;