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/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | 27 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
| 28 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 28 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 31 #include "components/metrics/proto/omnibox_event.pb.h" | 31 #include "components/metrics/proto/omnibox_event.pb.h" |
| 32 #include "components/mime_util/mime_util.h" | 32 #include "components/mime_util/mime_util.h" |
| 33 #include "components/omnibox/browser/autocomplete_classifier.h" | 33 #include "components/omnibox/browser/autocomplete_classifier.h" |
| 34 #include "components/omnibox/browser/autocomplete_match.h" | 34 #include "components/omnibox/browser/autocomplete_match.h" |
| 35 #include "components/prefs/pref_service.h" | 35 #include "components/prefs/pref_service.h" |
| 36 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/navigation_controller.h" | |
| 38 #include "content/public/browser/navigation_entry.h" | |
| 39 #include "content/public/browser/navigation_handle.h" | |
| 37 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
| 38 #include "content/public/browser/plugin_service.h" | 41 #include "content/public/browser/plugin_service.h" |
| 39 #include "content/public/browser/user_metrics.h" | 42 #include "content/public/browser/user_metrics.h" |
| 40 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/common/webplugininfo.h" | 44 #include "content/public/common/webplugininfo.h" |
| 42 #include "ipc/ipc_message.h" | 45 #include "ipc/ipc_message.h" |
| 43 #include "net/base/filename_util.h" | 46 #include "net/base/filename_util.h" |
| 44 #include "ui/base/models/list_selection_model.h" | 47 #include "ui/base/models/list_selection_model.h" |
| 45 #include "ui/gfx/image/image.h" | 48 #include "ui/gfx/image/image.h" |
| 46 #include "ui/views/controls/menu/menu_runner.h" | 49 #include "ui/views/controls/menu/menu_runner.h" |
| 47 #include "ui/views/widget/widget.h" | 50 #include "ui/views/widget/widget.h" |
| 48 #include "url/origin.h" | 51 #include "url/origin.h" |
| 49 | 52 |
| 50 using base::UserMetricsAction; | 53 using base::UserMetricsAction; |
| 51 using content::WebContents; | 54 using content::WebContents; |
| 52 | 55 |
| 53 namespace { | 56 namespace { |
| 54 | 57 |
| 55 TabRendererData::NetworkState TabContentsNetworkState( | 58 TabRendererData::NetworkState TabContentsNetworkState( |
| 56 WebContents* contents) { | 59 WebContents* contents) { |
| 57 if (!contents || !contents->IsLoadingToDifferentDocument()) | 60 if (!contents) |
| 58 return TabRendererData::NETWORK_STATE_NONE; | 61 return TabRendererData::NETWORK_STATE_NONE; |
| 62 | |
| 63 if (!contents->IsLoadingToDifferentDocument()) { | |
| 64 content::NavigationEntry* entry = | |
| 65 contents->GetController().GetLastCommittedEntry(); | |
| 66 if (entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR)) | |
| 67 return TabRendererData::NETWORK_STATE_ERROR; | |
| 68 return TabRendererData::NETWORK_STATE_NONE; | |
| 69 } | |
| 70 | |
| 59 if (contents->IsWaitingForResponse()) | 71 if (contents->IsWaitingForResponse()) |
| 60 return TabRendererData::NETWORK_STATE_WAITING; | 72 return TabRendererData::NETWORK_STATE_WAITING; |
| 61 return TabRendererData::NETWORK_STATE_LOADING; | 73 return TabRendererData::NETWORK_STATE_LOADING; |
| 62 } | 74 } |
| 63 | 75 |
| 64 bool DetermineTabStripLayoutStacked(PrefService* prefs, bool* adjust_layout) { | 76 bool DetermineTabStripLayoutStacked(PrefService* prefs, bool* adjust_layout) { |
| 65 *adjust_layout = false; | 77 *adjust_layout = false; |
| 66 // For ash, always allow entering stacked mode. | 78 // For ash, always allow entering stacked mode. |
| 67 #if defined(USE_ASH) | 79 #if defined(USE_ASH) |
| 68 *adjust_layout = true; | 80 *adjust_layout = true; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 // appropriately as the user moves through the menu. | 185 // appropriately as the user moves through the menu. |
| 174 TabStripModel::ContextMenuCommand last_command_; | 186 TabStripModel::ContextMenuCommand last_command_; |
| 175 | 187 |
| 176 DISALLOW_COPY_AND_ASSIGN(TabContextMenuContents); | 188 DISALLOW_COPY_AND_ASSIGN(TabContextMenuContents); |
| 177 }; | 189 }; |
| 178 | 190 |
| 179 //////////////////////////////////////////////////////////////////////////////// | 191 //////////////////////////////////////////////////////////////////////////////// |
| 180 // BrowserTabStripController, public: | 192 // BrowserTabStripController, public: |
| 181 | 193 |
| 182 BrowserTabStripController::BrowserTabStripController(Browser* browser, | 194 BrowserTabStripController::BrowserTabStripController(Browser* browser, |
| 183 TabStripModel* model) | 195 TabStripModel* model, |
| 196 BrowserView* browser_view) | |
| 184 : model_(model), | 197 : model_(model), |
| 185 tabstrip_(NULL), | 198 tabstrip_(NULL), |
| 186 browser_(browser), | 199 browser_(browser), |
| 200 browser_view_(browser_view), | |
| 187 hover_tab_selector_(model), | 201 hover_tab_selector_(model), |
| 188 weak_ptr_factory_(this) { | 202 weak_ptr_factory_(this) { |
| 189 model_->AddObserver(this); | 203 model_->AddObserver(this); |
| 190 | 204 |
| 191 local_pref_registrar_.Init(g_browser_process->local_state()); | 205 local_pref_registrar_.Init(g_browser_process->local_state()); |
| 192 local_pref_registrar_.Add( | 206 local_pref_registrar_.Add( |
| 193 prefs::kTabStripStackedLayout, | 207 prefs::kTabStripStackedLayout, |
| 194 base::Bind(&BrowserTabStripController::UpdateStackedLayout, | 208 base::Bind(&BrowserTabStripController::UpdateStackedLayout, |
| 195 base::Unretained(this))); | 209 base::Unretained(this))); |
| 196 } | 210 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 bool stacked_layout = DetermineTabStripLayoutStacked( | 396 bool stacked_layout = DetermineTabStripLayoutStacked( |
| 383 g_browser_process->local_state(), &adjust_layout); | 397 g_browser_process->local_state(), &adjust_layout); |
| 384 if (!adjust_layout || stacked_layout == tabstrip_->stacked_layout()) | 398 if (!adjust_layout || stacked_layout == tabstrip_->stacked_layout()) |
| 385 return; | 399 return; |
| 386 | 400 |
| 387 g_browser_process->local_state()->SetBoolean(prefs::kTabStripStackedLayout, | 401 g_browser_process->local_state()->SetBoolean(prefs::kTabStripStackedLayout, |
| 388 tabstrip_->stacked_layout()); | 402 tabstrip_->stacked_layout()); |
| 389 } | 403 } |
| 390 | 404 |
| 391 void BrowserTabStripController::OnStartedDraggingTabs() { | 405 void BrowserTabStripController::OnStartedDraggingTabs() { |
| 392 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 406 if (browser_view_ && !immersive_reveal_lock_.get()) { |
|
sky
2017/01/03 23:11:41
browser_view_ should never be null, right?
edwardjung
2017/01/05 16:59:45
Done.
| |
| 393 if (browser_view && !immersive_reveal_lock_.get()) { | |
| 394 // The top-of-window views should be revealed while the user is dragging | 407 // The top-of-window views should be revealed while the user is dragging |
| 395 // tabs in immersive fullscreen. The top-of-window views may not be already | 408 // tabs in immersive fullscreen. The top-of-window views may not be already |
| 396 // revealed if the user is attempting to attach a tab to a tabstrip | 409 // revealed if the user is attempting to attach a tab to a tabstrip |
| 397 // belonging to an immersive fullscreen window. | 410 // belonging to an immersive fullscreen window. |
| 398 immersive_reveal_lock_.reset( | 411 immersive_reveal_lock_.reset( |
| 399 browser_view->immersive_mode_controller()->GetRevealedLock( | 412 browser_view_->immersive_mode_controller()->GetRevealedLock( |
| 400 ImmersiveModeController::ANIMATE_REVEAL_NO)); | 413 ImmersiveModeController::ANIMATE_REVEAL_NO)); |
| 401 } | 414 } |
| 402 } | 415 } |
| 403 | 416 |
| 404 void BrowserTabStripController::OnStoppedDraggingTabs() { | 417 void BrowserTabStripController::OnStoppedDraggingTabs() { |
| 405 immersive_reveal_lock_.reset(); | 418 immersive_reveal_lock_.reset(); |
| 406 } | 419 } |
| 407 | 420 |
| 408 void BrowserTabStripController::CheckFileSupported(const GURL& url) { | 421 void BrowserTabStripController::CheckFileSupported(const GURL& url) { |
| 409 base::PostTaskAndReplyWithResult( | 422 base::PostTaskAndReplyWithResult( |
| 410 content::BrowserThread::GetBlockingPool(), | 423 content::BrowserThread::GetBlockingPool(), |
| 411 FROM_HERE, | 424 FROM_HERE, |
| 412 base::Bind(&FindURLMimeType, url), | 425 base::Bind(&FindURLMimeType, url), |
| 413 base::Bind(&BrowserTabStripController::OnFindURLMimeTypeCompleted, | 426 base::Bind(&BrowserTabStripController::OnFindURLMimeTypeCompleted, |
| 414 weak_ptr_factory_.GetWeakPtr(), | 427 weak_ptr_factory_.GetWeakPtr(), |
| 415 url)); | 428 url)); |
| 416 } | 429 } |
| 417 | 430 |
| 418 SkColor BrowserTabStripController::GetToolbarTopSeparatorColor() const { | 431 SkColor BrowserTabStripController::GetToolbarTopSeparatorColor() const { |
| 419 return BrowserView::GetBrowserViewForBrowser(browser_)->frame() | 432 return browser_view_->frame()->GetFrameView()->GetToolbarTopSeparatorColor(); |
| 420 ->GetFrameView()->GetToolbarTopSeparatorColor(); | 433 } |
| 434 | |
| 435 base::string16 BrowserTabStripController::GetAccessibleTabName( | |
| 436 const Tab* tab) const { | |
| 437 return browser_view_->GetAccessibleTabLabel( | |
| 438 false /* include_app_name */, tabstrip_->GetModelIndexOfTab(tab)); | |
| 421 } | 439 } |
| 422 | 440 |
| 423 //////////////////////////////////////////////////////////////////////////////// | 441 //////////////////////////////////////////////////////////////////////////////// |
| 424 // BrowserTabStripController, TabStripModelObserver implementation: | 442 // BrowserTabStripController, TabStripModelObserver implementation: |
| 425 | 443 |
| 426 void BrowserTabStripController::TabInsertedAt(TabStripModel* tab_strip_model, | 444 void BrowserTabStripController::TabInsertedAt(TabStripModel* tab_strip_model, |
| 427 WebContents* contents, | 445 WebContents* contents, |
| 428 int model_index, | 446 int model_index, |
| 429 bool is_active) { | 447 bool is_active) { |
| 430 DCHECK(contents); | 448 DCHECK(contents); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 content::WebPluginInfo plugin; | 589 content::WebPluginInfo plugin; |
| 572 tabstrip_->FileSupported( | 590 tabstrip_->FileSupported( |
| 573 url, | 591 url, |
| 574 mime_type.empty() || mime_util::IsSupportedMimeType(mime_type) || | 592 mime_type.empty() || mime_util::IsSupportedMimeType(mime_type) || |
| 575 content::PluginService::GetInstance()->GetPluginInfo( | 593 content::PluginService::GetInstance()->GetPluginInfo( |
| 576 -1, // process ID | 594 -1, // process ID |
| 577 MSG_ROUTING_NONE, // routing ID | 595 MSG_ROUTING_NONE, // routing ID |
| 578 model_->profile()->GetResourceContext(), url, url::Origin(), | 596 model_->profile()->GetResourceContext(), url, url::Origin(), |
| 579 mime_type, false, NULL, &plugin, NULL)); | 597 mime_type, false, NULL, &plugin, NULL)); |
| 580 } | 598 } |
| OLD | NEW |