Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: chrome/browser/cocoa/content_exceptions_window_controller.mm

Issue 3017011: Make content settings map updates live.
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/content_exceptions_window_controller.h" 5 #import "chrome/browser/cocoa/content_exceptions_window_controller.h"
6 6
7 #include "app/l10n_util_mac.h" 7 #include "app/l10n_util_mac.h"
8 #include "app/table_model_observer.h" 8 #include "app/table_model_observer.h"
9 #import "base/mac_util.h" 9 #import "base/mac_util.h"
10 #import "base/scoped_nsobject.h" 10 #import "base/scoped_nsobject.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 return NO; 59 return NO;
60 } 60 }
61 61
62 - (NSAttributedString*)attributedStringForObjectValue:(id)object 62 - (NSAttributedString*)attributedStringForObjectValue:(id)object
63 withDefaultAttributes:(NSDictionary*)attribs { 63 withDefaultAttributes:(NSDictionary*)attribs {
64 return nil; 64 return nil;
65 } 65 }
66 @end 66 @end
67 67
68 //////////////////////////////////////////////////////////////////////////////// 68 ////////////////////////////////////////////////////////////////////////////////
69 // UpdatingContentSettingsObserver 69 // ContentExceptionObserverBridge
70
71 // Observer for the content settings table model.
72 class ContentExceptionsTableModelObserver : public TableModelObserver {
73 public:
74 ContentExceptionsTableModelObserver(
75 ContentExceptionsWindowController* controller)
76 : controller_(controller) {}
77 virtual ~ContentExceptionsTableModelObserver() {}
78
79 virtual void OnModelChanged() {
80 [controller_ modelDidChange];
81 }
82 virtual void OnItemsChanged(int start, int length) {
83 [controller_ modelDidChange];
84 }
85 virtual void OnItemsAdded(int start, int length) {
86 [controller_ modelDidChange];
87 }
88 virtual void OnItemsRemoved(int start, int length) {
89 [controller_ modelDidChange];
90 }
91
92 private:
93 ContentExceptionsWindowController* controller_; // weak
94 };
70 95
71 // UpdatingContentSettingsObserver is a notification observer that tells a 96 // UpdatingContentSettingsObserver is a notification observer that tells a
72 // window controller to update its data on every notification. 97 // window controller to update its data on every notification.
73 class UpdatingContentSettingsObserver : public NotificationObserver { 98 class UpdatingContentSettingsObserver : public NotificationObserver {
74 public: 99 public:
75 UpdatingContentSettingsObserver(ContentExceptionsWindowController* controller) 100 UpdatingContentSettingsObserver(ContentExceptionsWindowController* controller)
76 : controller_(controller) { 101 : controller_(controller) {
77 // One would think one could register a TableModelObserver to be notified of 102 // One would think one could register a TableModelObserver to be notified of
78 // changes to ContentExceptionsTableModel. One would be wrong: The table 103 // changes to ContentExceptionsTableModel. One would be wrong: The table
79 // model only sends out changes that are made through the model, not for 104 // model only sends out changes that are made through the model, not for
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 - (id)initWithType:(ContentSettingsType)settingsType 181 - (id)initWithType:(ContentSettingsType)settingsType
157 settingsMap:(HostContentSettingsMap*)settingsMap { 182 settingsMap:(HostContentSettingsMap*)settingsMap {
158 NSString* nibpath = 183 NSString* nibpath =
159 [mac_util::MainAppBundle() pathForResource:@"ContentExceptionsWindow" 184 [mac_util::MainAppBundle() pathForResource:@"ContentExceptionsWindow"
160 ofType:@"nib"]; 185 ofType:@"nib"];
161 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { 186 if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
162 settingsType_ = settingsType; 187 settingsType_ = settingsType;
163 settingsMap_ = settingsMap; 188 settingsMap_ = settingsMap;
164 model_.reset(new ContentExceptionsTableModel(settingsMap_, settingsType_)); 189 model_.reset(new ContentExceptionsTableModel(settingsMap_, settingsType_));
165 showAsk_ = settingsType_ == CONTENT_SETTINGS_TYPE_COOKIES; 190 showAsk_ = settingsType_ == CONTENT_SETTINGS_TYPE_COOKIES;
166 tableObserver_.reset(new UpdatingContentSettingsObserver(self)); 191 tableObserver_.reset(new ContentExceptionsTableModelObserver(self));
192 model_->SetObserver(tableObserver_.get());
167 updatesEnabled_ = YES; 193 updatesEnabled_ = YES;
168 194
169 // TODO(thakis): autoremember window rect. 195 // TODO(thakis): autoremember window rect.
170 // TODO(thakis): sorting support. 196 // TODO(thakis): sorting support.
171 } 197 }
172 return self; 198 return self;
173 } 199 }
174 200
175 - (void)awakeFromNib { 201 - (void)awakeFromNib {
176 DCHECK([self window]); 202 DCHECK([self window]);
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 449
424 // This method appropriately sets the enabled states on the table's editing 450 // This method appropriately sets the enabled states on the table's editing
425 // buttons. 451 // buttons.
426 - (void)adjustEditingButtons { 452 - (void)adjustEditingButtons {
427 NSIndexSet* selection = [tableView_ selectedRowIndexes]; 453 NSIndexSet* selection = [tableView_ selectedRowIndexes];
428 [removeButton_ setEnabled:([selection count] > 0)]; 454 [removeButton_ setEnabled:([selection count] > 0)];
429 [removeAllButton_ setEnabled:([tableView_ numberOfRows] > 0)]; 455 [removeAllButton_ setEnabled:([tableView_ numberOfRows] > 0)];
430 } 456 }
431 457
432 - (void)modelDidChange { 458 - (void)modelDidChange {
459 // XXX: disable editing mode if active. write test for that.
460
433 // Some calls on |model_|, e.g. RemoveException(), change something on the 461 // Some calls on |model_|, e.g. RemoveException(), change something on the
434 // backing content settings map object (which sends a notification) and then 462 // backing content settings map object (which sends a notification) and then
435 // change more stuff in |model_|. If |model_| is deleted when the notification 463 // change more stuff in |model_|. If |model_| is deleted when the notification
436 // is sent, this second access causes a segmentation violation. Hence, disable 464 // is sent, this second access causes a segmentation violation. Hence, disable
437 // resetting |model_| while updates can be in progress. 465 // resetting |model_| while updates can be in progress.
438 if (!updatesEnabled_) 466 if (!updatesEnabled_)
439 return; 467 return;
440 468
441 // The model caches its data, meaning we need to recreate it on every change.
442 model_.reset(new ContentExceptionsTableModel(settingsMap_, settingsType_));
443
444 [tableView_ reloadData]; 469 [tableView_ reloadData];
445 [self adjustEditingButtons]; 470 [self adjustEditingButtons];
446 } 471 }
447 472
448 - (size_t)menuItemCount { 473 - (size_t)menuItemCount {
449 return showAsk_ ? arraysize(kAskSettings) : arraysize(kNoAskSettings); 474 return showAsk_ ? arraysize(kAskSettings) : arraysize(kNoAskSettings);
450 } 475 }
451 476
452 - (NSString*)titleForIndex:(size_t)index { 477 - (NSString*)titleForIndex:(size_t)index {
453 switch ([self settingForIndex:index]) { 478 switch ([self settingForIndex:index]) {
(...skipping 16 matching lines...) Expand all
470 - (size_t)indexForSetting:(ContentSetting)setting { 495 - (size_t)indexForSetting:(ContentSetting)setting {
471 for (size_t i = 0; i < [self menuItemCount]; ++i) { 496 for (size_t i = 0; i < [self menuItemCount]; ++i) {
472 if ([self settingForIndex:i] == setting) 497 if ([self settingForIndex:i] == setting)
473 return i; 498 return i;
474 } 499 }
475 NOTREACHED(); 500 NOTREACHED();
476 return 0; 501 return 0;
477 } 502 }
478 503
479 @end 504 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698