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" |
11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
12 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 12 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
13 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 13 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
14 #include "chrome/browser/autocomplete/autocomplete_input.h" | 14 #include "chrome/browser/autocomplete/autocomplete_input.h" |
15 #include "chrome/browser/autocomplete/autocomplete_match.h" | 15 #include "chrome/browser/autocomplete/autocomplete_match.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/extensions/tab_helper.h" | 18 #include "chrome/browser/extensions/tab_helper.h" |
19 #include "chrome/browser/favicon/favicon_tab_helper.h" | 19 #include "chrome/browser/favicon/favicon_tab_helper.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/search/search.h" | 21 #include "chrome/browser/search/search.h" |
22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_tabstrip.h" | 23 #include "chrome/browser/ui/browser_tabstrip.h" |
24 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 24 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
| 25 #include "chrome/browser/ui/tabs/tab_strip_layout_type_prefs.h" |
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
26 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" |
27 #include "chrome/browser/ui/tabs/tab_utils.h" | 28 #include "chrome/browser/ui/tabs/tab_utils.h" |
28 #include "chrome/browser/ui/views/frame/browser_view.h" | 29 #include "chrome/browser/ui/views/frame/browser_view.h" |
29 #include "chrome/browser/ui/views/tabs/tab.h" | 30 #include "chrome/browser/ui/views/tabs/tab.h" |
30 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | 31 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
31 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 32 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
32 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
34 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
(...skipping 17 matching lines...) Expand all Loading... |
52 | 53 |
53 TabRendererData::NetworkState TabContentsNetworkState( | 54 TabRendererData::NetworkState TabContentsNetworkState( |
54 WebContents* contents) { | 55 WebContents* contents) { |
55 if (!contents || !contents->IsLoading()) | 56 if (!contents || !contents->IsLoading()) |
56 return TabRendererData::NETWORK_STATE_NONE; | 57 return TabRendererData::NETWORK_STATE_NONE; |
57 if (contents->IsWaitingForResponse()) | 58 if (contents->IsWaitingForResponse()) |
58 return TabRendererData::NETWORK_STATE_WAITING; | 59 return TabRendererData::NETWORK_STATE_WAITING; |
59 return TabRendererData::NETWORK_STATE_LOADING; | 60 return TabRendererData::NETWORK_STATE_LOADING; |
60 } | 61 } |
61 | 62 |
62 TabStripLayoutType DetermineTabStripLayout( | 63 bool DetermineTabStripLayoutStacked( |
63 PrefService* prefs, | 64 PrefService* prefs, |
64 chrome::HostDesktopType host_desktop_type, | 65 chrome::HostDesktopType host_desktop_type, |
65 bool* adjust_layout) { | 66 bool* adjust_layout) { |
66 *adjust_layout = false; | 67 *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. | 68 // For ash, always allow entering stacked mode. |
72 if (host_desktop_type != chrome::HOST_DESKTOP_TYPE_ASH) | 69 if (host_desktop_type != chrome::HOST_DESKTOP_TYPE_ASH) |
73 return TAB_STRIP_LAYOUT_SHRINK; | 70 return false; |
74 *adjust_layout = true; | 71 *adjust_layout = true; |
75 switch (prefs->GetInteger(prefs::kTabStripLayoutType)) { | 72 return chrome::TabStripLayoutTypePrefs::GetStackedLayout(prefs); |
76 case TAB_STRIP_LAYOUT_STACKED: | |
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 stacked_layout = |
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 || stacked_layout == tabstrip_->stacked_layout()) |
399 return; | 392 return; |
400 | 393 |
401 g_browser_process->local_state()->SetInteger( | 394 chrome::TabStripLayoutTypePrefs::SetStackedLayout( |
402 prefs::kTabStripLayoutType, | 395 g_browser_process->local_state(), |
403 static_cast<int>(tabstrip_->layout_type())); | 396 tabstrip_->stacked_layout()); |
404 } | 397 } |
405 | 398 |
406 void BrowserTabStripController::OnStartedDraggingTabs() { | 399 void BrowserTabStripController::OnStartedDraggingTabs() { |
407 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 400 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
408 if (browser_view && !immersive_reveal_lock_.get()) { | 401 if (browser_view && !immersive_reveal_lock_.get()) { |
409 // The top-of-window views should be revealed while the user is dragging | 402 // 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 | 403 // 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 | 404 // revealed if the user is attempting to attach a tab to a tabstrip |
412 // belonging to an immersive fullscreen window. | 405 // belonging to an immersive fullscreen window. |
413 immersive_reveal_lock_.reset( | 406 immersive_reveal_lock_.reset( |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 // Cancel any pending tab transition. | 556 // Cancel any pending tab transition. |
564 hover_tab_selector_.CancelTabTransition(); | 557 hover_tab_selector_.CancelTabTransition(); |
565 | 558 |
566 TabRendererData data; | 559 TabRendererData data; |
567 SetTabRendererDataFromModel(contents, index, &data, NEW_TAB); | 560 SetTabRendererDataFromModel(contents, index, &data, NEW_TAB); |
568 tabstrip_->AddTabAt(index, data, is_active); | 561 tabstrip_->AddTabAt(index, data, is_active); |
569 } | 562 } |
570 | 563 |
571 void BrowserTabStripController::UpdateLayoutType() { | 564 void BrowserTabStripController::UpdateLayoutType() { |
572 bool adjust_layout = false; | 565 bool adjust_layout = false; |
573 TabStripLayoutType layout_type = | 566 bool stacked_layout = |
574 DetermineTabStripLayout(g_browser_process->local_state(), | 567 DetermineTabStripLayoutStacked(g_browser_process->local_state(), |
575 browser_->host_desktop_type(), &adjust_layout); | 568 browser_->host_desktop_type(), |
576 tabstrip_->SetLayoutType(layout_type, adjust_layout); | 569 &adjust_layout); |
| 570 tabstrip_->set_adjust_layout(adjust_layout); |
| 571 tabstrip_->SetStackedLayout(stacked_layout); |
577 } | 572 } |
578 | 573 |
579 void BrowserTabStripController::OnFindURLMimeTypeCompleted( | 574 void BrowserTabStripController::OnFindURLMimeTypeCompleted( |
580 const GURL& url, | 575 const GURL& url, |
581 const std::string& mime_type) { | 576 const std::string& mime_type) { |
582 // Check whether the mime type, if given, is known to be supported or whether | 577 // 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). | 578 // 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 | 579 // TODO(bauerb): This possibly uses stale information, but it's guaranteed not |
585 // to do disk access. | 580 // to do disk access. |
586 content::WebPluginInfo plugin; | 581 content::WebPluginInfo plugin; |
587 tabstrip_->FileSupported( | 582 tabstrip_->FileSupported( |
588 url, | 583 url, |
589 mime_type.empty() || | 584 mime_type.empty() || |
590 net::IsSupportedMimeType(mime_type) || | 585 net::IsSupportedMimeType(mime_type) || |
591 content::PluginService::GetInstance()->GetPluginInfo( | 586 content::PluginService::GetInstance()->GetPluginInfo( |
592 -1, // process ID | 587 -1, // process ID |
593 MSG_ROUTING_NONE, // routing ID | 588 MSG_ROUTING_NONE, // routing ID |
594 model_->profile()->GetResourceContext(), | 589 model_->profile()->GetResourceContext(), |
595 url, GURL(), mime_type, false, | 590 url, GURL(), mime_type, false, |
596 NULL, &plugin, NULL)); | 591 NULL, &plugin, NULL)); |
597 } | 592 } |
OLD | NEW |