| 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" |
| 11 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 12 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 13 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete_match.h" | 14 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 13 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/extensions/tab_helper.h" | 17 #include "chrome/browser/extensions/tab_helper.h" |
| 16 #include "chrome/browser/favicon/favicon_tab_helper.h" | 18 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/search/search.h" | 20 #include "chrome/browser/search/search.h" |
| 19 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_tabstrip.h" | 22 #include "chrome/browser/ui/browser_tabstrip.h" |
| 21 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 23 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" |
| 24 #include "chrome/browser/ui/tabs/tab_utils.h" | 26 #include "chrome/browser/ui/tabs/tab_utils.h" |
| 25 #include "chrome/browser/ui/views/frame/browser_view.h" | 27 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 26 #include "chrome/browser/ui/views/tabs/tab.h" | 28 #include "chrome/browser/ui/views/tabs/tab.h" |
| 27 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | 29 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
| 28 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 30 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 29 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 34 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 36 #include "content/public/browser/plugin_service.h" |
| 33 #include "content/public/browser/user_metrics.h" | 37 #include "content/public/browser/user_metrics.h" |
| 34 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
| 39 #include "content/public/common/webplugininfo.h" |
| 40 #include "ipc/ipc_message.h" |
| 41 #include "net/base/net_util.h" |
| 35 #include "ui/base/layout.h" | 42 #include "ui/base/layout.h" |
| 36 #include "ui/base/models/list_selection_model.h" | 43 #include "ui/base/models/list_selection_model.h" |
| 37 #include "ui/gfx/image/image.h" | 44 #include "ui/gfx/image/image.h" |
| 38 #include "ui/views/controls/menu/menu_item_view.h" | 45 #include "ui/views/controls/menu/menu_item_view.h" |
| 39 #include "ui/views/controls/menu/menu_runner.h" | 46 #include "ui/views/controls/menu/menu_runner.h" |
| 40 #include "ui/views/widget/widget.h" | 47 #include "ui/views/widget/widget.h" |
| 41 | 48 |
| 42 using content::UserMetricsAction; | 49 using content::UserMetricsAction; |
| 43 using content::WebContents; | 50 using content::WebContents; |
| 44 | 51 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 72 #endif | 79 #endif |
| 73 *adjust_layout = true; | 80 *adjust_layout = true; |
| 74 switch (prefs->GetInteger(prefs::kTabStripLayoutType)) { | 81 switch (prefs->GetInteger(prefs::kTabStripLayoutType)) { |
| 75 case TAB_STRIP_LAYOUT_STACKED: | 82 case TAB_STRIP_LAYOUT_STACKED: |
| 76 return TAB_STRIP_LAYOUT_STACKED; | 83 return TAB_STRIP_LAYOUT_STACKED; |
| 77 default: | 84 default: |
| 78 return TAB_STRIP_LAYOUT_SHRINK; | 85 return TAB_STRIP_LAYOUT_SHRINK; |
| 79 } | 86 } |
| 80 } | 87 } |
| 81 | 88 |
| 89 // Get the MIME type of the file pointed to by the url, based on the file's |
| 90 // extension. Must be called on a thread that allows IO. |
| 91 std::string FindURLMimeType(const GURL& url) { |
| 92 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 93 base::FilePath full_path; |
| 94 net::FileURLToFilePath(url, &full_path); |
| 95 |
| 96 // Get the MIME type based on the filename. |
| 97 std::string mime_type; |
| 98 net::GetMimeTypeFromFile(full_path, &mime_type); |
| 99 |
| 100 return mime_type; |
| 101 } |
| 102 |
| 82 } // namespace | 103 } // namespace |
| 83 | 104 |
| 84 class BrowserTabStripController::TabContextMenuContents | 105 class BrowserTabStripController::TabContextMenuContents |
| 85 : public ui::SimpleMenuModel::Delegate { | 106 : public ui::SimpleMenuModel::Delegate { |
| 86 public: | 107 public: |
| 87 TabContextMenuContents(Tab* tab, | 108 TabContextMenuContents(Tab* tab, |
| 88 BrowserTabStripController* controller) | 109 BrowserTabStripController* controller) |
| 89 : tab_(tab), | 110 : tab_(tab), |
| 90 controller_(controller), | 111 controller_(controller), |
| 91 last_command_(TabStripModel::CommandFirst) { | 112 last_command_(TabStripModel::CommandFirst) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 }; | 191 }; |
| 171 | 192 |
| 172 //////////////////////////////////////////////////////////////////////////////// | 193 //////////////////////////////////////////////////////////////////////////////// |
| 173 // BrowserTabStripController, public: | 194 // BrowserTabStripController, public: |
| 174 | 195 |
| 175 BrowserTabStripController::BrowserTabStripController(Browser* browser, | 196 BrowserTabStripController::BrowserTabStripController(Browser* browser, |
| 176 TabStripModel* model) | 197 TabStripModel* model) |
| 177 : model_(model), | 198 : model_(model), |
| 178 tabstrip_(NULL), | 199 tabstrip_(NULL), |
| 179 browser_(browser), | 200 browser_(browser), |
| 180 hover_tab_selector_(model) { | 201 hover_tab_selector_(model), |
| 202 weak_ptr_factory_(this) { |
| 181 model_->AddObserver(this); | 203 model_->AddObserver(this); |
| 182 | 204 |
| 183 local_pref_registrar_.Init(g_browser_process->local_state()); | 205 local_pref_registrar_.Init(g_browser_process->local_state()); |
| 184 local_pref_registrar_.Add( | 206 local_pref_registrar_.Add( |
| 185 prefs::kTabStripLayoutType, | 207 prefs::kTabStripLayoutType, |
| 186 base::Bind(&BrowserTabStripController::UpdateLayoutType, | 208 base::Bind(&BrowserTabStripController::UpdateLayoutType, |
| 187 base::Unretained(this))); | 209 base::Unretained(this))); |
| 188 } | 210 } |
| 189 | 211 |
| 190 BrowserTabStripController::~BrowserTabStripController() { | 212 BrowserTabStripController::~BrowserTabStripController() { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 immersive_reveal_lock_.reset( | 416 immersive_reveal_lock_.reset( |
| 395 browser_view->immersive_mode_controller()->GetRevealedLock( | 417 browser_view->immersive_mode_controller()->GetRevealedLock( |
| 396 ImmersiveModeController::ANIMATE_REVEAL_NO)); | 418 ImmersiveModeController::ANIMATE_REVEAL_NO)); |
| 397 } | 419 } |
| 398 } | 420 } |
| 399 | 421 |
| 400 void BrowserTabStripController::OnStoppedDraggingTabs() { | 422 void BrowserTabStripController::OnStoppedDraggingTabs() { |
| 401 immersive_reveal_lock_.reset(); | 423 immersive_reveal_lock_.reset(); |
| 402 } | 424 } |
| 403 | 425 |
| 426 void BrowserTabStripController::CheckFileSupported(const GURL& url) { |
| 427 base::PostTaskAndReplyWithResult( |
| 428 content::BrowserThread::GetBlockingPool(), |
| 429 FROM_HERE, |
| 430 base::Bind(&FindURLMimeType, url), |
| 431 base::Bind(&BrowserTabStripController::OnFindURLMimeTypeCompleted, |
| 432 weak_ptr_factory_.GetWeakPtr(), |
| 433 url)); |
| 434 } |
| 435 |
| 404 //////////////////////////////////////////////////////////////////////////////// | 436 //////////////////////////////////////////////////////////////////////////////// |
| 405 // BrowserTabStripController, TabStripModelObserver implementation: | 437 // BrowserTabStripController, TabStripModelObserver implementation: |
| 406 | 438 |
| 407 void BrowserTabStripController::TabInsertedAt(WebContents* contents, | 439 void BrowserTabStripController::TabInsertedAt(WebContents* contents, |
| 408 int model_index, | 440 int model_index, |
| 409 bool is_active) { | 441 bool is_active) { |
| 410 DCHECK(contents); | 442 DCHECK(contents); |
| 411 DCHECK(model_->ContainsIndex(model_index)); | 443 DCHECK(model_->ContainsIndex(model_index)); |
| 412 AddTab(contents, model_index, is_active); | 444 AddTab(contents, model_index, is_active); |
| 413 } | 445 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 tabstrip_->AddTabAt(index, data, is_active); | 571 tabstrip_->AddTabAt(index, data, is_active); |
| 540 } | 572 } |
| 541 | 573 |
| 542 void BrowserTabStripController::UpdateLayoutType() { | 574 void BrowserTabStripController::UpdateLayoutType() { |
| 543 bool adjust_layout = false; | 575 bool adjust_layout = false; |
| 544 TabStripLayoutType layout_type = | 576 TabStripLayoutType layout_type = |
| 545 DetermineTabStripLayout(g_browser_process->local_state(), | 577 DetermineTabStripLayout(g_browser_process->local_state(), |
| 546 browser_->host_desktop_type(), &adjust_layout); | 578 browser_->host_desktop_type(), &adjust_layout); |
| 547 tabstrip_->SetLayoutType(layout_type, adjust_layout); | 579 tabstrip_->SetLayoutType(layout_type, adjust_layout); |
| 548 } | 580 } |
| 581 |
| 582 void BrowserTabStripController::OnFindURLMimeTypeCompleted( |
| 583 const GURL& url, |
| 584 const std::string& mime_type) { |
| 585 // Check whether the mime type, if given, is known to be supported or whether |
| 586 // there is a plugin that supports the mime type (e.g. PDF). |
| 587 // TODO(bauerb): This possibly uses stale information, but it's guaranteed not |
| 588 // to do disk access. |
| 589 content::WebPluginInfo plugin; |
| 590 tabstrip_->FileSupported( |
| 591 url, |
| 592 mime_type.empty() || |
| 593 net::IsSupportedMimeType(mime_type) || |
| 594 content::PluginService::GetInstance()->GetPluginInfo( |
| 595 -1, // process ID |
| 596 MSG_ROUTING_NONE, // routing ID |
| 597 model_->profile()->GetResourceContext(), |
| 598 url, GURL(), mime_type, false, |
| 599 NULL, &plugin, NULL)); |
| 600 } |
| OLD | NEW |