OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif // OS_WIN | 10 #endif // OS_WIN |
(...skipping 2445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2456 | 2456 |
2457 bool Browser::CanDuplicateContentsAt(int index) { | 2457 bool Browser::CanDuplicateContentsAt(int index) { |
2458 NavigationController& nc = GetTabContentsAt(index)->controller(); | 2458 NavigationController& nc = GetTabContentsAt(index)->controller(); |
2459 return nc.tab_contents() && nc.GetLastCommittedEntry(); | 2459 return nc.tab_contents() && nc.GetLastCommittedEntry(); |
2460 } | 2460 } |
2461 | 2461 |
2462 void Browser::DuplicateContentsAt(int index) { | 2462 void Browser::DuplicateContentsAt(int index) { |
2463 TabContentsWrapper* contents = GetTabContentsWrapperAt(index); | 2463 TabContentsWrapper* contents = GetTabContentsWrapperAt(index); |
2464 CHECK(contents); | 2464 CHECK(contents); |
2465 TabContentsWrapper* contents_dupe = contents->Clone(); | 2465 TabContentsWrapper* contents_dupe = contents->Clone(); |
2466 InsertContentsDupe(contents, contents_dupe); | 2466 TabContents* new_contents = contents_dupe->tab_contents(); |
| 2467 |
| 2468 bool pinned = false; |
| 2469 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
| 2470 // If this is a tabbed browser, just create a duplicate tab inside the same |
| 2471 // window next to the tab being duplicated. |
| 2472 int index = tab_handler_->GetTabStripModel()-> |
| 2473 GetIndexOfTabContents(contents); |
| 2474 pinned = tab_handler_->GetTabStripModel()->IsTabPinned(index); |
| 2475 int add_types = TabStripModel::ADD_SELECTED | |
| 2476 TabStripModel::ADD_INHERIT_GROUP | |
| 2477 (pinned ? TabStripModel::ADD_PINNED : 0); |
| 2478 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, |
| 2479 contents_dupe, |
| 2480 add_types); |
| 2481 } else { |
| 2482 Browser* browser = NULL; |
| 2483 if (type_ & TYPE_APP) { |
| 2484 CHECK((type_ & TYPE_POPUP) == 0); |
| 2485 CHECK(type_ != TYPE_APP_PANEL); |
| 2486 browser = Browser::CreateForApp(app_name_, gfx::Size(), profile_, |
| 2487 false); |
| 2488 } else if (type_ == TYPE_POPUP) { |
| 2489 browser = Browser::CreateForType(TYPE_POPUP, profile_); |
| 2490 } |
| 2491 |
| 2492 // Preserve the size of the original window. The new window has already |
| 2493 // been given an offset by the OS, so we shouldn't copy the old bounds. |
| 2494 BrowserWindow* new_window = browser->window(); |
| 2495 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
| 2496 window()->GetRestoredBounds().size())); |
| 2497 |
| 2498 // We need to show the browser now. Otherwise ContainerWin assumes the |
| 2499 // TabContents is invisible and won't size it. |
| 2500 browser->window()->Show(); |
| 2501 |
| 2502 // The page transition below is only for the purpose of inserting the tab. |
| 2503 browser->AddTab(contents_dupe, PageTransition::LINK); |
| 2504 } |
| 2505 |
| 2506 if (profile_->HasSessionService()) { |
| 2507 SessionService* session_service = profile_->GetSessionService(); |
| 2508 if (session_service) |
| 2509 session_service->TabRestored(&new_contents->controller(), pinned); |
| 2510 } |
2467 } | 2511 } |
2468 | 2512 |
2469 void Browser::CloseFrameAfterDragSession() { | 2513 void Browser::CloseFrameAfterDragSession() { |
2470 #if defined(OS_WIN) || defined(OS_LINUX) | 2514 #if defined(OS_WIN) || defined(OS_LINUX) |
2471 // This is scheduled to run after we return to the message loop because | 2515 // This is scheduled to run after we return to the message loop because |
2472 // otherwise the frame will think the drag session is still active and ignore | 2516 // otherwise the frame will think the drag session is still active and ignore |
2473 // the request. | 2517 // the request. |
2474 // TODO(port): figure out what is required here in a cross-platform world | 2518 // TODO(port): figure out what is required here in a cross-platform world |
2475 MessageLoop::current()->PostTask( | 2519 MessageLoop::current()->PostTask( |
2476 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame)); | 2520 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame)); |
(...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4170 // Do not restore scroller position. | 4214 // Do not restore scroller position. |
4171 std::string content_state = webkit_glue::RemoveScrollOffsetFromHistoryState( | 4215 std::string content_state = webkit_glue::RemoveScrollOffsetFromHistoryState( |
4172 active_entry->content_state()); | 4216 active_entry->content_state()); |
4173 active_entry->set_content_state(content_state); | 4217 active_entry->set_content_state(content_state); |
4174 | 4218 |
4175 GURL url = GURL(chrome::kViewSourceScheme + std::string(":") + | 4219 GURL url = GURL(chrome::kViewSourceScheme + std::string(":") + |
4176 active_entry->url().spec()); | 4220 active_entry->url().spec()); |
4177 active_entry->set_virtual_url(url); | 4221 active_entry->set_virtual_url(url); |
4178 // Do not restore title, derive it from the url. | 4222 // Do not restore title, derive it from the url. |
4179 active_entry->set_title(string16()); | 4223 active_entry->set_title(string16()); |
4180 InsertContentsDupe(contents, view_source_contents); | |
4181 } | |
4182 | 4224 |
4183 void Browser::InsertContentsDupe( | 4225 // Now show view-source entry. |
4184 TabContentsWrapper* contents, | |
4185 TabContentsWrapper* contents_dupe) { | |
4186 CHECK(contents); | |
4187 | |
4188 TabContents* new_contents = contents_dupe->tab_contents(); | |
4189 bool pinned = false; | |
4190 | 4226 |
4191 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { | 4227 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
4192 // If this is a tabbed browser, just create a duplicate tab inside the same | 4228 // If this is a tabbed browser, just create a duplicate tab inside the same |
4193 // window next to the tab being duplicated. | 4229 // window next to the tab being duplicated. |
4194 int index = tab_handler_->GetTabStripModel()-> | 4230 int index = tab_handler_->GetTabStripModel()-> |
4195 GetIndexOfTabContents(contents); | 4231 GetIndexOfTabContents(contents); |
4196 pinned = tab_handler_->GetTabStripModel()->IsTabPinned(index); | |
4197 int add_types = TabStripModel::ADD_SELECTED | | 4232 int add_types = TabStripModel::ADD_SELECTED | |
4198 TabStripModel::ADD_INHERIT_GROUP | | 4233 TabStripModel::ADD_INHERIT_GROUP; |
4199 (pinned ? TabStripModel::ADD_PINNED : 0); | |
4200 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, | 4234 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, |
4201 contents_dupe, | 4235 view_source_contents, |
4202 add_types); | 4236 add_types); |
4203 } else { | 4237 } else { |
4204 Browser* browser = NULL; | 4238 Browser* browser = Browser::CreateForType(TYPE_NORMAL, profile_); |
4205 if (type_ & TYPE_APP) { | |
4206 CHECK((type_ & TYPE_POPUP) == 0); | |
4207 CHECK(type_ != TYPE_APP_PANEL); | |
4208 browser = Browser::CreateForApp(app_name_, gfx::Size(), profile_, | |
4209 false); | |
4210 } else if (type_ == TYPE_POPUP) { | |
4211 browser = Browser::CreateForType(TYPE_POPUP, profile_); | |
4212 } | |
4213 | 4239 |
4214 // Preserve the size of the original window. The new window has already | 4240 // Preserve the size of the original window. The new window has already |
4215 // been given an offset by the OS, so we shouldn't copy the old bounds. | 4241 // been given an offset by the OS, so we shouldn't copy the old bounds. |
4216 BrowserWindow* new_window = browser->window(); | 4242 BrowserWindow* new_window = browser->window(); |
4217 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), | 4243 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
4218 window()->GetRestoredBounds().size())); | 4244 window()->GetRestoredBounds().size())); |
4219 | 4245 |
4220 // We need to show the browser now. Otherwise ContainerWin assumes the | 4246 // We need to show the browser now. Otherwise ContainerWin assumes the |
4221 // TabContents is invisible and won't size it. | 4247 // TabContents is invisible and won't size it. |
4222 browser->window()->Show(); | 4248 browser->window()->Show(); |
4223 | 4249 |
4224 // The page transition below is only for the purpose of inserting the tab. | 4250 // The page transition below is only for the purpose of inserting the tab. |
4225 browser->AddTab(contents_dupe, PageTransition::LINK); | 4251 browser->AddTab(view_source_contents, PageTransition::LINK); |
4226 } | 4252 } |
4227 | 4253 |
4228 if (profile_->HasSessionService()) { | 4254 if (profile_->HasSessionService()) { |
4229 SessionService* session_service = profile_->GetSessionService(); | 4255 SessionService* session_service = profile_->GetSessionService(); |
4230 if (session_service) | 4256 if (session_service) |
4231 session_service->TabRestored(&new_contents->controller(), pinned); | 4257 session_service->TabRestored(&view_source_contents->controller(), false); |
4232 } | 4258 } |
4233 } | 4259 } |
OLD | NEW |