Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/tabs/browser_tab_strip_controller.h" | 5 #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 | 52 |
| 53 TabRendererData::NetworkState TabContentsNetworkState( | 53 TabRendererData::NetworkState TabContentsNetworkState( |
| 54 WebContents* contents) { | 54 WebContents* contents) { |
| 55 if (!contents || !contents->IsLoading()) | 55 if (!contents || !contents->IsLoading()) |
| 56 return TabRendererData::NETWORK_STATE_NONE; | 56 return TabRendererData::NETWORK_STATE_NONE; |
| 57 if (contents->IsWaitingForResponse()) | 57 if (contents->IsWaitingForResponse()) |
| 58 return TabRendererData::NETWORK_STATE_WAITING; | 58 return TabRendererData::NETWORK_STATE_WAITING; |
| 59 return TabRendererData::NETWORK_STATE_LOADING; | 59 return TabRendererData::NETWORK_STATE_LOADING; |
| 60 } | 60 } |
| 61 | 61 |
| 62 TabStripLayoutType DetermineTabStripLayout( | 62 bool DetermineTabStripLayoutStacked( |
| 63 PrefService* prefs, | 63 PrefService* prefs, |
| 64 chrome::HostDesktopType host_desktop_type, | 64 chrome::HostDesktopType host_desktop_type, |
| 65 bool* adjust_layout) { | 65 bool* adjust_layout) { |
| 66 *adjust_layout = false; | 66 *adjust_layout = false; |
| 67 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 68 switches::kEnableStackedTabStrip)) { | |
| 69 return TAB_STRIP_LAYOUT_STACKED; | |
| 70 } | |
| 71 // For ash, always allow entering stacked mode. | 67 // For ash, always allow entering stacked mode. |
| 72 if (host_desktop_type != chrome::HOST_DESKTOP_TYPE_ASH) | 68 if (host_desktop_type != chrome::HOST_DESKTOP_TYPE_ASH) |
| 73 return TAB_STRIP_LAYOUT_SHRINK; | 69 return false; |
| 74 *adjust_layout = true; | 70 *adjust_layout = true; |
| 75 switch (prefs->GetInteger(prefs::kTabStripLayoutType)) { | 71 return (prefs->GetInteger(prefs::kTabStripLayoutType) == |
| 76 case TAB_STRIP_LAYOUT_STACKED: | 72 TAB_STRIP_LAYOUT_STACKED); |
|
sky
2014/05/21 22:57:19
Seems silly to keep the enum and not use it. I bel
varkha
2014/05/23 17:43:23
Right, I left the enum as a way to document the va
| |
| 77 return TAB_STRIP_LAYOUT_STACKED; | |
| 78 default: | |
| 79 return TAB_STRIP_LAYOUT_SHRINK; | |
| 80 } | |
| 81 } | 73 } |
| 82 | 74 |
| 83 // Get the MIME type of the file pointed to by the url, based on the file's | 75 // Get the MIME type of the file pointed to by the url, based on the file's |
| 84 // extension. Must be called on a thread that allows IO. | 76 // extension. Must be called on a thread that allows IO. |
| 85 std::string FindURLMimeType(const GURL& url) { | 77 std::string FindURLMimeType(const GURL& url) { |
| 86 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 78 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 87 base::FilePath full_path; | 79 base::FilePath full_path; |
| 88 net::FileURLToFilePath(url, &full_path); | 80 net::FileURLToFilePath(url, &full_path); |
| 89 | 81 |
| 90 // Get the MIME type based on the filename. | 82 // Get the MIME type based on the filename. |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 if (match.destination_url.is_valid()) | 377 if (match.destination_url.is_valid()) |
| 386 model_->delegate()->AddTabAt(match.destination_url, -1, true); | 378 model_->delegate()->AddTabAt(match.destination_url, -1, true); |
| 387 } | 379 } |
| 388 | 380 |
| 389 bool BrowserTabStripController::IsIncognito() { | 381 bool BrowserTabStripController::IsIncognito() { |
| 390 return browser_->profile()->IsOffTheRecord(); | 382 return browser_->profile()->IsOffTheRecord(); |
| 391 } | 383 } |
| 392 | 384 |
| 393 void BrowserTabStripController::LayoutTypeMaybeChanged() { | 385 void BrowserTabStripController::LayoutTypeMaybeChanged() { |
| 394 bool adjust_layout = false; | 386 bool adjust_layout = false; |
| 395 TabStripLayoutType layout_type = | 387 bool layout_type_stacked = |
| 396 DetermineTabStripLayout(g_browser_process->local_state(), | 388 DetermineTabStripLayoutStacked(g_browser_process->local_state(), |
| 397 browser_->host_desktop_type(), &adjust_layout); | 389 browser_->host_desktop_type(), |
| 398 if (!adjust_layout || layout_type == tabstrip_->layout_type()) | 390 &adjust_layout); |
| 391 if (!adjust_layout || layout_type_stacked == tabstrip_->layout_type_stacked()) | |
| 399 return; | 392 return; |
| 400 | 393 |
| 401 g_browser_process->local_state()->SetInteger( | 394 g_browser_process->local_state()->SetInteger( |
| 402 prefs::kTabStripLayoutType, | 395 prefs::kTabStripLayoutType, |
| 403 static_cast<int>(tabstrip_->layout_type())); | 396 static_cast<int>(tabstrip_->layout_type_stacked() ? |
| 397 TAB_STRIP_LAYOUT_STACKED : TAB_STRIP_LAYOUT_SHRINK)); | |
| 404 } | 398 } |
| 405 | 399 |
| 406 void BrowserTabStripController::OnStartedDraggingTabs() { | 400 void BrowserTabStripController::OnStartedDraggingTabs() { |
| 407 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 401 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
| 408 if (browser_view && !immersive_reveal_lock_.get()) { | 402 if (browser_view && !immersive_reveal_lock_.get()) { |
| 409 // The top-of-window views should be revealed while the user is dragging | 403 // The top-of-window views should be revealed while the user is dragging |
| 410 // tabs in immersive fullscreen. The top-of-window views may not be already | 404 // tabs in immersive fullscreen. The top-of-window views may not be already |
| 411 // revealed if the user is attempting to attach a tab to a tabstrip | 405 // revealed if the user is attempting to attach a tab to a tabstrip |
| 412 // belonging to an immersive fullscreen window. | 406 // belonging to an immersive fullscreen window. |
| 413 immersive_reveal_lock_.reset( | 407 immersive_reveal_lock_.reset( |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 // Cancel any pending tab transition. | 557 // Cancel any pending tab transition. |
| 564 hover_tab_selector_.CancelTabTransition(); | 558 hover_tab_selector_.CancelTabTransition(); |
| 565 | 559 |
| 566 TabRendererData data; | 560 TabRendererData data; |
| 567 SetTabRendererDataFromModel(contents, index, &data, NEW_TAB); | 561 SetTabRendererDataFromModel(contents, index, &data, NEW_TAB); |
| 568 tabstrip_->AddTabAt(index, data, is_active); | 562 tabstrip_->AddTabAt(index, data, is_active); |
| 569 } | 563 } |
| 570 | 564 |
| 571 void BrowserTabStripController::UpdateLayoutType() { | 565 void BrowserTabStripController::UpdateLayoutType() { |
| 572 bool adjust_layout = false; | 566 bool adjust_layout = false; |
| 573 TabStripLayoutType layout_type = | 567 bool layout_type_stacked = |
| 574 DetermineTabStripLayout(g_browser_process->local_state(), | 568 DetermineTabStripLayoutStacked(g_browser_process->local_state(), |
| 575 browser_->host_desktop_type(), &adjust_layout); | 569 browser_->host_desktop_type(), |
| 576 tabstrip_->SetLayoutType(layout_type, adjust_layout); | 570 &adjust_layout); |
| 571 tabstrip_->set_adjust_layout(adjust_layout); | |
| 572 tabstrip_->SetLayoutTypeStacked(layout_type_stacked); | |
| 577 } | 573 } |
| 578 | 574 |
| 579 void BrowserTabStripController::OnFindURLMimeTypeCompleted( | 575 void BrowserTabStripController::OnFindURLMimeTypeCompleted( |
| 580 const GURL& url, | 576 const GURL& url, |
| 581 const std::string& mime_type) { | 577 const std::string& mime_type) { |
| 582 // Check whether the mime type, if given, is known to be supported or whether | 578 // Check whether the mime type, if given, is known to be supported or whether |
| 583 // there is a plugin that supports the mime type (e.g. PDF). | 579 // there is a plugin that supports the mime type (e.g. PDF). |
| 584 // TODO(bauerb): This possibly uses stale information, but it's guaranteed not | 580 // TODO(bauerb): This possibly uses stale information, but it's guaranteed not |
| 585 // to do disk access. | 581 // to do disk access. |
| 586 content::WebPluginInfo plugin; | 582 content::WebPluginInfo plugin; |
| 587 tabstrip_->FileSupported( | 583 tabstrip_->FileSupported( |
| 588 url, | 584 url, |
| 589 mime_type.empty() || | 585 mime_type.empty() || |
| 590 net::IsSupportedMimeType(mime_type) || | 586 net::IsSupportedMimeType(mime_type) || |
| 591 content::PluginService::GetInstance()->GetPluginInfo( | 587 content::PluginService::GetInstance()->GetPluginInfo( |
| 592 -1, // process ID | 588 -1, // process ID |
| 593 MSG_ROUTING_NONE, // routing ID | 589 MSG_ROUTING_NONE, // routing ID |
| 594 model_->profile()->GetResourceContext(), | 590 model_->profile()->GetResourceContext(), |
| 595 url, GURL(), mime_type, false, | 591 url, GURL(), mime_type, false, |
| 596 NULL, &plugin, NULL)); | 592 NULL, &plugin, NULL)); |
| 597 } | 593 } |
| OLD | NEW |