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" |
11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/extensions/tab_helper.h" | 14 #include "chrome/browser/extensions/tab_helper.h" |
15 #include "chrome/browser/favicon/favicon_utils.h" | 15 #include "chrome/browser/favicon/favicon_utils.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/search/search.h" | 17 #include "chrome/browser/search/search.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_navigator_params.h" | 19 #include "chrome/browser/ui/browser_navigator_params.h" |
20 #include "chrome/browser/ui/browser_tabstrip.h" | 20 #include "chrome/browser/ui/browser_tabstrip.h" |
21 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 21 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" |
24 #include "chrome/browser/ui/tabs/tab_utils.h" | 24 #include "chrome/browser/ui/tabs/tab_utils.h" |
25 #include "chrome/browser/ui/views/frame/browser_view.h" | |
26 #include "chrome/browser/ui/views/tabs/tab.h" | 25 #include "chrome/browser/ui/views/tabs/tab.h" |
27 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | 26 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
28 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 27 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
29 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
30 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
31 #include "components/metrics/proto/omnibox_event.pb.h" | 30 #include "components/metrics/proto/omnibox_event.pb.h" |
32 #include "components/mime_util/mime_util.h" | 31 #include "components/mime_util/mime_util.h" |
33 #include "components/omnibox/browser/autocomplete_classifier.h" | 32 #include "components/omnibox/browser/autocomplete_classifier.h" |
34 #include "components/omnibox/browser/autocomplete_match.h" | 33 #include "components/omnibox/browser/autocomplete_match.h" |
35 #include "components/prefs/pref_service.h" | 34 #include "components/prefs/pref_service.h" |
36 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/navigation_controller.h" |
| 37 #include "content/public/browser/navigation_entry.h" |
| 38 #include "content/public/browser/navigation_handle.h" |
37 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
38 #include "content/public/browser/plugin_service.h" | 40 #include "content/public/browser/plugin_service.h" |
39 #include "content/public/browser/user_metrics.h" | 41 #include "content/public/browser/user_metrics.h" |
40 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
41 #include "content/public/common/webplugininfo.h" | 43 #include "content/public/common/webplugininfo.h" |
42 #include "ipc/ipc_message.h" | 44 #include "ipc/ipc_message.h" |
43 #include "net/base/filename_util.h" | 45 #include "net/base/filename_util.h" |
44 #include "ui/base/models/list_selection_model.h" | 46 #include "ui/base/models/list_selection_model.h" |
45 #include "ui/gfx/image/image.h" | 47 #include "ui/gfx/image/image.h" |
46 #include "ui/views/controls/menu/menu_runner.h" | 48 #include "ui/views/controls/menu/menu_runner.h" |
47 #include "ui/views/widget/widget.h" | 49 #include "ui/views/widget/widget.h" |
48 #include "url/origin.h" | 50 #include "url/origin.h" |
49 | 51 |
50 using base::UserMetricsAction; | 52 using base::UserMetricsAction; |
51 using content::WebContents; | 53 using content::WebContents; |
52 | 54 |
53 namespace { | 55 namespace { |
54 | 56 |
55 TabRendererData::NetworkState TabContentsNetworkState( | 57 TabRendererData::NetworkState TabContentsNetworkState( |
56 WebContents* contents) { | 58 WebContents* contents) { |
57 if (!contents || !contents->IsLoadingToDifferentDocument()) | 59 if (!contents) |
58 return TabRendererData::NETWORK_STATE_NONE; | 60 return TabRendererData::NETWORK_STATE_NONE; |
| 61 |
| 62 if (!contents->IsLoadingToDifferentDocument()) { |
| 63 content::NavigationEntry* entry = |
| 64 contents->GetController().GetLastCommittedEntry(); |
| 65 if (entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR)) |
| 66 return TabRendererData::NETWORK_STATE_ERROR; |
| 67 return TabRendererData::NETWORK_STATE_NONE; |
| 68 } |
| 69 |
59 if (contents->IsWaitingForResponse()) | 70 if (contents->IsWaitingForResponse()) |
60 return TabRendererData::NETWORK_STATE_WAITING; | 71 return TabRendererData::NETWORK_STATE_WAITING; |
61 return TabRendererData::NETWORK_STATE_LOADING; | 72 return TabRendererData::NETWORK_STATE_LOADING; |
62 } | 73 } |
63 | 74 |
64 bool DetermineTabStripLayoutStacked(PrefService* prefs, bool* adjust_layout) { | 75 bool DetermineTabStripLayoutStacked(PrefService* prefs, bool* adjust_layout) { |
65 *adjust_layout = false; | 76 *adjust_layout = false; |
66 // For ash, always allow entering stacked mode. | 77 // For ash, always allow entering stacked mode. |
67 #if defined(USE_ASH) | 78 #if defined(USE_ASH) |
68 *adjust_layout = true; | 79 *adjust_layout = true; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // The last command that was selected, so that we can start/stop highlighting | 183 // The last command that was selected, so that we can start/stop highlighting |
173 // appropriately as the user moves through the menu. | 184 // appropriately as the user moves through the menu. |
174 TabStripModel::ContextMenuCommand last_command_; | 185 TabStripModel::ContextMenuCommand last_command_; |
175 | 186 |
176 DISALLOW_COPY_AND_ASSIGN(TabContextMenuContents); | 187 DISALLOW_COPY_AND_ASSIGN(TabContextMenuContents); |
177 }; | 188 }; |
178 | 189 |
179 //////////////////////////////////////////////////////////////////////////////// | 190 //////////////////////////////////////////////////////////////////////////////// |
180 // BrowserTabStripController, public: | 191 // BrowserTabStripController, public: |
181 | 192 |
182 BrowserTabStripController::BrowserTabStripController(Browser* browser, | 193 BrowserTabStripController::BrowserTabStripController(TabStripModel* model, |
183 TabStripModel* model) | 194 BrowserView* browser_view) |
184 : model_(model), | 195 : model_(model), |
185 tabstrip_(NULL), | 196 tabstrip_(NULL), |
186 browser_(browser), | 197 browser_view_(browser_view), |
187 hover_tab_selector_(model), | 198 hover_tab_selector_(model), |
188 weak_ptr_factory_(this) { | 199 weak_ptr_factory_(this) { |
189 model_->AddObserver(this); | 200 model_->AddObserver(this); |
190 | 201 |
191 local_pref_registrar_.Init(g_browser_process->local_state()); | 202 local_pref_registrar_.Init(g_browser_process->local_state()); |
192 local_pref_registrar_.Add( | 203 local_pref_registrar_.Add( |
193 prefs::kTabStripStackedLayout, | 204 prefs::kTabStripStackedLayout, |
194 base::Bind(&BrowserTabStripController::UpdateStackedLayout, | 205 base::Bind(&BrowserTabStripController::UpdateStackedLayout, |
195 base::Unretained(this))); | 206 base::Unretained(this))); |
196 } | 207 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 if (index != -1 && !drop_before) { | 341 if (index != -1 && !drop_before) { |
331 hover_tab_selector_.StartTabTransition(index); | 342 hover_tab_selector_.StartTabTransition(index); |
332 } else { | 343 } else { |
333 hover_tab_selector_.CancelTabTransition(); | 344 hover_tab_selector_.CancelTabTransition(); |
334 } | 345 } |
335 } | 346 } |
336 | 347 |
337 void BrowserTabStripController::PerformDrop(bool drop_before, | 348 void BrowserTabStripController::PerformDrop(bool drop_before, |
338 int index, | 349 int index, |
339 const GURL& url) { | 350 const GURL& url) { |
340 chrome::NavigateParams params(browser_, url, ui::PAGE_TRANSITION_LINK); | 351 chrome::NavigateParams params(browser_view_->browser(), url, |
| 352 ui::PAGE_TRANSITION_LINK); |
341 params.tabstrip_index = index; | 353 params.tabstrip_index = index; |
342 | 354 |
343 if (drop_before) { | 355 if (drop_before) { |
344 content::RecordAction(UserMetricsAction("Tab_DropURLBetweenTabs")); | 356 content::RecordAction(UserMetricsAction("Tab_DropURLBetweenTabs")); |
345 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; | 357 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
346 } else { | 358 } else { |
347 content::RecordAction(UserMetricsAction("Tab_DropURLOnTab")); | 359 content::RecordAction(UserMetricsAction("Tab_DropURLOnTab")); |
348 params.disposition = WindowOpenDisposition::CURRENT_TAB; | 360 params.disposition = WindowOpenDisposition::CURRENT_TAB; |
349 params.source_contents = model_->GetWebContentsAt(index); | 361 params.source_contents = model_->GetWebContentsAt(index); |
350 } | 362 } |
(...skipping 16 matching lines...) Expand all Loading... |
367 // Use autocomplete to clean up the text, going so far as to turn it into | 379 // Use autocomplete to clean up the text, going so far as to turn it into |
368 // a search query if necessary. | 380 // a search query if necessary. |
369 AutocompleteMatch match; | 381 AutocompleteMatch match; |
370 AutocompleteClassifierFactory::GetForProfile(profile())->Classify( | 382 AutocompleteClassifierFactory::GetForProfile(profile())->Classify( |
371 location, false, false, metrics::OmniboxEventProto::BLANK, &match, NULL); | 383 location, false, false, metrics::OmniboxEventProto::BLANK, &match, NULL); |
372 if (match.destination_url.is_valid()) | 384 if (match.destination_url.is_valid()) |
373 model_->delegate()->AddTabAt(match.destination_url, -1, true); | 385 model_->delegate()->AddTabAt(match.destination_url, -1, true); |
374 } | 386 } |
375 | 387 |
376 bool BrowserTabStripController::IsIncognito() { | 388 bool BrowserTabStripController::IsIncognito() { |
377 return browser_->profile()->GetProfileType() == Profile::INCOGNITO_PROFILE; | 389 return browser_view_->browser()->profile()->GetProfileType() == |
| 390 Profile::INCOGNITO_PROFILE; |
378 } | 391 } |
379 | 392 |
380 void BrowserTabStripController::StackedLayoutMaybeChanged() { | 393 void BrowserTabStripController::StackedLayoutMaybeChanged() { |
381 bool adjust_layout = false; | 394 bool adjust_layout = false; |
382 bool stacked_layout = DetermineTabStripLayoutStacked( | 395 bool stacked_layout = DetermineTabStripLayoutStacked( |
383 g_browser_process->local_state(), &adjust_layout); | 396 g_browser_process->local_state(), &adjust_layout); |
384 if (!adjust_layout || stacked_layout == tabstrip_->stacked_layout()) | 397 if (!adjust_layout || stacked_layout == tabstrip_->stacked_layout()) |
385 return; | 398 return; |
386 | 399 |
387 g_browser_process->local_state()->SetBoolean(prefs::kTabStripStackedLayout, | 400 g_browser_process->local_state()->SetBoolean(prefs::kTabStripStackedLayout, |
388 tabstrip_->stacked_layout()); | 401 tabstrip_->stacked_layout()); |
389 } | 402 } |
390 | 403 |
391 void BrowserTabStripController::OnStartedDraggingTabs() { | 404 void BrowserTabStripController::OnStartedDraggingTabs() { |
392 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 405 if (!immersive_reveal_lock_.get()) { |
393 if (browser_view && !immersive_reveal_lock_.get()) { | |
394 // The top-of-window views should be revealed while the user is dragging | 406 // 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 | 407 // 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 | 408 // revealed if the user is attempting to attach a tab to a tabstrip |
397 // belonging to an immersive fullscreen window. | 409 // belonging to an immersive fullscreen window. |
398 immersive_reveal_lock_.reset( | 410 immersive_reveal_lock_.reset( |
399 browser_view->immersive_mode_controller()->GetRevealedLock( | 411 browser_view_->immersive_mode_controller()->GetRevealedLock( |
400 ImmersiveModeController::ANIMATE_REVEAL_NO)); | 412 ImmersiveModeController::ANIMATE_REVEAL_NO)); |
401 } | 413 } |
402 } | 414 } |
403 | 415 |
404 void BrowserTabStripController::OnStoppedDraggingTabs() { | 416 void BrowserTabStripController::OnStoppedDraggingTabs() { |
405 immersive_reveal_lock_.reset(); | 417 immersive_reveal_lock_.reset(); |
406 } | 418 } |
407 | 419 |
408 void BrowserTabStripController::CheckFileSupported(const GURL& url) { | 420 void BrowserTabStripController::CheckFileSupported(const GURL& url) { |
409 base::PostTaskAndReplyWithResult( | 421 base::PostTaskAndReplyWithResult( |
410 content::BrowserThread::GetBlockingPool(), | 422 content::BrowserThread::GetBlockingPool(), |
411 FROM_HERE, | 423 FROM_HERE, |
412 base::Bind(&FindURLMimeType, url), | 424 base::Bind(&FindURLMimeType, url), |
413 base::Bind(&BrowserTabStripController::OnFindURLMimeTypeCompleted, | 425 base::Bind(&BrowserTabStripController::OnFindURLMimeTypeCompleted, |
414 weak_ptr_factory_.GetWeakPtr(), | 426 weak_ptr_factory_.GetWeakPtr(), |
415 url)); | 427 url)); |
416 } | 428 } |
417 | 429 |
418 SkColor BrowserTabStripController::GetToolbarTopSeparatorColor() const { | 430 SkColor BrowserTabStripController::GetToolbarTopSeparatorColor() const { |
419 return BrowserView::GetBrowserViewForBrowser(browser_)->frame() | 431 return browser_view_->frame()->GetFrameView()->GetToolbarTopSeparatorColor(); |
420 ->GetFrameView()->GetToolbarTopSeparatorColor(); | 432 } |
| 433 |
| 434 base::string16 BrowserTabStripController::GetAccessibleTabName( |
| 435 const Tab* tab) const { |
| 436 return browser_view_->GetAccessibleTabLabel( |
| 437 false /* include_app_name */, tabstrip_->GetModelIndexOfTab(tab)); |
421 } | 438 } |
422 | 439 |
423 //////////////////////////////////////////////////////////////////////////////// | 440 //////////////////////////////////////////////////////////////////////////////// |
424 // BrowserTabStripController, TabStripModelObserver implementation: | 441 // BrowserTabStripController, TabStripModelObserver implementation: |
425 | 442 |
426 void BrowserTabStripController::TabInsertedAt(TabStripModel* tab_strip_model, | 443 void BrowserTabStripController::TabInsertedAt(TabStripModel* tab_strip_model, |
427 WebContents* contents, | 444 WebContents* contents, |
428 int model_index, | 445 int model_index, |
429 bool is_active) { | 446 bool is_active) { |
430 DCHECK(contents); | 447 DCHECK(contents); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 content::WebPluginInfo plugin; | 588 content::WebPluginInfo plugin; |
572 tabstrip_->FileSupported( | 589 tabstrip_->FileSupported( |
573 url, | 590 url, |
574 mime_type.empty() || mime_util::IsSupportedMimeType(mime_type) || | 591 mime_type.empty() || mime_util::IsSupportedMimeType(mime_type) || |
575 content::PluginService::GetInstance()->GetPluginInfo( | 592 content::PluginService::GetInstance()->GetPluginInfo( |
576 -1, // process ID | 593 -1, // process ID |
577 MSG_ROUTING_NONE, // routing ID | 594 MSG_ROUTING_NONE, // routing ID |
578 model_->profile()->GetResourceContext(), url, url::Origin(), | 595 model_->profile()->GetResourceContext(), url, url::Origin(), |
579 mime_type, false, NULL, &plugin, NULL)); | 596 mime_type, false, NULL, &plugin, NULL)); |
580 } | 597 } |
OLD | NEW |