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

Side by Side Diff: chrome/browser/ui/cocoa/website_settings/website_settings_bubble_controller.mm

Issue 2232453002: Show a custom message in the page info bubble for view-source URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rsesek comment Created 4 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/website_settings/website_settings_bubble_contro ller.h" 5 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro ller.h"
6 6
7 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 10
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 176 }
177 177
178 @end 178 @end
179 179
180 @implementation WebsiteSettingsBubbleController 180 @implementation WebsiteSettingsBubbleController
181 181
182 - (CGFloat)defaultWindowWidth { 182 - (CGFloat)defaultWindowWidth {
183 return kDefaultWindowWidth; 183 return kDefaultWindowWidth;
184 } 184 }
185 185
186 bool IsInternalURL(const GURL& url) {
187 return url.SchemeIs(content::kChromeUIScheme) ||
188 url.SchemeIs(extensions::kExtensionScheme) ||
189 url.SchemeIs(content::kViewSourceScheme);
190 }
191
186 - (id)initWithParentWindow:(NSWindow*)parentWindow 192 - (id)initWithParentWindow:(NSWindow*)parentWindow
187 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge 193 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge
188 webContents:(content::WebContents*)webContents 194 webContents:(content::WebContents*)webContents
189 bubbleType:(BubbleType)bubbleType 195 url:(const GURL&)url
190 isDevToolsDisabled:(BOOL)isDevToolsDisabled { 196 isDevToolsDisabled:(BOOL)isDevToolsDisabled {
191 DCHECK(parentWindow); 197 DCHECK(parentWindow);
192 198
193 webContents_ = webContents; 199 webContents_ = webContents;
194 permissionsPresent_ = NO; 200 permissionsPresent_ = NO;
195 isDevToolsDisabled_ = isDevToolsDisabled; 201 isDevToolsDisabled_ = isDevToolsDisabled;
202 url_ = url;
196 203
197 // Use an arbitrary height; it will be changed in performLayout. 204 // Use an arbitrary height; it will be changed in performLayout.
198 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1); 205 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1);
199 // Create an empty window into which content is placed. 206 // Create an empty window into which content is placed.
200 base::scoped_nsobject<InfoBubbleWindow> window( 207 base::scoped_nsobject<InfoBubbleWindow> window(
201 [[InfoBubbleWindow alloc] initWithContentRect:contentRect 208 [[InfoBubbleWindow alloc] initWithContentRect:contentRect
202 styleMask:NSBorderlessWindowMask 209 styleMask:NSBorderlessWindowMask
203 backing:NSBackingStoreBuffered 210 backing:NSBackingStoreBuffered
204 defer:NO]); 211 defer:NO]);
205 212
206 if ((self = [super initWithWindow:window.get() 213 if ((self = [super initWithWindow:window.get()
207 parentWindow:parentWindow 214 parentWindow:parentWindow
208 anchoredAt:NSZeroPoint])) { 215 anchoredAt:NSZeroPoint])) {
209 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; 216 [[self bubble] setArrowLocation:info_bubble::kTopLeft];
210 217
211 // Create the container view that uses flipped coordinates. 218 // Create the container view that uses flipped coordinates.
212 NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300); 219 NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300);
213 contentView_.reset( 220 contentView_.reset(
214 [[FlippedView alloc] initWithFrame:contentFrame]); 221 [[FlippedView alloc] initWithFrame:contentFrame]);
215 222
216 // Replace the window's content. 223 // Replace the window's content.
217 [[[self window] contentView] setSubviews: 224 [[[self window] contentView] setSubviews:
218 [NSArray arrayWithObject:contentView_.get()]]; 225 [NSArray arrayWithObject:contentView_.get()]];
219 226
220 if (bubbleType == INTERNAL_PAGE) 227 if (IsInternalURL(url_)) {
221 [self initializeContentsForInternalPage:false]; 228 [self initializeContentsForInternalPage:url_];
222 else if (bubbleType == EXTENSION_PAGE) 229 } else {
223 [self initializeContentsForInternalPage:true];
224 else
225 [self initializeContents]; 230 [self initializeContents];
231 }
226 232
227 bridge_.reset(bridge); 233 bridge_.reset(bridge);
228 bridge_->set_bubble_controller(self); 234 bridge_->set_bubble_controller(self);
229 } 235 }
230 return self; 236 return self;
231 } 237 }
232 238
233 - (void)windowWillClose:(NSNotification*)notification { 239 - (void)windowWillClose:(NSNotification*)notification {
234 if (presenter_.get()) 240 if (presenter_.get())
235 presenter_->OnUIClosing(); 241 presenter_->OnUIClosing();
236 presenter_.reset(); 242 presenter_.reset();
237 [super windowWillClose:notification]; 243 [super windowWillClose:notification];
238 } 244 }
239 245
240 - (void)setPresenter:(WebsiteSettings*)presenter { 246 - (void)setPresenter:(WebsiteSettings*)presenter {
241 presenter_.reset(presenter); 247 presenter_.reset(presenter);
242 } 248 }
243 249
244 // Create the subviews for the bubble for internal Chrome pages. 250 // Create the subviews for the bubble for internal Chrome pages.
245 - (void)initializeContentsForInternalPage:(BOOL)isExtensionPage { 251 - (void)initializeContentsForInternalPage:(const GURL&)url {
246 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 252 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
247 253
248 NSPoint controlOrigin = NSMakePoint( 254 int text = IDR_PRODUCT_LOGO_16;
249 kInternalPageFramePadding, 255 int icon = IDR_PLUGINS_FAVICON;
250 kInternalPageFramePadding + info_bubble::kBubbleArrowHeight); 256 if (url.SchemeIs(extensions::kExtensionScheme)) {
251 NSImage* productLogoImage = 257 text = IDS_PAGE_INFO_EXTENSION_PAGE;
252 rb.GetNativeImageNamed(isExtensionPage ? IDR_PLUGINS_FAVICON 258 icon = IDR_PLUGINS_FAVICON;
253 : IDR_PRODUCT_LOGO_16) 259 } else if (url.SchemeIs(content::kViewSourceScheme)) {
254 .ToNSImage(); 260 // view-source scheme uses the same icon as other internal pages.
261 text = IDS_PAGE_INFO_VIEW_SOURCE_PAGE;
262 }
felt 2016/08/12 18:58:39 If I'm reading this right, the default is the cont
meacer 2016/08/12 21:13:49 I removed BubbleType for two reasons: - Correspond
263
264 NSPoint controlOrigin =
265 NSMakePoint(kInternalPageFramePadding,
266 kInternalPageFramePadding + info_bubble::kBubbleArrowHeight);
267 NSImage* productLogoImage = rb.GetNativeImageNamed(icon).ToNSImage();
255 NSImageView* imageView = [self addImageWithSize:[productLogoImage size] 268 NSImageView* imageView = [self addImageWithSize:[productLogoImage size]
256 toView:contentView_ 269 toView:contentView_
257 atPoint:controlOrigin]; 270 atPoint:controlOrigin];
258 [imageView setImage:productLogoImage]; 271 [imageView setImage:productLogoImage];
259 272
260 NSRect imageFrame = [imageView frame]; 273 NSRect imageFrame = [imageView frame];
261 controlOrigin.x += NSWidth(imageFrame) + kInternalPageImageSpacing; 274 controlOrigin.x += NSWidth(imageFrame) + kInternalPageImageSpacing;
262 base::string16 text = 275 NSTextField* textField = [self addText:l10n_util::GetStringUTF16(text)
263 l10n_util::GetStringUTF16(isExtensionPage ? IDS_PAGE_INFO_EXTENSION_PAGE
264 : IDS_PAGE_INFO_INTERNAL_PAGE);
265 NSTextField* textField = [self addText:text
266 withSize:[NSFont smallSystemFontSize] 276 withSize:[NSFont smallSystemFontSize]
267 bold:NO 277 bold:NO
268 toView:contentView_ 278 toView:contentView_
269 atPoint:controlOrigin]; 279 atPoint:controlOrigin];
270 // Center the image vertically with the text. Previously this code centered 280 // Center the image vertically with the text. Previously this code centered
271 // the text vertically while holding the image in place. That produced correct 281 // the text vertically while holding the image in place. That produced correct
272 // results when the image, at 26x26, was taller than (or just slightly 282 // results when the image, at 26x26, was taller than (or just slightly
273 // shorter) than the text, but produced incorrect results once the icon 283 // shorter) than the text, but produced incorrect results once the icon
274 // shrank to 16x16. The icon should now always be shorter than the text. 284 // shrank to 16x16. The icon should now always be shorter than the text.
275 // See crbug.com/572044 . 285 // See crbug.com/572044 .
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 web_contents, virtual_url, security_info); 1137 web_contents, virtual_url, security_info);
1128 return; 1138 return;
1129 } 1139 }
1130 1140
1131 // Don't show the popup if it's already being shown. Since this method is 1141 // Don't show the popup if it's already being shown. Since this method is
1132 // called each time the location icon is clicked, each click toggles the popup 1142 // called each time the location icon is clicked, each click toggles the popup
1133 // in and out. 1143 // in and out.
1134 if (g_is_popup_showing) 1144 if (g_is_popup_showing)
1135 return; 1145 return;
1136 1146
1137 BubbleType bubble_type = WEB_PAGE;
1138 if (virtual_url.SchemeIs(content::kChromeUIScheme))
1139 bubble_type = INTERNAL_PAGE;
1140 else if (virtual_url.SchemeIs(extensions::kExtensionScheme))
1141 bubble_type = EXTENSION_PAGE;
1142
1143 // Create the bridge. This will be owned by the bubble controller. 1147 // Create the bridge. This will be owned by the bubble controller.
1144 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(web_contents); 1148 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(web_contents);
1145 1149
1146 bool is_devtools_disabled = 1150 bool is_devtools_disabled =
1147 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); 1151 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled);
1148 1152
1149 // Create the bubble controller. It will dealloc itself when it closes, 1153 // Create the bubble controller. It will dealloc itself when it closes,
1150 // resetting |g_is_popup_showing|. 1154 // resetting |g_is_popup_showing|.
1151 WebsiteSettingsBubbleController* bubble_controller = 1155 WebsiteSettingsBubbleController* bubble_controller =
1152 [[WebsiteSettingsBubbleController alloc] 1156 [[WebsiteSettingsBubbleController alloc]
1153 initWithParentWindow:parent 1157 initWithParentWindow:parent
1154 websiteSettingsUIBridge:bridge 1158 websiteSettingsUIBridge:bridge
1155 webContents:web_contents 1159 webContents:web_contents
1156 bubbleType:bubble_type 1160 url:virtual_url
1157 isDevToolsDisabled:is_devtools_disabled]; 1161 isDevToolsDisabled:is_devtools_disabled];
1158 1162
1159 if (bubble_type == WEB_PAGE) { 1163 if (!IsInternalURL(virtual_url)) {
1160 // Initialize the presenter, which holds the model and controls the UI. 1164 // Initialize the presenter, which holds the model and controls the UI.
1161 // This is also owned by the bubble controller. 1165 // This is also owned by the bubble controller.
1162 WebsiteSettings* presenter = new WebsiteSettings( 1166 WebsiteSettings* presenter = new WebsiteSettings(
1163 bridge, profile, 1167 bridge, profile,
1164 TabSpecificContentSettings::FromWebContents(web_contents), web_contents, 1168 TabSpecificContentSettings::FromWebContents(web_contents), web_contents,
1165 virtual_url, security_info, content::CertStore::GetInstance()); 1169 virtual_url, security_info, content::CertStore::GetInstance());
1166 [bubble_controller setPresenter:presenter]; 1170 [bubble_controller setPresenter:presenter];
1167 } 1171 }
1168 1172
1169 [bubble_controller showWindow:nil]; 1173 [bubble_controller showWindow:nil];
(...skipping 19 matching lines...) Expand all
1189 void WebsiteSettingsUIBridge::SetPermissionInfo( 1193 void WebsiteSettingsUIBridge::SetPermissionInfo(
1190 const PermissionInfoList& permission_info_list, 1194 const PermissionInfoList& permission_info_list,
1191 const ChosenObjectInfoList& chosen_object_info_list) { 1195 const ChosenObjectInfoList& chosen_object_info_list) {
1192 [bubble_controller_ setPermissionInfo:permission_info_list 1196 [bubble_controller_ setPermissionInfo:permission_info_list
1193 andChosenObjects:chosen_object_info_list]; 1197 andChosenObjects:chosen_object_info_list];
1194 } 1198 }
1195 1199
1196 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { 1200 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) {
1197 // TODO(lgarron): Remove this from the interface. (crbug.com/571533) 1201 // TODO(lgarron): Remove this from the interface. (crbug.com/571533)
1198 } 1202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698