| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 #include "content/public/browser/notification_service.h" | 65 #include "content/public/browser/notification_service.h" |
| 66 #include "content/public/browser/page_navigator.h" | 66 #include "content/public/browser/page_navigator.h" |
| 67 #include "content/public/browser/render_view_host.h" | 67 #include "content/public/browser/render_view_host.h" |
| 68 #include "content/public/browser/user_metrics.h" | 68 #include "content/public/browser/user_metrics.h" |
| 69 #include "content/public/browser/web_contents.h" | 69 #include "content/public/browser/web_contents.h" |
| 70 #include "content/public/browser/web_contents_view.h" | 70 #include "content/public/browser/web_contents_view.h" |
| 71 #include "content/public/common/content_restriction.h" | 71 #include "content/public/common/content_restriction.h" |
| 72 #include "content/public/common/renderer_preferences.h" | 72 #include "content/public/common/renderer_preferences.h" |
| 73 #include "content/public/common/url_constants.h" | 73 #include "content/public/common/url_constants.h" |
| 74 #include "net/base/escape.h" | 74 #include "net/base/escape.h" |
| 75 #include "webkit/glue/glue_serialize.h" | |
| 76 #include "webkit/user_agent/user_agent_util.h" | 75 #include "webkit/user_agent/user_agent_util.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 |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 | 983 |
| 985 void ViewSource(Browser* browser, WebContents* contents) { | 984 void ViewSource(Browser* browser, WebContents* contents) { |
| 986 DCHECK(contents); | 985 DCHECK(contents); |
| 987 | 986 |
| 988 // Use the last committed entry, since the pending entry hasn't loaded yet and | 987 // Use the last committed entry, since the pending entry hasn't loaded yet and |
| 989 // won't be copied into the cloned tab. | 988 // won't be copied into the cloned tab. |
| 990 NavigationEntry* entry = contents->GetController().GetLastCommittedEntry(); | 989 NavigationEntry* entry = contents->GetController().GetLastCommittedEntry(); |
| 991 if (!entry) | 990 if (!entry) |
| 992 return; | 991 return; |
| 993 | 992 |
| 994 ViewSource(browser, contents, entry->GetURL(), entry->GetContentState()); | 993 ViewSource(browser, contents, entry->GetURL(), entry->GetPageState()); |
| 995 } | 994 } |
| 996 | 995 |
| 997 void ViewSource(Browser* browser, | 996 void ViewSource(Browser* browser, |
| 998 WebContents* contents, | 997 WebContents* contents, |
| 999 const GURL& url, | 998 const GURL& url, |
| 1000 const std::string& content_state) { | 999 const content::PageState& page_state) { |
| 1001 content::RecordAction(UserMetricsAction("ViewSource")); | 1000 content::RecordAction(UserMetricsAction("ViewSource")); |
| 1002 DCHECK(contents); | 1001 DCHECK(contents); |
| 1003 | 1002 |
| 1004 // Note that Clone does not copy the pending or transient entries, so the | 1003 // Note that Clone does not copy the pending or transient entries, so the |
| 1005 // active entry in view_source_contents will be the last committed entry. | 1004 // active entry in view_source_contents will be the last committed entry. |
| 1006 WebContents* view_source_contents = contents->Clone(); | 1005 WebContents* view_source_contents = contents->Clone(); |
| 1007 view_source_contents->GetController().PruneAllButActive(); | 1006 view_source_contents->GetController().PruneAllButActive(); |
| 1008 NavigationEntry* active_entry = | 1007 NavigationEntry* active_entry = |
| 1009 view_source_contents->GetController().GetActiveEntry(); | 1008 view_source_contents->GetController().GetActiveEntry(); |
| 1010 if (!active_entry) | 1009 if (!active_entry) |
| 1011 return; | 1010 return; |
| 1012 | 1011 |
| 1013 GURL view_source_url = GURL(kViewSourceScheme + std::string(":") + | 1012 GURL view_source_url = GURL(kViewSourceScheme + std::string(":") + |
| 1014 url.spec()); | 1013 url.spec()); |
| 1015 active_entry->SetVirtualURL(view_source_url); | 1014 active_entry->SetVirtualURL(view_source_url); |
| 1016 | 1015 |
| 1017 // Do not restore scroller position. | 1016 // Do not restore scroller position. |
| 1018 active_entry->SetContentState( | 1017 active_entry->SetPageState(page_state.RemoveScrollOffset()); |
| 1019 webkit_glue::RemoveScrollOffsetFromHistoryState(content_state)); | |
| 1020 | 1018 |
| 1021 // Do not restore title, derive it from the url. | 1019 // Do not restore title, derive it from the url. |
| 1022 active_entry->SetTitle(string16()); | 1020 active_entry->SetTitle(string16()); |
| 1023 | 1021 |
| 1024 // Now show view-source entry. | 1022 // Now show view-source entry. |
| 1025 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { | 1023 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { |
| 1026 // If this is a tabbed browser, just create a duplicate tab inside the same | 1024 // If this is a tabbed browser, just create a duplicate tab inside the same |
| 1027 // window next to the tab being duplicated. | 1025 // window next to the tab being duplicated. |
| 1028 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); | 1026 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); |
| 1029 int add_types = TabStripModel::ADD_ACTIVE | | 1027 int add_types = TabStripModel::ADD_ACTIVE | |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(), | 1093 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(), |
| 1096 browser->host_desktop_type())); | 1094 browser->host_desktop_type())); |
| 1097 app_browser->tab_strip_model()->AppendWebContents(contents, true); | 1095 app_browser->tab_strip_model()->AppendWebContents(contents, true); |
| 1098 | 1096 |
| 1099 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 1097 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 1100 contents->GetRenderViewHost()->SyncRendererPrefs(); | 1098 contents->GetRenderViewHost()->SyncRendererPrefs(); |
| 1101 app_browser->window()->Show(); | 1099 app_browser->window()->Show(); |
| 1102 } | 1100 } |
| 1103 | 1101 |
| 1104 } // namespace chrome | 1102 } // namespace chrome |
| OLD | NEW |