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

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: Lint 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
« no previous file with comments | « 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 active_entry->set_url(url);
darin (slow to review) 2010/12/13 21:45:38 I was not expecting this set_url call. Is that ne
1546 InsertContentsDupe(contents, view_source_contents);
1539 } 1547 }
1540 1548
1541 void Browser::ShowFindBar() { 1549 void Browser::ShowFindBar() {
1542 GetFindBarController()->Show(); 1550 GetFindBarController()->Show();
1543 } 1551 }
1544 1552
1545 bool Browser::SupportsWindowFeature(WindowFeature feature) const { 1553 bool Browser::SupportsWindowFeature(WindowFeature feature) const {
1546 return SupportsWindowFeatureImpl(feature, true); 1554 return SupportsWindowFeatureImpl(feature, true);
1547 } 1555 }
1548 1556
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
2146 case IDC_TOGGLE_VERTICAL_TABS: ToggleUseVerticalTabs(); break; 2154 case IDC_TOGGLE_VERTICAL_TABS: ToggleUseVerticalTabs(); break;
2147 #if defined(OS_CHROMEOS) 2155 #if defined(OS_CHROMEOS)
2148 case IDC_SEARCH: Search(); break; 2156 case IDC_SEARCH: Search(); break;
2149 case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break; 2157 case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break;
2150 #endif 2158 #endif
2151 2159
2152 // Page-related commands 2160 // Page-related commands
2153 case IDC_SAVE_PAGE: SavePage(); break; 2161 case IDC_SAVE_PAGE: SavePage(); break;
2154 case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break; 2162 case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break;
2155 case IDC_BOOKMARK_ALL_TABS: BookmarkAllTabs(); break; 2163 case IDC_BOOKMARK_ALL_TABS: BookmarkAllTabs(); break;
2156 case IDC_VIEW_SOURCE: ViewSource(); break; 2164 case IDC_VIEW_SOURCE: ViewSelectedSource(); break;
2157 case IDC_EMAIL_PAGE_LOCATION: EmailPageLocation(); break; 2165 case IDC_EMAIL_PAGE_LOCATION: EmailPageLocation(); break;
2158 case IDC_PRINT: Print(); break; 2166 case IDC_PRINT: Print(); break;
2159 case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break; 2167 case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break;
2160 case IDC_ENCODING_UTF8: 2168 case IDC_ENCODING_UTF8:
2161 case IDC_ENCODING_UTF16LE: 2169 case IDC_ENCODING_UTF16LE:
2162 case IDC_ENCODING_ISO88591: 2170 case IDC_ENCODING_ISO88591:
2163 case IDC_ENCODING_WINDOWS1252: 2171 case IDC_ENCODING_WINDOWS1252:
2164 case IDC_ENCODING_GBK: 2172 case IDC_ENCODING_GBK:
2165 case IDC_ENCODING_GB18030: 2173 case IDC_ENCODING_GB18030:
2166 case IDC_ENCODING_BIG5HKSCS: 2174 case IDC_ENCODING_BIG5HKSCS:
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
2445 return contents; 2453 return contents;
2446 } 2454 }
2447 2455
2448 bool Browser::CanDuplicateContentsAt(int index) { 2456 bool Browser::CanDuplicateContentsAt(int index) {
2449 NavigationController& nc = GetTabContentsAt(index)->controller(); 2457 NavigationController& nc = GetTabContentsAt(index)->controller();
2450 return nc.tab_contents() && nc.GetLastCommittedEntry(); 2458 return nc.tab_contents() && nc.GetLastCommittedEntry();
2451 } 2459 }
2452 2460
2453 void Browser::DuplicateContentsAt(int index) { 2461 void Browser::DuplicateContentsAt(int index) {
2454 TabContentsWrapper* contents = GetTabContentsWrapperAt(index); 2462 TabContentsWrapper* contents = GetTabContentsWrapperAt(index);
2455 TabContents* new_contents = NULL;
2456 DCHECK(contents); 2463 DCHECK(contents);
2457 bool pinned = false;
2458 2464
2459 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { 2465 TabContentsWrapper* contents_dupe = contents->Clone();
2460 // If this is a tabbed browser, just create a duplicate tab inside the same 2466 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 } 2467 }
2502 2468
2503 void Browser::CloseFrameAfterDragSession() { 2469 void Browser::CloseFrameAfterDragSession() {
2504 #if defined(OS_WIN) || defined(OS_LINUX) 2470 #if defined(OS_WIN) || defined(OS_LINUX)
2505 // This is scheduled to run after we return to the message loop because 2471 // 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 2472 // otherwise the frame will think the drag session is still active and ignore
2507 // the request. 2473 // the request.
2508 // TODO(port): figure out what is required here in a cross-platform world 2474 // TODO(port): figure out what is required here in a cross-platform world
2509 MessageLoop::current()->PostTask( 2475 MessageLoop::current()->PostTask(
2510 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame)); 2476 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); 3060 window()->ConfirmAddSearchProvider(template_url, profile);
3095 } 3061 }
3096 3062
3097 void Browser::ShowPageInfo(Profile* profile, 3063 void Browser::ShowPageInfo(Profile* profile,
3098 const GURL& url, 3064 const GURL& url,
3099 const NavigationEntry::SSLStatus& ssl, 3065 const NavigationEntry::SSLStatus& ssl,
3100 bool show_history) { 3066 bool show_history) {
3101 window()->ShowPageInfo(profile, url, ssl, show_history); 3067 window()->ShowPageInfo(profile, url, ssl, show_history);
3102 } 3068 }
3103 3069
3070 void Browser::ViewSourceForTab(TabContents* contents) {
3071 DCHECK(contents);
3072 int index = tabstrip_model()->GetWrapperIndex(contents);
3073 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index);
3074 ViewSource(wrapper);
3075 }
3076
3104 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 3077 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
3105 bool* is_keyboard_shortcut) { 3078 bool* is_keyboard_shortcut) {
3106 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); 3079 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
3107 } 3080 }
3108 3081
3109 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { 3082 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
3110 window()->HandleKeyboardEvent(event); 3083 window()->HandleKeyboardEvent(event);
3111 } 3084 }
3112 3085
3113 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { 3086 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) {
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
4160 return false; 4133 return false;
4161 } 4134 }
4162 4135
4163 void Browser::CreateInstantIfNecessary() { 4136 void Browser::CreateInstantIfNecessary() {
4164 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && 4137 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) &&
4165 !profile()->IsOffTheRecord()) { 4138 !profile()->IsOffTheRecord()) {
4166 instant_.reset(new InstantController(profile_, this)); 4139 instant_.reset(new InstantController(profile_, this));
4167 instant_unload_handler_.reset(new InstantUnloadHandler(this)); 4140 instant_unload_handler_.reset(new InstantUnloadHandler(this));
4168 } 4141 }
4169 } 4142 }
4143
4144 void Browser::InsertContentsDupe(
4145 TabContentsWrapper* contents,
4146 TabContentsWrapper* contents_dupe) {
4147 DCHECK(contents);
4148
4149 TabContents* new_contents = contents_dupe->tab_contents();
4150 bool pinned = false;
4151
4152 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) {
4153 // If this is a tabbed browser, just create a duplicate tab inside the same
4154 // window next to the tab being duplicated.
4155 int index = tab_handler_->GetTabStripModel()->
4156 GetIndexOfTabContents(contents);
4157 pinned = tab_handler_->GetTabStripModel()->IsTabPinned(index);
4158 int add_types = TabStripModel::ADD_SELECTED |
4159 TabStripModel::ADD_INHERIT_GROUP |
4160 (pinned ? TabStripModel::ADD_PINNED : 0);
4161 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1,
4162 contents_dupe,
4163 add_types);
4164 } else {
4165 Browser* browser = NULL;
4166 if (type_ & TYPE_APP) {
4167 DCHECK((type_ & TYPE_POPUP) == 0);
4168 DCHECK(type_ != TYPE_APP_PANEL);
4169 browser = Browser::CreateForApp(app_name_, extension_app_, profile_,
4170 false);
4171 } else if (type_ == TYPE_POPUP) {
4172 browser = Browser::CreateForType(TYPE_POPUP, profile_);
4173 }
4174
4175 // Preserve the size of the original window. The new window has already
4176 // been given an offset by the OS, so we shouldn't copy the old bounds.
4177 BrowserWindow* new_window = browser->window();
4178 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(),
4179 window()->GetRestoredBounds().size()));
4180
4181 // We need to show the browser now. Otherwise ContainerWin assumes the
4182 // TabContents is invisible and won't size it.
4183 browser->window()->Show();
4184
4185 // The page transition below is only for the purpose of inserting the tab.
4186 browser->AddTab(contents_dupe, PageTransition::LINK);
4187 }
4188
4189 if (profile_->HasSessionService()) {
4190 SessionService* session_service = profile_->GetSessionService();
4191 if (session_service)
4192 session_service->TabRestored(&new_contents->controller(), pinned);
4193 }
4194 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698