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

Side by Side Diff: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm

Issue 682113002: Fix accelerators in avatar gaia webview on mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment added Created 6 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
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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/lifetime/application_lifetime.h" 17 #include "chrome/browser/lifetime/application_lifetime.h"
17 #include "chrome/browser/prefs/incognito_mode_prefs.h" 18 #include "chrome/browser/prefs/incognito_mode_prefs.h"
18 #include "chrome/browser/profiles/avatar_menu.h" 19 #include "chrome/browser/profiles/avatar_menu.h"
19 #include "chrome/browser/profiles/avatar_menu_observer.h" 20 #include "chrome/browser/profiles/avatar_menu_observer.h"
20 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 21 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
21 #include "chrome/browser/profiles/profile_info_cache.h" 22 #include "chrome/browser/profiles/profile_info_cache.h"
22 #include "chrome/browser/profiles/profile_manager.h" 23 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/browser/profiles/profile_metrics.h" 24 #include "chrome/browser/profiles/profile_metrics.h"
24 #include "chrome/browser/profiles/profile_window.h" 25 #include "chrome/browser/profiles/profile_window.h"
25 #include "chrome/browser/profiles/profiles_state.h" 26 #include "chrome/browser/profiles/profiles_state.h"
26 #include "chrome/browser/signin/local_auth.h" 27 #include "chrome/browser/signin/local_auth.h"
27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
28 #include "chrome/browser/signin/signin_header_helper.h" 29 #include "chrome/browser/signin/signin_header_helper.h"
29 #include "chrome/browser/signin/signin_manager_factory.h" 30 #include "chrome/browser/signin/signin_manager_factory.h"
30 #include "chrome/browser/signin/signin_promo.h" 31 #include "chrome/browser/signin/signin_promo.h"
31 #include "chrome/browser/signin/signin_ui_util.h" 32 #include "chrome/browser/signin/signin_ui_util.h"
32 #include "chrome/browser/ui/browser.h" 33 #include "chrome/browser/ui/browser.h"
33 #include "chrome/browser/ui/browser_commands.h" 34 #include "chrome/browser/ui/browser_commands.h"
34 #include "chrome/browser/ui/browser_window.h" 35 #include "chrome/browser/ui/browser_window.h"
35 #include "chrome/browser/ui/chrome_pages.h" 36 #include "chrome/browser/ui/chrome_pages.h"
36 #include "chrome/browser/ui/chrome_style.h" 37 #include "chrome/browser/ui/chrome_style.h"
38 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
37 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 39 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
38 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 40 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
39 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" 41 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h"
40 #include "chrome/browser/ui/singleton_tabs.h" 42 #include "chrome/browser/ui/singleton_tabs.h"
41 #include "chrome/browser/ui/user_manager.h" 43 #include "chrome/browser/ui/user_manager.h"
42 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 44 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
43 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 45 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
44 #include "chrome/common/pref_names.h" 46 #include "chrome/common/pref_names.h"
45 #include "chrome/common/url_constants.h" 47 #include "chrome/common/url_constants.h"
46 #include "chrome/grit/chromium_strings.h" 48 #include "chrome/grit/chromium_strings.h"
47 #include "chrome/grit/generated_resources.h" 49 #include "chrome/grit/generated_resources.h"
48 #include "components/signin/core/browser/mutable_profile_oauth2_token_service.h" 50 #include "components/signin/core/browser/mutable_profile_oauth2_token_service.h"
49 #include "components/signin/core/browser/profile_oauth2_token_service.h" 51 #include "components/signin/core/browser/profile_oauth2_token_service.h"
50 #include "components/signin/core/browser/signin_manager.h" 52 #include "components/signin/core/browser/signin_manager.h"
51 #include "components/signin/core/common/profile_management_switches.h" 53 #include "components/signin/core/common/profile_management_switches.h"
54 #include "content/public/browser/native_web_keyboard_event.h"
52 #include "content/public/browser/notification_service.h" 55 #include "content/public/browser/notification_service.h"
53 #include "content/public/browser/render_widget_host_view.h" 56 #include "content/public/browser/render_widget_host_view.h"
54 #include "content/public/browser/web_contents.h" 57 #include "content/public/browser/web_contents.h"
55 #include "google_apis/gaia/oauth2_token_service.h" 58 #include "google_apis/gaia/oauth2_token_service.h"
56 #include "grit/theme_resources.h" 59 #include "grit/theme_resources.h"
57 #include "skia/ext/skia_utils_mac.h" 60 #include "skia/ext/skia_utils_mac.h"
58 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" 61 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h"
59 #import "ui/base/cocoa/cocoa_base_utils.h" 62 #import "ui/base/cocoa/cocoa_base_utils.h"
60 #import "ui/base/cocoa/controls/blue_label_button.h" 63 #import "ui/base/cocoa/controls/blue_label_button.h"
61 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" 64 #import "ui/base/cocoa/controls/hyperlink_button_cell.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 243 }
241 244
242 bool HasAuthError(Profile* profile) { 245 bool HasAuthError(Profile* profile) {
243 const SigninErrorController* error_controller = 246 const SigninErrorController* error_controller =
244 profiles::GetSigninErrorController(profile); 247 profiles::GetSigninErrorController(profile);
245 return error_controller && error_controller->HasError(); 248 return error_controller && error_controller->HasError();
246 } 249 }
247 250
248 } // namespace 251 } // namespace
249 252
253 // Custom WebContentsDelegate that allows handling of hotkeys and suppresses
254 // the context menu.
255 class GaiaWebContentsDelegate : public content::WebContentsDelegate {
256 public:
257 GaiaWebContentsDelegate() {}
258 ~GaiaWebContentsDelegate() override {}
259
260 private:
261 // content::WebContentsDelegate:
262 bool HandleContextMenu(const content::ContextMenuParams& params) override;
263 void HandleKeyboardEvent(
264 content::WebContents* source,
265 const content::NativeWebKeyboardEvent& event) override;
266
267 DISALLOW_COPY_AND_ASSIGN(GaiaWebContentsDelegate);
268 };
269
270 bool GaiaWebContentsDelegate::HandleContextMenu(
271 const content::ContextMenuParams& params) {
272 // Suppresses the context menu because some features, such as inspecting
273 // elements, are not appropriate in a bubble.
274 return true;
275 }
276
277 void GaiaWebContentsDelegate::HandleKeyboardEvent(
278 content::WebContents* source,
279 const content::NativeWebKeyboardEvent& event) {
280 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event])
281 return;
282
283 int chrome_command_id = [BrowserWindowUtils getCommandId:event];
284
285 bool is_text_editing_command =
286 (event.modifiers & blink::WebInputEvent::MetaKey) &&
287 (event.windowsKeyCode == ui::VKEY_A ||
288 event.windowsKeyCode == ui::VKEY_V);
289
290 // TODO(guohui): maybe should add an accelerator for the back button.
291 if (chrome_command_id == IDC_CLOSE_WINDOW || chrome_command_id == IDC_EXIT ||
292 is_text_editing_command) {
293 [[NSApp mainMenu] performKeyEquivalent:event.os_event];
294 }
295 }
296
250 // Class that listens to changes to the OAuth2Tokens for the active profile, 297 // Class that listens to changes to the OAuth2Tokens for the active profile,
251 // changes to the avatar menu model or browser close notifications. 298 // changes to the avatar menu model or browser close notifications.
252 class ActiveProfileObserverBridge : public AvatarMenuObserver, 299 class ActiveProfileObserverBridge : public AvatarMenuObserver,
253 public content::NotificationObserver, 300 public content::NotificationObserver,
254 public OAuth2TokenService::Observer { 301 public OAuth2TokenService::Observer {
255 public: 302 public:
256 ActiveProfileObserverBridge(ProfileChooserController* controller, 303 ActiveProfileObserverBridge(ProfileChooserController* controller,
257 Browser* browser) 304 Browser* browser)
258 : controller_(controller), 305 : controller_(controller),
259 browser_(browser), 306 browser_(browser),
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 - (void)moveDown:(id)sender { 1107 - (void)moveDown:(id)sender {
1061 [[self window] selectNextKeyView:self]; 1108 [[self window] selectNextKeyView:self];
1062 } 1109 }
1063 1110
1064 - (void)moveUp:(id)sender { 1111 - (void)moveUp:(id)sender {
1065 [[self window] selectPreviousKeyView:self]; 1112 [[self window] selectPreviousKeyView:self];
1066 } 1113 }
1067 1114
1068 - (void)cleanUpEmbeddedViewContents { 1115 - (void)cleanUpEmbeddedViewContents {
1069 webContents_.reset(); 1116 webContents_.reset();
1117 webContentsDelegate_.reset();
1070 } 1118 }
1071 1119
1072 - (id)initWithBrowser:(Browser*)browser 1120 - (id)initWithBrowser:(Browser*)browser
1073 anchoredAt:(NSPoint)point 1121 anchoredAt:(NSPoint)point
1074 viewMode:(profiles::BubbleViewMode)viewMode 1122 viewMode:(profiles::BubbleViewMode)viewMode
1075 tutorialMode:(profiles::TutorialMode)tutorialMode 1123 tutorialMode:(profiles::TutorialMode)tutorialMode
1076 serviceType:(signin::GAIAServiceType)serviceType { 1124 serviceType:(signin::GAIAServiceType)serviceType {
1077 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] 1125 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc]
1078 initWithContentRect:ui::kWindowSizeDeterminedLater 1126 initWithContentRect:ui::kWindowSizeDeterminedLater
1079 styleMask:NSBorderlessWindowMask 1127 styleMask:NSBorderlessWindowMask
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 errorController ? errorController->error_username() : std::string()); 1946 errorController ? errorController->error_username() : std::string());
1899 messageId = IDS_PROFILES_GAIA_REAUTH_TITLE; 1947 messageId = IDS_PROFILES_GAIA_REAUTH_TITLE;
1900 break; 1948 break;
1901 default: 1949 default:
1902 NOTREACHED() << "Called with invalid mode=" << viewMode_; 1950 NOTREACHED() << "Called with invalid mode=" << viewMode_;
1903 break; 1951 break;
1904 } 1952 }
1905 1953
1906 webContents_.reset(content::WebContents::Create( 1954 webContents_.reset(content::WebContents::Create(
1907 content::WebContents::CreateParams(browser_->profile()))); 1955 content::WebContents::CreateParams(browser_->profile())));
1956
1957 webContentsDelegate_.reset(new GaiaWebContentsDelegate());
1958 webContents_->SetDelegate(webContentsDelegate_.get());
1908 webContents_->GetController().LoadURL(url, 1959 webContents_->GetController().LoadURL(url,
1909 content::Referrer(), 1960 content::Referrer(),
1910 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 1961 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
1911 std::string()); 1962 std::string());
1912 NSView* webview = webContents_->GetNativeView(); 1963 NSView* webview = webContents_->GetNativeView();
1913 [webview setFrameSize:NSMakeSize(kFixedGaiaViewWidth, kFixedGaiaViewHeight)]; 1964 [webview setFrameSize:NSMakeSize(kFixedGaiaViewWidth, kFixedGaiaViewHeight)];
1914 [container addSubview:webview]; 1965 [container addSubview:webview];
1915 content::RenderWidgetHostView* rwhv = webContents_->GetRenderWidgetHostView(); 1966 content::RenderWidgetHostView* rwhv = webContents_->GetRenderWidgetHostView();
1916 if (rwhv) 1967 if (rwhv)
1917 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); 1968 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
2204 } 2255 }
2205 2256
2206 - (bool)shouldShowGoIncognito { 2257 - (bool)shouldShowGoIncognito {
2207 bool incognitoAvailable = 2258 bool incognitoAvailable =
2208 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2259 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2209 IncognitoModePrefs::DISABLED; 2260 IncognitoModePrefs::DISABLED;
2210 return incognitoAvailable && !browser_->profile()->IsGuestSession(); 2261 return incognitoAvailable && !browser_->profile()->IsGuestSession();
2211 } 2262 }
2212 2263
2213 @end 2264 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h ('k') | chrome/browser/ui/views/profiles/profile_chooser_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698