OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/ui/cocoa/content_settings/collected_cookies_mac.h" | 5 #import "chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #import "base/mac/mac_util.h" | 9 #import "base/mac/mac_util.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 - (void)sheetDidEnd:(NSWindow*)sheet | 71 - (void)sheetDidEnd:(NSWindow*)sheet |
72 returnCode:(int)returnCode | 72 returnCode:(int)returnCode |
73 contextInfo:(void*)contextInfo { | 73 contextInfo:(void*)contextInfo { |
74 collectedCookies_->OnSheetDidEnd(sheet); | 74 collectedCookies_->OnSheetDidEnd(sheet); |
75 } | 75 } |
76 @end | 76 @end |
77 | 77 |
78 #pragma mark Constrained window delegate | 78 #pragma mark Constrained window delegate |
79 | 79 |
80 CollectedCookiesMac::CollectedCookiesMac(NSWindow* parent, | 80 CollectedCookiesMac::CollectedCookiesMac(NSWindow* parent, |
81 TabContents* tab_contents) | 81 TabContentsWrapper* wrapper) |
82 : ConstrainedWindowMacDelegateCustomSheet( | 82 : ConstrainedWindowMacDelegateCustomSheet( |
83 [[[CollectedCookiesSheetBridge alloc] | 83 [[[CollectedCookiesSheetBridge alloc] |
84 initWithCollectedCookiesMac:this] autorelease], | 84 initWithCollectedCookiesMac:this] autorelease], |
85 @selector(sheetDidEnd:returnCode:contextInfo:)), | 85 @selector(sheetDidEnd:returnCode:contextInfo:)) { |
86 tab_contents_(tab_contents) { | 86 TabSpecificContentSettings* content_settings = wrapper->content_settings(); |
87 TabSpecificContentSettings* content_settings = | |
88 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents)-> | |
89 content_settings(); | |
90 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, | 87 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, |
91 Source<TabSpecificContentSettings>(content_settings)); | 88 Source<TabSpecificContentSettings>(content_settings)); |
92 | 89 |
93 sheet_controller_ = [[CollectedCookiesWindowController alloc] | 90 sheet_controller_ = [[CollectedCookiesWindowController alloc] |
94 initWithTabContents:tab_contents]; | 91 initWithTabContentsWrapper:wrapper]; |
95 | 92 |
96 set_sheet([sheet_controller_ window]); | 93 set_sheet([sheet_controller_ window]); |
97 | 94 |
98 window_ = new ConstrainedWindowMac(tab_contents, this); | 95 window_ = new ConstrainedWindowMac(wrapper->tab_contents(), this); |
99 } | 96 } |
100 | 97 |
101 CollectedCookiesMac::~CollectedCookiesMac() { | 98 CollectedCookiesMac::~CollectedCookiesMac() { |
102 NSWindow* window = [sheet_controller_ window]; | 99 NSWindow* window = [sheet_controller_ window]; |
103 if (window_ && window && is_sheet_open()) { | 100 if (window_ && window && is_sheet_open()) { |
104 window_ = NULL; | 101 window_ = NULL; |
105 [NSApp endSheet:window]; | 102 [NSApp endSheet:window]; |
106 } | 103 } |
107 } | 104 } |
108 | 105 |
(...skipping 26 matching lines...) Expand all Loading... |
135 @implementation CollectedCookiesWindowController | 132 @implementation CollectedCookiesWindowController |
136 | 133 |
137 @synthesize allowedCookiesButtonsEnabled = | 134 @synthesize allowedCookiesButtonsEnabled = |
138 allowedCookiesButtonsEnabled_; | 135 allowedCookiesButtonsEnabled_; |
139 @synthesize blockedCookiesButtonsEnabled = | 136 @synthesize blockedCookiesButtonsEnabled = |
140 blockedCookiesButtonsEnabled_; | 137 blockedCookiesButtonsEnabled_; |
141 | 138 |
142 @synthesize allowedTreeController = allowedTreeController_; | 139 @synthesize allowedTreeController = allowedTreeController_; |
143 @synthesize blockedTreeController = blockedTreeController_; | 140 @synthesize blockedTreeController = blockedTreeController_; |
144 | 141 |
145 - (id)initWithTabContents:(TabContents*)tabContents { | 142 - (id)initWithTabContentsWrapper:(TabContentsWrapper*)wrapper { |
146 DCHECK(tabContents); | 143 DCHECK(wrapper); |
147 | 144 |
148 NSString* nibpath = | 145 NSString* nibpath = |
149 [base::mac::MainAppBundle() pathForResource:@"CollectedCookies" | 146 [base::mac::MainAppBundle() pathForResource:@"CollectedCookies" |
150 ofType:@"nib"]; | 147 ofType:@"nib"]; |
151 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 148 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
152 tabContents_ = tabContents; | 149 wrapper_ = wrapper; |
153 [self loadTreeModelFromTabContents]; | 150 [self loadTreeModelFromTabContentsWrapper]; |
154 | 151 |
155 animation_.reset([[NSViewAnimation alloc] init]); | 152 animation_.reset([[NSViewAnimation alloc] init]); |
156 [animation_ setAnimationBlockingMode:NSAnimationNonblocking]; | 153 [animation_ setAnimationBlockingMode:NSAnimationNonblocking]; |
157 } | 154 } |
158 return self; | 155 return self; |
159 } | 156 } |
160 | 157 |
161 - (void)awakeFromNib { | 158 - (void)awakeFromNib { |
162 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 159 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
163 NSImage* infoIcon = rb.GetNativeImageNamed(IDR_INFO); | 160 NSImage* infoIcon = rb.GetNativeImageNamed(IDR_INFO); |
(...skipping 15 matching lines...) Expand all Loading... |
179 [[NSGradient alloc] initWithStartingColor:bannerStartingColor | 176 [[NSGradient alloc] initWithStartingColor:bannerStartingColor |
180 endingColor:bannerEndingColor]); | 177 endingColor:bannerEndingColor]); |
181 [infoBar_ setGradient:bannerGradient]; | 178 [infoBar_ setGradient:bannerGradient]; |
182 | 179 |
183 NSColor* bannerStrokeColor = | 180 NSColor* bannerStrokeColor = |
184 [NSColor colorWithCalibratedWhite:kBannerStrokeColor | 181 [NSColor colorWithCalibratedWhite:kBannerStrokeColor |
185 alpha:1.0]; | 182 alpha:1.0]; |
186 [infoBar_ setStrokeColor:bannerStrokeColor]; | 183 [infoBar_ setStrokeColor:bannerStrokeColor]; |
187 | 184 |
188 // Change the label of the blocked cookies part if necessary. | 185 // Change the label of the blocked cookies part if necessary. |
189 Profile* profile = | 186 Profile* profile = wrapper_->profile(); |
190 Profile::FromBrowserContext(tabContents_->browser_context()); | |
191 if (profile->GetHostContentSettingsMap()->BlockThirdPartyCookies()) { | 187 if (profile->GetHostContentSettingsMap()->BlockThirdPartyCookies()) { |
192 [blockedCookiesText_ setStringValue:l10n_util::GetNSString( | 188 [blockedCookiesText_ setStringValue:l10n_util::GetNSString( |
193 IDS_COLLECTED_COOKIES_BLOCKED_THIRD_PARTY_BLOCKING_ENABLED)]; | 189 IDS_COLLECTED_COOKIES_BLOCKED_THIRD_PARTY_BLOCKING_ENABLED)]; |
194 CGFloat textDeltaY = [GTMUILocalizerAndLayoutTweaker | 190 CGFloat textDeltaY = [GTMUILocalizerAndLayoutTweaker |
195 sizeToFitFixedWidthTextField:blockedCookiesText_]; | 191 sizeToFitFixedWidthTextField:blockedCookiesText_]; |
196 | 192 |
197 // Shrink the blocked cookies outline view. | 193 // Shrink the blocked cookies outline view. |
198 NSRect frame = [blockedScrollView_ frame]; | 194 NSRect frame = [blockedScrollView_ frame]; |
199 frame.size.height -= textDeltaY; | 195 frame.size.height -= textDeltaY; |
200 [blockedScrollView_ setFrame:frame]; | 196 [blockedScrollView_ setFrame:frame]; |
(...skipping 11 matching lines...) Expand all Loading... |
212 [[detailsViewController_.get() view] setFrame:viewFrameRect]; | 208 [[detailsViewController_.get() view] setFrame:viewFrameRect]; |
213 [[cookieDetailsViewPlaceholder_ superview] | 209 [[cookieDetailsViewPlaceholder_ superview] |
214 replaceSubview:cookieDetailsViewPlaceholder_ | 210 replaceSubview:cookieDetailsViewPlaceholder_ |
215 with:detailView]; | 211 with:detailView]; |
216 | 212 |
217 [self tabView:tabView_ didSelectTabViewItem:[tabView_ selectedTabViewItem]]; | 213 [self tabView:tabView_ didSelectTabViewItem:[tabView_ selectedTabViewItem]]; |
218 } | 214 } |
219 | 215 |
220 - (void)windowWillClose:(NSNotification*)notif { | 216 - (void)windowWillClose:(NSNotification*)notif { |
221 if (contentSettingsChanged_) { | 217 if (contentSettingsChanged_) { |
222 TabContentsWrapper::GetCurrentWrapperForContents(tabContents_)-> | 218 wrapper_->infobar_tab_helper()->AddInfoBar( |
223 infobar_tab_helper()->AddInfoBar( | 219 new CollectedCookiesInfoBarDelegate(wrapper_->tab_contents())); |
224 new CollectedCookiesInfoBarDelegate(tabContents_)); | |
225 } | 220 } |
226 [allowedOutlineView_ setDelegate:nil]; | 221 [allowedOutlineView_ setDelegate:nil]; |
227 [blockedOutlineView_ setDelegate:nil]; | 222 [blockedOutlineView_ setDelegate:nil]; |
228 [animation_ stopAnimation]; | 223 [animation_ stopAnimation]; |
229 [self autorelease]; | 224 [self autorelease]; |
230 } | 225 } |
231 | 226 |
232 - (IBAction)closeSheet:(id)sender { | 227 - (IBAction)closeSheet:(id)sender { |
233 [NSApp endSheet:[self window]]; | 228 [NSApp endSheet:[self window]]; |
234 } | 229 } |
235 | 230 |
236 - (void)addException:(ContentSetting)setting | 231 - (void)addException:(ContentSetting)setting |
237 forTreeController:(NSTreeController*)controller { | 232 forTreeController:(NSTreeController*)controller { |
238 NSArray* nodes = [controller selectedNodes]; | 233 NSArray* nodes = [controller selectedNodes]; |
239 BOOL multipleDomainsChanged = NO; | 234 BOOL multipleDomainsChanged = NO; |
240 string16 lastDomain; | 235 string16 lastDomain; |
241 for (NSTreeNode* treeNode in nodes) { | 236 for (NSTreeNode* treeNode in nodes) { |
242 CocoaCookieTreeNode* node = [treeNode representedObject]; | 237 CocoaCookieTreeNode* node = [treeNode representedObject]; |
243 CookieTreeNode* cookie = static_cast<CookieTreeNode*>([node treeNode]); | 238 CookieTreeNode* cookie = static_cast<CookieTreeNode*>([node treeNode]); |
244 if (cookie->GetDetailedInfo().node_type != | 239 if (cookie->GetDetailedInfo().node_type != |
245 CookieTreeNode::DetailedInfo::TYPE_ORIGIN) { | 240 CookieTreeNode::DetailedInfo::TYPE_ORIGIN) { |
246 continue; | 241 continue; |
247 } | 242 } |
248 Profile* profile = | 243 Profile* profile = wrapper_->profile(); |
249 Profile::FromBrowserContext(tabContents_->browser_context()); | |
250 CookieTreeOriginNode* origin_node = | 244 CookieTreeOriginNode* origin_node = |
251 static_cast<CookieTreeOriginNode*>(cookie); | 245 static_cast<CookieTreeOriginNode*>(cookie); |
252 origin_node->CreateContentException(profile->GetHostContentSettingsMap(), | 246 origin_node->CreateContentException(profile->GetHostContentSettingsMap(), |
253 setting); | 247 setting); |
254 if (!lastDomain.empty()) | 248 if (!lastDomain.empty()) |
255 multipleDomainsChanged = YES; | 249 multipleDomainsChanged = YES; |
256 lastDomain = origin_node->GetTitle(); | 250 lastDomain = origin_node->GetTitle(); |
257 } | 251 } |
258 if (multipleDomainsChanged) | 252 if (multipleDomainsChanged) |
259 [self showInfoBarForMultipleDomainsAndSetting:setting]; | 253 [self showInfoBarForMultipleDomainsAndSetting:setting]; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 346 } |
353 if (isAllowedOutlineView) { | 347 if (isAllowedOutlineView) { |
354 [self setAllowedCookiesButtonsEnabled:NO]; | 348 [self setAllowedCookiesButtonsEnabled:NO]; |
355 } else { | 349 } else { |
356 [self setBlockedCookiesButtonsEnabled:NO]; | 350 [self setBlockedCookiesButtonsEnabled:NO]; |
357 } | 351 } |
358 } | 352 } |
359 | 353 |
360 // Initializes the |allowedTreeModel_| and |blockedTreeModel_|, and builds | 354 // Initializes the |allowedTreeModel_| and |blockedTreeModel_|, and builds |
361 // the |cocoaAllowedTreeModel_| and |cocoaBlockedTreeModel_|. | 355 // the |cocoaAllowedTreeModel_| and |cocoaBlockedTreeModel_|. |
362 - (void)loadTreeModelFromTabContents { | 356 - (void)loadTreeModelFromTabContentsWrapper { |
363 TabSpecificContentSettings* content_settings = | 357 TabSpecificContentSettings* content_settings = wrapper_->content_settings(); |
364 TabContentsWrapper::GetCurrentWrapperForContents(tabContents_)-> | |
365 content_settings(); | |
366 allowedTreeModel_.reset(content_settings->GetAllowedCookiesTreeModel()); | 358 allowedTreeModel_.reset(content_settings->GetAllowedCookiesTreeModel()); |
367 blockedTreeModel_.reset(content_settings->GetBlockedCookiesTreeModel()); | 359 blockedTreeModel_.reset(content_settings->GetBlockedCookiesTreeModel()); |
368 | 360 |
369 // Convert the model's icons from Skia to Cocoa. | 361 // Convert the model's icons from Skia to Cocoa. |
370 std::vector<SkBitmap> skiaIcons; | 362 std::vector<SkBitmap> skiaIcons; |
371 allowedTreeModel_->GetIcons(&skiaIcons); | 363 allowedTreeModel_->GetIcons(&skiaIcons); |
372 icons_.reset([[NSMutableArray alloc] init]); | 364 icons_.reset([[NSMutableArray alloc] init]); |
373 for (std::vector<SkBitmap>::iterator it = skiaIcons.begin(); | 365 for (std::vector<SkBitmap>::iterator it = skiaIcons.begin(); |
374 it != skiaIcons.end(); ++it) { | 366 it != skiaIcons.end(); ++it) { |
375 [icons_ addObject:gfx::SkBitmapToNSImage(*it)]; | 367 [icons_ addObject:gfx::SkBitmapToNSImage(*it)]; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 treeController = blockedTreeController_; | 505 treeController = blockedTreeController_; |
514 break; | 506 break; |
515 default: | 507 default: |
516 NOTREACHED(); | 508 NOTREACHED(); |
517 return; | 509 return; |
518 } | 510 } |
519 [detailsViewController_ configureBindingsForTreeController:treeController]; | 511 [detailsViewController_ configureBindingsForTreeController:treeController]; |
520 } | 512 } |
521 | 513 |
522 @end | 514 @end |
OLD | NEW |