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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller.mm

Issue 12386019: Instant: Use only one hidden WebContents per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <numeric> 8 #include <numeric>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/mac/bundle_locations.h" 11 #include "base/mac/bundle_locations.h"
12 #include "base/mac/mac_util.h" 12 #include "base/mac/mac_util.h"
13 #import "base/memory/scoped_nsobject.h" 13 #import "base/memory/scoped_nsobject.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/app/chrome_command_ids.h" // IDC_* 16 #include "chrome/app/chrome_command_ids.h" // IDC_*
17 #include "chrome/browser/bookmarks/bookmark_editor.h" 17 #include "chrome/browser/bookmarks/bookmark_editor.h"
18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
19 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/instant/instant_controller.h"
20 #include "chrome/browser/managed_mode/managed_mode.h" 21 #include "chrome/browser/managed_mode/managed_mode.h"
21 #include "chrome/browser/profiles/avatar_menu_model.h" 22 #include "chrome/browser/profiles/avatar_menu_model.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/profiles/profile_info_cache.h" 24 #include "chrome/browser/profiles/profile_info_cache.h"
24 #include "chrome/browser/profiles/profile_manager.h" 25 #include "chrome/browser/profiles/profile_manager.h"
25 #include "chrome/browser/signin/signin_ui_util.h" 26 #include "chrome/browser/signin/signin_ui_util.h"
26 #include "chrome/browser/themes/theme_service.h" 27 #include "chrome/browser/themes/theme_service.h"
27 #include "chrome/browser/themes/theme_service_factory.h" 28 #include "chrome/browser/themes/theme_service_factory.h"
28 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
29 #include "chrome/browser/ui/browser_command_controller.h" 30 #include "chrome/browser/ui/browser_command_controller.h"
(...skipping 15 matching lines...) Expand all
45 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa .h" 46 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa .h"
46 #import "chrome/browser/ui/cocoa/fast_resize_view.h" 47 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
47 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" 48 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
48 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" 49 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
49 #import "chrome/browser/ui/cocoa/framed_browser_window.h" 50 #import "chrome/browser/ui/cocoa/framed_browser_window.h"
50 #import "chrome/browser/ui/cocoa/fullscreen_window.h" 51 #import "chrome/browser/ui/cocoa/fullscreen_window.h"
51 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 52 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
52 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" 53 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h"
53 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" 54 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h"
54 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" 55 #import "chrome/browser/ui/cocoa/status_bubble_mac.h"
55 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" 56 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h"
56 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" 57 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h"
57 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" 58 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
58 #import "chrome/browser/ui/cocoa/tabpose_window.h" 59 #import "chrome/browser/ui/cocoa/tabpose_window.h"
59 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 60 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
60 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 61 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
61 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" 62 #import "chrome/browser/ui/cocoa/tabs/tab_view.h"
62 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 63 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
63 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 64 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
64 #include "chrome/browser/ui/omnibox/location_bar.h" 65 #include "chrome/browser/ui/omnibox/location_bar.h"
65 #include "chrome/browser/ui/search/search.h"
66 #include "chrome/browser/ui/search/search_model.h"
67 #include "chrome/browser/ui/tabs/dock_info.h" 66 #include "chrome/browser/ui/tabs/dock_info.h"
68 #include "chrome/browser/ui/tabs/tab_strip_model.h" 67 #include "chrome/browser/ui/tabs/tab_strip_model.h"
69 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" 68 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
70 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" 69 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h"
71 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" 70 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h"
72 #include "chrome/browser/ui/window_sizer/window_sizer.h" 71 #include "chrome/browser/ui/window_sizer/window_sizer.h"
73 #include "chrome/common/chrome_switches.h" 72 #include "chrome/common/chrome_switches.h"
74 #include "chrome/common/url_constants.h" 73 #include "chrome/common/url_constants.h"
75 #include "content/public/browser/render_view_host.h" 74 #include "content/public/browser/render_view_host.h"
76 #include "content/public/browser/render_widget_host_view.h" 75 #include "content/public/browser/render_widget_host_view.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 325
327 // Puts the incognito badge on the window frame, if necessary. 326 // Puts the incognito badge on the window frame, if necessary.
328 [self installAvatar]; 327 [self installAvatar];
329 328
330 // Create a sub-controller for the docked devTools and add its view to the 329 // Create a sub-controller for the docked devTools and add its view to the
331 // hierarchy. 330 // hierarchy.
332 devToolsController_.reset([[DevToolsController alloc] init]); 331 devToolsController_.reset([[DevToolsController alloc] init]);
333 [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]]; 332 [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]];
334 [[self tabContentArea] addSubview:[devToolsController_ view]]; 333 [[self tabContentArea] addSubview:[devToolsController_ view]];
335 334
336 // Create the previewable contents controller. This provides the switch 335 // Create the overlayable contents controller. This provides the switch
337 // view that TabStripController needs. 336 // view that TabStripController needs.
338 previewableContentsController_.reset( 337 overlayableContentsController_.reset(
339 [[PreviewableContentsController alloc] initWithBrowser:browser 338 [[OverlayableContentsController alloc] initWithBrowser:browser
340 windowController:self]); 339 windowController:self]);
341 [[previewableContentsController_ view] 340 [[overlayableContentsController_ view]
342 setFrame:[[devToolsController_ view] bounds]]; 341 setFrame:[[devToolsController_ view] bounds]];
343 [[devToolsController_ view] 342 [[devToolsController_ view]
344 addSubview:[previewableContentsController_ view]]; 343 addSubview:[overlayableContentsController_ view]];
345 344
346 // Create a controller for the tab strip, giving it the model object for 345 // Create a controller for the tab strip, giving it the model object for
347 // this window's Browser and the tab strip view. The controller will handle 346 // this window's Browser and the tab strip view. The controller will handle
348 // registering for the appropriate tab notifications from the back-end and 347 // registering for the appropriate tab notifications from the back-end and
349 // managing the creation of new tabs. 348 // managing the creation of new tabs.
350 [self createTabStripController]; 349 [self createTabStripController];
351 350
352 // Create a controller for the toolbar, giving it the toolbar model object 351 // Create a controller for the toolbar, giving it the toolbar model object
353 // and the toolbar view from the nib. The controller will handle 352 // and the toolbar view from the nib. The controller will handle
354 // registering for the appropriate command state changes from the back-end. 353 // registering for the appropriate command state changes from the back-end.
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 } 509 }
511 510
512 - (LocationBarViewMac*)locationBarBridge { 511 - (LocationBarViewMac*)locationBarBridge {
513 return [toolbarController_ locationBarBridge]; 512 return [toolbarController_ locationBarBridge];
514 } 513 }
515 514
516 - (NSView*)floatingBarBackingView { 515 - (NSView*)floatingBarBackingView {
517 return floatingBarBackingView_; 516 return floatingBarBackingView_;
518 } 517 }
519 518
520 - (PreviewableContentsController*)previewableContentsController { 519 - (OverlayableContentsController*)overlayableContentsController {
521 return previewableContentsController_; 520 return overlayableContentsController_;
522 } 521 }
523 522
524 - (Profile*)profile { 523 - (Profile*)profile {
525 return browser_->profile(); 524 return browser_->profile();
526 } 525 }
527 526
528 - (AvatarButtonController*)avatarButtonController { 527 - (AvatarButtonController*)avatarButtonController {
529 return avatarButtonController_.get(); 528 return avatarButtonController_.get();
530 } 529 }
531 530
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 } 1192 }
1194 1193
1195 - (BOOL)handledByExtensionCommand:(NSEvent*)event { 1194 - (BOOL)handledByExtensionCommand:(NSEvent*)event {
1196 return extension_keybinding_registry_->ProcessKeyEvent( 1195 return extension_keybinding_registry_->ProcessKeyEvent(
1197 content::NativeWebKeyboardEvent(event)); 1196 content::NativeWebKeyboardEvent(event));
1198 } 1197 }
1199 1198
1200 // StatusBubble delegate method: tell the status bubble the frame it should 1199 // StatusBubble delegate method: tell the status bubble the frame it should
1201 // position itself in. 1200 // position itself in.
1202 - (NSRect)statusBubbleBaseFrame { 1201 - (NSRect)statusBubbleBaseFrame {
1203 NSView* view = [previewableContentsController_ view]; 1202 NSView* view = [overlayableContentsController_ view];
1204 return [view convertRect:[view bounds] toView:nil]; 1203 return [view convertRect:[view bounds] toView:nil];
1205 } 1204 }
1206 1205
1207 - (void)updateToolbarWithContents:(WebContents*)tab 1206 - (void)updateToolbarWithContents:(WebContents*)tab
1208 shouldRestoreState:(BOOL)shouldRestore { 1207 shouldRestoreState:(BOOL)shouldRestore {
1209 [toolbarController_ updateToolbarWithContents:tab 1208 [toolbarController_ updateToolbarWithContents:tab
1210 shouldRestoreState:shouldRestore]; 1209 shouldRestoreState:shouldRestore];
1211 } 1210 }
1212 1211
1213 - (void)setStarredState:(BOOL)isStarred { 1212 - (void)setStarredState:(BOOL)isStarred {
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 // Update the bookmark bar. 1572 // Update the bookmark bar.
1574 // Must do it after devtools updates, otherwise bookmark bar might 1573 // Must do it after devtools updates, otherwise bookmark bar might
1575 // call resizeView -> layoutSubviews and cause unnecessary relayout. 1574 // call resizeView -> layoutSubviews and cause unnecessary relayout.
1576 // TODO(viettrungluu): perhaps update to not terminate running animations (if 1575 // TODO(viettrungluu): perhaps update to not terminate running animations (if
1577 // applicable)? 1576 // applicable)?
1578 windowShim_->BookmarkBarStateChanged( 1577 windowShim_->BookmarkBarStateChanged(
1579 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); 1578 BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
1580 1579
1581 [infoBarContainerController_ changeWebContents:contents]; 1580 [infoBarContainerController_ changeWebContents:contents];
1582 1581
1583 [previewableContentsController_ onActivateTabWithContents:contents]; 1582 [overlayableContentsController_ onActivateTabWithContents:contents];
1584 } 1583 }
1585 1584
1586 - (void)onTabChanged:(TabStripModelObserver::TabChangeType)change 1585 - (void)onTabChanged:(TabStripModelObserver::TabChangeType)change
1587 withContents:(WebContents*)contents { 1586 withContents:(WebContents*)contents {
1588 // Update titles if this is the currently selected tab and if it isn't just 1587 // Update titles if this is the currently selected tab and if it isn't just
1589 // the loading state which changed. 1588 // the loading state which changed.
1590 if (change != TabStripModelObserver::LOADING_ONLY) 1589 if (change != TabStripModelObserver::LOADING_ONLY)
1591 windowShim_->UpdateTitleBar(); 1590 windowShim_->UpdateTitleBar();
1592 1591
1593 // Update the bookmark bar if this is the currently selected tab and if it 1592 // Update the bookmark bar if this is the currently selected tab and if it
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 - (void)commitInstant { 1926 - (void)commitInstant {
1928 if (chrome::BrowserInstantController* controller = 1927 if (chrome::BrowserInstantController* controller =
1929 browser_->instant_controller()) 1928 browser_->instant_controller())
1930 controller->instant()->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); 1929 controller->instant()->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
1931 } 1930 }
1932 1931
1933 - (NSRect)instantFrame { 1932 - (NSRect)instantFrame {
1934 // The view's bounds are in its own coordinate system. Convert that to the 1933 // The view's bounds are in its own coordinate system. Convert that to the
1935 // window base coordinate system, then translate it into the screen's 1934 // window base coordinate system, then translate it into the screen's
1936 // coordinate system. 1935 // coordinate system.
1937 NSView* view = [previewableContentsController_ view]; 1936 NSView* view = [overlayableContentsController_ view];
1938 if (!view) 1937 if (!view)
1939 return NSZeroRect; 1938 return NSZeroRect;
1940 1939
1941 NSRect frame = [view convertRect:[view bounds] toView:nil]; 1940 NSRect frame = [view convertRect:[view bounds] toView:nil];
1942 NSPoint originInScreenCoords = 1941 NSPoint originInScreenCoords =
1943 [[view window] convertBaseToScreen:frame.origin]; 1942 [[view window] convertBaseToScreen:frame.origin];
1944 frame.origin = originInScreenCoords; 1943 frame.origin = originInScreenCoords;
1945 1944
1946 // Account for the bookmark bar height if it is currently in the detached 1945 // Account for the bookmark bar height if it is currently in the detached
1947 // state on the new tab page. 1946 // state on the new tab page.
1948 if ([bookmarkBarController_ isInState:BookmarkBar::DETACHED]) 1947 if ([bookmarkBarController_ isInState:BookmarkBar::DETACHED])
1949 frame.size.height += NSHeight([[bookmarkBarController_ view] bounds]); 1948 frame.size.height += NSHeight([[bookmarkBarController_ view] bounds]);
1950 1949
1951 return frame; 1950 return frame;
1952 } 1951 }
1953 1952
1954 - (void)sheetDidEnd:(NSWindow*)sheet 1953 - (void)sheetDidEnd:(NSWindow*)sheet
1955 returnCode:(NSInteger)code 1954 returnCode:(NSInteger)code
1956 context:(void*)context { 1955 context:(void*)context {
1957 [sheet orderOut:self]; 1956 [sheet orderOut:self];
1958 } 1957 }
1959 1958
1960 - (void)updateBookmarkBarStateForInstantPreview { 1959 - (void)updateBookmarkBarStateForInstantOverlay {
1961 [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]]; 1960 [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]];
1962 [self updateContentOffsets]; 1961 [self updateContentOffsets];
1963 [self updateSubviewZOrder:[self inPresentationMode]]; 1962 [self updateSubviewZOrder:[self inPresentationMode]];
1964 } 1963 }
1965 1964
1966 @end // @implementation BrowserWindowController 1965 @end // @implementation BrowserWindowController
1967 1966
1968 1967
1969 @implementation BrowserWindowController(Fullscreen) 1968 @implementation BrowserWindowController(Fullscreen)
1970 1969
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2210 2209
2211 - (BOOL)supportsBookmarkBar { 2210 - (BOOL)supportsBookmarkBar {
2212 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; 2211 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR];
2213 } 2212 }
2214 2213
2215 - (BOOL)isTabbedWindow { 2214 - (BOOL)isTabbedWindow {
2216 return browser_->is_type_tabbed(); 2215 return browser_->is_type_tabbed();
2217 } 2216 }
2218 2217
2219 @end // @implementation BrowserWindowController(WindowType) 2218 @end // @implementation BrowserWindowController(WindowType)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698