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

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

Issue 220040: [Mac] Enable "Edit Search Engines" in Omnibox context menu. (Closed)
Patch Set: nop to make sure I'm logging in. Created 11 years, 2 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "base/mac_util.h" 7 #import "base/mac_util.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #import "chrome/browser/cocoa/edit_search_engine_cocoa_controller.h" 10 #import "chrome/browser/cocoa/edit_search_engine_cocoa_controller.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 KeywordEditorController* controller = [controller_ controller]; 44 KeywordEditorController* controller = [controller_ controller];
45 if (template_url) { 45 if (template_url) {
46 controller->ModifyTemplateURL(template_url, title, keyword, url); 46 controller->ModifyTemplateURL(template_url, title, keyword, url);
47 } else { 47 } else {
48 controller->AddTemplateURL(title, keyword, url); 48 controller->AddTemplateURL(title, keyword, url);
49 } 49 }
50 } 50 }
51 51
52 // KeywordEditorCocoaController ----------------------------------------------- 52 // KeywordEditorCocoaController -----------------------------------------------
53 53
54 namespace {
55
56 typedef std::map<Profile*,KeywordEditorCocoaController*> ProfileControllerMap;
57
58 } // namespace
59
54 @implementation KeywordEditorCocoaController 60 @implementation KeywordEditorCocoaController
55 61
62 + (KeywordEditorCocoaController*)sharedInstanceForProfile:(Profile*)profile {
63 ProfileControllerMap* map = Singleton<ProfileControllerMap>::get();
64 DCHECK(map != NULL);
65 ProfileControllerMap::iterator it = map->find(profile);
66 if (it != map->end()) {
67 return it->second;
68 }
69 return nil;
70 }
71
72 // TODO(shess): The Windows code watches a single global window which
73 // is not distinguished by profile. This code could distinguish by
74 // profile by checking the controller's class and profile.
75 + (void)showKeywordEditor:(Profile*)profile {
76 // http://crbug.com/23359 describes a case where this panel is
77 // opened from an incognito window, which can leave the panel
78 // holding onto a stale profile. Since the same panel is used
79 // either way, arrange to use the original profile instead.
80 if (profile->IsOffTheRecord()) {
81 profile = profile->GetOriginalProfile();
82 }
83
84 ProfileControllerMap* map = Singleton<ProfileControllerMap>::get();
85 DCHECK(map != NULL);
86 ProfileControllerMap::iterator it = map->find(profile);
87 if (it == map->end()) {
88 // Since we don't currently support multiple profiles, this class
89 // has not been tested against them, so document that assumption.
90 DCHECK_EQ(map->size(), 0U);
91
92 KeywordEditorCocoaController* controller =
93 [[self alloc] initWithProfile:profile];
94 it = map->insert(std::make_pair(profile, controller)).first;
95 }
96
97 [it->second showWindow:nil];
98 }
99
56 - (id)initWithProfile:(Profile*)profile { 100 - (id)initWithProfile:(Profile*)profile {
57 DCHECK(profile); 101 DCHECK(profile);
58 NSString* nibpath = [mac_util::MainAppBundle() 102 NSString* nibpath = [mac_util::MainAppBundle()
59 pathForResource:@"KeywordEditor" 103 pathForResource:@"KeywordEditor"
60 ofType:@"nib"]; 104 ofType:@"nib"];
61 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { 105 if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
62 profile_ = profile; 106 profile_ = profile;
63 controller_.reset(new KeywordEditorController(profile_)); 107 controller_.reset(new KeywordEditorController(profile_));
64 observer_.reset(new KeywordEditorModelObserver(self)); 108 observer_.reset(new KeywordEditorModelObserver(self));
65 controller_->url_model()->AddObserver(observer_.get()); 109 controller_->url_model()->AddObserver(observer_.get());
(...skipping 23 matching lines...) Expand all
89 } 133 }
90 134
91 [self adjustEditingButtons]; 135 [self adjustEditingButtons];
92 [tableView_ setDoubleAction:@selector(editKeyword:)]; 136 [tableView_ setDoubleAction:@selector(editKeyword:)];
93 [tableView_ setTarget:self]; 137 [tableView_ setTarget:self];
94 } 138 }
95 139
96 // When the window closes, clean ourselves up. 140 // When the window closes, clean ourselves up.
97 - (void)windowWillClose:(NSNotification*)notif { 141 - (void)windowWillClose:(NSNotification*)notif {
98 [self autorelease]; 142 [self autorelease];
143
144 ProfileControllerMap* map = Singleton<ProfileControllerMap>::get();
145 ProfileControllerMap::iterator it = map->find(profile_);
146 // It should not be possible for this to be missing.
147 // TODO(shess): Except that the unit test reaches in directly.
148 // Consider circling around and refactoring that.
149 //DCHECK(it != map->end());
150 if (it != map->end()) {
151 map->erase(it);
152 }
99 } 153 }
100 154
101 // The last page info window that was moved will determine the location of the 155 // The last page info window that was moved will determine the location of the
102 // next new one. 156 // next new one.
103 - (void)windowDidMove:(NSNotification*)notif { 157 - (void)windowDidMove:(NSNotification*)notif {
104 if (g_browser_process && g_browser_process->local_state()) { 158 if (g_browser_process && g_browser_process->local_state()) {
105 NSWindow* window = [self window]; 159 NSWindow* window = [self window];
106 [window saveWindowPositionToPrefs:g_browser_process->local_state() 160 [window saveWindowPositionToPrefs:g_browser_process->local_state()
107 withPath:prefs::kKeywordEditorWindowPlacement]; 161 withPath:prefs::kKeywordEditorWindowPlacement];
108 } 162 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 if ([selection count] != 1) { 287 if ([selection count] != 1) {
234 [makeDefaultButton_ setEnabled:NO]; 288 [makeDefaultButton_ setEnabled:NO];
235 } else { 289 } else {
236 const TemplateURL& url = 290 const TemplateURL& url =
237 controller_->table_model()->GetTemplateURL([selection firstIndex]); 291 controller_->table_model()->GetTemplateURL([selection firstIndex]);
238 [makeDefaultButton_ setEnabled:controller_->CanMakeDefault(&url)]; 292 [makeDefaultButton_ setEnabled:controller_->CanMakeDefault(&url)];
239 } 293 }
240 } 294 }
241 295
242 @end 296 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698