blob: 6aad6113263e3397e3eb5c2622d40ef0c6884a5d [file] [log] [blame]
[email protected]3a80ea332012-01-09 19:53:291// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7d791652010-12-01 16:34:492// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
6
[email protected]a932d9e2011-09-29 01:14:347#include "base/bind.h"
[email protected]7d791652010-12-01 16:34:498#include "base/command_line.h"
9#include "base/logging.h"
[email protected]d82a3c9f2012-02-22 04:46:0010#include "base/mac/mac_util.h"
[email protected]7d791652010-12-01 16:34:4911#include "base/message_loop.h"
12#include "base/sys_string_conversions.h"
13#include "chrome/app/chrome_command_ids.h"
14#include "chrome/browser/bookmarks/bookmark_utils.h"
15#include "chrome/browser/download/download_shelf.h"
[email protected]7d791652010-12-01 16:34:4916#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3317#include "chrome/browser/profiles/profile.h"
[email protected]7d791652010-12-01 16:34:4918#include "chrome/browser/ui/browser.h"
19#include "chrome/browser/ui/browser_list.h"
[email protected]7d2d08152011-10-25 22:58:4720#import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h"
[email protected]2f733a02011-10-06 15:17:3421#import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h"
[email protected]464f0012011-07-07 02:12:5122#import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h"
[email protected]7d791652010-12-01 16:34:4923#import "chrome/browser/ui/cocoa/browser_window_controller.h"
[email protected]3a1381d2011-08-26 18:12:1324#import "chrome/browser/ui/cocoa/browser_window_utils.h"
[email protected]7d791652010-12-01 16:34:4925#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
[email protected]fa8102292011-01-20 16:21:2326#import "chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h"
[email protected]7d791652010-12-01 16:34:4927#import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
[email protected]632983f2011-08-08 22:51:2428#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
[email protected]7d791652010-12-01 16:34:4929#import "chrome/browser/ui/cocoa/html_dialog_window_controller.h"
[email protected]51152d6d2011-11-07 01:55:1230#import "chrome/browser/ui/cocoa/info_bubble_view.h"
[email protected]7d791652010-12-01 16:34:4931#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
[email protected]a7d83ca2011-03-06 14:41:0732#import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
[email protected]7d791652010-12-01 16:34:4933#include "chrome/browser/ui/cocoa/restart_browser.h"
34#include "chrome/browser/ui/cocoa/status_bubble_mac.h"
35#include "chrome/browser/ui/cocoa/task_manager_mac.h"
[email protected]8450c4f2011-01-19 22:16:2236#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
[email protected]7e2514c2011-11-28 20:04:4537#include "chrome/browser/ui/page_info_bubble.h"
[email protected]6a3ec2312010-12-02 19:30:1938#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]7b937362011-10-05 08:28:0739#include "chrome/browser/ui/webui/task_manager_dialog.h"
[email protected]432115822011-07-10 15:52:2740#include "chrome/common/chrome_notification_types.h"
[email protected]7d791652010-12-01 16:34:4941#include "chrome/common/pref_names.h"
[email protected]ad50def52011-10-19 23:17:0742#include "content/public/browser/notification_source.h"
[email protected]8bc38d22011-10-14 20:39:2043#include "content/public/browser/native_web_keyboard_event.h"
[email protected]6c2381d2011-10-19 02:52:5344#include "content/public/browser/notification_details.h"
[email protected]e8558cf22012-01-10 03:10:5145#include "content/public/browser/web_contents.h"
[email protected]7d791652010-12-01 16:34:4946#include "grit/chromium_strings.h"
47#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1748#include "ui/base/l10n/l10n_util_mac.h"
[email protected]08397d52011-02-05 01:53:3849#include "ui/gfx/rect.h"
[email protected]7d791652010-12-01 16:34:4950
[email protected]d583e3f22011-12-27 21:38:1751using content::SSLStatus;
[email protected]2a6bc3e2011-12-28 23:51:3352using content::WebContents;
[email protected]d583e3f22011-12-27 21:38:1753
[email protected]400eaf82011-08-22 15:47:3954// Replicate specific 10.7 SDK declarations for building with prior SDKs.
55#if !defined(MAC_OS_X_VERSION_10_7) || \
56 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
57
58enum {
59 NSWindowAnimationBehaviorDefault = 0,
60 NSWindowAnimationBehaviorNone = 2,
61 NSWindowAnimationBehaviorDocumentWindow = 3,
62 NSWindowAnimationBehaviorUtilityWindow = 4,
63 NSWindowAnimationBehaviorAlertPanel = 5
64};
65typedef NSInteger NSWindowAnimationBehavior;
66
67@interface NSWindow (LionSDKDeclarations)
68- (NSWindowAnimationBehavior)animationBehavior;
69- (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior;
70@end
71
72#endif // MAC_OS_X_VERSION_10_7
73
[email protected]7d791652010-12-01 16:34:4974BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser,
[email protected]400eaf82011-08-22 15:47:3975 BrowserWindowController* controller)
[email protected]7d791652010-12-01 16:34:4976 : browser_(browser),
77 controller_(controller),
[email protected]ad996342012-01-14 00:29:5978 confirm_close_factory_(browser),
79 attention_request_id_(0) {
[email protected]cfecf9432011-09-27 17:10:0880
[email protected]3710d0002011-10-11 00:35:0081 pref_change_registrar_.Init(browser_->profile()->GetPrefs());
82 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this);
83
[email protected]cfecf9432011-09-27 17:10:0884 initial_show_state_ = browser_->GetSavedWindowShowState();
[email protected]7d791652010-12-01 16:34:4985}
86
87BrowserWindowCocoa::~BrowserWindowCocoa() {
88}
89
90void BrowserWindowCocoa::Show() {
91 // The Browser associated with this browser window must become the active
92 // browser at the time |Show()| is called. This is the natural behaviour under
93 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:|
94 // until we return to the runloop. Therefore any calls to
95 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return
96 // the previous browser instead if we don't explicitly set it here.
97 BrowserList::SetLastActive(browser_);
98
[email protected]8bc061f2011-08-31 22:46:2399 bool is_session_restore = browser_->is_session_restore();
[email protected]b5cc93c2011-09-02 02:33:42100 NSWindowAnimationBehavior saved_animation_behavior =
101 NSWindowAnimationBehaviorDefault;
[email protected]8bc061f2011-08-31 22:46:23102 bool did_save_animation_behavior = false;
103 // Turn off swishing when restoring windows.
104 if (is_session_restore &&
105 [window() respondsToSelector:@selector(animationBehavior)] &&
106 [window() respondsToSelector:@selector(setAnimationBehavior:)]) {
107 did_save_animation_behavior = true;
108 saved_animation_behavior = [window() animationBehavior];
109 [window() setAnimationBehavior:NSWindowAnimationBehaviorNone];
110 }
[email protected]400eaf82011-08-22 15:47:39111
[email protected]8bc061f2011-08-31 22:46:23112 [window() makeKeyAndOrderFront:controller_];
[email protected]400eaf82011-08-22 15:47:39113
[email protected]8bc061f2011-08-31 22:46:23114 // When creating windows from nibs it is necessary to |makeKeyAndOrderFront:|
115 // prior to |orderOut:| then |miniaturize:| when restoring windows in the
116 // minimized state.
[email protected]cfecf9432011-09-27 17:10:08117 if (initial_show_state_ == ui::SHOW_STATE_MINIMIZED) {
[email protected]400eaf82011-08-22 15:47:39118 [window() orderOut:controller_];
119 [window() miniaturize:controller_];
[email protected]85b0ac62012-02-09 01:57:43120 } else if (initial_show_state_ == ui::SHOW_STATE_FULLSCREEN) {
121 browser_->ToggleFullscreenMode(false);
[email protected]400eaf82011-08-22 15:47:39122 }
[email protected]cfecf9432011-09-27 17:10:08123 initial_show_state_ = ui::SHOW_STATE_DEFAULT;
[email protected]8bc061f2011-08-31 22:46:23124
125 // Restore window animation behavior.
126 if (did_save_animation_behavior)
127 [window() setAnimationBehavior:saved_animation_behavior];
[email protected]2f516c792011-09-19 22:22:09128
129 browser_->OnWindowDidShow();
[email protected]7d791652010-12-01 16:34:49130}
131
[email protected]d4db6c702011-03-28 21:49:14132void BrowserWindowCocoa::ShowInactive() {
[email protected]400eaf82011-08-22 15:47:39133 [window() orderFront:controller_];
[email protected]d4db6c702011-03-28 21:49:14134}
135
[email protected]7d791652010-12-01 16:34:49136void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) {
[email protected]ccb5895f2011-06-09 21:16:14137 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds];
138
[email protected]55c87fa2011-10-15 07:28:28139 ExitFullscreen();
[email protected]ccb5895f2011-06-09 21:16:14140 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0,
141 real_bounds.width(),
142 real_bounds.height());
[email protected]7d791652010-12-01 16:34:49143 // Flip coordinates based on the primary screen.
144 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
145 cocoa_bounds.origin.y =
[email protected]ccb5895f2011-06-09 21:16:14146 [screen frame].size.height - real_bounds.height() - real_bounds.y();
[email protected]7d791652010-12-01 16:34:49147
148 [window() setFrame:cocoa_bounds display:YES];
149}
150
151// Callers assume that this doesn't immediately delete the Browser object.
152// The controller implementing the window delegate methods called from
153// |-performClose:| must take precautions to ensure that.
154void BrowserWindowCocoa::Close() {
155 // If there is an overlay window, we contain a tab being dragged between
156 // windows. Don't hide the window as it makes the UI extra confused. We can
157 // still close the window, as that will happen when the drag completes.
[email protected]5ae6c502012-02-06 20:06:11158 if ([controller_ overlayWindow])
[email protected]7d791652010-12-01 16:34:49159 [controller_ deferPerformClose];
[email protected]5ae6c502012-02-06 20:06:11160 else
[email protected]7d791652010-12-01 16:34:49161 [window() performClose:controller_];
[email protected]7d791652010-12-01 16:34:49162}
163
164void BrowserWindowCocoa::Activate() {
165 [controller_ activate];
166}
167
168void BrowserWindowCocoa::Deactivate() {
169 // TODO(jcivelli): http://crbug.com/51364 Implement me.
170 NOTIMPLEMENTED();
171}
172
[email protected]ad996342012-01-14 00:29:59173void BrowserWindowCocoa::FlashFrame(bool flash) {
174 if (flash) {
175 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest];
176 } else {
177 [NSApp cancelUserAttentionRequest:attention_request_id_];
178 attention_request_id_ = 0;
179 }
[email protected]7d791652010-12-01 16:34:49180}
181
182bool BrowserWindowCocoa::IsActive() const {
183 return [window() isKeyWindow];
184}
185
186gfx::NativeWindow BrowserWindowCocoa::GetNativeHandle() {
187 return window();
188}
189
190BrowserWindowTesting* BrowserWindowCocoa::GetBrowserWindowTesting() {
191 return NULL;
192}
193
194StatusBubble* BrowserWindowCocoa::GetStatusBubble() {
195 return [controller_ statusBubble];
196}
197
[email protected]c9bd2e82011-04-15 23:28:19198void BrowserWindowCocoa::ToolbarSizeChanged(bool is_animating) {
[email protected]7d791652010-12-01 16:34:49199 // According to beng, this is an ugly method that comes from the days when the
[email protected]e8558cf22012-01-10 03:10:51200 // download shelf was a ChromeView attached to the WebContents, and as its
[email protected]7d791652010-12-01 16:34:49201 // size changed via animation it notified through TCD/etc to the browser view
202 // to relayout for each tick of the animation. We don't need anything of the
203 // sort on Mac.
204}
205
206void BrowserWindowCocoa::UpdateTitleBar() {
207 NSString* newTitle =
208 base::SysUTF16ToNSString(browser_->GetWindowTitleForCurrentTab());
209
[email protected]d78e615e2011-09-06 21:46:03210 pending_window_title_.reset(
211 [BrowserWindowUtils scheduleReplaceOldTitle:pending_window_title_.get()
212 withNewTitle:newTitle
213 forWindow:window()]);
[email protected]7d791652010-12-01 16:34:49214}
215
[email protected]09b29342011-06-24 19:18:48216void BrowserWindowCocoa::BookmarkBarStateChanged(
217 BookmarkBar::AnimateChangeType change_type) {
218 // TODO: route changes to state through this.
[email protected]7d791652010-12-01 16:34:49219}
220
221void BrowserWindowCocoa::UpdateDevTools() {
222 [controller_ updateDevToolsForContents:
[email protected]4ca15302012-01-03 05:53:20223 browser_->GetSelectedWebContents()];
[email protected]7d791652010-12-01 16:34:49224}
225
[email protected]853e16eb2011-12-29 16:58:19226void BrowserWindowCocoa::SetDevToolsDockSide(DevToolsDockSide side) {
227 [controller_ setDevToolsDockToRight:side == DEVTOOLS_DOCK_SIDE_RIGHT];
228}
229
[email protected]7d791652010-12-01 16:34:49230void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) {
231 // Do nothing on Mac.
232}
233
234void BrowserWindowCocoa::SetStarredState(bool is_starred) {
235 [controller_ setStarredState:is_starred ? YES : NO];
236}
237
238gfx::Rect BrowserWindowCocoa::GetRestoredBounds() const {
239 // Flip coordinates based on the primary screen.
240 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
241 NSRect frame = [controller_ regularWindowFrame];
242 gfx::Rect bounds(frame.origin.x, 0, frame.size.width, frame.size.height);
243 bounds.set_y([screen frame].size.height - frame.origin.y - frame.size.height);
244 return bounds;
245}
246
[email protected]d479b8e22011-02-09 05:19:49247gfx::Rect BrowserWindowCocoa::GetBounds() const {
248 return GetRestoredBounds();
249}
250
[email protected]7d791652010-12-01 16:34:49251bool BrowserWindowCocoa::IsMaximized() const {
252 return [window() isZoomed];
253}
254
[email protected]400eaf82011-08-22 15:47:39255bool BrowserWindowCocoa::IsMinimized() const {
256 return [window() isMiniaturized];
257}
258
[email protected]541e3ee2011-11-22 01:31:10259void BrowserWindowCocoa::Maximize() {
260 // Zoom toggles so only call if not already maximized.
261 if (!IsMaximized())
262 [window() zoom:controller_];
263}
264
265void BrowserWindowCocoa::Minimize() {
266 [window() miniaturize:controller_];
267}
268
269void BrowserWindowCocoa::Restore() {
270 if (IsMaximized())
271 [window() zoom:controller_]; // Toggles zoom mode.
272 else if (IsMinimized())
273 [window() deminiaturize:controller_];
274}
275
[email protected]8d944b32011-10-17 06:11:53276void BrowserWindowCocoa::EnterFullscreen(
[email protected]22d74a6b2011-10-17 20:30:31277 const GURL& url, FullscreenExitBubbleType bubble_type) {
278 [controller_ enterFullscreenForURL:url
279 bubbleType:bubble_type];
[email protected]55c87fa2011-10-15 07:28:28280}
281
282void BrowserWindowCocoa::ExitFullscreen() {
[email protected]22d74a6b2011-10-17 20:30:31283 [controller_ exitFullscreen];
[email protected]8d944b32011-10-17 06:11:53284}
285
286void BrowserWindowCocoa::UpdateFullscreenExitBubbleContent(
287 const GURL& url,
288 FullscreenExitBubbleType bubble_type) {
[email protected]22d74a6b2011-10-17 20:30:31289 [controller_ updateFullscreenExitBubbleURL:url bubbleType:bubble_type];
[email protected]7d791652010-12-01 16:34:49290}
291
292bool BrowserWindowCocoa::IsFullscreen() const {
[email protected]8d944b32011-10-17 06:11:53293 return [controller_ isFullscreen];
[email protected]7d791652010-12-01 16:34:49294}
295
296bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const {
297 return false;
298}
299
300void BrowserWindowCocoa::ConfirmAddSearchProvider(
301 const TemplateURL* template_url,
302 Profile* profile) {
[email protected]464f0012011-07-07 02:12:51303 // The controller will release itself when the window closes.
304 EditSearchEngineCocoaController* editor =
305 [[EditSearchEngineCocoaController alloc] initWithProfile:profile
306 delegate:NULL
307 templateURL:template_url];
308 [NSApp beginSheet:[editor window]
309 modalForWindow:window()
310 modalDelegate:controller_
311 didEndSelector:@selector(sheetDidEnd:returnCode:context:)
312 contextInfo:NULL];
[email protected]7d791652010-12-01 16:34:49313}
314
315LocationBar* BrowserWindowCocoa::GetLocationBar() const {
316 return [controller_ locationBarBridge];
317}
318
319void BrowserWindowCocoa::SetFocusToLocationBar(bool select_all) {
320 [controller_ focusLocationBar:select_all ? YES : NO];
321}
322
323void BrowserWindowCocoa::UpdateReloadStopState(bool is_loading, bool force) {
324 [controller_ setIsLoading:is_loading force:force];
325}
326
327void BrowserWindowCocoa::UpdateToolbar(TabContentsWrapper* contents,
328 bool should_restore_state) {
[email protected]83a2610a2012-01-05 01:00:27329 [controller_ updateToolbarWithContents:contents->web_contents()
[email protected]7d791652010-12-01 16:34:49330 shouldRestoreState:should_restore_state ? YES : NO];
331}
332
333void BrowserWindowCocoa::FocusToolbar() {
334 // Not needed on the Mac.
335}
336
337void BrowserWindowCocoa::FocusAppMenu() {
338 // Chrome uses the standard Mac OS X menu bar, so this isn't needed.
339}
340
341void BrowserWindowCocoa::RotatePaneFocus(bool forwards) {
342 // Not needed on the Mac.
343}
344
345void BrowserWindowCocoa::FocusBookmarksToolbar() {
346 // Not needed on the Mac.
347}
348
349void BrowserWindowCocoa::FocusChromeOSStatus() {
350 // Not needed on the Mac.
351}
352
353bool BrowserWindowCocoa::IsBookmarkBarVisible() const {
[email protected]a007e732011-08-05 13:32:19354 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
[email protected]7d791652010-12-01 16:34:49355}
356
357bool BrowserWindowCocoa::IsBookmarkBarAnimating() const {
358 return [controller_ isBookmarkBarAnimating];
359}
360
[email protected]95bf8a5b2010-12-22 16:04:07361bool BrowserWindowCocoa::IsTabStripEditable() const {
362 return ![controller_ isDragSessionActive];
363}
364
[email protected]7d791652010-12-01 16:34:49365bool BrowserWindowCocoa::IsToolbarVisible() const {
366 return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
367 browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
368}
369
[email protected]b7a756d42012-01-23 18:08:17370gfx::Rect BrowserWindowCocoa::GetRootWindowResizerRect() const {
[email protected]9f8727092012-02-08 01:38:18371 if (IsDownloadShelfVisible())
372 return gfx::Rect();
[email protected]b7a756d42012-01-23 18:08:17373 NSRect tabRect = [controller_ selectedTabGrowBoxRect];
374 return gfx::Rect(NSRectToCGRect(tabRect));
375}
376
[email protected]5f58c2af2012-01-11 17:55:29377bool BrowserWindowCocoa::IsPanel() const {
378 return false;
379}
380
[email protected]7d791652010-12-01 16:34:49381// This is called from Browser, which in turn is called directly from
382// a menu option. All we do here is set a preference. The act of
383// setting the preference sends notifications to all windows who then
384// know what to do.
385void BrowserWindowCocoa::ToggleBookmarkBar() {
386 bookmark_utils::ToggleWhenVisible(browser_->profile());
387}
388
389void BrowserWindowCocoa::AddFindBar(
390 FindBarCocoaController* find_bar_cocoa_controller) {
[email protected]632983f2011-08-08 22:51:24391 [controller_ addFindBar:find_bar_cocoa_controller];
[email protected]7d791652010-12-01 16:34:49392}
393
[email protected]4c6b474b72011-02-24 21:35:21394void BrowserWindowCocoa::ShowAboutChromeDialog() {
[email protected]287b90602011-03-02 22:43:27395 // Go through AppController's implementation to bring up the branded panel.
396 [[NSApp delegate] orderFrontStandardAboutPanel:nil];
[email protected]7d791652010-12-01 16:34:49397}
398
399void BrowserWindowCocoa::ShowUpdateChromeDialog() {
[email protected]678dae82011-02-11 20:03:08400 restart_browser::RequestRestart(window());
[email protected]7d791652010-12-01 16:34:49401}
402
403void BrowserWindowCocoa::ShowTaskManager() {
[email protected]7b937362011-10-05 08:28:07404#if defined(WEBUI_TASK_MANAGER)
405 TaskManagerDialog::Show();
406#else
407 // Uses WebUI TaskManager when swiches is set. It is beta feature.
[email protected]54ae4e92012-02-16 15:19:05408 if (TaskManagerDialog::UseWebUITaskManager()) {
[email protected]7b937362011-10-05 08:28:07409 TaskManagerDialog::Show();
410 } else {
411 TaskManagerMac::Show(false);
412 }
413#endif // defined(WEBUI_TASK_MANAGER)
[email protected]adb6a84d2011-02-07 16:58:40414}
415
416void BrowserWindowCocoa::ShowBackgroundPages() {
[email protected]7b937362011-10-05 08:28:07417#if defined(WEBUI_TASK_MANAGER)
418 TaskManagerDialog::ShowBackgroundPages();
419#else
420 // Uses WebUI TaskManager when swiches is set. It is beta feature.
[email protected]54ae4e92012-02-16 15:19:05421 if (TaskManagerDialog::UseWebUITaskManager()) {
[email protected]7b937362011-10-05 08:28:07422 TaskManagerDialog::ShowBackgroundPages();
423 } else {
424 TaskManagerMac::Show(true);
425 }
426#endif // defined(WEBUI_TASK_MANAGER)
[email protected]7d791652010-12-01 16:34:49427}
428
429void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url,
430 bool already_bookmarked) {
431 [controller_ showBookmarkBubbleForURL:url
432 alreadyBookmarked:(already_bookmarked ? YES : NO)];
433}
434
435bool BrowserWindowCocoa::IsDownloadShelfVisible() const {
436 return [controller_ isDownloadShelfVisible] != NO;
437}
438
439DownloadShelf* BrowserWindowCocoa::GetDownloadShelf() {
440 DownloadShelfController* shelfController = [controller_ downloadShelf];
441 return [shelfController bridge];
442}
443
[email protected]a3627e62011-09-07 00:04:57444void BrowserWindowCocoa::ShowCollectedCookiesDialog(
445 TabContentsWrapper* wrapper) {
[email protected]7d791652010-12-01 16:34:49446 // Deletes itself on close.
[email protected]a3627e62011-09-07 00:04:57447 new CollectedCookiesMac(GetNativeHandle(), wrapper);
[email protected]7d791652010-12-01 16:34:49448}
449
[email protected]7d791652010-12-01 16:34:49450// We allow closing the window here since the real quit decision on Mac is made
451// in [AppController quit:].
452void BrowserWindowCocoa::ConfirmBrowserCloseWithPendingDownloads() {
453 // Call InProgressDownloadResponse asynchronously to avoid a crash when the
454 // browser window is closed here (http://crbug.com/44454).
[email protected]a932d9e2011-09-29 01:14:34455 MessageLoop::current()->PostTask(FROM_HERE,
456 base::Bind(&Browser::InProgressDownloadResponse,
457 confirm_close_factory_.GetWeakPtr(), true));
[email protected]7d791652010-12-01 16:34:49458}
459
[email protected]7d791652010-12-01 16:34:49460void BrowserWindowCocoa::UserChangedTheme() {
461 [controller_ userChangedTheme];
462}
463
464int BrowserWindowCocoa::GetExtraRenderViewHeight() const {
465 // Currently this is only used on linux.
466 return 0;
467}
468
[email protected]2a6bc3e2011-12-28 23:51:33469void BrowserWindowCocoa::WebContentsFocused(WebContents* contents) {
[email protected]7d791652010-12-01 16:34:49470 NOTIMPLEMENTED();
471}
472
473void BrowserWindowCocoa::ShowPageInfo(Profile* profile,
474 const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17475 const SSLStatus& ssl,
[email protected]7d791652010-12-01 16:34:49476 bool show_history) {
477 browser::ShowPageInfoBubble(window(), profile, url, ssl, show_history);
478}
479
[email protected]b8e681e82012-02-20 10:18:47480void BrowserWindowCocoa::ShowWebsiteSettings(
481 Profile* profile,
482 TabContentsWrapper* tab_contents_wrapper,
483 const GURL& url,
484 const content::SSLStatus& ssl,
485 bool show_history) {
486}
487
[email protected]7d791652010-12-01 16:34:49488void BrowserWindowCocoa::ShowAppMenu() {
489 // No-op. Mac doesn't support showing the menus via alt keys.
490}
491
492bool BrowserWindowCocoa::PreHandleKeyboardEvent(
493 const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) {
[email protected]3a1381d2011-08-26 18:12:13494 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event])
[email protected]7d791652010-12-01 16:34:49495 return false;
496
[email protected]3a1381d2011-08-26 18:12:13497 int id = [BrowserWindowUtils getCommandId:event];
[email protected]7d791652010-12-01 16:34:49498 if (id == -1)
499 return false;
500
[email protected]3a1381d2011-08-26 18:12:13501 if (browser_->IsReservedCommandOrKey(id, event)) {
502 return [BrowserWindowUtils handleKeyboardEvent:event.os_event
503 inWindow:window()];
504 }
[email protected]7d791652010-12-01 16:34:49505
[email protected]3a1381d2011-08-26 18:12:13506 DCHECK(is_keyboard_shortcut);
[email protected]7d791652010-12-01 16:34:49507 *is_keyboard_shortcut = true;
[email protected]7d791652010-12-01 16:34:49508 return false;
509}
510
511void BrowserWindowCocoa::HandleKeyboardEvent(
512 const NativeWebKeyboardEvent& event) {
[email protected]3a1381d2011-08-26 18:12:13513 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event])
514 [BrowserWindowUtils handleKeyboardEvent:event.os_event inWindow:window()];
[email protected]7d791652010-12-01 16:34:49515}
516
517void BrowserWindowCocoa::ShowCreateWebAppShortcutsDialog(
[email protected]f847e6082011-03-24 00:08:26518 TabContentsWrapper* tab_contents) {
[email protected]7d791652010-12-01 16:34:49519 NOTIMPLEMENTED();
520}
521
522void BrowserWindowCocoa::ShowCreateChromeAppShortcutsDialog(
523 Profile* profile, const Extension* app) {
524 NOTIMPLEMENTED();
525}
526
527void BrowserWindowCocoa::Cut() {
528 [NSApp sendAction:@selector(cut:) to:nil from:nil];
529}
530
531void BrowserWindowCocoa::Copy() {
532 [NSApp sendAction:@selector(copy:) to:nil from:nil];
533}
534
535void BrowserWindowCocoa::Paste() {
536 [NSApp sendAction:@selector(paste:) to:nil from:nil];
537}
538
[email protected]7d791652010-12-01 16:34:49539void BrowserWindowCocoa::OpenTabpose() {
540 [controller_ openTabpose];
541}
542
[email protected]8d944b32011-10-17 06:11:53543void BrowserWindowCocoa::EnterPresentationMode(
544 const GURL& url,
545 FullscreenExitBubbleType bubble_type) {
[email protected]22d74a6b2011-10-17 20:30:31546 [controller_ enterPresentationModeForURL:url
547 bubbleType:bubble_type];
[email protected]8d944b32011-10-17 06:11:53548}
549
550void BrowserWindowCocoa::ExitPresentationMode() {
[email protected]22d74a6b2011-10-17 20:30:31551 [controller_ exitPresentationMode];
[email protected]d3766932011-08-04 22:18:23552}
553
554bool BrowserWindowCocoa::InPresentationMode() {
555 return [controller_ inPresentationMode];
556}
557
[email protected]e3690ed2011-03-25 20:25:14558void BrowserWindowCocoa::ShowInstant(TabContentsWrapper* preview) {
[email protected]83a2610a2012-01-05 01:00:27559 [controller_ showInstant:preview->web_contents()];
[email protected]7d791652010-12-01 16:34:49560}
561
[email protected]3e481282011-10-15 15:39:50562void BrowserWindowCocoa::HideInstant() {
[email protected]7d791652010-12-01 16:34:49563 [controller_ hideInstant];
[email protected]7d791652010-12-01 16:34:49564}
565
566gfx::Rect BrowserWindowCocoa::GetInstantBounds() {
567 // Flip coordinates based on the primary screen.
568 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
569 NSRect monitorFrame = [screen frame];
570 NSRect frame = [controller_ instantFrame];
571 gfx::Rect bounds(NSRectToCGRect(frame));
572 bounds.set_y(NSHeight(monitorFrame) - bounds.y() - bounds.height());
573 return bounds;
574}
575
[email protected]588300d2011-04-28 21:06:35576WindowOpenDisposition BrowserWindowCocoa::GetDispositionForPopupBounds(
577 const gfx::Rect& bounds) {
[email protected]d82a3c9f2012-02-22 04:46:00578 // In Lion fullscreen mode, convert popups into tabs.
579 if (base::mac::IsOSLionOrLater() && IsFullscreen())
580 return NEW_FOREGROUND_TAB;
[email protected]588300d2011-04-28 21:06:35581 return NEW_POPUP;
582}
583
[email protected]632983f2011-08-08 22:51:24584FindBar* BrowserWindowCocoa::CreateFindBar() {
585 // We could push the AddFindBar() call into the FindBarBridge
586 // constructor or the FindBarCocoaController init, but that makes
587 // unit testing difficult, since we would also require a
588 // BrowserWindow object.
589 FindBarBridge* bridge = new FindBarBridge();
590 AddFindBar(bridge->find_bar_cocoa_controller());
591 return bridge;
592}
593
[email protected]432115822011-07-10 15:52:27594void BrowserWindowCocoa::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53595 const content::NotificationSource& source,
596 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27597 switch (type) {
[email protected]3710d0002011-10-11 00:35:00598 case chrome::NOTIFICATION_PREF_CHANGED: {
[email protected]7ac4b872011-10-19 03:30:42599 const std::string& pref_name =
600 *content::Details<std::string>(details).ptr();
[email protected]3710d0002011-10-11 00:35:00601 DCHECK(pref_name == prefs::kShowBookmarkBar);
602 [controller_ updateBookmarkBarVisibilityWithAnimation:YES];
[email protected]7d791652010-12-01 16:34:49603 break;
[email protected]3710d0002011-10-11 00:35:00604 }
[email protected]7d791652010-12-01 16:34:49605 default:
606 NOTREACHED(); // we don't ask for anything else!
607 break;
608 }
609}
610
611void BrowserWindowCocoa::DestroyBrowser() {
612 [controller_ destroyBrowser];
613
614 // at this point the controller is dead (autoreleased), so
615 // make sure we don't try to reference it any more.
616}
617
618NSWindow* BrowserWindowCocoa::window() const {
619 return [controller_ window];
620}
621
[email protected]0ec4898e2011-12-30 21:09:24622void BrowserWindowCocoa::ShowAvatarBubble(WebContents* web_contents,
[email protected]2f733a02011-10-06 15:17:34623 const gfx::Rect& rect) {
[email protected]0ec4898e2011-12-30 21:09:24624 NSView* view = web_contents->GetNativeView();
[email protected]79ac3cb2011-10-12 17:11:21625 NSRect bounds = [view bounds];
626 NSPoint point;
627 point.x = NSMinX(bounds) + rect.right();
628 // The view's origin is at the bottom but |rect|'s origin is at the top.
629 point.y = NSMaxY(bounds) - rect.bottom();
[email protected]2f733a02011-10-06 15:17:34630 point = [view convertPoint:point toView:nil];
631 point = [[view window] convertBaseToScreen:point];
632
633 // |menu| will automatically release itself on close.
634 AvatarMenuBubbleController* menu =
635 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_
636 anchoredAt:point];
[email protected]51152d6d2011-11-07 01:55:12637 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge];
[email protected]2f733a02011-10-06 15:17:34638 [menu showWindow:nil];
639}
[email protected]7d2d08152011-10-25 22:58:47640
641void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() {
642 [[controller_ avatarButtonController] showAvatarBubble];
643}