| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/cocoa/collected_cookies_mac.h" | 5 #import "chrome/browser/cocoa/collected_cookies_mac.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "app/l10n_util_mac.h" | 9 #include "app/l10n_util_mac.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| 11 #import "base/mac_util.h" | 11 #import "base/mac_util.h" |
| 12 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
| 13 #include "chrome/browser/cocoa/content_settings_dialog_controller.h" |
| 14 #include "chrome/browser/profile.h" |
| 13 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
| 14 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 15 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 16 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 17 #include "skia/ext/skia_utils_mac.h" | 19 #include "skia/ext/skia_utils_mac.h" |
| 18 #include "third_party/apple/ImageAndTextCell.h" | 20 #include "third_party/apple/ImageAndTextCell.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 | 22 |
| 23 static const CGFloat kMinCollectedCookiesViewHeight = 116; |
| 24 |
| 21 #pragma mark Bridge between the constrained window delegate and the sheet | 25 #pragma mark Bridge between the constrained window delegate and the sheet |
| 22 | 26 |
| 23 // The delegate used to forward the events from the sheet to the constrained | 27 // The delegate used to forward the events from the sheet to the constrained |
| 24 // window delegate. | 28 // window delegate. |
| 25 @interface CollectedCookiesSheetBridge : NSObject { | 29 @interface CollectedCookiesSheetBridge : NSObject { |
| 26 CollectedCookiesMac* collectedCookies_; // weak | 30 CollectedCookiesMac* collectedCookies_; // weak |
| 27 } | 31 } |
| 28 - (id)initWithCollectedCookiesMac:(CollectedCookiesMac*)collectedCookies; | 32 - (id)initWithCollectedCookiesMac:(CollectedCookiesMac*)collectedCookies; |
| 29 - (void)sheetDidEnd:(NSWindow*)sheet | 33 - (void)sheetDidEnd:(NSWindow*)sheet |
| 30 returnCode:(int)returnCode | 34 returnCode:(int)returnCode |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 void CollectedCookiesMac::OnSheetDidEnd(NSWindow* sheet) { | 96 void CollectedCookiesMac::OnSheetDidEnd(NSWindow* sheet) { |
| 93 [sheet orderOut:sheet_controller_]; | 97 [sheet orderOut:sheet_controller_]; |
| 94 if (window_) | 98 if (window_) |
| 95 window_->CloseConstrainedWindow(); | 99 window_->CloseConstrainedWindow(); |
| 96 } | 100 } |
| 97 | 101 |
| 98 #pragma mark Window Controller | 102 #pragma mark Window Controller |
| 99 | 103 |
| 100 @implementation CollectedCookiesWindowController | 104 @implementation CollectedCookiesWindowController |
| 101 | 105 |
| 106 @synthesize allowedCookiesButtonsEnabled = |
| 107 allowedCookiesButtonsEnabled_; |
| 108 @synthesize blockedCookiesButtonsEnabled = |
| 109 blockedCookiesButtonsEnabled_; |
| 110 |
| 102 @synthesize allowedTreeController = allowedTreeController_; | 111 @synthesize allowedTreeController = allowedTreeController_; |
| 103 @synthesize blockedTreeController = blockedTreeController_; | 112 @synthesize blockedTreeController = blockedTreeController_; |
| 104 | 113 |
| 105 - (id)initWithTabContents:(TabContents*)tabContents { | 114 - (id)initWithTabContents:(TabContents*)tabContents { |
| 106 DCHECK(tabContents); | 115 DCHECK(tabContents); |
| 107 NSString* nibpath = | 116 NSString* nibpath = |
| 108 [mac_util::MainAppBundle() pathForResource:@"CollectedCookies" | 117 [mac_util::MainAppBundle() pathForResource:@"CollectedCookies" |
| 109 ofType:@"nib"]; | 118 ofType:@"nib"]; |
| 110 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 119 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
| 111 tabContents_ = tabContents; | 120 tabContents_ = tabContents; |
| 112 | 121 |
| 113 [self loadTreeModelFromTabContents]; | 122 [self loadTreeModelFromTabContents]; |
| 114 } | 123 } |
| 115 return self; | 124 return self; |
| 116 } | 125 } |
| 117 | 126 |
| 118 - (void)windowWillClose:(NSNotification*)notif { | 127 - (void)windowWillClose:(NSNotification*)notif { |
| 119 [allowedOutlineView_ setDelegate:nil]; | 128 [allowedOutlineView_ setDelegate:nil]; |
| 120 [blockedOutlineView_ setDelegate:nil]; | 129 [blockedOutlineView_ setDelegate:nil]; |
| 121 [self autorelease]; | 130 [self autorelease]; |
| 122 } | 131 } |
| 123 | 132 |
| 124 - (IBAction)closeSheet:(id)sender { | 133 - (IBAction)closeSheet:(id)sender { |
| 125 [NSApp endSheet:[self window]]; | 134 [NSApp endSheet:[self window]]; |
| 126 } | 135 } |
| 127 | 136 |
| 137 - (void)addException:(ContentSetting)setting |
| 138 forTreeController:(NSTreeController*)controller { |
| 139 NSArray* nodes = [controller selectedNodes]; |
| 140 for (NSTreeNode* treeNode in nodes) { |
| 141 CocoaCookieTreeNode* node = [treeNode representedObject]; |
| 142 CookieTreeNode* cookie = static_cast<CookieTreeNode*>([node treeNode]); |
| 143 if (cookie->GetDetailedInfo().node_type != |
| 144 CookieTreeNode::DetailedInfo::TYPE_ORIGIN) { |
| 145 continue; |
| 146 } |
| 147 CookieTreeOriginNode* origin_node = |
| 148 static_cast<CookieTreeOriginNode*>(cookie); |
| 149 origin_node->CreateContentException( |
| 150 tabContents_->profile()->GetHostContentSettingsMap(), |
| 151 setting); |
| 152 } |
| 153 [[ContentSettingsDialogController |
| 154 showContentSettingsForType:CONTENT_SETTINGS_TYPE_COOKIES |
| 155 profile:tabContents_->profile()] |
| 156 showCookieExceptions:self]; |
| 157 } |
| 158 |
| 159 - (IBAction)allowOrigin:(id)sender { |
| 160 [self addException:CONTENT_SETTING_ALLOW |
| 161 forTreeController:blockedTreeController_]; |
| 162 } |
| 163 |
| 164 - (IBAction)allowForSessionFromOrigin:(id)sender { |
| 165 [self addException:CONTENT_SETTING_SESSION_ONLY |
| 166 forTreeController:blockedTreeController_]; |
| 167 } |
| 168 |
| 169 - (IBAction)blockOrigin:(id)sender { |
| 170 [self addException:CONTENT_SETTING_BLOCK |
| 171 forTreeController:allowedTreeController_]; |
| 172 } |
| 173 |
| 174 - (CGFloat) splitView:(NSSplitView *)sender |
| 175 constrainMinCoordinate:(CGFloat)proposedMin |
| 176 ofSubviewAt:(NSInteger)offset { |
| 177 return proposedMin + kMinCollectedCookiesViewHeight; |
| 178 } |
| 179 - (CGFloat) splitView:(NSSplitView *)sender |
| 180 constrainMaxCoordinate:(CGFloat)proposedMax |
| 181 ofSubviewAt:(NSInteger)offset { |
| 182 return proposedMax - kMinCollectedCookiesViewHeight; |
| 183 } |
| 184 - (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview { |
| 185 return YES; |
| 186 } |
| 187 |
| 128 - (CocoaCookieTreeNode*)cocoaAllowedTreeModel { | 188 - (CocoaCookieTreeNode*)cocoaAllowedTreeModel { |
| 129 return cocoaAllowedTreeModel_.get(); | 189 return cocoaAllowedTreeModel_.get(); |
| 130 } | 190 } |
| 131 - (void)setCocoaAllowedTreeModel:(CocoaCookieTreeNode*)model { | 191 - (void)setCocoaAllowedTreeModel:(CocoaCookieTreeNode*)model { |
| 132 cocoaAllowedTreeModel_.reset([model retain]); | 192 cocoaAllowedTreeModel_.reset([model retain]); |
| 133 } | 193 } |
| 134 | 194 |
| 135 - (CookiesTreeModel*)allowedTreeModel { | 195 - (CookiesTreeModel*)allowedTreeModel { |
| 136 return allowedTreeModel_.get(); | 196 return allowedTreeModel_.get(); |
| 137 } | 197 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 159 index = blockedTreeModel_->GetIconIndex([node treeNode]); | 219 index = blockedTreeModel_->GetIconIndex([node treeNode]); |
| 160 NSImage* icon = nil; | 220 NSImage* icon = nil; |
| 161 if (index >= 0) | 221 if (index >= 0) |
| 162 icon = [icons_ objectAtIndex:index]; | 222 icon = [icons_ objectAtIndex:index]; |
| 163 else | 223 else |
| 164 icon = [icons_ lastObject]; | 224 icon = [icons_ lastObject]; |
| 165 DCHECK([cell isKindOfClass:[ImageAndTextCell class]]); | 225 DCHECK([cell isKindOfClass:[ImageAndTextCell class]]); |
| 166 [static_cast<ImageAndTextCell*>(cell) setImage:icon]; | 226 [static_cast<ImageAndTextCell*>(cell) setImage:icon]; |
| 167 } | 227 } |
| 168 | 228 |
| 229 - (void)outlineViewSelectionDidChange:(NSNotification*)notif { |
| 230 BOOL isAllowedOutlineView; |
| 231 if ([notif object] == allowedOutlineView_) { |
| 232 isAllowedOutlineView = YES; |
| 233 } else if ([notif object] == blockedOutlineView_) { |
| 234 isAllowedOutlineView = NO; |
| 235 } else { |
| 236 NOTREACHED(); |
| 237 return; |
| 238 } |
| 239 NSTreeController* controller = |
| 240 isAllowedOutlineView ? allowedTreeController_ : blockedTreeController_; |
| 241 |
| 242 NSArray* nodes = [controller selectedNodes]; |
| 243 for (NSTreeNode* treeNode in nodes) { |
| 244 CocoaCookieTreeNode* node = [treeNode representedObject]; |
| 245 CookieTreeNode* cookie = static_cast<CookieTreeNode*>([node treeNode]); |
| 246 if (cookie->GetDetailedInfo().node_type != |
| 247 CookieTreeNode::DetailedInfo::TYPE_ORIGIN) { |
| 248 continue; |
| 249 } |
| 250 CookieTreeOriginNode* origin_node = |
| 251 static_cast<CookieTreeOriginNode*>(cookie); |
| 252 if (origin_node->CanCreateContentException()) { |
| 253 if (isAllowedOutlineView) { |
| 254 [self setAllowedCookiesButtonsEnabled:YES]; |
| 255 } else { |
| 256 [self setBlockedCookiesButtonsEnabled:YES]; |
| 257 } |
| 258 return; |
| 259 } |
| 260 } |
| 261 if (isAllowedOutlineView) { |
| 262 [self setAllowedCookiesButtonsEnabled:NO]; |
| 263 } else { |
| 264 [self setBlockedCookiesButtonsEnabled:NO]; |
| 265 } |
| 266 } |
| 267 |
| 169 // Initializes the |allowedTreeModel_| and |blockedTreeModel_|, and builds | 268 // Initializes the |allowedTreeModel_| and |blockedTreeModel_|, and builds |
| 170 // the |cocoaAllowedTreeModel_| and |cocoaBlockedTreeModel_|. | 269 // the |cocoaAllowedTreeModel_| and |cocoaBlockedTreeModel_|. |
| 171 - (void)loadTreeModelFromTabContents { | 270 - (void)loadTreeModelFromTabContents { |
| 172 TabSpecificContentSettings* content_settings = | 271 TabSpecificContentSettings* content_settings = |
| 173 tabContents_->GetTabSpecificContentSettings(); | 272 tabContents_->GetTabSpecificContentSettings(); |
| 174 allowedTreeModel_.reset(content_settings->GetAllowedCookiesTreeModel()); | 273 allowedTreeModel_.reset(content_settings->GetAllowedCookiesTreeModel()); |
| 175 blockedTreeModel_.reset(content_settings->GetBlockedCookiesTreeModel()); | 274 blockedTreeModel_.reset(content_settings->GetBlockedCookiesTreeModel()); |
| 176 | 275 |
| 177 // Convert the model's icons from Skia to Cocoa. | 276 // Convert the model's icons from Skia to Cocoa. |
| 178 std::vector<SkBitmap> skiaIcons; | 277 std::vector<SkBitmap> skiaIcons; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 194 scoped_nsobject<CocoaCookieTreeNode> model( | 293 scoped_nsobject<CocoaCookieTreeNode> model( |
| 195 [[CocoaCookieTreeNode alloc] initWithNode:root]); | 294 [[CocoaCookieTreeNode alloc] initWithNode:root]); |
| 196 [self setCocoaAllowedTreeModel:model.get()]; // Takes ownership. | 295 [self setCocoaAllowedTreeModel:model.get()]; // Takes ownership. |
| 197 root = static_cast<CookieTreeNode*>(blockedTreeModel_->GetRoot()); | 296 root = static_cast<CookieTreeNode*>(blockedTreeModel_->GetRoot()); |
| 198 model.reset( | 297 model.reset( |
| 199 [[CocoaCookieTreeNode alloc] initWithNode:root]); | 298 [[CocoaCookieTreeNode alloc] initWithNode:root]); |
| 200 [self setCocoaBlockedTreeModel:model.get()]; // Takes ownership. | 299 [self setCocoaBlockedTreeModel:model.get()]; // Takes ownership. |
| 201 } | 300 } |
| 202 | 301 |
| 203 @end | 302 @end |
| OLD | NEW |