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

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

Issue 10868072: Make TabContents ctor private; poke hole for existing callers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: all green Created 8 years, 3 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/ui/browser.cc ('k') | chrome/browser/ui/browser_tabstrip.cc » ('j') | 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 #endif 77 #endif
78 78
79 using content::NavigationController; 79 using content::NavigationController;
80 using content::NavigationEntry; 80 using content::NavigationEntry;
81 using content::OpenURLParams; 81 using content::OpenURLParams;
82 using content::Referrer; 82 using content::Referrer;
83 using content::SSLStatus; 83 using content::SSLStatus;
84 using content::UserMetricsAction; 84 using content::UserMetricsAction;
85 using content::WebContents; 85 using content::WebContents;
86 86
87 // TODO(avi): Kill this when TabContents goes away.
88 class BrowserCommandsTabContentsCreator {
89 public:
90 static TabContents* CreateTabContents(content::WebContents* contents) {
91 return TabContents::Factory::CreateTabContents(contents);
92 }
93 static TabContents* CloneTabContents(TabContents* contents) {
94 return TabContents::Factory::CloneTabContents(contents);
95 }
96 };
97
87 namespace chrome { 98 namespace chrome {
88 namespace { 99 namespace {
89 100
90 WebContents* GetOrCloneTabForDisposition(Browser* browser, 101 WebContents* GetOrCloneTabForDisposition(Browser* browser,
91 WindowOpenDisposition disposition) { 102 WindowOpenDisposition disposition) {
92 TabContents* current_tab = GetActiveTabContents(browser); 103 TabContents* current_tab = GetActiveTabContents(browser);
93 switch (disposition) { 104 switch (disposition) {
94 case NEW_FOREGROUND_TAB: 105 case NEW_FOREGROUND_TAB:
95 case NEW_BACKGROUND_TAB: { 106 case NEW_BACKGROUND_TAB: {
96 current_tab = current_tab->Clone(); 107 current_tab =
108 BrowserCommandsTabContentsCreator::CloneTabContents(current_tab);
97 browser->tab_strip_model()->AddTabContents( 109 browser->tab_strip_model()->AddTabContents(
98 current_tab, -1, content::PAGE_TRANSITION_LINK, 110 current_tab, -1, content::PAGE_TRANSITION_LINK,
99 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE : 111 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE :
100 TabStripModel::ADD_NONE); 112 TabStripModel::ADD_NONE);
101 break; 113 break;
102 } 114 }
103 case NEW_WINDOW: { 115 case NEW_WINDOW: {
104 current_tab = current_tab->Clone(); 116 current_tab =
117 BrowserCommandsTabContentsCreator::CloneTabContents(current_tab);
105 Browser* b = new Browser(Browser::CreateParams(browser->profile())); 118 Browser* b = new Browser(Browser::CreateParams(browser->profile()));
106 b->tab_strip_model()->AddTabContents( 119 b->tab_strip_model()->AddTabContents(
107 current_tab, -1, content::PAGE_TRANSITION_LINK, 120 current_tab, -1, content::PAGE_TRANSITION_LINK,
108 TabStripModel::ADD_ACTIVE); 121 TabStripModel::ADD_ACTIVE);
109 b->window()->Show(); 122 b->window()->Show();
110 break; 123 break;
111 } 124 }
112 default: 125 default:
113 break; 126 break;
114 } 127 }
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 496 }
484 497
485 bool CanDuplicateTab(const Browser* browser) { 498 bool CanDuplicateTab(const Browser* browser) {
486 WebContents* contents = GetActiveWebContents(browser); 499 WebContents* contents = GetActiveWebContents(browser);
487 return contents && contents->GetController().GetLastCommittedEntry(); 500 return contents && contents->GetController().GetLastCommittedEntry();
488 } 501 }
489 502
490 void DuplicateTabAt(Browser* browser, int index) { 503 void DuplicateTabAt(Browser* browser, int index) {
491 TabContents* contents = GetTabContentsAt(browser, index); 504 TabContents* contents = GetTabContentsAt(browser, index);
492 CHECK(contents); 505 CHECK(contents);
493 TabContents* contents_dupe = contents->Clone(); 506 TabContents* contents_dupe =
507 BrowserCommandsTabContentsCreator::CloneTabContents(contents);
494 508
495 bool pinned = false; 509 bool pinned = false;
496 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { 510 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) {
497 // If this is a tabbed browser, just create a duplicate tab inside the same 511 // If this is a tabbed browser, just create a duplicate tab inside the same
498 // window next to the tab being duplicated. 512 // window next to the tab being duplicated.
499 int index = browser->tab_strip_model()->GetIndexOfTabContents(contents); 513 int index = browser->tab_strip_model()->GetIndexOfTabContents(contents);
500 pinned = browser->tab_strip_model()->IsTabPinned(index); 514 pinned = browser->tab_strip_model()->IsTabPinned(index);
501 int add_types = TabStripModel::ADD_ACTIVE | 515 int add_types = TabStripModel::ADD_ACTIVE |
502 TabStripModel::ADD_INHERIT_GROUP | 516 TabStripModel::ADD_INHERIT_GROUP |
503 (pinned ? TabStripModel::ADD_PINNED : 0); 517 (pinned ? TabStripModel::ADD_PINNED : 0);
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 902
889 void ViewSource(Browser* browser, 903 void ViewSource(Browser* browser,
890 TabContents* contents, 904 TabContents* contents,
891 const GURL& url, 905 const GURL& url,
892 const std::string& content_state) { 906 const std::string& content_state) {
893 content::RecordAction(UserMetricsAction("ViewSource")); 907 content::RecordAction(UserMetricsAction("ViewSource"));
894 DCHECK(contents); 908 DCHECK(contents);
895 909
896 // Note that Clone does not copy the pending or transient entries, so the 910 // 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. 911 // active entry in view_source_contents will be the last committed entry.
898 TabContents* view_source_contents = contents->Clone(); 912 TabContents* view_source_contents =
913 BrowserCommandsTabContentsCreator::CloneTabContents(contents);
899 view_source_contents->web_contents()->GetController().PruneAllButActive(); 914 view_source_contents->web_contents()->GetController().PruneAllButActive();
900 NavigationEntry* active_entry = 915 NavigationEntry* active_entry =
901 view_source_contents->web_contents()->GetController().GetActiveEntry(); 916 view_source_contents->web_contents()->GetController().GetActiveEntry();
902 if (!active_entry) 917 if (!active_entry)
903 return; 918 return;
904 919
905 GURL view_source_url = GURL(kViewSourceScheme + std::string(":") + 920 GURL view_source_url = GURL(kViewSourceScheme + std::string(":") +
906 url.spec()); 921 url.spec());
907 active_entry->SetVirtualURL(view_source_url); 922 active_entry->SetVirtualURL(view_source_url);
908 923
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 std::string app_name = web_app::GenerateApplicationNameFromURL(url); 987 std::string app_name = web_app::GenerateApplicationNameFromURL(url);
973 988
974 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 989 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
975 if (index >= 0) 990 if (index >= 0)
976 browser->tab_strip_model()->DetachTabContentsAt(index); 991 browser->tab_strip_model()->DetachTabContentsAt(index);
977 992
978 Browser* app_browser = new Browser( 993 Browser* app_browser = new Browser(
979 Browser::CreateParams::CreateForApp( 994 Browser::CreateParams::CreateForApp(
980 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile())); 995 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile()));
981 TabContents* tab_contents = TabContents::FromWebContents(contents); 996 TabContents* tab_contents = TabContents::FromWebContents(contents);
982 if (!tab_contents) 997 if (!tab_contents) {
983 tab_contents = new TabContents(contents); 998 tab_contents =
999 BrowserCommandsTabContentsCreator::CreateTabContents(contents);
1000 }
984 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true); 1001 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true);
985 1002
986 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 1003 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
987 contents->GetRenderViewHost()->SyncRendererPrefs(); 1004 contents->GetRenderViewHost()->SyncRendererPrefs();
988 app_browser->window()->Show(); 1005 app_browser->window()->Show();
989 } 1006 }
990 1007
991 } // namespace chrome 1008 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/browser_tabstrip.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698