Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 5716003: View source after POST command isn't what you expected. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added navigation controller test. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« chrome/browser/ui/browser.h ('K') | « chrome/browser/ui/browser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 } 1520 }
1521 1521
1522 void Browser::SavePage() { 1522 void Browser::SavePage() {
1523 UserMetrics::RecordAction(UserMetricsAction("SavePage"), profile_); 1523 UserMetrics::RecordAction(UserMetricsAction("SavePage"), profile_);
1524 TabContents* current_tab = GetSelectedTabContents(); 1524 TabContents* current_tab = GetSelectedTabContents();
1525 if (current_tab && current_tab->contents_mime_type() == "application/pdf") 1525 if (current_tab && current_tab->contents_mime_type() == "application/pdf")
1526 UserMetrics::RecordAction(UserMetricsAction("PDF.SavePage"), profile_); 1526 UserMetrics::RecordAction(UserMetricsAction("PDF.SavePage"), profile_);
1527 GetSelectedTabContents()->OnSavePage(); 1527 GetSelectedTabContents()->OnSavePage();
1528 } 1528 }
1529 1529
1530 void Browser::ViewSource() { 1530 void Browser::ViewSelectedSource() {
1531 ViewSource(GetSelectedTabContentsWrapper());
1532 }
1533
1534 void Browser::ViewSource(TabContentsWrapper* contents) {
1531 UserMetrics::RecordAction(UserMetricsAction("ViewSource"), profile_); 1535 UserMetrics::RecordAction(UserMetricsAction("ViewSource"), profile_);
1536 DCHECK(contents);
1532 1537
1533 TabContents* current_tab = GetSelectedTabContents(); 1538 TabContentsWrapper* view_source_contents = contents->Clone();
1534 NavigationEntry* entry = current_tab->controller().GetLastCommittedEntry(); 1539 view_source_contents->controller().PruneAllButActive();
1535 if (entry) { 1540 NavigationEntry* active_entry =
1536 OpenURL(GURL(chrome::kViewSourceScheme + std::string(":") + 1541 view_source_contents->controller().GetActiveEntry();
1537 entry->url().spec()), GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); 1542 GURL url = GURL(chrome::kViewSourceScheme + std::string(":") +
1538 } 1543 active_entry->url().spec());
1544 active_entry->set_virtual_url(url);
1545 InsertContentsDupe(contents, view_source_contents);
1539 } 1546 }
1540 1547
1541 void Browser::ShowFindBar() { 1548 void Browser::ShowFindBar() {
1542 GetFindBarController()->Show(); 1549 GetFindBarController()->Show();
1543 } 1550 }
1544 1551
1545 bool Browser::SupportsWindowFeature(WindowFeature feature) const { 1552 bool Browser::SupportsWindowFeature(WindowFeature feature) const {
1546 return SupportsWindowFeatureImpl(feature, true); 1553 return SupportsWindowFeatureImpl(feature, true);
1547 } 1554 }
1548 1555
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
2146 case IDC_TOGGLE_VERTICAL_TABS: ToggleUseVerticalTabs(); break; 2153 case IDC_TOGGLE_VERTICAL_TABS: ToggleUseVerticalTabs(); break;
2147 #if defined(OS_CHROMEOS) 2154 #if defined(OS_CHROMEOS)
2148 case IDC_SEARCH: Search(); break; 2155 case IDC_SEARCH: Search(); break;
2149 case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break; 2156 case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break;
2150 #endif 2157 #endif
2151 2158
2152 // Page-related commands 2159 // Page-related commands
2153 case IDC_SAVE_PAGE: SavePage(); break; 2160 case IDC_SAVE_PAGE: SavePage(); break;
2154 case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break; 2161 case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break;
2155 case IDC_BOOKMARK_ALL_TABS: BookmarkAllTabs(); break; 2162 case IDC_BOOKMARK_ALL_TABS: BookmarkAllTabs(); break;
2156 case IDC_VIEW_SOURCE: ViewSource(); break; 2163 case IDC_VIEW_SOURCE: ViewSelectedSource(); break;
2157 case IDC_EMAIL_PAGE_LOCATION: EmailPageLocation(); break; 2164 case IDC_EMAIL_PAGE_LOCATION: EmailPageLocation(); break;
2158 case IDC_PRINT: Print(); break; 2165 case IDC_PRINT: Print(); break;
2159 case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break; 2166 case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break;
2160 case IDC_ENCODING_UTF8: 2167 case IDC_ENCODING_UTF8:
2161 case IDC_ENCODING_UTF16LE: 2168 case IDC_ENCODING_UTF16LE:
2162 case IDC_ENCODING_ISO88591: 2169 case IDC_ENCODING_ISO88591:
2163 case IDC_ENCODING_WINDOWS1252: 2170 case IDC_ENCODING_WINDOWS1252:
2164 case IDC_ENCODING_GBK: 2171 case IDC_ENCODING_GBK:
2165 case IDC_ENCODING_GB18030: 2172 case IDC_ENCODING_GB18030:
2166 case IDC_ENCODING_BIG5HKSCS: 2173 case IDC_ENCODING_BIG5HKSCS:
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
2445 return contents; 2452 return contents;
2446 } 2453 }
2447 2454
2448 bool Browser::CanDuplicateContentsAt(int index) { 2455 bool Browser::CanDuplicateContentsAt(int index) {
2449 NavigationController& nc = GetTabContentsAt(index)->controller(); 2456 NavigationController& nc = GetTabContentsAt(index)->controller();
2450 return nc.tab_contents() && nc.GetLastCommittedEntry(); 2457 return nc.tab_contents() && nc.GetLastCommittedEntry();
2451 } 2458 }
2452 2459
2453 void Browser::DuplicateContentsAt(int index) { 2460 void Browser::DuplicateContentsAt(int index) {
2454 TabContentsWrapper* contents = GetTabContentsWrapperAt(index); 2461 TabContentsWrapper* contents = GetTabContentsWrapperAt(index);
2455 TabContents* new_contents = NULL;
2456 DCHECK(contents); 2462 DCHECK(contents);
2457 bool pinned = false;
2458 2463
2459 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { 2464 TabContentsWrapper* contents_dupe = contents->Clone();
2460 // If this is a tabbed browser, just create a duplicate tab inside the same 2465 InsertContentsDupe(contents, contents_dupe);
2461 // window next to the tab being duplicated.
2462 TabContentsWrapper* wrapper = contents->Clone();
2463 new_contents = wrapper->tab_contents();
2464 pinned = tab_handler_->GetTabStripModel()->IsTabPinned(index);
2465 int add_types = TabStripModel::ADD_SELECTED |
2466 TabStripModel::ADD_INHERIT_GROUP |
2467 (pinned ? TabStripModel::ADD_PINNED : 0);
2468 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1,
2469 wrapper,
2470 add_types);
2471 } else {
2472 Browser* browser = NULL;
2473 if (type_ & TYPE_APP) {
2474 DCHECK((type_ & TYPE_POPUP) == 0);
2475 DCHECK(type_ != TYPE_APP_PANEL);
2476 browser = Browser::CreateForApp(app_name_, extension_app_, profile_,
2477 false);
2478 } else if (type_ == TYPE_POPUP) {
2479 browser = Browser::CreateForType(TYPE_POPUP, profile_);
2480 }
2481
2482 // Preserve the size of the original window. The new window has already
2483 // been given an offset by the OS, so we shouldn't copy the old bounds.
2484 BrowserWindow* new_window = browser->window();
2485 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(),
2486 window()->GetRestoredBounds().size()));
2487
2488 // We need to show the browser now. Otherwise ContainerWin assumes the
2489 // TabContents is invisible and won't size it.
2490 browser->window()->Show();
2491
2492 // The page transition below is only for the purpose of inserting the tab.
2493 new_contents = browser->AddTab(contents->Clone(), PageTransition::LINK);
2494 }
2495
2496 if (profile_->HasSessionService()) {
2497 SessionService* session_service = profile_->GetSessionService();
2498 if (session_service)
2499 session_service->TabRestored(&new_contents->controller(), pinned);
2500 }
2501 } 2466 }
2502 2467
2503 void Browser::CloseFrameAfterDragSession() { 2468 void Browser::CloseFrameAfterDragSession() {
2504 #if defined(OS_WIN) || defined(OS_LINUX) 2469 #if defined(OS_WIN) || defined(OS_LINUX)
2505 // This is scheduled to run after we return to the message loop because 2470 // This is scheduled to run after we return to the message loop because
2506 // otherwise the frame will think the drag session is still active and ignore 2471 // otherwise the frame will think the drag session is still active and ignore
2507 // the request. 2472 // the request.
2508 // TODO(port): figure out what is required here in a cross-platform world 2473 // TODO(port): figure out what is required here in a cross-platform world
2509 MessageLoop::current()->PostTask( 2474 MessageLoop::current()->PostTask(
2510 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame)); 2475 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame));
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
3094 window()->ConfirmAddSearchProvider(template_url, profile); 3059 window()->ConfirmAddSearchProvider(template_url, profile);
3095 } 3060 }
3096 3061
3097 void Browser::ShowPageInfo(Profile* profile, 3062 void Browser::ShowPageInfo(Profile* profile,
3098 const GURL& url, 3063 const GURL& url,
3099 const NavigationEntry::SSLStatus& ssl, 3064 const NavigationEntry::SSLStatus& ssl,
3100 bool show_history) { 3065 bool show_history) {
3101 window()->ShowPageInfo(profile, url, ssl, show_history); 3066 window()->ShowPageInfo(profile, url, ssl, show_history);
3102 } 3067 }
3103 3068
3069 void Browser::ViewSourceForTab(TabContents* contents) {
3070 DCHECK(contents);
3071 int index = tabstrip_model()->GetWrapperIndex(contents);
3072 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index);
3073 ViewSource(wrapper);
3074 }
3075
3104 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 3076 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
3105 bool* is_keyboard_shortcut) { 3077 bool* is_keyboard_shortcut) {
3106 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); 3078 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
3107 } 3079 }
3108 3080
3109 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { 3081 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
3110 window()->HandleKeyboardEvent(event); 3082 window()->HandleKeyboardEvent(event);
3111 } 3083 }
3112 3084
3113 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { 3085 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) {
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
4160 return false; 4132 return false;
4161 } 4133 }
4162 4134
4163 void Browser::CreateInstantIfNecessary() { 4135 void Browser::CreateInstantIfNecessary() {
4164 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && 4136 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) &&
4165 !profile()->IsOffTheRecord()) { 4137 !profile()->IsOffTheRecord()) {
4166 instant_.reset(new InstantController(profile_, this)); 4138 instant_.reset(new InstantController(profile_, this));
4167 instant_unload_handler_.reset(new InstantUnloadHandler(this)); 4139 instant_unload_handler_.reset(new InstantUnloadHandler(this));
4168 } 4140 }
4169 } 4141 }
4142
4143 void Browser::InsertContentsDupe(
4144 TabContentsWrapper* contents,
4145 TabContentsWrapper* contents_dupe) {
4146 DCHECK(contents);
4147
4148 TabContents* new_contents = contents_dupe->tab_contents();
4149 bool pinned = false;
4150
4151 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) {
4152 // If this is a tabbed browser, just create a duplicate tab inside the same
4153 // window next to the tab being duplicated.
4154 int index = tab_handler_->GetTabStripModel()->
4155 GetIndexOfTabContents(contents);
4156 pinned = tab_handler_->GetTabStripModel()->IsTabPinned(index);
4157 int add_types = TabStripModel::ADD_SELECTED |
4158 TabStripModel::ADD_INHERIT_GROUP |
4159 (pinned ? TabStripModel::ADD_PINNED : 0);
4160 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1,
4161 contents_dupe,
4162 add_types);
4163 } else {
4164 Browser* browser = NULL;
4165 if (type_ & TYPE_APP) {
4166 DCHECK((type_ & TYPE_POPUP) == 0);
4167 DCHECK(type_ != TYPE_APP_PANEL);
4168 browser = Browser::CreateForApp(app_name_, extension_app_, profile_,
4169 false);
4170 } else if (type_ == TYPE_POPUP) {
4171 browser = Browser::CreateForType(TYPE_POPUP, profile_);
4172 }
4173
4174 // Preserve the size of the original window. The new window has already
4175 // been given an offset by the OS, so we shouldn't copy the old bounds.
4176 BrowserWindow* new_window = browser->window();
4177 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(),
4178 window()->GetRestoredBounds().size()));
4179
4180 // We need to show the browser now. Otherwise ContainerWin assumes the
4181 // TabContents is invisible and won't size it.
4182 browser->window()->Show();
4183
4184 // The page transition below is only for the purpose of inserting the tab.
4185 browser->AddTab(contents_dupe, PageTransition::LINK);
4186 }
4187
4188 if (profile_->HasSessionService()) {
4189 SessionService* session_service = profile_->GetSessionService();
4190 if (session_service)
4191 session_service->TabRestored(&new_contents->controller(), pinned);
4192 }
4193 }
OLDNEW
« chrome/browser/ui/browser.h ('K') | « chrome/browser/ui/browser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698