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 | |
Alexei Svitkine (slow)
2014/10/28 18:27:23
Nit: No need for empty line here.
guohui
2014/10/28 18:53:40
Done.
| |
259 virtual ~GaiaWebContentsDelegate() {} | |
Alexei Svitkine (slow)
2014/10/28 18:27:23
Nit: I think the preferred syntax is now:
~GaiaWe
guohui
2014/10/28 18:53:40
Done.
| |
260 | |
261 private: | |
262 // Overridden from content::WebContentsDelegate. | |
263 bool HandleContextMenu(const content::ContextMenuParams& params) override; | |
264 void HandleKeyboardEvent( | |
265 content::WebContents* source, | |
266 const content::NativeWebKeyboardEvent& event) override; | |
267 }; | |
Alexei Svitkine (slow)
2014/10/28 18:27:23
DISALLOW_COPY_AND_ASSIGN()
guohui
2014/10/28 18:53:40
Done.
| |
268 | |
269 bool GaiaWebContentsDelegate::HandleContextMenu( | |
270 const content::ContextMenuParams& params) { | |
271 // Suppresses the context menu in non-debug mode. | |
272 #ifndef NDEBUG | |
273 return false; | |
274 #else | |
275 return true; | |
276 #endif | |
277 } | |
278 | |
279 void GaiaWebContentsDelegate::HandleKeyboardEvent( | |
280 content::WebContents* source, | |
281 const content::NativeWebKeyboardEvent& event) { | |
282 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) | |
283 return; | |
284 | |
285 int chromeCommandId = [BrowserWindowUtils getCommandId:event]; | |
Alexei Svitkine (slow)
2014/10/28 18:27:23
Use hacker_style in C++ classes.
guohui
2014/10/28 18:53:40
Done.
| |
286 | |
287 bool isTextEditingCommand = | |
288 (event.modifiers & blink::WebInputEvent::MetaKey) && | |
289 (event.windowsKeyCode == ui::VKEY_A || | |
290 event.windowsKeyCode == ui::VKEY_V); | |
Roger Tawa OOO till Jul 10th
2014/10/28 18:58:13
How about VKEY_C ?
| |
291 | |
292 // TODO(guohui): maybe should add an accelerator for the back button. | |
293 if (chromeCommandId == IDC_CLOSE_WINDOW || chromeCommandId == IDC_EXIT || | |
294 isTextEditingCommand) { | |
295 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; | |
296 } | |
297 } | |
298 | |
250 // Class that listens to changes to the OAuth2Tokens for the active profile, | 299 // Class that listens to changes to the OAuth2Tokens for the active profile, |
251 // changes to the avatar menu model or browser close notifications. | 300 // changes to the avatar menu model or browser close notifications. |
252 class ActiveProfileObserverBridge : public AvatarMenuObserver, | 301 class ActiveProfileObserverBridge : public AvatarMenuObserver, |
253 public content::NotificationObserver, | 302 public content::NotificationObserver, |
254 public OAuth2TokenService::Observer { | 303 public OAuth2TokenService::Observer { |
255 public: | 304 public: |
256 ActiveProfileObserverBridge(ProfileChooserController* controller, | 305 ActiveProfileObserverBridge(ProfileChooserController* controller, |
257 Browser* browser) | 306 Browser* browser) |
258 : controller_(controller), | 307 : controller_(controller), |
259 browser_(browser), | 308 browser_(browser), |
(...skipping 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1898 errorController ? errorController->error_username() : std::string()); | 1947 errorController ? errorController->error_username() : std::string()); |
1899 messageId = IDS_PROFILES_GAIA_REAUTH_TITLE; | 1948 messageId = IDS_PROFILES_GAIA_REAUTH_TITLE; |
1900 break; | 1949 break; |
1901 default: | 1950 default: |
1902 NOTREACHED() << "Called with invalid mode=" << viewMode_; | 1951 NOTREACHED() << "Called with invalid mode=" << viewMode_; |
1903 break; | 1952 break; |
1904 } | 1953 } |
1905 | 1954 |
1906 webContents_.reset(content::WebContents::Create( | 1955 webContents_.reset(content::WebContents::Create( |
1907 content::WebContents::CreateParams(browser_->profile()))); | 1956 content::WebContents::CreateParams(browser_->profile()))); |
1957 | |
1958 webContentsDelegate_.reset(new GaiaWebContentsDelegate()); | |
1959 webContents_->SetDelegate(webContentsDelegate_.get()); | |
1908 webContents_->GetController().LoadURL(url, | 1960 webContents_->GetController().LoadURL(url, |
1909 content::Referrer(), | 1961 content::Referrer(), |
1910 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1962 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1911 std::string()); | 1963 std::string()); |
1912 NSView* webview = webContents_->GetNativeView(); | 1964 NSView* webview = webContents_->GetNativeView(); |
1913 [webview setFrameSize:NSMakeSize(kFixedGaiaViewWidth, kFixedGaiaViewHeight)]; | 1965 [webview setFrameSize:NSMakeSize(kFixedGaiaViewWidth, kFixedGaiaViewHeight)]; |
1914 [container addSubview:webview]; | 1966 [container addSubview:webview]; |
1915 content::RenderWidgetHostView* rwhv = webContents_->GetRenderWidgetHostView(); | 1967 content::RenderWidgetHostView* rwhv = webContents_->GetRenderWidgetHostView(); |
1916 if (rwhv) | 1968 if (rwhv) |
1917 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); | 1969 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2204 } | 2256 } |
2205 | 2257 |
2206 - (bool)shouldShowGoIncognito { | 2258 - (bool)shouldShowGoIncognito { |
2207 bool incognitoAvailable = | 2259 bool incognitoAvailable = |
2208 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2260 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
2209 IncognitoModePrefs::DISABLED; | 2261 IncognitoModePrefs::DISABLED; |
2210 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2262 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
2211 } | 2263 } |
2212 | 2264 |
2213 @end | 2265 @end |
OLD | NEW |