Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / browser_tab_strip_model_delegate.cc
blob3fcd43844e69e35756ac84a27bd84ac88c17f727
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/browser_tab_strip_model_delegate.h"
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sessions/tab_restore_service.h"
12 #include "chrome/browser/sessions/tab_restore_service_factory.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/browser_navigator.h"
16 #include "chrome/browser/ui/browser_tabstrip.h"
17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/fast_unload_controller.h"
19 #include "chrome/browser/ui/tab_helpers.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/browser/ui/unload_controller.h"
22 #include "chrome/common/chrome_switches.h"
23 #include "content/public/browser/site_instance.h"
24 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_contents_delegate.h"
26 #include "ipc/ipc_message.h"
28 namespace chrome {
30 ////////////////////////////////////////////////////////////////////////////////
31 // BrowserTabStripModelDelegate, public:
33 BrowserTabStripModelDelegate::BrowserTabStripModelDelegate(Browser* browser)
34 : browser_(browser),
35 weak_factory_(this) {
38 BrowserTabStripModelDelegate::~BrowserTabStripModelDelegate() {
41 ////////////////////////////////////////////////////////////////////////////////
42 // BrowserTabStripModelDelegate, TabStripModelDelegate implementation:
44 void BrowserTabStripModelDelegate::AddTabAt(const GURL& url,
45 int index,
46 bool foreground) {
47 chrome::AddTabAt(browser_, url, index, foreground);
50 Browser* BrowserTabStripModelDelegate::CreateNewStripWithContents(
51 const std::vector<NewStripContents>& contentses,
52 const gfx::Rect& window_bounds,
53 bool maximize) {
54 DCHECK(browser_->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP));
56 // Create an empty new browser window the same size as the old one.
57 Browser::CreateParams params(browser_->profile(),
58 browser_->host_desktop_type());
59 params.initial_bounds = window_bounds;
60 params.initial_show_state =
61 maximize ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_NORMAL;
62 Browser* browser = new Browser(params);
63 TabStripModel* new_model = browser->tab_strip_model();
65 for (size_t i = 0; i < contentses.size(); ++i) {
66 NewStripContents item = contentses[i];
68 // Enforce that there is an active tab in the strip at all times by forcing
69 // the first web contents to be marked as active.
70 if (i == 0)
71 item.add_types |= TabStripModel::ADD_ACTIVE;
73 new_model->InsertWebContentsAt(
74 static_cast<int>(i), item.web_contents, item.add_types);
75 // Make sure the loading state is updated correctly, otherwise the throbber
76 // won't start if the page is loading.
77 // TODO(beng): find a better way of doing this.
78 static_cast<content::WebContentsDelegate*>(browser)->
79 LoadingStateChanged(item.web_contents, true);
82 return browser;
85 void BrowserTabStripModelDelegate::WillAddWebContents(
86 content::WebContents* contents) {
87 TabHelpers::AttachTabHelpers(contents);
90 int BrowserTabStripModelDelegate::GetDragActions() const {
91 return TabStripModelDelegate::TAB_TEAROFF_ACTION |
92 (browser_->tab_strip_model()->count() > 1
93 ? TabStripModelDelegate::TAB_MOVE_ACTION : 0);
96 bool BrowserTabStripModelDelegate::CanDuplicateContentsAt(int index) {
97 return CanDuplicateTabAt(browser_, index);
100 void BrowserTabStripModelDelegate::DuplicateContentsAt(int index) {
101 DuplicateTabAt(browser_, index);
104 void BrowserTabStripModelDelegate::CreateHistoricalTab(
105 content::WebContents* contents) {
106 // We don't create historical tabs for incognito windows or windows without
107 // profiles.
108 if (!browser_->profile() || browser_->profile()->IsOffTheRecord())
109 return;
111 TabRestoreService* service =
112 TabRestoreServiceFactory::GetForProfile(browser_->profile());
114 // We only create historical tab entries for tabbed browser windows.
115 if (service && browser_->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) {
116 service->CreateHistoricalTab(
117 contents,
118 browser_->tab_strip_model()->GetIndexOfWebContents(contents));
122 bool BrowserTabStripModelDelegate::RunUnloadListenerBeforeClosing(
123 content::WebContents* contents) {
124 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
125 switches::kEnableFastUnload)) {
126 return chrome::FastUnloadController::RunUnloadEventsHelper(contents);
128 return chrome::UnloadController::RunUnloadEventsHelper(contents);
131 bool BrowserTabStripModelDelegate::ShouldRunUnloadListenerBeforeClosing(
132 content::WebContents* contents) {
133 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
134 switches::kEnableFastUnload)) {
135 return chrome::FastUnloadController::ShouldRunUnloadEventsHelper(contents);
137 return chrome::UnloadController::ShouldRunUnloadEventsHelper(contents);
140 bool BrowserTabStripModelDelegate::CanBookmarkAllTabs() const {
141 return chrome::CanBookmarkAllTabs(browser_);
144 void BrowserTabStripModelDelegate::BookmarkAllTabs() {
145 chrome::BookmarkAllTabs(browser_);
148 TabStripModelDelegate::RestoreTabType
149 BrowserTabStripModelDelegate::GetRestoreTabType() {
150 return chrome::GetRestoreTabType(browser_);
153 void BrowserTabStripModelDelegate::RestoreTab() {
154 chrome::RestoreTab(browser_);
157 ////////////////////////////////////////////////////////////////////////////////
158 // BrowserTabStripModelDelegate, private:
160 void BrowserTabStripModelDelegate::CloseFrame() {
161 browser_->window()->Close();
164 } // namespace chrome