OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 #include "content/public/browser/render_view_host.h" | 66 #include "content/public/browser/render_view_host.h" |
67 #include "content/public/browser/user_metrics.h" | 67 #include "content/public/browser/user_metrics.h" |
68 #include "content/public/browser/web_contents.h" | 68 #include "content/public/browser/web_contents.h" |
69 #include "content/public/browser/web_contents_view.h" | 69 #include "content/public/browser/web_contents_view.h" |
70 #include "content/public/common/content_restriction.h" | 70 #include "content/public/common/content_restriction.h" |
71 #include "content/public/common/renderer_preferences.h" | 71 #include "content/public/common/renderer_preferences.h" |
72 #include "content/public/common/url_constants.h" | 72 #include "content/public/common/url_constants.h" |
73 #include "content/public/common/url_utils.h" | 73 #include "content/public/common/url_utils.h" |
74 #include "net/base/escape.h" | 74 #include "net/base/escape.h" |
75 #include "webkit/common/user_agent/user_agent_util.h" | 75 #include "webkit/common/user_agent/user_agent_util.h" |
76 #include "webkit/glue/glue_serialize.h" | |
77 | 76 |
78 #if defined(OS_MACOSX) | 77 #if defined(OS_MACOSX) |
79 #include "ui/base/cocoa/find_pasteboard.h" | 78 #include "ui/base/cocoa/find_pasteboard.h" |
80 #endif | 79 #endif |
81 | 80 |
82 #if defined(OS_WIN) | 81 #if defined(OS_WIN) |
83 #include "chrome/browser/ui/metro_pin_tab_helper_win.h" | 82 #include "chrome/browser/ui/metro_pin_tab_helper_win.h" |
84 #include "win8/util/win8_util.h" | 83 #include "win8/util/win8_util.h" |
85 #endif | 84 #endif |
86 | 85 |
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
989 | 988 |
990 void ViewSource(Browser* browser, WebContents* contents) { | 989 void ViewSource(Browser* browser, WebContents* contents) { |
991 DCHECK(contents); | 990 DCHECK(contents); |
992 | 991 |
993 // Use the last committed entry, since the pending entry hasn't loaded yet and | 992 // Use the last committed entry, since the pending entry hasn't loaded yet and |
994 // won't be copied into the cloned tab. | 993 // won't be copied into the cloned tab. |
995 NavigationEntry* entry = contents->GetController().GetLastCommittedEntry(); | 994 NavigationEntry* entry = contents->GetController().GetLastCommittedEntry(); |
996 if (!entry) | 995 if (!entry) |
997 return; | 996 return; |
998 | 997 |
999 ViewSource(browser, contents, entry->GetURL(), entry->GetContentState()); | 998 ViewSource(browser, contents, entry->GetURL(), entry->GetPageState()); |
1000 } | 999 } |
1001 | 1000 |
1002 void ViewSource(Browser* browser, | 1001 void ViewSource(Browser* browser, |
1003 WebContents* contents, | 1002 WebContents* contents, |
1004 const GURL& url, | 1003 const GURL& url, |
1005 const std::string& content_state) { | 1004 const content::PageState& page_state) { |
1006 content::RecordAction(UserMetricsAction("ViewSource")); | 1005 content::RecordAction(UserMetricsAction("ViewSource")); |
1007 DCHECK(contents); | 1006 DCHECK(contents); |
1008 | 1007 |
1009 // Note that Clone does not copy the pending or transient entries, so the | 1008 // Note that Clone does not copy the pending or transient entries, so the |
1010 // active entry in view_source_contents will be the last committed entry. | 1009 // active entry in view_source_contents will be the last committed entry. |
1011 WebContents* view_source_contents = contents->Clone(); | 1010 WebContents* view_source_contents = contents->Clone(); |
1012 view_source_contents->GetController().PruneAllButActive(); | 1011 view_source_contents->GetController().PruneAllButActive(); |
1013 NavigationEntry* active_entry = | 1012 NavigationEntry* active_entry = |
1014 view_source_contents->GetController().GetActiveEntry(); | 1013 view_source_contents->GetController().GetActiveEntry(); |
1015 if (!active_entry) | 1014 if (!active_entry) |
1016 return; | 1015 return; |
1017 | 1016 |
1018 GURL view_source_url = GURL(kViewSourceScheme + std::string(":") + | 1017 GURL view_source_url = GURL(kViewSourceScheme + std::string(":") + |
1019 url.spec()); | 1018 url.spec()); |
1020 active_entry->SetVirtualURL(view_source_url); | 1019 active_entry->SetVirtualURL(view_source_url); |
1021 | 1020 |
1022 // Do not restore scroller position. | 1021 // Do not restore scroller position. |
1023 active_entry->SetContentState( | 1022 active_entry->SetPageState(page_state.RemoveScrollOffset()); |
Tom Sepez
2013/05/24 17:46:49
Do we similarly want to strip out the referenced f
| |
1024 webkit_glue::RemoveScrollOffsetFromHistoryState(content_state)); | |
1025 | 1023 |
1026 // Do not restore title, derive it from the url. | 1024 // Do not restore title, derive it from the url. |
1027 active_entry->SetTitle(string16()); | 1025 active_entry->SetTitle(string16()); |
1028 | 1026 |
1029 // Now show view-source entry. | 1027 // Now show view-source entry. |
1030 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { | 1028 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { |
1031 // If this is a tabbed browser, just create a duplicate tab inside the same | 1029 // If this is a tabbed browser, just create a duplicate tab inside the same |
1032 // window next to the tab being duplicated. | 1030 // window next to the tab being duplicated. |
1033 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); | 1031 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); |
1034 int add_types = TabStripModel::ADD_ACTIVE | | 1032 int add_types = TabStripModel::ADD_ACTIVE | |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1100 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(), | 1098 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(), |
1101 browser->host_desktop_type())); | 1099 browser->host_desktop_type())); |
1102 app_browser->tab_strip_model()->AppendWebContents(contents, true); | 1100 app_browser->tab_strip_model()->AppendWebContents(contents, true); |
1103 | 1101 |
1104 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 1102 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
1105 contents->GetRenderViewHost()->SyncRendererPrefs(); | 1103 contents->GetRenderViewHost()->SyncRendererPrefs(); |
1106 app_browser->window()->Show(); | 1104 app_browser->window()->Show(); |
1107 } | 1105 } |
1108 | 1106 |
1109 } // namespace chrome | 1107 } // namespace chrome |
OLD | NEW |