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

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

Issue 10829308: Use the last committed entry for View Source. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months 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/browser_commands_unittest.cc ('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) 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/browser_commands.h" 5 #include "chrome/browser/ui/browser_commands.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/bookmarks/bookmark_editor.h" 10 #include "chrome/browser/bookmarks/bookmark_editor.h"
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 869
870 bool IsDebuggerAttachedToCurrentTab(Browser* browser) { 870 bool IsDebuggerAttachedToCurrentTab(Browser* browser) {
871 WebContents* contents = chrome::GetActiveWebContents(browser); 871 WebContents* contents = chrome::GetActiveWebContents(browser);
872 return contents ? 872 return contents ?
873 content::DevToolsAgentHostRegistry::IsDebuggerAttached(contents) : false; 873 content::DevToolsAgentHostRegistry::IsDebuggerAttached(contents) : false;
874 } 874 }
875 875
876 void ViewSource(Browser* browser, TabContents* contents) { 876 void ViewSource(Browser* browser, TabContents* contents) {
877 DCHECK(contents); 877 DCHECK(contents);
878 878
879 NavigationEntry* active_entry = 879 // Use the last committed entry, since the pending entry hasn't loaded yet and
880 contents->web_contents()->GetController().GetActiveEntry(); 880 // won't be copied into the cloned tab.
881 if (!active_entry) 881 NavigationEntry* entry =
882 contents->web_contents()->GetController().GetLastCommittedEntry();
883 if (!entry)
882 return; 884 return;
883 885
884 ViewSource(browser, contents, active_entry->GetURL(), 886 ViewSource(browser, contents, entry->GetURL(), entry->GetContentState());
885 active_entry->GetContentState());
886 } 887 }
887 888
888 void ViewSource(Browser* browser, 889 void ViewSource(Browser* browser,
889 TabContents* contents, 890 TabContents* contents,
890 const GURL& url, 891 const GURL& url,
891 const std::string& content_state) { 892 const std::string& content_state) {
892 content::RecordAction(UserMetricsAction("ViewSource")); 893 content::RecordAction(UserMetricsAction("ViewSource"));
893 DCHECK(contents); 894 DCHECK(contents);
894 895
896 // Note that Clone does not copy the pending or transient entries, so the
897 // active entry in view_source_contents will be the last committed entry.
895 TabContents* view_source_contents = contents->Clone(); 898 TabContents* view_source_contents = contents->Clone();
896 view_source_contents->web_contents()->GetController().PruneAllButActive(); 899 view_source_contents->web_contents()->GetController().PruneAllButActive();
897 NavigationEntry* active_entry = 900 NavigationEntry* active_entry =
898 view_source_contents->web_contents()->GetController().GetActiveEntry(); 901 view_source_contents->web_contents()->GetController().GetActiveEntry();
899 if (!active_entry) 902 if (!active_entry)
900 return; 903 return;
901 904
902 GURL view_source_url = GURL(kViewSourceScheme + std::string(":") + 905 GURL view_source_url = GURL(kViewSourceScheme + std::string(":") +
903 url.spec()); 906 url.spec());
904 active_entry->SetVirtualURL(view_source_url); 907 active_entry->SetVirtualURL(view_source_url);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 if (!tab_contents) 982 if (!tab_contents)
980 tab_contents = new TabContents(contents); 983 tab_contents = new TabContents(contents);
981 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true); 984 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true);
982 985
983 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 986 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
984 contents->GetRenderViewHost()->SyncRendererPrefs(); 987 contents->GetRenderViewHost()->SyncRendererPrefs();
985 app_browser->window()->Show(); 988 app_browser->window()->Show();
986 } 989 }
987 990
988 } // namespace chrome 991 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/browser_commands_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698