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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.mm

Issue 9456019: Add GTK interface for installing bundles of extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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/extensions/extension_install_dialog_controller. h" 5 #import "chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller. h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/mac/mac_util.h" 8 #include "base/mac/mac_util.h"
9 #include "base/memory/scoped_nsobject.h" 9 #include "base/memory/scoped_nsobject.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 @synthesize warningsField = warningsField_; 76 @synthesize warningsField = warningsField_;
77 @synthesize cancelButton = cancelButton_; 77 @synthesize cancelButton = cancelButton_;
78 @synthesize okButton = okButton_; 78 @synthesize okButton = okButton_;
79 @synthesize warningsSeparator = warningsSeparator_; 79 @synthesize warningsSeparator = warningsSeparator_;
80 @synthesize ratingStars = ratingStars_; 80 @synthesize ratingStars = ratingStars_;
81 @synthesize ratingCountField = ratingCountField_; 81 @synthesize ratingCountField = ratingCountField_;
82 @synthesize userCountField = userCountField_; 82 @synthesize userCountField = userCountField_;
83 83
84 - (id)initWithParentWindow:(NSWindow*)window 84 - (id)initWithParentWindow:(NSWindow*)window
85 profile:(Profile*)profile 85 profile:(Profile*)profile
86 extension:(const Extension*)extension
87 delegate:(ExtensionInstallUI::Delegate*)delegate 86 delegate:(ExtensionInstallUI::Delegate*)delegate
88 icon:(SkBitmap*)icon
89 prompt:(const ExtensionInstallUI::Prompt&)prompt { 87 prompt:(const ExtensionInstallUI::Prompt&)prompt {
90 NSString* nibpath = nil; 88 NSString* nibpath = nil;
91 89
92 // We use a different XIB in the case of inline installs or no permission 90 // We use a different XIB in the case of inline installs or no permission
93 // warnings, that respectively show webstore ratings data and are a more 91 // warnings, that respectively show webstore ratings data and are a more
94 // nicely laid out. 92 // nicely laid out.
95 if (prompt.type() == ExtensionInstallUI::INLINE_INSTALL_PROMPT) { 93 if (prompt.type() == ExtensionInstallUI::INLINE_INSTALL_PROMPT) {
96 nibpath = [base::mac::FrameworkBundle() 94 nibpath = [base::mac::FrameworkBundle()
97 pathForResource:@"ExtensionInstallPromptInline" 95 pathForResource:@"ExtensionInstallPromptInline"
98 ofType:@"nib"]; 96 ofType:@"nib"];
99 } else if (prompt.GetPermissionCount() == 0) { 97 } else if (prompt.GetPermissionCount() == 0) {
100 nibpath = [base::mac::FrameworkBundle() 98 nibpath = [base::mac::FrameworkBundle()
101 pathForResource:@"ExtensionInstallPromptNoWarnings" 99 pathForResource:@"ExtensionInstallPromptNoWarnings"
102 ofType:@"nib"]; 100 ofType:@"nib"];
103 } else { 101 } else {
104 nibpath = [base::mac::FrameworkBundle() 102 nibpath = [base::mac::FrameworkBundle()
105 pathForResource:@"ExtensionInstallPrompt" 103 pathForResource:@"ExtensionInstallPrompt"
106 ofType:@"nib"]; 104 ofType:@"nib"];
107 } 105 }
108 106
109 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { 107 if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
110 parentWindow_ = window; 108 parentWindow_ = window;
111 profile_ = profile; 109 profile_ = profile;
112 icon_ = *icon;
113 delegate_ = delegate; 110 delegate_ = delegate;
114 extension_ = extension;
115 prompt_.reset(new ExtensionInstallUI::Prompt(prompt)); 111 prompt_.reset(new ExtensionInstallUI::Prompt(prompt));
116 } 112 }
117 return self; 113 return self;
118 } 114 }
119 115
120 - (void)runAsModalSheet { 116 - (void)runAsModalSheet {
121 [NSApp beginSheet:[self window] 117 [NSApp beginSheet:[self window]
122 modalForWindow:parentWindow_ 118 modalForWindow:parentWindow_
123 modalDelegate:self 119 modalDelegate:self
124 didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) 120 didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
125 contextInfo:nil]; 121 contextInfo:nil];
126 } 122 }
127 123
128 - (IBAction)storeLinkClicked:(id)sender { 124 - (IBAction)storeLinkClicked:(id)sender {
129 GURL store_url( 125 GURL store_url(extension_urls::GetWebstoreItemDetailURLPrefix() +
130 extension_urls::GetWebstoreItemDetailURLPrefix() + extension_->id()); 126 prompt_->extension()->id());
131 BrowserList::GetLastActiveWithProfile(profile_)->OpenURL(OpenURLParams( 127 BrowserList::GetLastActiveWithProfile(profile_)->OpenURL(OpenURLParams(
132 store_url, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, 128 store_url, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK,
133 false)); 129 false));
134 130
135 delegate_->InstallUIAbort(/*user_initiated=*/true); 131 delegate_->InstallUIAbort(/*user_initiated=*/true);
136 [NSApp endSheet:[self window]]; 132 [NSApp endSheet:[self window]];
137 } 133 }
138 134
139 - (IBAction)cancel:(id)sender { 135 - (IBAction)cancel:(id)sender {
140 delegate_->InstallUIAbort(/*user_initiated=*/true); 136 delegate_->InstallUIAbort(/*user_initiated=*/true);
141 [NSApp endSheet:[self window]]; 137 [NSApp endSheet:[self window]];
142 } 138 }
143 139
144 - (IBAction)ok:(id)sender { 140 - (IBAction)ok:(id)sender {
145 delegate_->InstallUIProceed(); 141 delegate_->InstallUIProceed();
146 [NSApp endSheet:[self window]]; 142 [NSApp endSheet:[self window]];
147 } 143 }
148 144
149 - (void)awakeFromNib { 145 - (void)awakeFromNib {
150 // Make sure we're the window's delegate as set in the nib. 146 // Make sure we're the window's delegate as set in the nib.
151 DCHECK_EQ(self, static_cast<ExtensionInstallDialogController*>( 147 DCHECK_EQ(self, static_cast<ExtensionInstallDialogController*>(
152 [[self window] delegate])); 148 [[self window] delegate]));
153 149
154 // Set control labels. 150 // Set control labels.
155 [titleField_ setStringValue:base::SysUTF16ToNSString( 151 [titleField_ setStringValue:base::SysUTF16ToNSString(prompt_->GetHeading())];
156 prompt_->GetHeading(extension_->name()))];
157 [okButton_ setTitle:base::SysUTF16ToNSString( 152 [okButton_ setTitle:base::SysUTF16ToNSString(
158 prompt_->GetAcceptButtonLabel())]; 153 prompt_->GetAcceptButtonLabel())];
159 [cancelButton_ setTitle:prompt_->HasAbortButtonLabel() ? 154 [cancelButton_ setTitle:prompt_->HasAbortButtonLabel() ?
160 base::SysUTF16ToNSString(prompt_->GetAbortButtonLabel()) : 155 base::SysUTF16ToNSString(prompt_->GetAbortButtonLabel()) :
161 l10n_util::GetNSString(IDS_CANCEL)]; 156 l10n_util::GetNSString(IDS_CANCEL)];
162 if ([self isInlineInstall]) { 157 if ([self isInlineInstall]) {
163 prompt_->AppendRatingStars(AppendRatingStarsShim, self); 158 prompt_->AppendRatingStars(AppendRatingStarsShim, self);
164 [ratingCountField_ setStringValue:base::SysUTF16ToNSString( 159 [ratingCountField_ setStringValue:base::SysUTF16ToNSString(
165 prompt_->GetRatingCount())]; 160 prompt_->GetRatingCount())];
166 [userCountField_ setStringValue:base::SysUTF16ToNSString( 161 [userCountField_ setStringValue:base::SysUTF16ToNSString(
167 prompt_->GetUserCount())]; 162 prompt_->GetUserCount())];
168 } 163 }
169 164
170 NSImage* image = gfx::SkBitmapToNSImage(icon_); 165 [iconView_ setImage:prompt_->icon().ToNSImage()];
171 [iconView_ setImage:image];
172 166
173 // Resize |titleField_| to fit the title. 167 // Resize |titleField_| to fit the title.
174 CGFloat originalTitleWidth = [titleField_ frame].size.width; 168 CGFloat originalTitleWidth = [titleField_ frame].size.width;
175 [titleField_ sizeToFit]; 169 [titleField_ sizeToFit];
176 CGFloat newTitleWidth = [titleField_ frame].size.width; 170 CGFloat newTitleWidth = [titleField_ frame].size.width;
177 if (newTitleWidth > originalTitleWidth) { 171 if (newTitleWidth > originalTitleWidth) {
178 NSRect frame = [[self window] frame]; 172 NSRect frame = [[self window] frame];
179 frame.size.width += newTitleWidth - originalTitleWidth; 173 frame.size.width += newTitleWidth - originalTitleWidth;
180 [[self window] setFrame:frame display:NO]; 174 [[self window] setFrame:frame display:NO];
181 } 175 }
182 176
183 // Resize |okButton_| and |cancelButton_| to fit the button labels, but keep 177 // Resize |okButton_| and |cancelButton_| to fit the button labels, but keep
184 // them right-aligned. 178 // them right-aligned.
185 NSSize buttonDelta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:okButton_]; 179 NSSize buttonDelta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:okButton_];
186 if (buttonDelta.width) { 180 if (buttonDelta.width) {
187 [okButton_ setFrame:NSOffsetRect([okButton_ frame], -buttonDelta.width, 0)]; 181 [okButton_ setFrame:NSOffsetRect([okButton_ frame], -buttonDelta.width, 0)];
188 [cancelButton_ setFrame:NSOffsetRect([cancelButton_ frame], 182 [cancelButton_ setFrame:NSOffsetRect([cancelButton_ frame],
189 -buttonDelta.width, 0)]; 183 -buttonDelta.width, 0)];
190 } 184 }
191 buttonDelta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_]; 185 buttonDelta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_];
192 if (buttonDelta.width) { 186 if (buttonDelta.width) {
193 [cancelButton_ setFrame:NSOffsetRect([cancelButton_ frame], 187 [cancelButton_ setFrame:NSOffsetRect([cancelButton_ frame],
194 -buttonDelta.width, 0)]; 188 -buttonDelta.width, 0)];
195 } 189 }
196 190
197 CGFloat totalOffset = 0.0; 191 CGFloat totalOffset = 0.0;
198 // If there are any warnings, then we have to do some special layout. 192 // If there are any warnings, then we have to do some special layout.
199 if (prompt_->GetPermissionCount() > 0) { 193 if (prompt_->GetPermissionCount() > 0) {
200 [subtitleField_ setStringValue:base::SysUTF16ToNSString( 194 [subtitleField_ setStringValue:base::SysUTF16ToNSString(
201 prompt_->GetPermissionsHeader())]; 195 prompt_->GetPermissionsHeading())];
202 196
203 // We display the permission warnings as a simple text string, separated by 197 // We display the permission warnings as a simple text string, separated by
204 // newlines. 198 // newlines.
205 NSMutableString* joinedWarnings = [NSMutableString string]; 199 NSMutableString* joinedWarnings = [NSMutableString string];
206 for (size_t i = 0; i < prompt_->GetPermissionCount(); ++i) { 200 for (size_t i = 0; i < prompt_->GetPermissionCount(); ++i) {
207 if (i > 0) 201 if (i > 0)
208 [joinedWarnings appendString:@"\n"]; 202 [joinedWarnings appendString:@"\n"];
209 [joinedWarnings appendString:base::SysUTF16ToNSString( 203 [joinedWarnings appendString:base::SysUTF16ToNSString(
210 prompt_->GetPermission(i))]; 204 prompt_->GetPermission(i))];
211 } 205 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 skiaImage->width(), skiaImage->height()); 282 skiaImage->width(), skiaImage->height());
289 [view setFrame:starBounds]; 283 [view setFrame:starBounds];
290 [ratingStars_ addSubview:view]; 284 [ratingStars_ addSubview:view];
291 } 285 }
292 286
293 @end // ExtensionInstallDialogController 287 @end // ExtensionInstallDialogController
294 288
295 void ShowExtensionInstallDialogImpl( 289 void ShowExtensionInstallDialogImpl(
296 Profile* profile, 290 Profile* profile,
297 ExtensionInstallUI::Delegate* delegate, 291 ExtensionInstallUI::Delegate* delegate,
298 const Extension* extension,
299 SkBitmap* icon,
300 const ExtensionInstallUI::Prompt& prompt) { 292 const ExtensionInstallUI::Prompt& prompt) {
301 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); 293 Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
302 if (!browser) { 294 if (!browser) {
303 delegate->InstallUIAbort(false); 295 delegate->InstallUIAbort(false);
304 return; 296 return;
305 } 297 }
306 298
307 BrowserWindow* window = browser->window(); 299 BrowserWindow* window = browser->window();
308 if (!window) { 300 if (!window) {
309 delegate->InstallUIAbort(false); 301 delegate->InstallUIAbort(false);
310 return; 302 return;
311 } 303 }
312 304
313 gfx::NativeWindow native_window = window->GetNativeHandle(); 305 gfx::NativeWindow native_window = window->GetNativeHandle();
314 306
315 ExtensionInstallDialogController* controller = 307 ExtensionInstallDialogController* controller =
316 [[ExtensionInstallDialogController alloc] 308 [[ExtensionInstallDialogController alloc]
317 initWithParentWindow:native_window 309 initWithParentWindow:native_window
318 profile:profile 310 profile:profile
319 extension:extension
320 delegate:delegate 311 delegate:delegate
321 icon:icon
322 prompt:prompt]; 312 prompt:prompt];
323 313
324 // TODO(mihaip): Switch this to be tab-modal (http://crbug.com/95455) 314 // TODO(mihaip): Switch this to be tab-modal (http://crbug.com/95455)
325 [controller runAsModalSheet]; 315 [controller runAsModalSheet];
326 } 316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698