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

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

Issue 1917013002: Use a different string and icon for chrome-extension pages in Page Info Bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/mac/bind_objc_block.h" 12 #include "base/mac/bind_objc_block.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/sys_string_conversions.h" 15 #include "base/strings/sys_string_conversions.h"
16 #import "chrome/browser/certificate_viewer.h" 16 #import "chrome/browser/certificate_viewer.h"
17 #include "chrome/browser/devtools/devtools_toggle_action.h" 17 #include "chrome/browser/devtools/devtools_toggle_action.h"
18 #include "chrome/browser/devtools/devtools_window.h" 18 #include "chrome/browser/devtools/devtools_window.h"
19 #include "chrome/browser/infobars/infobar_service.h" 19 #include "chrome/browser/infobars/infobar_service.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser_dialogs.h" 21 #include "chrome/browser/ui/browser_dialogs.h"
22 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 22 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
23 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 23 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
24 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 24 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
25 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 25 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
26 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" 26 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h"
27 #import "chrome/browser/ui/tab_dialogs.h" 27 #import "chrome/browser/ui/tab_dialogs.h"
28 #include "chrome/browser/ui/website_settings/permission_menu_model.h" 28 #include "chrome/browser/ui/website_settings/permission_menu_model.h"
29 #include "chrome/browser/ui/website_settings/website_settings_utils.h"
30 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
32 #include "chrome/grit/chromium_strings.h" 31 #include "chrome/grit/chromium_strings.h"
33 #include "chrome/grit/generated_resources.h" 32 #include "chrome/grit/generated_resources.h"
34 #include "chrome/grit/theme_resources.h" 33 #include "chrome/grit/theme_resources.h"
35 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
36 #include "content/public/browser/cert_store.h" 35 #include "content/public/browser/cert_store.h"
37 #include "content/public/browser/page_navigator.h" 36 #include "content/public/browser/page_navigator.h"
38 #include "content/public/browser/ssl_host_state_delegate.h" 37 #include "content/public/browser/ssl_host_state_delegate.h"
39 #include "content/public/browser/user_metrics.h" 38 #include "content/public/browser/user_metrics.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 174
176 @implementation WebsiteSettingsBubbleController 175 @implementation WebsiteSettingsBubbleController
177 176
178 - (CGFloat)defaultWindowWidth { 177 - (CGFloat)defaultWindowWidth {
179 return kDefaultWindowWidth; 178 return kDefaultWindowWidth;
180 } 179 }
181 180
182 - (id)initWithParentWindow:(NSWindow*)parentWindow 181 - (id)initWithParentWindow:(NSWindow*)parentWindow
183 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge 182 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge
184 webContents:(content::WebContents*)webContents 183 webContents:(content::WebContents*)webContents
185 isInternalPage:(BOOL)isInternalPage 184 bubbleType:(BubbleType)bubbleType
186 isDevToolsDisabled:(BOOL)isDevToolsDisabled { 185 isDevToolsDisabled:(BOOL)isDevToolsDisabled {
187 DCHECK(parentWindow); 186 DCHECK(parentWindow);
188 187
189 webContents_ = webContents; 188 webContents_ = webContents;
190 permissionsPresent_ = NO; 189 permissionsPresent_ = NO;
191 isDevToolsDisabled_ = isDevToolsDisabled; 190 isDevToolsDisabled_ = isDevToolsDisabled;
192 191
193 // Use an arbitrary height; it will be changed in performLayout. 192 // Use an arbitrary height; it will be changed in performLayout.
194 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1); 193 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1);
195 // Create an empty window into which content is placed. 194 // Create an empty window into which content is placed.
(...skipping 10 matching lines...) Expand all
206 205
207 // Create the container view that uses flipped coordinates. 206 // Create the container view that uses flipped coordinates.
208 NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300); 207 NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300);
209 contentView_.reset( 208 contentView_.reset(
210 [[FlippedView alloc] initWithFrame:contentFrame]); 209 [[FlippedView alloc] initWithFrame:contentFrame]);
211 210
212 // Replace the window's content. 211 // Replace the window's content.
213 [[[self window] contentView] setSubviews: 212 [[[self window] contentView] setSubviews:
214 [NSArray arrayWithObject:contentView_.get()]]; 213 [NSArray arrayWithObject:contentView_.get()]];
215 214
216 if (isInternalPage) 215 if (bubbleType == INTERNAL_PAGE)
217 [self initializeContentsForInternalPage]; 216 [self initializeContentsForInternalPage:false];
217 else if (bubbleType == EXTENSION_PAGE)
218 [self initializeContentsForInternalPage:true];
218 else 219 else
219 [self initializeContents]; 220 [self initializeContents];
220 221
221 bridge_.reset(bridge); 222 bridge_.reset(bridge);
222 bridge_->set_bubble_controller(self); 223 bridge_->set_bubble_controller(self);
223 } 224 }
224 return self; 225 return self;
225 } 226 }
226 227
227 - (void)windowWillClose:(NSNotification*)notification { 228 - (void)windowWillClose:(NSNotification*)notification {
228 if (presenter_.get()) 229 if (presenter_.get())
229 presenter_->OnUIClosing(); 230 presenter_->OnUIClosing();
230 presenter_.reset(); 231 presenter_.reset();
231 [super windowWillClose:notification]; 232 [super windowWillClose:notification];
232 } 233 }
233 234
234 - (void)setPresenter:(WebsiteSettings*)presenter { 235 - (void)setPresenter:(WebsiteSettings*)presenter {
235 presenter_.reset(presenter); 236 presenter_.reset(presenter);
236 } 237 }
237 238
238 // Create the subviews for the bubble for internal Chrome pages. 239 // Create the subviews for the bubble for internal Chrome pages.
239 - (void)initializeContentsForInternalPage { 240 - (void)initializeContentsForInternalPage:(BOOL)isExtensionPage {
240 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 241 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
241 242
242 NSPoint controlOrigin = NSMakePoint( 243 NSPoint controlOrigin = NSMakePoint(
243 kInternalPageFramePadding, 244 kInternalPageFramePadding,
244 kInternalPageFramePadding + info_bubble::kBubbleArrowHeight); 245 kInternalPageFramePadding + info_bubble::kBubbleArrowHeight);
245 NSImage* productLogoImage = 246 NSImage* productLogoImage =
246 rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_16).ToNSImage(); 247 rb.GetNativeImageNamed(isExtensionPage ? IDR_PLUGINS_FAVICON
248 : IDR_PRODUCT_LOGO_16)
249 .ToNSImage();
247 NSImageView* imageView = [self addImageWithSize:[productLogoImage size] 250 NSImageView* imageView = [self addImageWithSize:[productLogoImage size]
248 toView:contentView_ 251 toView:contentView_
249 atPoint:controlOrigin]; 252 atPoint:controlOrigin];
250 [imageView setImage:productLogoImage]; 253 [imageView setImage:productLogoImage];
251 254
252 NSRect imageFrame = [imageView frame]; 255 NSRect imageFrame = [imageView frame];
253 controlOrigin.x += NSWidth(imageFrame) + kInternalPageImageSpacing; 256 controlOrigin.x += NSWidth(imageFrame) + kInternalPageImageSpacing;
254 base::string16 text = l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE); 257 base::string16 text =
258 l10n_util::GetStringUTF16(isExtensionPage ? IDS_PAGE_INFO_EXTENSION_PAGE
259 : IDS_PAGE_INFO_INTERNAL_PAGE);
255 NSTextField* textField = [self addText:text 260 NSTextField* textField = [self addText:text
256 withSize:[NSFont smallSystemFontSize] 261 withSize:[NSFont smallSystemFontSize]
257 bold:NO 262 bold:NO
258 toView:contentView_ 263 toView:contentView_
259 atPoint:controlOrigin]; 264 atPoint:controlOrigin];
260 // Center the image vertically with the text. Previously this code centered 265 // Center the image vertically with the text. Previously this code centered
261 // the text vertically while holding the image in place. That produced correct 266 // the text vertically while holding the image in place. That produced correct
262 // results when the image, at 26x26, was taller than (or just slightly 267 // results when the image, at 26x26, was taller than (or just slightly
263 // shorter) than the text, but produced incorrect results once the icon 268 // shorter) than the text, but produced incorrect results once the icon
264 // shrank to 16x16. The icon should now always be shorter than the text. 269 // shrank to 16x16. The icon should now always be shorter than the text.
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 content::WebContents* web_contents, 1113 content::WebContents* web_contents,
1109 const GURL& url, 1114 const GURL& url,
1110 const security_state::SecurityStateModel::SecurityInfo& security_info) { 1115 const security_state::SecurityStateModel::SecurityInfo& security_info) {
1111 if (chrome::ToolkitViewsDialogsEnabled()) { 1116 if (chrome::ToolkitViewsDialogsEnabled()) {
1112 chrome::ShowWebsiteSettingsBubbleViewsAtPoint( 1117 chrome::ShowWebsiteSettingsBubbleViewsAtPoint(
1113 gfx::ScreenPointFromNSPoint(AnchorPointForWindow(parent)), profile, 1118 gfx::ScreenPointFromNSPoint(AnchorPointForWindow(parent)), profile,
1114 web_contents, url, security_info); 1119 web_contents, url, security_info);
1115 return; 1120 return;
1116 } 1121 }
1117 1122
1118 bool is_internal_page = InternalChromePage(url); 1123 BubbleType bubble_type = WEB_PAGE;
1124 if (url.SchemeIs("chrome"))
palmer 2016/04/26 22:43:45 Nit: Better to use the kFooScheme constants?
meacer 2016/04/26 23:01:16 Done.
1125 bubble_type = INTERNAL_PAGE;
1126 else if (url.SchemeIs("chrome-extension"))
1127 bubble_type = EXTENSION_PAGE;
1119 1128
1120 // Create the bridge. This will be owned by the bubble controller. 1129 // Create the bridge. This will be owned by the bubble controller.
1121 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(web_contents); 1130 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(web_contents);
1122 1131
1123 bool is_devtools_disabled = 1132 bool is_devtools_disabled =
1124 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); 1133 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled);
1125 1134
1126 // Create the bubble controller. It will dealloc itself when it closes. 1135 // Create the bubble controller. It will dealloc itself when it closes.
1127 WebsiteSettingsBubbleController* bubble_controller = 1136 WebsiteSettingsBubbleController* bubble_controller =
1128 [[WebsiteSettingsBubbleController alloc] 1137 [[WebsiteSettingsBubbleController alloc]
1129 initWithParentWindow:parent 1138 initWithParentWindow:parent
1130 websiteSettingsUIBridge:bridge 1139 websiteSettingsUIBridge:bridge
1131 webContents:web_contents 1140 webContents:web_contents
1132 isInternalPage:is_internal_page 1141 bubbleType:bubble_type
1133 isDevToolsDisabled:is_devtools_disabled]; 1142 isDevToolsDisabled:is_devtools_disabled];
1134 1143
1135 if (!is_internal_page) { 1144 if (bubble_type == WEB_PAGE) {
1136 // Initialize the presenter, which holds the model and controls the UI. 1145 // Initialize the presenter, which holds the model and controls the UI.
1137 // This is also owned by the bubble controller. 1146 // This is also owned by the bubble controller.
1138 WebsiteSettings* presenter = new WebsiteSettings( 1147 WebsiteSettings* presenter = new WebsiteSettings(
1139 bridge, profile, 1148 bridge, profile,
1140 TabSpecificContentSettings::FromWebContents(web_contents), web_contents, 1149 TabSpecificContentSettings::FromWebContents(web_contents), web_contents,
1141 url, security_info, content::CertStore::GetInstance()); 1150 url, security_info, content::CertStore::GetInstance());
1142 [bubble_controller setPresenter:presenter]; 1151 [bubble_controller setPresenter:presenter];
1143 } 1152 }
1144 1153
1145 [bubble_controller showWindow:nil]; 1154 [bubble_controller showWindow:nil];
(...skipping 19 matching lines...) Expand all
1165 void WebsiteSettingsUIBridge::SetPermissionInfo( 1174 void WebsiteSettingsUIBridge::SetPermissionInfo(
1166 const PermissionInfoList& permission_info_list, 1175 const PermissionInfoList& permission_info_list,
1167 const ChosenObjectInfoList& chosen_object_info_list) { 1176 const ChosenObjectInfoList& chosen_object_info_list) {
1168 [bubble_controller_ setPermissionInfo:permission_info_list 1177 [bubble_controller_ setPermissionInfo:permission_info_list
1169 andChosenObjects:chosen_object_info_list]; 1178 andChosenObjects:chosen_object_info_list];
1170 } 1179 }
1171 1180
1172 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { 1181 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) {
1173 // TODO(lgarron): Remove this from the interface. (crbug.com/571533) 1182 // TODO(lgarron): Remove this from the interface. (crbug.com/571533)
1174 } 1183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698