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

Side by Side Diff: chrome/browser/ui/views/frame/browser_view.cc

Issue 1152613003: Implement sidebar support for extension action popups (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move SidebarManager to ExtensionSystem and remove notifications Created 5 years, 6 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
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 #include "chrome/browser/ui/views/frame/browser_view.h" 5 #include "chrome/browser/ui/views/frame/browser_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/profiler/scoped_tracker.h" 15 #include "base/profiler/scoped_tracker.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "chrome/app/chrome_command_ids.h" 17 #include "chrome/app/chrome_command_ids.h"
18 #include "chrome/app/chrome_dll_resource.h" 18 #include "chrome/app/chrome_dll_resource.h"
19 #include "chrome/browser/app_mode/app_mode_utils.h" 19 #include "chrome/browser/app_mode/app_mode_utils.h"
20 #include "chrome/browser/bookmarks/bookmark_stats.h" 20 #include "chrome/browser/bookmarks/bookmark_stats.h"
21 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/chrome_notification_types.h" 22 #include "chrome/browser/chrome_notification_types.h"
23 #include "chrome/browser/extensions/extension_util.h" 23 #include "chrome/browser/extensions/extension_util.h"
24 #include "chrome/browser/extensions/sidebar_container.h"
25 #include "chrome/browser/extensions/sidebar_manager.h"
24 #include "chrome/browser/extensions/tab_helper.h" 26 #include "chrome/browser/extensions/tab_helper.h"
25 #include "chrome/browser/infobars/infobar_service.h" 27 #include "chrome/browser/infobars/infobar_service.h"
26 #include "chrome/browser/native_window_notification_source.h" 28 #include "chrome/browser/native_window_notification_source.h"
27 #include "chrome/browser/profiles/avatar_menu.h" 29 #include "chrome/browser/profiles/avatar_menu.h"
28 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 31 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
30 #include "chrome/browser/profiles/profile_info_cache.h" 32 #include "chrome/browser/profiles/profile_info_cache.h"
31 #include "chrome/browser/profiles/profile_manager.h" 33 #include "chrome/browser/profiles/profile_manager.h"
32 #include "chrome/browser/profiles/profile_window.h" 34 #include "chrome/browser/profiles/profile_window.h"
33 #include "chrome/browser/profiles/profiles_state.h" 35 #include "chrome/browser/profiles/profiles_state.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 #include "ui/base/resource/resource_bundle.h" 126 #include "ui/base/resource/resource_bundle.h"
125 #include "ui/base/theme_provider.h" 127 #include "ui/base/theme_provider.h"
126 #include "ui/content_accelerators/accelerator_util.h" 128 #include "ui/content_accelerators/accelerator_util.h"
127 #include "ui/events/event_utils.h" 129 #include "ui/events/event_utils.h"
128 #include "ui/gfx/canvas.h" 130 #include "ui/gfx/canvas.h"
129 #include "ui/gfx/color_utils.h" 131 #include "ui/gfx/color_utils.h"
130 #include "ui/gfx/geometry/rect_conversions.h" 132 #include "ui/gfx/geometry/rect_conversions.h"
131 #include "ui/gfx/screen.h" 133 #include "ui/gfx/screen.h"
132 #include "ui/strings/grit/ui_strings.h" 134 #include "ui/strings/grit/ui_strings.h"
133 #include "ui/views/controls/button/menu_button.h" 135 #include "ui/views/controls/button/menu_button.h"
136 #include "ui/views/controls/single_split_view.h"
137 #include "ui/views/controls/single_split_view_listener.h"
134 #include "ui/views/controls/textfield/textfield.h" 138 #include "ui/views/controls/textfield/textfield.h"
135 #include "ui/views/controls/webview/webview.h" 139 #include "ui/views/controls/webview/webview.h"
136 #include "ui/views/focus/external_focus_tracker.h" 140 #include "ui/views/focus/external_focus_tracker.h"
137 #include "ui/views/focus/view_storage.h" 141 #include "ui/views/focus/view_storage.h"
142 #include "ui/views/layout/box_layout.h"
138 #include "ui/views/layout/grid_layout.h" 143 #include "ui/views/layout/grid_layout.h"
139 #include "ui/views/widget/native_widget.h" 144 #include "ui/views/widget/native_widget.h"
140 #include "ui/views/widget/root_view.h" 145 #include "ui/views/widget/root_view.h"
141 #include "ui/views/widget/widget.h" 146 #include "ui/views/widget/widget.h"
142 #include "ui/views/window/dialog_delegate.h" 147 #include "ui/views/window/dialog_delegate.h"
143 148
144 #if defined(USE_AURA) 149 #if defined(USE_AURA)
145 #include "ui/aura/client/window_tree_client.h" 150 #include "ui/aura/client/window_tree_client.h"
146 #include "ui/aura/window.h" 151 #include "ui/aura/window.h"
147 #include "ui/aura/window_tree_host.h" 152 #include "ui/aura/window_tree_host.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 517
513 // Explicitly set browser_ to null. 518 // Explicitly set browser_ to null.
514 browser_.reset(); 519 browser_.reset();
515 } 520 }
516 521
517 void BrowserView::Init(Browser* browser) { 522 void BrowserView::Init(Browser* browser) {
518 browser_.reset(browser); 523 browser_.reset(browser);
519 browser_->tab_strip_model()->AddObserver(this); 524 browser_->tab_strip_model()->AddObserver(this);
520 immersive_mode_controller_.reset( 525 immersive_mode_controller_.reset(
521 chrome::CreateImmersiveModeController(browser_->host_desktop_type())); 526 chrome::CreateImmersiveModeController(browser_->host_desktop_type()));
527
528 extensions::SidebarManager* sidebar_manager =
529 extensions::SidebarManager::GetFromContext(browser_->profile());
530 sidebar_manager->AddObserver(this);
522 } 531 }
523 532
524 // static 533 // static
525 BrowserView* BrowserView::GetBrowserViewForNativeWindow( 534 BrowserView* BrowserView::GetBrowserViewForNativeWindow(
526 gfx::NativeWindow window) { 535 gfx::NativeWindow window) {
527 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 536 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
528 return widget ? 537 return widget ?
529 reinterpret_cast<BrowserView*>(widget->GetNativeWindowProperty( 538 reinterpret_cast<BrowserView*>(widget->GetNativeWindowProperty(
530 kBrowserViewKey)) : nullptr; 539 kBrowserViewKey)) : nullptr;
531 } 540 }
532 541
533 // static 542 // static
534 BrowserView* BrowserView::GetBrowserViewForBrowser(const Browser* browser) { 543 BrowserView* BrowserView::GetBrowserViewForBrowser(const Browser* browser) {
535 return static_cast<BrowserView*>(browser->window()); 544 return static_cast<BrowserView*>(browser->window());
536 } 545 }
537 546
538 void BrowserView::InitStatusBubble() { 547 void BrowserView::InitStatusBubble() {
539 status_bubble_.reset(new StatusBubbleViews(contents_web_view_)); 548 status_bubble_.reset(new StatusBubbleViews(contents_web_view_));
540 contents_web_view_->SetStatusBubble(status_bubble_.get()); 549 contents_web_view_->SetStatusBubble(status_bubble_.get());
541 } 550 }
542 551
552 bool BrowserView::SplitHandleMoved(views::SingleSplitView* sender) {
553 for (int i = 0; i < sender->child_count(); ++i)
554 sender->child_at(i)->InvalidateLayout();
555 SchedulePaint();
556 Layout();
557 return false;
558 }
559
543 gfx::Rect BrowserView::GetToolbarBounds() const { 560 gfx::Rect BrowserView::GetToolbarBounds() const {
544 gfx::Rect toolbar_bounds(toolbar_->bounds()); 561 gfx::Rect toolbar_bounds(toolbar_->bounds());
545 if (toolbar_bounds.IsEmpty()) 562 if (toolbar_bounds.IsEmpty())
546 return toolbar_bounds; 563 return toolbar_bounds;
547 // The apparent toolbar edges are outside the "real" toolbar edges. 564 // The apparent toolbar edges are outside the "real" toolbar edges.
548 toolbar_bounds.Inset(-views::NonClientFrameView::kClientEdgeThickness, 0); 565 toolbar_bounds.Inset(-views::NonClientFrameView::kClientEdgeThickness, 0);
549 return toolbar_bounds; 566 return toolbar_bounds;
550 } 567 }
551 568
552 gfx::Rect BrowserView::GetFindBarBoundingBox() const { 569 gfx::Rect BrowserView::GetFindBarBoundingBox() const {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 } 664 }
648 665
649 WebContents* BrowserView::GetActiveWebContents() const { 666 WebContents* BrowserView::GetActiveWebContents() const {
650 return browser_->tab_strip_model()->GetActiveWebContents(); 667 return browser_->tab_strip_model()->GetActiveWebContents();
651 } 668 }
652 669
653 gfx::ImageSkia BrowserView::GetOTRAvatarIcon() const { 670 gfx::ImageSkia BrowserView::GetOTRAvatarIcon() const {
654 return *GetThemeProvider()->GetImageSkiaNamed(IDR_OTR_ICON); 671 return *GetThemeProvider()->GetImageSkiaNamed(IDR_OTR_ICON);
655 } 672 }
656 673
674 void BrowserView::OnSidebarShown(content::WebContents* tab,
675 const std::string& content_id) {
676 UpdateSidebarForContents(tab);
677 }
678
679 void BrowserView::OnSidebarHidden(content::WebContents* tab,
680 const std::string& content_id) {
681 UpdateSidebarForContents(tab);
682 }
683
657 /////////////////////////////////////////////////////////////////////////////// 684 ///////////////////////////////////////////////////////////////////////////////
658 // BrowserView, BrowserWindow implementation: 685 // BrowserView, BrowserWindow implementation:
659 686
660 void BrowserView::Show() { 687 void BrowserView::Show() {
661 #if !defined(OS_WIN) 688 #if !defined(OS_WIN)
662 // The Browser associated with this browser window must become the active 689 // The Browser associated with this browser window must become the active
663 // browser at the time |Show()| is called. This is the natural behavior under 690 // browser at the time |Show()| is called. This is the natural behavior under
664 // Windows and Ash, but other platforms will not trigger 691 // Windows and Ash, but other platforms will not trigger
665 // OnWidgetActivationChanged() until we return to the runloop. Therefore any 692 // OnWidgetActivationChanged() until we return to the runloop. Therefore any
666 // calls to Browser::GetLastActive() will return the wrong result if we do not 693 // calls to Browser::GetLastActive() will return the wrong result if we do not
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 PermissionBubbleManager::FromWebContents(new_contents)->SetView( 903 PermissionBubbleManager::FromWebContents(new_contents)->SetView(
877 permission_bubble_.get()); 904 permission_bubble_.get());
878 } 905 }
879 906
880 UpdateUIForContents(new_contents); 907 UpdateUIForContents(new_contents);
881 908
882 // Layout for DevTools _before_ setting the both main and devtools WebContents 909 // Layout for DevTools _before_ setting the both main and devtools WebContents
883 // to avoid toggling the size of any of them. 910 // to avoid toggling the size of any of them.
884 UpdateDevToolsForContents(new_contents, !change_tab_contents); 911 UpdateDevToolsForContents(new_contents, !change_tab_contents);
885 912
913 UpdateSidebarForContents(new_contents);
886 if (change_tab_contents) { 914 if (change_tab_contents) {
887 web_contents_close_handler_->ActiveTabChanged(); 915 web_contents_close_handler_->ActiveTabChanged();
888 contents_web_view_->SetWebContents(new_contents); 916 contents_web_view_->SetWebContents(new_contents);
889 // The second layout update should be no-op. It will just set the 917 // The second layout update should be no-op. It will just set the
890 // DevTools WebContents. 918 // DevTools WebContents.
891 UpdateDevToolsForContents(new_contents, true); 919 UpdateDevToolsForContents(new_contents, true);
892 } 920 }
893 921
894 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && 922 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() &&
895 GetWidget()->IsVisible()) { 923 GetWidget()->IsVisible()) {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 anchor_view = toolbar_->app_menu(); 1332 anchor_view = toolbar_->app_menu();
1305 else 1333 else
1306 anchor_view = toolbar_->location_bar(); 1334 anchor_view = toolbar_->location_bar();
1307 1335
1308 OneClickSigninBubbleView::ShowBubble(type, email, error_message, 1336 OneClickSigninBubbleView::ShowBubble(type, email, error_message,
1309 delegate.Pass(), anchor_view, 1337 delegate.Pass(), anchor_view,
1310 start_sync_callback); 1338 start_sync_callback);
1311 } 1339 }
1312 #endif 1340 #endif
1313 1341
1342 int BrowserView::GetSidebarWidth() const {
1343 if (!sidebar_container_ || !sidebar_container_->visible())
1344 return 0;
1345 return sidebar_split_->divider_offset();
1346 }
1347
1314 void BrowserView::SetDownloadShelfVisible(bool visible) { 1348 void BrowserView::SetDownloadShelfVisible(bool visible) {
1315 // This can be called from the superclass destructor, when it destroys our 1349 // This can be called from the superclass destructor, when it destroys our
1316 // child views. At that point, browser_ is already gone. 1350 // child views. At that point, browser_ is already gone.
1317 if (!browser_) 1351 if (!browser_)
1318 return; 1352 return;
1319 1353
1320 if (visible && IsDownloadShelfVisible() != visible) { 1354 if (visible && IsDownloadShelfVisible() != visible) {
1321 // Invoke GetDownloadShelf to force the shelf to be created. 1355 // Invoke GetDownloadShelf to force the shelf to be created.
1322 GetDownloadShelf(); 1356 GetDownloadShelf();
1323 } 1357 }
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 // browser_->GetActiveWebContents() will return null or something else. 1591 // browser_->GetActiveWebContents() will return null or something else.
1558 if (index == browser_->tab_strip_model()->active_index()) { 1592 if (index == browser_->tab_strip_model()->active_index()) {
1559 // We need to reset the current tab contents to null before it gets 1593 // We need to reset the current tab contents to null before it gets
1560 // freed. This is because the focus manager performs some operations 1594 // freed. This is because the focus manager performs some operations
1561 // on the selected WebContents when it is removed. 1595 // on the selected WebContents when it is removed.
1562 web_contents_close_handler_->ActiveTabChanged(); 1596 web_contents_close_handler_->ActiveTabChanged();
1563 contents_web_view_->SetWebContents(nullptr); 1597 contents_web_view_->SetWebContents(nullptr);
1564 infobar_container_->ChangeInfoBarManager(nullptr); 1598 infobar_container_->ChangeInfoBarManager(nullptr);
1565 UpdateDevToolsForContents(nullptr, true); 1599 UpdateDevToolsForContents(nullptr, true);
1566 } 1600 }
1601 UpdateSidebarForContents(NULL);
1567 } 1602 }
1568 1603
1569 void BrowserView::TabDeactivated(WebContents* contents) { 1604 void BrowserView::TabDeactivated(WebContents* contents) {
1570 if (PermissionBubbleManager::FromWebContents(contents)) 1605 if (PermissionBubbleManager::FromWebContents(contents))
1571 PermissionBubbleManager::FromWebContents(contents)->SetView(nullptr); 1606 PermissionBubbleManager::FromWebContents(contents)->SetView(nullptr);
1572 1607
1573 // We do not store the focus when closing the tab to work-around bug 4633. 1608 // We do not store the focus when closing the tab to work-around bug 4633.
1574 // Some reports seem to show that the focus manager and/or focused view can 1609 // Some reports seem to show that the focus manager and/or focused view can
1575 // be garbage at that point, it is not clear why. 1610 // be garbage at that point, it is not clear why.
1576 if (!contents->IsBeingDestroyed()) 1611 if (!contents->IsBeingDestroyed())
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 devtools_web_view_->SetVisible(false); 2070 devtools_web_view_->SetVisible(false);
2036 2071
2037 contents_container_ = new views::View(); 2072 contents_container_ = new views::View();
2038 contents_container_->set_background(views::Background::CreateSolidBackground( 2073 contents_container_->set_background(views::Background::CreateSolidBackground(
2039 ThemeProperties::GetDefaultColor( 2074 ThemeProperties::GetDefaultColor(
2040 ThemeProperties::COLOR_CONTROL_BACKGROUND))); 2075 ThemeProperties::COLOR_CONTROL_BACKGROUND)));
2041 contents_container_->AddChildView(devtools_web_view_); 2076 contents_container_->AddChildView(devtools_web_view_);
2042 contents_container_->AddChildView(contents_web_view_); 2077 contents_container_->AddChildView(contents_web_view_);
2043 contents_container_->SetLayoutManager(new ContentsLayoutManager( 2078 contents_container_->SetLayoutManager(new ContentsLayoutManager(
2044 devtools_web_view_, contents_web_view_)); 2079 devtools_web_view_, contents_web_view_));
2045 AddChildView(contents_container_); 2080
2046 set_contents_view(contents_container_); 2081 sidebar_web_view_ = new views::WebView(browser_->profile());
2082 sidebar_web_view_->set_id(VIEW_ID_SIDE_BAR_VIEW);
2083 sidebar_web_view_->SetVisible(false);
2084
2085 sidebar_container_ = new views::View();
2086 sidebar_container_->AddChildView(sidebar_web_view_);
2087 sidebar_container_->set_id(VIEW_ID_SIDE_BAR_CONTAINER);
2088 sidebar_container_->SetVisible(false);
2089
2090 sidebar_split_ = new views::SingleSplitView(
2091 contents_container_, sidebar_container_,
2092 views::SingleSplitView::HORIZONTAL_SPLIT, this);
2093
2094 sidebar_split_->set_id(VIEW_ID_SIDE_BAR_SPLIT);
2095 sidebar_split_->set_background(views::Background::CreateSolidBackground(
2096 GetWidget()->GetThemeProvider()->GetColor(
2097 ThemeProperties::COLOR_TOOLBAR)));
2098 sidebar_split_->set_resize_leading_on_bounds_change(false);
2099 AddChildView(sidebar_split_);
2100 set_contents_view(sidebar_split_);
2047 2101
2048 // Top container holds tab strip and toolbar and lives at the front of the 2102 // Top container holds tab strip and toolbar and lives at the front of the
2049 // view hierarchy. 2103 // view hierarchy.
2050 top_container_ = new TopContainerView(this); 2104 top_container_ = new TopContainerView(this);
2051 AddChildView(top_container_); 2105 AddChildView(top_container_);
2052 2106
2053 // TabStrip takes ownership of the controller. 2107 // TabStrip takes ownership of the controller.
2054 BrowserTabStripController* tabstrip_controller = 2108 BrowserTabStripController* tabstrip_controller =
2055 new BrowserTabStripController(browser_.get(), 2109 new BrowserTabStripController(browser_.get(),
2056 browser_->tab_strip_model()); 2110 browser_->tab_strip_model());
2057 tabstrip_ = new TabStrip(tabstrip_controller); 2111 tabstrip_ = new TabStrip(tabstrip_controller);
2058 top_container_->AddChildView(tabstrip_); 2112 top_container_->AddChildView(tabstrip_);
2059 tabstrip_controller->InitFromModel(tabstrip_); 2113 tabstrip_controller->InitFromModel(tabstrip_);
2060 2114
2061 toolbar_ = new ToolbarView(browser_.get()); 2115 toolbar_ = new ToolbarView(browser_.get());
2062 top_container_->AddChildView(toolbar_); 2116 top_container_->AddChildView(toolbar_);
2063 toolbar_->Init(); 2117 toolbar_->Init();
2064 2118
2065 InitStatusBubble(); 2119 InitStatusBubble();
2066 2120
2067 // Create do-nothing view for the sake of controlling the z-order of the find 2121 // Create do-nothing view for the sake of controlling the z-order of the find
2068 // bar widget. 2122 // bar widget.
2069 find_bar_host_view_ = new View(); 2123 find_bar_host_view_ = new View();
2070 AddChildView(find_bar_host_view_); 2124 AddChildView(find_bar_host_view_);
2071 2125
2072 immersive_mode_controller_->Init(this); 2126 immersive_mode_controller_->Init(this);
2073 2127
2074 BrowserViewLayout* browser_view_layout = new BrowserViewLayout; 2128 BrowserViewLayout* browser_view_layout = new BrowserViewLayout;
2075 browser_view_layout->Init(new BrowserViewLayoutDelegateImpl(this), 2129 browser_view_layout->Init(
2076 browser(), 2130 new BrowserViewLayoutDelegateImpl(this), browser(), this, top_container_,
2077 this, 2131 tabstrip_, toolbar_, infobar_container_, sidebar_split_,
2078 top_container_, 2132 GetContentsLayoutManager(), immersive_mode_controller_.get());
2079 tabstrip_,
2080 toolbar_,
2081 infobar_container_,
2082 contents_container_,
2083 GetContentsLayoutManager(),
2084 immersive_mode_controller_.get());
2085 SetLayoutManager(browser_view_layout); 2133 SetLayoutManager(browser_view_layout);
2086 2134
2087 #if defined(OS_WIN) 2135 #if defined(OS_WIN)
2088 // Create a custom JumpList and add it to an observer of TabRestoreService 2136 // Create a custom JumpList and add it to an observer of TabRestoreService
2089 // so we can update the custom JumpList when a tab is added or removed. 2137 // so we can update the custom JumpList when a tab is added or removed.
2090 if (JumpList::Enabled()) { 2138 if (JumpList::Enabled()) {
2091 load_complete_listener_.reset(new LoadCompleteListener(this)); 2139 load_complete_listener_.reset(new LoadCompleteListener(this));
2092 } 2140 }
2093 #endif 2141 #endif
2094 2142
2095 GetLocationBar()->GetOmniboxView()->model()->popup_model()->AddObserver(this); 2143 GetLocationBar()->GetOmniboxView()->model()->popup_model()->AddObserver(this);
2096 } 2144 }
2097 2145
2146 void BrowserView::UpdateSidebarForContents(content::WebContents* new_contents) {
2147 if (!sidebar_container_)
2148 return; // Happens when sidebar is not allowed.
2149 extensions::SidebarManager* sidebar_manager =
2150 extensions::SidebarManager::GetFromContext(browser_->profile());
2151 if (!sidebar_manager)
2152 return; // Happens only in tests.s
2153
2154 WebContents* sidebar_contents = NULL;
2155 if (new_contents) {
2156 SidebarContainer* client_host =
2157 sidebar_manager->GetActiveSidebarContainerFor(new_contents);
2158 if (client_host)
2159 sidebar_contents = client_host->host_contents();
2160 }
2161
2162 bool visible = NULL != sidebar_contents;
2163
2164 bool should_show = visible && !sidebar_container_->visible();
2165 bool should_hide = !visible && sidebar_container_->visible();
2166
2167 // Update sidebar content.
2168 WebContents* old_contents =
2169 static_cast<WebContents*>(sidebar_web_view_->web_contents());
2170
2171 sidebar_web_view_->SetWebContents(sidebar_contents);
2172
2173 sidebar_manager->NotifyStateChanges(old_contents, sidebar_contents);
2174
2175 // Update sidebar UI width.
2176 if (should_show) {
2177 // Restore split offset.
2178 int sidebar_width = g_browser_process->local_state()->GetInteger(
2179 prefs::kExtensionSidebarWidth);
2180 if (sidebar_width < 0) {
2181 // By default sidebar width is 1/7th of the current page content width.
2182 sidebar_width = sidebar_split_->width() / 7;
2183 }
2184 int min_sidebar_width = sidebar_split_->GetMinimumSize().width();
2185 // Not allowed to be wider than 50% of the split-view's frame
2186 sidebar_width = std::min(sidebar_split_->width() / 2 - min_sidebar_width,
2187 std::max(min_sidebar_width, sidebar_width));
2188 sidebar_split_->set_divider_offset(sidebar_split_->width() - sidebar_width);
2189
2190 sidebar_container_->SetVisible(true);
2191 sidebar_web_view_->SetVisible(true);
2192 sidebar_split_->InvalidateLayout();
2193 Layout();
2194
2195 } else if (should_hide) {
2196 // Store split offset when hiding sidebar only.
2197 g_browser_process->local_state()->SetInteger(
2198 prefs::kExtensionSidebarWidth,
2199 sidebar_split_->width() - sidebar_split_->divider_offset());
2200
2201 sidebar_container_->SetVisible(false);
2202 sidebar_split_->InvalidateLayout();
2203 Layout();
2204 }
2205 }
2206
2098 void BrowserView::LoadingAnimationCallback() { 2207 void BrowserView::LoadingAnimationCallback() {
2099 base::TimeTicks now = base::TimeTicks::Now(); 2208 base::TimeTicks now = base::TimeTicks::Now();
2100 if (!last_animation_time_.is_null()) { 2209 if (!last_animation_time_.is_null()) {
2101 UMA_HISTOGRAM_TIMES( 2210 UMA_HISTOGRAM_TIMES(
2102 "Tabs.LoadingAnimationTime", 2211 "Tabs.LoadingAnimationTime",
2103 now - last_animation_time_); 2212 now - last_animation_time_);
2104 } 2213 }
2105 last_animation_time_ = now; 2214 last_animation_time_ = now;
2106 if (browser_->is_type_tabbed()) { 2215 if (browser_->is_type_tabbed()) {
2107 // Loading animations are shown in the tab for tabbed windows. We check the 2216 // Loading animations are shown in the tab for tabbed windows. We check the
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
2615 return immersive_mode_controller()->IsEnabled(); 2724 return immersive_mode_controller()->IsEnabled();
2616 } 2725 }
2617 2726
2618 views::Widget* BrowserView::GetBubbleAssociatedWidget() { 2727 views::Widget* BrowserView::GetBubbleAssociatedWidget() {
2619 return GetWidget(); 2728 return GetWidget();
2620 } 2729 }
2621 2730
2622 gfx::Rect BrowserView::GetTopContainerBoundsInScreen() { 2731 gfx::Rect BrowserView::GetTopContainerBoundsInScreen() {
2623 return top_container_->GetBoundsInScreen(); 2732 return top_container_->GetBoundsInScreen();
2624 } 2733 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698