 Chromium Code Reviews
 Chromium Code Reviews Issue 6692001:
  Add in DOMBrowserView and Frame related classes  (Closed) 
  Base URL: http://git.chromium.org/git/chromium.git@trunk
    
  
    Issue 6692001:
  Add in DOMBrowserView and Frame related classes  (Closed) 
  Base URL: http://git.chromium.org/git/chromium.git@trunk| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) | 
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> | 
| 9 #endif | 9 #endif | 
| 10 | 10 | 
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 #endif | 465 #endif | 
| 466 | 466 | 
| 467 // We destroy the download shelf before |browser_| to remove its child | 467 // We destroy the download shelf before |browser_| to remove its child | 
| 468 // download views from the set of download observers (since the observed | 468 // download views from the set of download observers (since the observed | 
| 469 // downloads can be destroyed along with |browser_| and the observer | 469 // downloads can be destroyed along with |browser_| and the observer | 
| 470 // notifications will call back into deleted objects). | 470 // notifications will call back into deleted objects). | 
| 471 download_shelf_.reset(); | 471 download_shelf_.reset(); | 
| 472 | 472 | 
| 473 // The TabStrip attaches a listener to the model. Make sure we shut down the | 473 // The TabStrip attaches a listener to the model. Make sure we shut down the | 
| 474 // TabStrip first so that it can cleanly remove the listener. | 474 // TabStrip first so that it can cleanly remove the listener. | 
| 475 tabstrip_->parent()->RemoveChildView(tabstrip_); | 475 if (tabstrip_) { | 
| 476 delete tabstrip_; | 476 tabstrip_->parent()->RemoveChildView(tabstrip_); | 
| 477 tabstrip_ = NULL; | 477 delete tabstrip_; | 
| 478 | 478 tabstrip_ = NULL; | 
| 479 } | |
| 479 // Child views maintain PrefMember attributes that point to | 480 // Child views maintain PrefMember attributes that point to | 
| 480 // OffTheRecordProfile's PrefService which gets deleted by ~Browser. | 481 // OffTheRecordProfile's PrefService which gets deleted by ~Browser. | 
| 481 RemoveAllChildViews(true); | 482 RemoveAllChildViews(true); | 
| 482 // Explicitly set browser_ to NULL. | 483 // Explicitly set browser_ to NULL. | 
| 483 browser_.reset(); | 484 browser_.reset(); | 
| 484 } | 485 } | 
| 485 | 486 | 
| 486 // static | 487 // static | 
| 487 BrowserView* BrowserView::GetBrowserViewForNativeWindow( | 488 BrowserView* BrowserView::GetBrowserViewForNativeWindow( | 
| 488 gfx::NativeWindow window) { | 489 gfx::NativeWindow window) { | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 506 // Comment out for one cycle to see if this fixes dist tests. | 507 // Comment out for one cycle to see if this fixes dist tests. | 
| 507 // tabstrip_->DestroyDragController(); | 508 // tabstrip_->DestroyDragController(); | 
| 508 | 509 | 
| 509 status_bubble_->Reposition(); | 510 status_bubble_->Reposition(); | 
| 510 | 511 | 
| 511 BrowserBubbleHost::WindowMoved(); | 512 BrowserBubbleHost::WindowMoved(); | 
| 512 | 513 | 
| 513 browser::HideBookmarkBubbleView(); | 514 browser::HideBookmarkBubbleView(); | 
| 514 | 515 | 
| 515 // Close the omnibox popup, if any. | 516 // Close the omnibox popup, if any. | 
| 516 if (toolbar_->location_bar()) | 517 if (toolbar_) | 
| 517 toolbar_->location_bar()->location_entry()->ClosePopup(); | 518 if (toolbar_->location_bar()) | 
| 
oshima
2011/03/14 20:09:22
if (toolbar_ && toolbar_->location_bar())
 
rharrison
2011/03/15 22:01:21
Done.
 | |
| 519 toolbar_->location_bar()->location_entry()->ClosePopup(); | |
| 518 } | 520 } | 
| 519 | 521 | 
| 520 void BrowserView::WindowMoveOrResizeStarted() { | 522 void BrowserView::WindowMoveOrResizeStarted() { | 
| 521 TabContents* tab_contents = GetSelectedTabContents(); | 523 TabContents* tab_contents = GetSelectedTabContents(); | 
| 522 if (tab_contents) | 524 if (tab_contents) | 
| 523 tab_contents->WindowMoveOrResizeStarted(); | 525 tab_contents->WindowMoveOrResizeStarted(); | 
| 524 } | 526 } | 
| 525 | 527 | 
| 526 gfx::Rect BrowserView::GetToolbarBounds() const { | 528 gfx::Rect BrowserView::GetToolbarBounds() const { | 
| 527 gfx::Rect toolbar_bounds(toolbar_->bounds()); | 529 gfx::Rect toolbar_bounds(toolbar_->bounds()); | 
| (...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1654 if (active) | 1656 if (active) | 
| 1655 BrowserList::SetLastActive(browser_.get()); | 1657 BrowserList::SetLastActive(browser_.get()); | 
| 1656 } | 1658 } | 
| 1657 | 1659 | 
| 1658 /////////////////////////////////////////////////////////////////////////////// | 1660 /////////////////////////////////////////////////////////////////////////////// | 
| 1659 // BrowserView, views::ClientView overrides: | 1661 // BrowserView, views::ClientView overrides: | 
| 1660 | 1662 | 
| 1661 bool BrowserView::CanClose() { | 1663 bool BrowserView::CanClose() { | 
| 1662 // You cannot close a frame for which there is an active originating drag | 1664 // You cannot close a frame for which there is an active originating drag | 
| 1663 // session. | 1665 // session. | 
| 1664 if (!tabstrip_->IsTabStripCloseable()) | 1666 if (tabstrip_) | 
| 1665 return false; | 1667 if (!tabstrip_->IsTabStripCloseable()) | 
| 
oshima
2011/03/14 20:09:22
if (tabstrip_ && ...)
 
rharrison
2011/03/15 22:01:21
Done.
 | |
| 1668 return false; | |
| 1666 | 1669 | 
| 1667 // Give beforeunload handlers the chance to cancel the close before we hide | 1670 // Give beforeunload handlers the chance to cancel the close before we hide | 
| 1668 // the window below. | 1671 // the window below. | 
| 1669 if (!browser_->ShouldCloseWindow()) | 1672 if (!browser_->ShouldCloseWindow()) | 
| 1670 return false; | 1673 return false; | 
| 1671 | 1674 | 
| 1672 if (!browser_->tabstrip_model()->empty()) { | 1675 if (!browser_->tabstrip_model()->empty()) { | 
| 1673 // Tab strip isn't empty. Hide the frame (so it appears to have closed | 1676 // Tab strip isn't empty. Hide the frame (so it appears to have closed | 
| 1674 // immediately) and close all the tabs, allowing the renderers to shut | 1677 // immediately) and close all the tabs, allowing the renderers to shut | 
| 1675 // down. When the tab strip is empty we'll be called back again. | 1678 // down. When the tab strip is empty we'll be called back again. | 
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1813 void BrowserView::InitTabStrip(TabStripModel* model) { | 1816 void BrowserView::InitTabStrip(TabStripModel* model) { | 
| 1814 // Throw away the existing tabstrip if we're switching display modes. | 1817 // Throw away the existing tabstrip if we're switching display modes. | 
| 1815 scoped_ptr<AbstractTabStripView> old_strip(tabstrip_); | 1818 scoped_ptr<AbstractTabStripView> old_strip(tabstrip_); | 
| 1816 if (tabstrip_) | 1819 if (tabstrip_) | 
| 1817 tabstrip_->parent()->RemoveChildView(tabstrip_); | 1820 tabstrip_->parent()->RemoveChildView(tabstrip_); | 
| 1818 | 1821 | 
| 1819 tabstrip_ = CreateTabStrip(browser_.get(), model, UseVerticalTabs()); | 1822 tabstrip_ = CreateTabStrip(browser_.get(), model, UseVerticalTabs()); | 
| 1820 AddChildView(tabstrip_); | 1823 AddChildView(tabstrip_); | 
| 1821 } | 1824 } | 
| 1822 | 1825 | 
| 1823 /////////////////////////////////////////////////////////////////////////////// | 1826 ToolbarView* BrowserView::CreateToolbar() const { | 
| 1824 // BrowserView, private: | 1827 return new ToolbarView(browser_.get()); | 
| 1828 } | |
| 1825 | 1829 | 
| 1826 void BrowserView::Init() { | 1830 void BrowserView::Init() { | 
| 1827 SetLayoutManager(CreateLayoutManager()); | 1831 SetLayoutManager(CreateLayoutManager()); | 
| 1828 // Stow a pointer to this object onto the window handle so that we can get at | 1832 // Stow a pointer to this object onto the window handle so that we can get at | 
| 1829 // it later when all we have is a native view. | 1833 // it later when all we have is a native view. | 
| 1830 GetWidget()->native_widget()->SetNativeWindowProperty(kBrowserViewKey, this); | 1834 GetWidget()->native_widget()->SetNativeWindowProperty(kBrowserViewKey, this); | 
| 1831 | 1835 | 
| 1832 // Stow a pointer to the browser's profile onto the window handle so that we | 1836 // Stow a pointer to the browser's profile onto the window handle so that we | 
| 1833 // can get it later when all we have is a native view. | 1837 // can get it later when all we have is a native view. | 
| 1834 GetWidget()->native_widget()->SetNativeWindowProperty(Profile::kProfileKey, | 1838 GetWidget()->native_widget()->SetNativeWindowProperty(Profile::kProfileKey, | 
| 1835 browser_->profile()); | 1839 browser_->profile()); | 
| 1836 | 1840 | 
| 1837 // Start a hung plugin window detector for this browser object (as long as | 1841 // Start a hung plugin window detector for this browser object (as long as | 
| 1838 // hang detection is not disabled). | 1842 // hang detection is not disabled). | 
| 1839 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 1843 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 
| 1840 switches::kDisableHangMonitor)) { | 1844 switches::kDisableHangMonitor)) { | 
| 1841 InitHangMonitor(); | 1845 InitHangMonitor(); | 
| 1842 } | 1846 } | 
| 1843 | 1847 | 
| 1844 LoadAccelerators(); | 1848 LoadAccelerators(); | 
| 1845 | 1849 | 
| 1846 InitTabStrip(browser_->tabstrip_model()); | 1850 InitTabStrip(browser_->tabstrip_model()); | 
| 1847 | 1851 | 
| 1848 toolbar_ = new ToolbarView(browser_.get()); | 1852 SetToolbar(CreateToolbar()); | 
| 1849 AddChildView(toolbar_); | |
| 1850 toolbar_->Init(browser_->profile()); | |
| 1851 | 1853 | 
| 1852 infobar_container_ = new InfoBarContainer(this); | 1854 infobar_container_ = new InfoBarContainer(this); | 
| 1853 AddChildView(infobar_container_); | 1855 AddChildView(infobar_container_); | 
| 1854 | 1856 | 
| 1855 contents_container_ = new TabContentsContainer; | 1857 contents_container_ = new TabContentsContainer; | 
| 1856 contents_ = new ContentsContainer(contents_container_); | 1858 contents_ = new ContentsContainer(contents_container_); | 
| 1857 | 1859 | 
| 1858 SkColor bg_color = GetWidget()->GetThemeProvider()-> | 1860 SkColor bg_color = GetWidget()->GetThemeProvider()-> | 
| 1859 GetColor(BrowserThemeProvider::COLOR_TOOLBAR); | 1861 GetColor(BrowserThemeProvider::COLOR_TOOLBAR); | 
| 1860 | 1862 | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1913 aeropeek_manager_.reset(new AeroPeekManager( | 1915 aeropeek_manager_.reset(new AeroPeekManager( | 
| 1914 frame_->GetWindow()->GetNativeWindow())); | 1916 frame_->GetWindow()->GetNativeWindow())); | 
| 1915 browser_->tabstrip_model()->AddObserver(aeropeek_manager_.get()); | 1917 browser_->tabstrip_model()->AddObserver(aeropeek_manager_.get()); | 
| 1916 } | 1918 } | 
| 1917 #endif | 1919 #endif | 
| 1918 | 1920 | 
| 1919 // We're now initialized and ready to process Layout requests. | 1921 // We're now initialized and ready to process Layout requests. | 
| 1920 ignore_layout_ = false; | 1922 ignore_layout_ = false; | 
| 1921 } | 1923 } | 
| 1922 | 1924 | 
| 1925 void BrowserView::LoadingAnimationCallback() { | |
| 1926 base::TimeTicks now = base::TimeTicks::Now(); | |
| 1927 if (!last_animation_time_.is_null()) { | |
| 1928 UMA_HISTOGRAM_TIMES( | |
| 1929 "Tabs.LoadingAnimationTime", | |
| 1930 now - last_animation_time_); | |
| 1931 } | |
| 1932 last_animation_time_ = now; | |
| 1933 if (browser_->type() == Browser::TYPE_NORMAL) { | |
| 1934 // Loading animations are shown in the tab for tabbed windows. We check the | |
| 1935 // browser type instead of calling IsTabStripVisible() because the latter | |
| 1936 // will return false for fullscreen windows, but we still need to update | |
| 1937 // their animations (so that when they come out of fullscreen mode they'll | |
| 1938 // be correct). | |
| 1939 tabstrip_->UpdateLoadingAnimations(); | |
| 1940 } else if (ShouldShowWindowIcon()) { | |
| 1941 // ... or in the window icon area for popups and app windows. | |
| 1942 TabContents* tab_contents = browser_->GetSelectedTabContents(); | |
| 1943 // GetSelectedTabContents can return NULL for example under Purify when | |
| 1944 // the animations are running slowly and this function is called on a timer | |
| 1945 // through LoadingAnimationCallback. | |
| 1946 frame_->UpdateThrobber(tab_contents && tab_contents->is_loading()); | |
| 1947 } | |
| 1948 } | |
| 1949 | |
| 1950 /////////////////////////////////////////////////////////////////////////////// | |
| 1951 // BrowserView, private: | |
| 1952 | |
| 1923 #if defined(OS_WIN) | 1953 #if defined(OS_WIN) | 
| 1924 void BrowserView::InitSystemMenu() { | 1954 void BrowserView::InitSystemMenu() { | 
| 1925 system_menu_contents_.reset(new views::SystemMenuModel(this)); | 1955 system_menu_contents_.reset(new views::SystemMenuModel(this)); | 
| 1926 // We add the menu items in reverse order so that insertion_index never needs | 1956 // We add the menu items in reverse order so that insertion_index never needs | 
| 1927 // to change. | 1957 // to change. | 
| 1928 if (IsBrowserTypeNormal()) | 1958 if (IsBrowserTypeNormal()) | 
| 1929 BuildSystemMenuForBrowserWindow(); | 1959 BuildSystemMenuForBrowserWindow(); | 
| 1930 else | 1960 else | 
| 1931 BuildSystemMenuForAppOrPopupWindow(browser_->type() == Browser::TYPE_APP); | 1961 BuildSystemMenuForAppOrPopupWindow(browser_->type() == Browser::TYPE_APP); | 
| 1932 system_menu_.reset( | 1962 system_menu_.reset( | 
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2364 case APPCOMMAND_REDO: | 2394 case APPCOMMAND_REDO: | 
| 2365 case APPCOMMAND_SPELL_CHECK: | 2395 case APPCOMMAND_SPELL_CHECK: | 
| 2366 default: return -1; | 2396 default: return -1; | 
| 2367 } | 2397 } | 
| 2368 #else | 2398 #else | 
| 2369 // App commands are Windows-specific so there's nothing to do here. | 2399 // App commands are Windows-specific so there's nothing to do here. | 
| 2370 return -1; | 2400 return -1; | 
| 2371 #endif | 2401 #endif | 
| 2372 } | 2402 } | 
| 2373 | 2403 | 
| 2374 void BrowserView::LoadingAnimationCallback() { | |
| 2375 base::TimeTicks now = base::TimeTicks::Now(); | |
| 2376 if (!last_animation_time_.is_null()) { | |
| 2377 UMA_HISTOGRAM_TIMES( | |
| 2378 "Tabs.LoadingAnimationTime", | |
| 2379 now - last_animation_time_); | |
| 2380 } | |
| 2381 last_animation_time_ = now; | |
| 2382 if (browser_->type() == Browser::TYPE_NORMAL) { | |
| 2383 // Loading animations are shown in the tab for tabbed windows. We check the | |
| 2384 // browser type instead of calling IsTabStripVisible() because the latter | |
| 2385 // will return false for fullscreen windows, but we still need to update | |
| 2386 // their animations (so that when they come out of fullscreen mode they'll | |
| 2387 // be correct). | |
| 2388 tabstrip_->UpdateLoadingAnimations(); | |
| 2389 } else if (ShouldShowWindowIcon()) { | |
| 2390 // ... or in the window icon area for popups and app windows. | |
| 2391 TabContents* tab_contents = browser_->GetSelectedTabContents(); | |
| 2392 // GetSelectedTabContents can return NULL for example under Purify when | |
| 2393 // the animations are running slowly and this function is called on a timer | |
| 2394 // through LoadingAnimationCallback. | |
| 2395 frame_->UpdateThrobber(tab_contents && tab_contents->is_loading()); | |
| 2396 } | |
| 2397 } | |
| 2398 | |
| 2399 void BrowserView::InitHangMonitor() { | 2404 void BrowserView::InitHangMonitor() { | 
| 2400 #if defined(OS_WIN) | 2405 #if defined(OS_WIN) | 
| 2401 PrefService* pref_service = g_browser_process->local_state(); | 2406 PrefService* pref_service = g_browser_process->local_state(); | 
| 2402 if (!pref_service) | 2407 if (!pref_service) | 
| 2403 return; | 2408 return; | 
| 2404 | 2409 | 
| 2405 int plugin_message_response_timeout = | 2410 int plugin_message_response_timeout = | 
| 2406 pref_service->GetInteger(prefs::kPluginMessageResponseTimeout); | 2411 pref_service->GetInteger(prefs::kPluginMessageResponseTimeout); | 
| 2407 int hung_plugin_detect_freq = | 2412 int hung_plugin_detect_freq = | 
| 2408 pref_service->GetInteger(prefs::kHungPluginDetectFrequency); | 2413 pref_service->GetInteger(prefs::kHungPluginDetectFrequency); | 
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2514 // Update all the UI bits. | 2519 // Update all the UI bits. | 
| 2515 UpdateTitleBar(); | 2520 UpdateTitleBar(); | 
| 2516 // No need to update Toolbar because it's already updated in | 2521 // No need to update Toolbar because it's already updated in | 
| 2517 // browser.cc. | 2522 // browser.cc. | 
| 2518 } | 2523 } | 
| 2519 | 2524 | 
| 2520 gfx::Size BrowserView::GetResizeCornerSize() const { | 2525 gfx::Size BrowserView::GetResizeCornerSize() const { | 
| 2521 return ResizeCorner::GetSize(); | 2526 return ResizeCorner::GetSize(); | 
| 2522 } | 2527 } | 
| 2523 | 2528 | 
| 2529 void BrowserView::SetToolbar(ToolbarView* toolbar) { | |
| 2530 if (!toolbar) | |
| 2531 return; | |
| 
oshima
2011/03/14 20:09:22
Can this happen? If not, use CHECK/DCHECK. If yes,
 
rharrison
2011/03/15 22:01:21
Yes, since we override the function CreateToolbar
 | |
| 2532 toolbar_ = toolbar; | |
| 2533 AddChildView(toolbar_); | |
| 2534 toolbar_->Init(browser_->profile()); | |
| 2535 } | |
| 2536 | |
| 2524 #if !defined(OS_CHROMEOS) | 2537 #if !defined(OS_CHROMEOS) | 
| 2525 // static | 2538 // static | 
| 2526 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 2539 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 
| 2527 // Create the view and the frame. The frame will attach itself via the view | 2540 // Create the view and the frame. The frame will attach itself via the view | 
| 2528 // so we don't need to do anything with the pointer. | 2541 // so we don't need to do anything with the pointer. | 
| 2529 BrowserView* view = new BrowserView(browser); | 2542 BrowserView* view = new BrowserView(browser); | 
| 2530 BrowserFrame::Create(view, browser->profile()); | 2543 BrowserFrame::Create(view, browser->profile()); | 
| 2531 | 2544 | 
| 2532 view->GetWindow()->non_client_view()->SetAccessibleName( | 2545 view->GetWindow()->non_client_view()->SetAccessibleName( | 
| 2533 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 2546 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 
| 2534 | 2547 | 
| 2535 return view; | 2548 return view; | 
| 2536 } | 2549 } | 
| 2537 #endif | 2550 #endif | 
| 2538 | 2551 | 
| 2539 // static | 2552 // static | 
| 2540 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { | 2553 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { | 
| 2541 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); | 2554 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); | 
| 2542 } | 2555 } | 
| OLD | NEW |