| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
| 10 #import "base/mac/mac_util.h" | 10 #import "base/mac/mac_util.h" |
| 11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
| 12 #include "chrome/browser/browsing_data_appcache_helper.h" | 12 #include "chrome/browser/browsing_data_appcache_helper.h" |
| 13 #include "chrome/browser/browsing_data_cookie_helper.h" | 13 #include "chrome/browser/browsing_data_cookie_helper.h" |
| 14 #include "chrome/browser/browsing_data_database_helper.h" | 14 #include "chrome/browser/browsing_data_database_helper.h" |
| 15 #include "chrome/browser/browsing_data_file_system_helper.h" | 15 #include "chrome/browser/browsing_data_file_system_helper.h" |
| 16 #include "chrome/browser/browsing_data_indexed_db_helper.h" | 16 #include "chrome/browser/browsing_data_indexed_db_helper.h" |
| 17 #include "chrome/browser/browsing_data_local_storage_helper.h" | 17 #include "chrome/browser/browsing_data_local_storage_helper.h" |
| 18 #include "chrome/browser/browsing_data_server_bound_cert_helper.h" | 18 #include "chrome/browser/browsing_data_server_bound_cert_helper.h" |
| 19 #include "chrome/browser/content_settings/cookie_settings.h" | 19 #include "chrome/browser/content_settings/cookie_settings.h" |
| 20 #include "chrome/browser/content_settings/local_shared_objects_container.h" | 20 #include "chrome/browser/content_settings/local_shared_objects_container.h" |
| 21 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 21 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 22 #include "chrome/browser/infobars/infobar_tab_helper.h" | 22 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 23 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/browser_dialogs.h" | 25 #include "chrome/browser/ui/browser_dialogs.h" |
| 26 #include "chrome/browser/ui/cocoa/constrained_window_mac.h" | 26 #include "chrome/browser/ui/cocoa/constrained_window_mac.h" |
| 27 #import "chrome/browser/ui/cocoa/content_settings/cookie_details_view_controller
.h" | 27 #import "chrome/browser/ui/cocoa/content_settings/cookie_details_view_controller
.h" |
| 28 #import "chrome/browser/ui/cocoa/vertical_gradient_view.h" | 28 #import "chrome/browser/ui/cocoa/vertical_gradient_view.h" |
| 29 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" | 29 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" |
| 30 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 30 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 31 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
| 32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 33 #include "content/public/browser/notification_details.h" | 33 #include "content/public/browser/notification_details.h" |
| 34 #include "content/public/browser/notification_source.h" | 34 #include "content/public/browser/notification_source.h" |
| 35 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
| 36 #include "grit/theme_resources.h" | 36 #include "grit/theme_resources.h" |
| 37 #include "skia/ext/skia_utils_mac.h" | 37 #include "skia/ext/skia_utils_mac.h" |
| 38 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 38 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
| 39 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 39 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 40 #include "third_party/apple_sample_code/ImageAndTextCell.h" | 40 #include "third_party/apple_sample_code/ImageAndTextCell.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 kAllowedCookiesTabIndex = 0, | 56 kAllowedCookiesTabIndex = 0, |
| 57 kBlockedCookiesTabIndex | 57 kBlockedCookiesTabIndex |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 namespace browser { | 62 namespace browser { |
| 63 | 63 |
| 64 // Declared in browser_dialogs.h so others don't have to depend on our header. | 64 // Declared in browser_dialogs.h so others don't have to depend on our header. |
| 65 void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window, | 65 void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window, |
| 66 TabContentsWrapper* wrapper) { | 66 TabContents* tab_contents) { |
| 67 // Deletes itself on close. | 67 // Deletes itself on close. |
| 68 new CollectedCookiesMac(parent_window, wrapper); | 68 new CollectedCookiesMac(parent_window, tab_contents); |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace browser | 71 } // namespace browser |
| 72 | 72 |
| 73 #pragma mark Bridge between the constrained window delegate and the sheet | 73 #pragma mark Bridge between the constrained window delegate and the sheet |
| 74 | 74 |
| 75 // The delegate used to forward the events from the sheet to the constrained | 75 // The delegate used to forward the events from the sheet to the constrained |
| 76 // window delegate. | 76 // window delegate. |
| 77 @interface CollectedCookiesSheetBridge : NSObject { | 77 @interface CollectedCookiesSheetBridge : NSObject { |
| 78 CollectedCookiesMac* collectedCookies_; // weak | 78 CollectedCookiesMac* collectedCookies_; // weak |
| (...skipping 15 matching lines...) Expand all Loading... |
| 94 - (void)sheetDidEnd:(NSWindow*)sheet | 94 - (void)sheetDidEnd:(NSWindow*)sheet |
| 95 returnCode:(int)returnCode | 95 returnCode:(int)returnCode |
| 96 contextInfo:(void*)contextInfo { | 96 contextInfo:(void*)contextInfo { |
| 97 collectedCookies_->OnSheetDidEnd(sheet); | 97 collectedCookies_->OnSheetDidEnd(sheet); |
| 98 } | 98 } |
| 99 @end | 99 @end |
| 100 | 100 |
| 101 #pragma mark Constrained window delegate | 101 #pragma mark Constrained window delegate |
| 102 | 102 |
| 103 CollectedCookiesMac::CollectedCookiesMac(NSWindow* parent, | 103 CollectedCookiesMac::CollectedCookiesMac(NSWindow* parent, |
| 104 TabContentsWrapper* wrapper) | 104 TabContents* tab_contents) |
| 105 : ConstrainedWindowMacDelegateCustomSheet( | 105 : ConstrainedWindowMacDelegateCustomSheet( |
| 106 [[[CollectedCookiesSheetBridge alloc] | 106 [[[CollectedCookiesSheetBridge alloc] |
| 107 initWithCollectedCookiesMac:this] autorelease], | 107 initWithCollectedCookiesMac:this] autorelease], |
| 108 @selector(sheetDidEnd:returnCode:contextInfo:)) { | 108 @selector(sheetDidEnd:returnCode:contextInfo:)) { |
| 109 TabSpecificContentSettings* content_settings = wrapper->content_settings(); | 109 TabSpecificContentSettings* content_settings = |
| 110 tab_contents->content_settings(); |
| 110 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, | 111 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, |
| 111 content::Source<TabSpecificContentSettings>(content_settings)); | 112 content::Source<TabSpecificContentSettings>(content_settings)); |
| 112 | 113 |
| 113 sheet_controller_ = [[CollectedCookiesWindowController alloc] | 114 sheet_controller_ = [[CollectedCookiesWindowController alloc] |
| 114 initWithTabContentsWrapper:wrapper]; | 115 initWithTabContents:tab_contents]; |
| 115 | 116 |
| 116 set_sheet([sheet_controller_ window]); | 117 set_sheet([sheet_controller_ window]); |
| 117 | 118 |
| 118 window_ = new ConstrainedWindowMac(wrapper, this); | 119 window_ = new ConstrainedWindowMac(tab_contents, this); |
| 119 } | 120 } |
| 120 | 121 |
| 121 CollectedCookiesMac::~CollectedCookiesMac() { | 122 CollectedCookiesMac::~CollectedCookiesMac() { |
| 122 NSWindow* window = [sheet_controller_ window]; | 123 NSWindow* window = [sheet_controller_ window]; |
| 123 if (window_ && window && is_sheet_open()) { | 124 if (window_ && window && is_sheet_open()) { |
| 124 window_ = NULL; | 125 window_ = NULL; |
| 125 [NSApp endSheet:window]; | 126 [NSApp endSheet:window]; |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 | 129 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 155 @implementation CollectedCookiesWindowController | 156 @implementation CollectedCookiesWindowController |
| 156 | 157 |
| 157 @synthesize allowedCookiesButtonsEnabled = | 158 @synthesize allowedCookiesButtonsEnabled = |
| 158 allowedCookiesButtonsEnabled_; | 159 allowedCookiesButtonsEnabled_; |
| 159 @synthesize blockedCookiesButtonsEnabled = | 160 @synthesize blockedCookiesButtonsEnabled = |
| 160 blockedCookiesButtonsEnabled_; | 161 blockedCookiesButtonsEnabled_; |
| 161 | 162 |
| 162 @synthesize allowedTreeController = allowedTreeController_; | 163 @synthesize allowedTreeController = allowedTreeController_; |
| 163 @synthesize blockedTreeController = blockedTreeController_; | 164 @synthesize blockedTreeController = blockedTreeController_; |
| 164 | 165 |
| 165 - (id)initWithTabContentsWrapper:(TabContentsWrapper*)wrapper { | 166 - (id)initWithTabContents:(TabContents*)tab_contents { |
| 166 DCHECK(wrapper); | 167 DCHECK(tab_contents); |
| 167 | 168 |
| 168 NSString* nibpath = | 169 NSString* nibpath = |
| 169 [base::mac::FrameworkBundle() pathForResource:@"CollectedCookies" | 170 [base::mac::FrameworkBundle() pathForResource:@"CollectedCookies" |
| 170 ofType:@"nib"]; | 171 ofType:@"nib"]; |
| 171 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 172 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
| 172 wrapper_ = wrapper; | 173 tab_contents_ = tab_contents; |
| 173 [self loadTreeModelFromTabContentsWrapper]; | 174 [self loadTreeModelFromTabContents]; |
| 174 | 175 |
| 175 animation_.reset([[NSViewAnimation alloc] init]); | 176 animation_.reset([[NSViewAnimation alloc] init]); |
| 176 [animation_ setAnimationBlockingMode:NSAnimationNonblocking]; | 177 [animation_ setAnimationBlockingMode:NSAnimationNonblocking]; |
| 177 } | 178 } |
| 178 return self; | 179 return self; |
| 179 } | 180 } |
| 180 | 181 |
| 181 - (void)awakeFromNib { | 182 - (void)awakeFromNib { |
| 182 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 183 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 183 NSImage* infoIcon = rb.GetNativeImageNamed(IDR_INFO); | 184 NSImage* infoIcon = rb.GetNativeImageNamed(IDR_INFO); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 199 [[NSGradient alloc] initWithStartingColor:bannerStartingColor | 200 [[NSGradient alloc] initWithStartingColor:bannerStartingColor |
| 200 endingColor:bannerEndingColor]); | 201 endingColor:bannerEndingColor]); |
| 201 [infoBar_ setGradient:bannerGradient]; | 202 [infoBar_ setGradient:bannerGradient]; |
| 202 | 203 |
| 203 NSColor* bannerStrokeColor = | 204 NSColor* bannerStrokeColor = |
| 204 [NSColor colorWithCalibratedWhite:kBannerStrokeColor | 205 [NSColor colorWithCalibratedWhite:kBannerStrokeColor |
| 205 alpha:1.0]; | 206 alpha:1.0]; |
| 206 [infoBar_ setStrokeColor:bannerStrokeColor]; | 207 [infoBar_ setStrokeColor:bannerStrokeColor]; |
| 207 | 208 |
| 208 // Change the label of the blocked cookies part if necessary. | 209 // Change the label of the blocked cookies part if necessary. |
| 209 Profile* profile = wrapper_->profile(); | 210 Profile* profile = tab_contents_->profile(); |
| 210 if (profile->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies)) { | 211 if (profile->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies)) { |
| 211 [blockedCookiesText_ setStringValue:l10n_util::GetNSString( | 212 [blockedCookiesText_ setStringValue:l10n_util::GetNSString( |
| 212 IDS_COLLECTED_COOKIES_BLOCKED_THIRD_PARTY_BLOCKING_ENABLED)]; | 213 IDS_COLLECTED_COOKIES_BLOCKED_THIRD_PARTY_BLOCKING_ENABLED)]; |
| 213 CGFloat textDeltaY = [GTMUILocalizerAndLayoutTweaker | 214 CGFloat textDeltaY = [GTMUILocalizerAndLayoutTweaker |
| 214 sizeToFitFixedWidthTextField:blockedCookiesText_]; | 215 sizeToFitFixedWidthTextField:blockedCookiesText_]; |
| 215 | 216 |
| 216 // Shrink the blocked cookies outline view. | 217 // Shrink the blocked cookies outline view. |
| 217 NSRect frame = [blockedScrollView_ frame]; | 218 NSRect frame = [blockedScrollView_ frame]; |
| 218 frame.size.height -= textDeltaY; | 219 frame.size.height -= textDeltaY; |
| 219 [blockedScrollView_ setFrame:frame]; | 220 [blockedScrollView_ setFrame:frame]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 231 [[detailsViewController_.get() view] setFrame:viewFrameRect]; | 232 [[detailsViewController_.get() view] setFrame:viewFrameRect]; |
| 232 [[cookieDetailsViewPlaceholder_ superview] | 233 [[cookieDetailsViewPlaceholder_ superview] |
| 233 replaceSubview:cookieDetailsViewPlaceholder_ | 234 replaceSubview:cookieDetailsViewPlaceholder_ |
| 234 with:detailView]; | 235 with:detailView]; |
| 235 | 236 |
| 236 [self tabView:tabView_ didSelectTabViewItem:[tabView_ selectedTabViewItem]]; | 237 [self tabView:tabView_ didSelectTabViewItem:[tabView_ selectedTabViewItem]]; |
| 237 } | 238 } |
| 238 | 239 |
| 239 - (void)windowWillClose:(NSNotification*)notif { | 240 - (void)windowWillClose:(NSNotification*)notif { |
| 240 if (contentSettingsChanged_) { | 241 if (contentSettingsChanged_) { |
| 241 InfoBarTabHelper* infobar_helper = wrapper_->infobar_tab_helper(); | 242 InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); |
| 242 infobar_helper->AddInfoBar( | 243 infobar_helper->AddInfoBar( |
| 243 new CollectedCookiesInfoBarDelegate(infobar_helper)); | 244 new CollectedCookiesInfoBarDelegate(infobar_helper)); |
| 244 } | 245 } |
| 245 [allowedOutlineView_ setDelegate:nil]; | 246 [allowedOutlineView_ setDelegate:nil]; |
| 246 [blockedOutlineView_ setDelegate:nil]; | 247 [blockedOutlineView_ setDelegate:nil]; |
| 247 [animation_ stopAnimation]; | 248 [animation_ stopAnimation]; |
| 248 [self autorelease]; | 249 [self autorelease]; |
| 249 } | 250 } |
| 250 | 251 |
| 251 - (IBAction)closeSheet:(id)sender { | 252 - (IBAction)closeSheet:(id)sender { |
| 252 [NSApp endSheet:[self window]]; | 253 [NSApp endSheet:[self window]]; |
| 253 } | 254 } |
| 254 | 255 |
| 255 - (void)addException:(ContentSetting)setting | 256 - (void)addException:(ContentSetting)setting |
| 256 forTreeController:(NSTreeController*)controller { | 257 forTreeController:(NSTreeController*)controller { |
| 257 NSArray* nodes = [controller selectedNodes]; | 258 NSArray* nodes = [controller selectedNodes]; |
| 258 BOOL multipleDomainsChanged = NO; | 259 BOOL multipleDomainsChanged = NO; |
| 259 string16 lastDomain; | 260 string16 lastDomain; |
| 260 for (NSTreeNode* treeNode in nodes) { | 261 for (NSTreeNode* treeNode in nodes) { |
| 261 CocoaCookieTreeNode* node = [treeNode representedObject]; | 262 CocoaCookieTreeNode* node = [treeNode representedObject]; |
| 262 CookieTreeNode* cookie = static_cast<CookieTreeNode*>([node treeNode]); | 263 CookieTreeNode* cookie = static_cast<CookieTreeNode*>([node treeNode]); |
| 263 if (cookie->GetDetailedInfo().node_type != | 264 if (cookie->GetDetailedInfo().node_type != |
| 264 CookieTreeNode::DetailedInfo::TYPE_ORIGIN) { | 265 CookieTreeNode::DetailedInfo::TYPE_ORIGIN) { |
| 265 continue; | 266 continue; |
| 266 } | 267 } |
| 267 Profile* profile = wrapper_->profile(); | 268 Profile* profile = tab_contents_->profile(); |
| 268 CookieTreeOriginNode* origin_node = | 269 CookieTreeOriginNode* origin_node = |
| 269 static_cast<CookieTreeOriginNode*>(cookie); | 270 static_cast<CookieTreeOriginNode*>(cookie); |
| 270 origin_node->CreateContentException( | 271 origin_node->CreateContentException( |
| 271 CookieSettings::Factory::GetForProfile(profile), setting); | 272 CookieSettings::Factory::GetForProfile(profile), setting); |
| 272 if (!lastDomain.empty()) | 273 if (!lastDomain.empty()) |
| 273 multipleDomainsChanged = YES; | 274 multipleDomainsChanged = YES; |
| 274 lastDomain = origin_node->GetTitle(); | 275 lastDomain = origin_node->GetTitle(); |
| 275 } | 276 } |
| 276 if (multipleDomainsChanged) | 277 if (multipleDomainsChanged) |
| 277 [self showInfoBarForMultipleDomainsAndSetting:setting]; | 278 [self showInfoBarForMultipleDomainsAndSetting:setting]; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 371 } |
| 371 if (isAllowedOutlineView) { | 372 if (isAllowedOutlineView) { |
| 372 [self setAllowedCookiesButtonsEnabled:NO]; | 373 [self setAllowedCookiesButtonsEnabled:NO]; |
| 373 } else { | 374 } else { |
| 374 [self setBlockedCookiesButtonsEnabled:NO]; | 375 [self setBlockedCookiesButtonsEnabled:NO]; |
| 375 } | 376 } |
| 376 } | 377 } |
| 377 | 378 |
| 378 // Initializes the |allowedTreeModel_| and |blockedTreeModel_|, and builds | 379 // Initializes the |allowedTreeModel_| and |blockedTreeModel_|, and builds |
| 379 // the |cocoaAllowedTreeModel_| and |cocoaBlockedTreeModel_|. | 380 // the |cocoaAllowedTreeModel_| and |cocoaBlockedTreeModel_|. |
| 380 - (void)loadTreeModelFromTabContentsWrapper { | 381 - (void)loadTreeModelFromTabContents { |
| 381 TabSpecificContentSettings* content_settings = wrapper_->content_settings(); | 382 TabSpecificContentSettings* content_settings = |
| 383 tab_contents_->content_settings(); |
| 382 | 384 |
| 383 const LocalSharedObjectsContainer& allowed_lsos = | 385 const LocalSharedObjectsContainer& allowed_lsos = |
| 384 content_settings->allowed_local_shared_objects(); | 386 content_settings->allowed_local_shared_objects(); |
| 385 allowedTreeModel_.reset( | 387 allowedTreeModel_.reset( |
| 386 new CookiesTreeModel(allowed_lsos.cookies()->Clone(), | 388 new CookiesTreeModel(allowed_lsos.cookies()->Clone(), |
| 387 allowed_lsos.databases()->Clone(), | 389 allowed_lsos.databases()->Clone(), |
| 388 allowed_lsos.local_storages()->Clone(), | 390 allowed_lsos.local_storages()->Clone(), |
| 389 allowed_lsos.session_storages()->Clone(), | 391 allowed_lsos.session_storages()->Clone(), |
| 390 allowed_lsos.appcaches()->Clone(), | 392 allowed_lsos.appcaches()->Clone(), |
| 391 allowed_lsos.indexed_dbs()->Clone(), | 393 allowed_lsos.indexed_dbs()->Clone(), |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 treeController = blockedTreeController_; | 556 treeController = blockedTreeController_; |
| 555 break; | 557 break; |
| 556 default: | 558 default: |
| 557 NOTREACHED(); | 559 NOTREACHED(); |
| 558 return; | 560 return; |
| 559 } | 561 } |
| 560 [detailsViewController_ configureBindingsForTreeController:treeController]; | 562 [detailsViewController_ configureBindingsForTreeController:treeController]; |
| 561 } | 563 } |
| 562 | 564 |
| 563 @end | 565 @end |
| OLD | NEW |