Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 // Overridden from content::WebContentsDelegate. | |
|
Alexei Svitkine (slow)
2014/10/28 18:58:42
Nit: Change comment to:
// content::WebContentsDe
guohui
2014/10/28 19:02:39
Done.
| |
| 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 in non-debug mode. | |
| 273 #ifndef NDEBUG | |
| 274 return false; | |
| 275 #else | |
| 276 return true; | |
| 277 #endif | |
| 278 } | |
| 279 | |
| 280 void GaiaWebContentsDelegate::HandleKeyboardEvent( | |
| 281 content::WebContents* source, | |
| 282 const content::NativeWebKeyboardEvent& event) { | |
| 283 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) | |
| 284 return; | |
| 285 | |
| 286 int chrome_command_id = [BrowserWindowUtils getCommandId:event]; | |
| 287 | |
| 288 bool is_text_editing_command = | |
| 289 (event.modifiers & blink::WebInputEvent::MetaKey) && | |
| 290 (event.windowsKeyCode == ui::VKEY_A || | |
| 291 event.windowsKeyCode == ui::VKEY_V); | |
| 292 | |
| 293 // TODO(guohui): maybe should add an accelerator for the back button. | |
| 294 if (chrome_command_id == IDC_CLOSE_WINDOW || chrome_command_id == IDC_EXIT || | |
| 295 is_text_editing_command) { | |
| 296 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; | |
| 297 } | |
| 298 } | |
| 299 | |
| 250 // Class that listens to changes to the OAuth2Tokens for the active profile, | 300 // Class that listens to changes to the OAuth2Tokens for the active profile, |
| 251 // changes to the avatar menu model or browser close notifications. | 301 // changes to the avatar menu model or browser close notifications. |
| 252 class ActiveProfileObserverBridge : public AvatarMenuObserver, | 302 class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| 253 public content::NotificationObserver, | 303 public content::NotificationObserver, |
| 254 public OAuth2TokenService::Observer { | 304 public OAuth2TokenService::Observer { |
| 255 public: | 305 public: |
| 256 ActiveProfileObserverBridge(ProfileChooserController* controller, | 306 ActiveProfileObserverBridge(ProfileChooserController* controller, |
| 257 Browser* browser) | 307 Browser* browser) |
| 258 : controller_(controller), | 308 : controller_(controller), |
| 259 browser_(browser), | 309 browser_(browser), |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1060 - (void)moveDown:(id)sender { | 1110 - (void)moveDown:(id)sender { |
| 1061 [[self window] selectNextKeyView:self]; | 1111 [[self window] selectNextKeyView:self]; |
| 1062 } | 1112 } |
| 1063 | 1113 |
| 1064 - (void)moveUp:(id)sender { | 1114 - (void)moveUp:(id)sender { |
| 1065 [[self window] selectPreviousKeyView:self]; | 1115 [[self window] selectPreviousKeyView:self]; |
| 1066 } | 1116 } |
| 1067 | 1117 |
| 1068 - (void)cleanUpEmbeddedViewContents { | 1118 - (void)cleanUpEmbeddedViewContents { |
| 1069 webContents_.reset(); | 1119 webContents_.reset(); |
| 1120 webContentsDelegate_.reset(); | |
| 1070 } | 1121 } |
| 1071 | 1122 |
| 1072 - (id)initWithBrowser:(Browser*)browser | 1123 - (id)initWithBrowser:(Browser*)browser |
| 1073 anchoredAt:(NSPoint)point | 1124 anchoredAt:(NSPoint)point |
| 1074 viewMode:(profiles::BubbleViewMode)viewMode | 1125 viewMode:(profiles::BubbleViewMode)viewMode |
| 1075 tutorialMode:(profiles::TutorialMode)tutorialMode | 1126 tutorialMode:(profiles::TutorialMode)tutorialMode |
| 1076 serviceType:(signin::GAIAServiceType)serviceType { | 1127 serviceType:(signin::GAIAServiceType)serviceType { |
| 1077 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] | 1128 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] |
| 1078 initWithContentRect:ui::kWindowSizeDeterminedLater | 1129 initWithContentRect:ui::kWindowSizeDeterminedLater |
| 1079 styleMask:NSBorderlessWindowMask | 1130 styleMask:NSBorderlessWindowMask |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1898 errorController ? errorController->error_username() : std::string()); | 1949 errorController ? errorController->error_username() : std::string()); |
| 1899 messageId = IDS_PROFILES_GAIA_REAUTH_TITLE; | 1950 messageId = IDS_PROFILES_GAIA_REAUTH_TITLE; |
| 1900 break; | 1951 break; |
| 1901 default: | 1952 default: |
| 1902 NOTREACHED() << "Called with invalid mode=" << viewMode_; | 1953 NOTREACHED() << "Called with invalid mode=" << viewMode_; |
| 1903 break; | 1954 break; |
| 1904 } | 1955 } |
| 1905 | 1956 |
| 1906 webContents_.reset(content::WebContents::Create( | 1957 webContents_.reset(content::WebContents::Create( |
| 1907 content::WebContents::CreateParams(browser_->profile()))); | 1958 content::WebContents::CreateParams(browser_->profile()))); |
| 1959 | |
| 1960 webContentsDelegate_.reset(new GaiaWebContentsDelegate()); | |
| 1961 webContents_->SetDelegate(webContentsDelegate_.get()); | |
| 1908 webContents_->GetController().LoadURL(url, | 1962 webContents_->GetController().LoadURL(url, |
| 1909 content::Referrer(), | 1963 content::Referrer(), |
| 1910 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1964 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 1911 std::string()); | 1965 std::string()); |
| 1912 NSView* webview = webContents_->GetNativeView(); | 1966 NSView* webview = webContents_->GetNativeView(); |
| 1913 [webview setFrameSize:NSMakeSize(kFixedGaiaViewWidth, kFixedGaiaViewHeight)]; | 1967 [webview setFrameSize:NSMakeSize(kFixedGaiaViewWidth, kFixedGaiaViewHeight)]; |
| 1914 [container addSubview:webview]; | 1968 [container addSubview:webview]; |
| 1915 content::RenderWidgetHostView* rwhv = webContents_->GetRenderWidgetHostView(); | 1969 content::RenderWidgetHostView* rwhv = webContents_->GetRenderWidgetHostView(); |
| 1916 if (rwhv) | 1970 if (rwhv) |
| 1917 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); | 1971 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2204 } | 2258 } |
| 2205 | 2259 |
| 2206 - (bool)shouldShowGoIncognito { | 2260 - (bool)shouldShowGoIncognito { |
| 2207 bool incognitoAvailable = | 2261 bool incognitoAvailable = |
| 2208 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2262 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2209 IncognitoModePrefs::DISABLED; | 2263 IncognitoModePrefs::DISABLED; |
| 2210 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2264 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
| 2211 } | 2265 } |
| 2212 | 2266 |
| 2213 @end | 2267 @end |
| OLD | NEW |