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

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

Issue 5238002: Reintegrate 552 r66225-r66645.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/552d/src/
Patch Set: '' Created 10 years, 1 month 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 | Annotate | Revision Log
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.h" 7 #include "app/l10n_util.h"
8 #include "app/l10n_util_mac.h" 8 #include "app/l10n_util_mac.h"
9 #include "app/table_model_observer.h" 9 #include "app/table_model_observer.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #import "base/mac_util.h" 11 #import "base/mac_util.h"
12 #import "base/scoped_nsobject.h" 12 #import "base/scoped_nsobject.h"
13 #include "base/sys_string_conversions.h" 13 #include "base/sys_string_conversions.h"
14 #include "chrome/browser/content_exceptions_table_model.h" 14 #include "chrome/browser/content_exceptions_table_model.h"
15 #include "chrome/browser/content_setting_combo_model.h"
15 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/notification_registrar.h" 17 #include "chrome/common/notification_registrar.h"
17 #include "chrome/common/notification_service.h" 18 #include "chrome/common/notification_service.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
19 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" 20 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
20 21
21 @interface ContentExceptionsWindowController (Private) 22 @interface ContentExceptionsWindowController (Private)
22 - (id)initWithType:(ContentSettingsType)settingsType 23 - (id)initWithType:(ContentSettingsType)settingsType
23 settingsMap:(HostContentSettingsMap*)settingsMap 24 settingsMap:(HostContentSettingsMap*)settingsMap
24 otrSettingsMap:(HostContentSettingsMap*)otrSettingsMap; 25 otrSettingsMap:(HostContentSettingsMap*)otrSettingsMap;
25 - (void)updateRow:(NSInteger)row 26 - (void)updateRow:(NSInteger)row
26 withEntry:(const HostContentSettingsMap::PatternSettingPair&)entry 27 withEntry:(const HostContentSettingsMap::PatternSettingPair&)entry
27 forOtr:(BOOL)isOtr; 28 forOtr:(BOOL)isOtr;
28 - (void)adjustEditingButtons; 29 - (void)adjustEditingButtons;
29 - (void)modelDidChange; 30 - (void)modelDidChange;
30 - (size_t)menuItemCount;
31 - (NSString*)titleForIndex:(size_t)index; 31 - (NSString*)titleForIndex:(size_t)index;
32 - (ContentSetting)settingForIndex:(size_t)index;
33 - (size_t)indexForSetting:(ContentSetting)setting;
34 @end 32 @end
35 33
36 //////////////////////////////////////////////////////////////////////////////// 34 ////////////////////////////////////////////////////////////////////////////////
37 // PatternFormatter 35 // PatternFormatter
38 36
39 // A simple formatter that accepts text that vaguely looks like a pattern. 37 // A simple formatter that accepts text that vaguely looks like a pattern.
40 @interface PatternFormatter : NSFormatter 38 @interface PatternFormatter : NSFormatter
41 @end 39 @end
42 40
43 @implementation PatternFormatter 41 @implementation PatternFormatter
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 case CONTENT_SETTINGS_TYPE_POPUPS: 117 case CONTENT_SETTINGS_TYPE_POPUPS:
120 return l10n_util::GetNSStringWithFixup(IDS_POPUP_EXCEPTION_TITLE); 118 return l10n_util::GetNSStringWithFixup(IDS_POPUP_EXCEPTION_TITLE);
121 default: 119 default:
122 NOTREACHED(); 120 NOTREACHED();
123 } 121 }
124 return @""; 122 return @"";
125 } 123 }
126 124
127 const CGFloat kButtonBarHeight = 35.0; 125 const CGFloat kButtonBarHeight = 35.0;
128 126
129 // The settings shown in the combobox for plug-ins;
130 const ContentSetting kPluginSettings[] = { CONTENT_SETTING_ALLOW,
131 CONTENT_SETTING_ASK,
132 CONTENT_SETTING_BLOCK };
133
134 // The settings shown in the combobox if showSession_ is false;
135 const ContentSetting kNoSessionSettings[] = { CONTENT_SETTING_ALLOW,
136 CONTENT_SETTING_BLOCK };
137
138 // The settings shown in the combobox if showSession_ is true;
139 const ContentSetting kSessionSettings[] = { CONTENT_SETTING_ALLOW,
140 CONTENT_SETTING_SESSION_ONLY,
141 CONTENT_SETTING_BLOCK };
142
143 } // namespace 127 } // namespace
144 128
145 //////////////////////////////////////////////////////////////////////////////// 129 ////////////////////////////////////////////////////////////////////////////////
146 // ContentExceptionsWindowController implementation 130 // ContentExceptionsWindowController implementation
147 131
148 static ContentExceptionsWindowController* 132 static ContentExceptionsWindowController*
149 g_exceptionWindows[CONTENT_SETTINGS_NUM_TYPES] = { nil }; 133 g_exceptionWindows[CONTENT_SETTINGS_NUM_TYPES] = { nil };
150 134
151 @implementation ContentExceptionsWindowController 135 @implementation ContentExceptionsWindowController
152 136
(...skipping 15 matching lines...) Expand all
168 otrSettingsMap:(HostContentSettingsMap*)otrSettingsMap { 152 otrSettingsMap:(HostContentSettingsMap*)otrSettingsMap {
169 NSString* nibpath = 153 NSString* nibpath =
170 [mac_util::MainAppBundle() pathForResource:@"ContentExceptionsWindow" 154 [mac_util::MainAppBundle() pathForResource:@"ContentExceptionsWindow"
171 ofType:@"nib"]; 155 ofType:@"nib"];
172 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { 156 if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
173 settingsType_ = settingsType; 157 settingsType_ = settingsType;
174 settingsMap_ = settingsMap; 158 settingsMap_ = settingsMap;
175 otrSettingsMap_ = otrSettingsMap; 159 otrSettingsMap_ = otrSettingsMap;
176 model_.reset(new ContentExceptionsTableModel( 160 model_.reset(new ContentExceptionsTableModel(
177 settingsMap_, otrSettingsMap_, settingsType_)); 161 settingsMap_, otrSettingsMap_, settingsType_));
178 showSession_ = settingsType_ == CONTENT_SETTINGS_TYPE_COOKIES; 162 popup_model_.reset(new ContentSettingComboModel(settingsType_));
179 otrAllowed_ = otrSettingsMap != NULL; 163 otrAllowed_ = otrSettingsMap != NULL;
180 tableObserver_.reset(new UpdatingContentSettingsObserver(self)); 164 tableObserver_.reset(new UpdatingContentSettingsObserver(self));
181 updatesEnabled_ = YES; 165 updatesEnabled_ = YES;
182 166
183 // TODO(thakis): autoremember window rect. 167 // TODO(thakis): autoremember window rect.
184 // TODO(thakis): sorting support. 168 // TODO(thakis): sorting support.
185 } 169 }
186 return self; 170 return self;
187 } 171 }
188 172
189 - (void)awakeFromNib { 173 - (void)awakeFromNib {
190 DCHECK([self window]); 174 DCHECK([self window]);
191 DCHECK_EQ(self, [[self window] delegate]); 175 DCHECK_EQ(self, [[self window] delegate]);
192 DCHECK(tableView_); 176 DCHECK(tableView_);
193 DCHECK_EQ(self, [tableView_ dataSource]); 177 DCHECK_EQ(self, [tableView_ dataSource]);
194 DCHECK_EQ(self, [tableView_ delegate]); 178 DCHECK_EQ(self, [tableView_ delegate]);
195 179
196 [[self window] setTitle:GetWindowTitle(settingsType_)]; 180 [[self window] setTitle:GetWindowTitle(settingsType_)];
197 181
198 CGFloat minWidth = [[addButton_ superview] bounds].size.width + 182 CGFloat minWidth = [[addButton_ superview] bounds].size.width +
199 [[doneButton_ superview] bounds].size.width; 183 [[doneButton_ superview] bounds].size.width;
200 [self setMinWidth:minWidth]; 184 [self setMinWidth:minWidth];
201 185
202 [self adjustEditingButtons]; 186 [self adjustEditingButtons];
203 187
204 // Initialize menu for the data cell in the "action" column. 188 // Initialize menu for the data cell in the "action" column.
205 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@"exceptionMenu"]); 189 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@"exceptionMenu"]);
206 for (size_t i = 0; i < [self menuItemCount]; ++i) { 190 for (int i = 0; i < popup_model_->GetItemCount(); ++i) {
207 scoped_nsobject<NSMenuItem> allowItem([[NSMenuItem alloc] 191 NSString* title =
208 initWithTitle:[self titleForIndex:i] action:NULL keyEquivalent:@""]); 192 l10n_util::FixUpWindowsStyleLabel(popup_model_->GetItemAt(i));
209 [allowItem.get() setTag:[self settingForIndex:i]]; 193 scoped_nsobject<NSMenuItem> allowItem(
194 [[NSMenuItem alloc] initWithTitle:title action:NULL keyEquivalent:@""]);
195 [allowItem.get() setTag:popup_model_->SettingForIndex(i)];
210 [menu.get() addItem:allowItem.get()]; 196 [menu.get() addItem:allowItem.get()];
211 } 197 }
212 NSCell* menuCell = 198 NSCell* menuCell =
213 [[tableView_ tableColumnWithIdentifier:@"action"] dataCell]; 199 [[tableView_ tableColumnWithIdentifier:@"action"] dataCell];
214 [menuCell setMenu:menu.get()]; 200 [menuCell setMenu:menu.get()];
215 201
216 NSCell* patternCell = 202 NSCell* patternCell =
217 [[tableView_ tableColumnWithIdentifier:@"pattern"] dataCell]; 203 [[tableView_ tableColumnWithIdentifier:@"pattern"] dataCell];
218 [patternCell setFormatter:[[[PatternFormatter alloc] init] autorelease]]; 204 [patternCell setFormatter:[[[PatternFormatter alloc] init] autorelease]];
219 205
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } else { 354 } else {
369 entry = &model_->entry_at(row); 355 entry = &model_->entry_at(row);
370 isOtr = model_->entry_is_off_the_record(row) ? 1 : 0; 356 isOtr = model_->entry_is_off_the_record(row) ? 1 : 0;
371 } 357 }
372 358
373 NSObject* result = nil; 359 NSObject* result = nil;
374 NSString* identifier = [tableColumn identifier]; 360 NSString* identifier = [tableColumn identifier];
375 if ([identifier isEqualToString:@"pattern"]) { 361 if ([identifier isEqualToString:@"pattern"]) {
376 result = base::SysUTF8ToNSString(entry->first.AsString()); 362 result = base::SysUTF8ToNSString(entry->first.AsString());
377 } else if ([identifier isEqualToString:@"action"]) { 363 } else if ([identifier isEqualToString:@"action"]) {
378 result = [NSNumber numberWithInt:[self indexForSetting:entry->second]]; 364 result =
365 [NSNumber numberWithInt:popup_model_->IndexForSetting(entry->second)];
379 } else if ([identifier isEqualToString:@"otr"]) { 366 } else if ([identifier isEqualToString:@"otr"]) {
380 result = [NSNumber numberWithInt:isOtr]; 367 result = [NSNumber numberWithInt:isOtr];
381 } else { 368 } else {
382 NOTREACHED(); 369 NOTREACHED();
383 } 370 }
384 return result; 371 return result;
385 } 372 }
386 373
387 // Updates exception at |row| to contain the data in |entry|. 374 // Updates exception at |row| to contain the data in |entry|.
388 - (void)updateRow:(NSInteger)row 375 - (void)updateRow:(NSInteger)row
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 bool wasOtr = isOtr; 416 bool wasOtr = isOtr;
430 417
431 // Modify it. 418 // Modify it.
432 NSString* identifier = [tableColumn identifier]; 419 NSString* identifier = [tableColumn identifier];
433 if ([identifier isEqualToString:@"pattern"]) { 420 if ([identifier isEqualToString:@"pattern"]) {
434 entry.first = HostContentSettingsMap::Pattern( 421 entry.first = HostContentSettingsMap::Pattern(
435 base::SysNSStringToUTF8(object)); 422 base::SysNSStringToUTF8(object));
436 } 423 }
437 if ([identifier isEqualToString:@"action"]) { 424 if ([identifier isEqualToString:@"action"]) {
438 int index = [object intValue]; 425 int index = [object intValue];
439 entry.second = [self settingForIndex:index]; 426 entry.second = popup_model_->SettingForIndex(index);
440 } 427 }
441 if ([identifier isEqualToString:@"otr"]) { 428 if ([identifier isEqualToString:@"otr"]) {
442 isOtr = [object intValue] != 0; 429 isOtr = [object intValue] != 0;
443 } 430 }
444 431
445 // Commit modification, if any. 432 // Commit modification, if any.
446 if (isNewRow) { 433 if (isNewRow) {
447 newException_.reset(); 434 newException_.reset();
448 if (![identifier isEqualToString:@"pattern"]) { 435 if (![identifier isEqualToString:@"pattern"]) {
449 [tableView_ reloadData]; 436 [tableView_ reloadData];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 return; 480 return;
494 481
495 // The model caches its data, meaning we need to recreate it on every change. 482 // The model caches its data, meaning we need to recreate it on every change.
496 model_.reset(new ContentExceptionsTableModel( 483 model_.reset(new ContentExceptionsTableModel(
497 settingsMap_, otrSettingsMap_, settingsType_)); 484 settingsMap_, otrSettingsMap_, settingsType_));
498 485
499 [tableView_ reloadData]; 486 [tableView_ reloadData];
500 [self adjustEditingButtons]; 487 [self adjustEditingButtons];
501 } 488 }
502 489
503 - (size_t)menuItemCount {
504 if (settingsType_ == CONTENT_SETTINGS_TYPE_PLUGINS)
505 return arraysize(kPluginSettings);
506 return showSession_ ? arraysize(kSessionSettings)
507 : arraysize(kNoSessionSettings);
508 }
509
510 - (NSString*)titleForIndex:(size_t)index {
511 switch ([self settingForIndex:index]) {
512 case CONTENT_SETTING_ALLOW:
513 return l10n_util::GetNSStringWithFixup(IDS_EXCEPTIONS_ALLOW_BUTTON);
514 case CONTENT_SETTING_ASK:
515 return l10n_util::GetNSStringWithFixup(IDS_EXCEPTIONS_ASK_BUTTON);
516 case CONTENT_SETTING_BLOCK:
517 return l10n_util::GetNSStringWithFixup(IDS_EXCEPTIONS_BLOCK_BUTTON);
518 case CONTENT_SETTING_SESSION_ONLY:
519 return l10n_util::GetNSStringWithFixup(
520 IDS_EXCEPTIONS_SESSION_ONLY_BUTTON);
521 default:
522 NOTREACHED();
523 }
524 return @"";
525 }
526
527 - (ContentSetting)settingForIndex:(size_t)index {
528 if (settingsType_ == CONTENT_SETTINGS_TYPE_PLUGINS)
529 return kPluginSettings[index];
530 return showSession_ ? kSessionSettings[index] : kNoSessionSettings[index];
531 }
532
533 - (size_t)indexForSetting:(ContentSetting)setting {
534 for (size_t i = 0; i < [self menuItemCount]; ++i) {
535 if ([self settingForIndex:i] == setting)
536 return i;
537 }
538 NOTREACHED();
539 return 0;
540 }
541
542 @end 490 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/content_exceptions_window_controller.h ('k') | chrome/browser/cocoa/content_setting_bubble_cocoa.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698