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

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

Issue 9225053: Add a blocking version of the sync promo dialog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 8 years, 10 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
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_init.h" 5 #include "chrome/browser/ui/browser_init.h"
6 6
7 #include <algorithm> // For max(). 7 #include <algorithm> // For max().
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "chrome/browser/search_engines/template_url_service.h" 56 #include "chrome/browser/search_engines/template_url_service.h"
57 #include "chrome/browser/search_engines/template_url_service_factory.h" 57 #include "chrome/browser/search_engines/template_url_service_factory.h"
58 #include "chrome/browser/sessions/session_restore.h" 58 #include "chrome/browser/sessions/session_restore.h"
59 #include "chrome/browser/sessions/session_service.h" 59 #include "chrome/browser/sessions/session_service.h"
60 #include "chrome/browser/sessions/session_service_factory.h" 60 #include "chrome/browser/sessions/session_service_factory.h"
61 #include "chrome/browser/shell_integration.h" 61 #include "chrome/browser/shell_integration.h"
62 #include "chrome/browser/tab_contents/link_infobar_delegate.h" 62 #include "chrome/browser/tab_contents/link_infobar_delegate.h"
63 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" 63 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h"
64 #include "chrome/browser/tabs/pinned_tab_codec.h" 64 #include "chrome/browser/tabs/pinned_tab_codec.h"
65 #include "chrome/browser/tabs/tab_strip_model.h" 65 #include "chrome/browser/tabs/tab_strip_model.h"
66 #include "chrome/browser/ui/browser_dialogs.h"
66 #include "chrome/browser/ui/browser_list.h" 67 #include "chrome/browser/ui/browser_list.h"
67 #include "chrome/browser/ui/browser_navigator.h" 68 #include "chrome/browser/ui/browser_navigator.h"
68 #include "chrome/browser/ui/browser_window.h" 69 #include "chrome/browser/ui/browser_window.h"
70 #include "chrome/browser/ui/dialog_style.h"
69 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 71 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
72 #include "chrome/browser/ui/webui/sync_promo/sync_promo_dialog.h"
70 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" 73 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
71 #include "chrome/common/chrome_constants.h" 74 #include "chrome/common/chrome_constants.h"
75 #include "chrome/common/chrome_notification_types.h"
72 #include "chrome/common/chrome_paths.h" 76 #include "chrome/common/chrome_paths.h"
73 #include "chrome/common/chrome_result_codes.h" 77 #include "chrome/common/chrome_result_codes.h"
74 #include "chrome/common/chrome_switches.h" 78 #include "chrome/common/chrome_switches.h"
75 #include "chrome/common/chrome_version_info.h" 79 #include "chrome/common/chrome_version_info.h"
76 #include "chrome/common/extensions/extension_constants.h" 80 #include "chrome/common/extensions/extension_constants.h"
77 #include "chrome/common/pref_names.h" 81 #include "chrome/common/pref_names.h"
78 #include "chrome/common/url_constants.h" 82 #include "chrome/common/url_constants.h"
79 #include "chrome/installer/util/browser_distribution.h" 83 #include "chrome/installer/util/browser_distribution.h"
80 #include "content/browser/child_process_security_policy.h" 84 #include "content/browser/child_process_security_policy.h"
81 #include "content/public/browser/browser_thread.h" 85 #include "content/public/browser/browser_thread.h"
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 1144
1141 Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser( 1145 Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser(
1142 Browser* browser, 1146 Browser* browser,
1143 bool process_startup, 1147 bool process_startup,
1144 const std::vector<GURL>& urls) { 1148 const std::vector<GURL>& urls) {
1145 std::vector<Tab> tabs; 1149 std::vector<Tab> tabs;
1146 UrlsToTabs(urls, &tabs); 1150 UrlsToTabs(urls, &tabs);
1147 return OpenTabsInBrowser(browser, process_startup, tabs); 1151 return OpenTabsInBrowser(browser, process_startup, tabs);
1148 } 1152 }
1149 1153
1154 size_t BrowserInit::LaunchWithProfile::ShowSyncPromoDialog(
sky 2012/01/30 18:13:41 Make position match that of header.
sail 2012/01/30 21:00:39 Done.
1155 Browser** browser,
1156 bool process_startup,
1157 std::vector<Tab>* tabs) {
1158 DCHECK(browser);
1159 DCHECK(tabs);
1160
1161 if (!profile_ || *browser || !process_startup ||
Dan Beam 2012/01/30 18:10:05 You may want to leave comment clarifying what you'
sail 2012/01/30 21:00:39 Done.
1162 SyncPromoUI::GetSyncPromoVersion() != SyncPromoUI::VERSION_DIALOG) {
1163 return std::string::npos;
1164 }
1165
1166 for (size_t i = 0; i < tabs->size(); ++i) {
1167 GURL url((*tabs)[i].url);
1168 if (url.SchemeIs(chrome::kChromeUIScheme) &&
1169 url.host() == chrome::kChromeUISyncPromoHost) {
1170 SyncPromoDialog dialog(profile_, url);
1171 dialog.ShowDialog();
1172 *browser = dialog.spawned_browser();
1173 if (dialog.sync_promo_was_closed()) {
1174 tabs->erase(tabs->begin() + i);
1175 return 0;
sky 2012/01/30 18:13:41 I don't understand the return value here. CAn you
sail 2012/01/30 21:00:39 Done.
1176 } else {
1177 return 1;
1178 }
1179 }
1180 }
1181
1182 return std::string::npos;
1183 }
1184
1150 Browser* BrowserInit::LaunchWithProfile::OpenTabsInBrowser( 1185 Browser* BrowserInit::LaunchWithProfile::OpenTabsInBrowser(
1151 Browser* browser, 1186 Browser* browser,
1152 bool process_startup, 1187 bool process_startup,
1153 const std::vector<Tab>& tabs) { 1188 const std::vector<Tab>& in_tabs) {
1154 DCHECK(!tabs.empty()); 1189 DCHECK(!in_tabs.empty());
1190
1155 // If we don't yet have a profile, try to use the one we're given from 1191 // If we don't yet have a profile, try to use the one we're given from
1156 // |browser|. While we may not end up actually using |browser| (since it 1192 // |browser|. While we may not end up actually using |browser| (since it
1157 // could be a popup window), we can at least use the profile. 1193 // could be a popup window), we can at least use the profile.
1158 if (!profile_ && browser) 1194 if (!profile_ && browser)
1159 profile_ = browser->profile(); 1195 profile_ = browser->profile();
1160 1196
1197 std::vector<Tab> tabs(in_tabs);
1198 size_t active_tab_index =
1199 ShowSyncPromoDialog(&browser, process_startup, &tabs);
1200 bool first_tab = active_tab_index == std::string::npos;
1201
1161 if (!browser || !browser->is_type_tabbed()) { 1202 if (!browser || !browser->is_type_tabbed()) {
1162 browser = Browser::Create(profile_); 1203 browser = Browser::Create(profile_);
1163 } else { 1204 } else {
1164 #if defined(TOOLKIT_GTK) 1205 #if defined(TOOLKIT_GTK)
1165 // Setting the time of the last action on the window here allows us to steal 1206 // Setting the time of the last action on the window here allows us to steal
1166 // focus, which is what the user wants when opening a new tab in an existing 1207 // focus, which is what the user wants when opening a new tab in an existing
1167 // browser window. 1208 // browser window.
1168 gtk_util::SetWMLastUserActionTime(browser->window()->GetNativeHandle()); 1209 gtk_util::SetWMLastUserActionTime(browser->window()->GetNativeHandle());
1169 #endif 1210 #endif
1170 } 1211 }
1171 1212
1172 #if !defined(OS_MACOSX) 1213 #if !defined(OS_MACOSX)
1173 // In kiosk mode, we want to always be fullscreen, so switch to that now. 1214 // In kiosk mode, we want to always be fullscreen, so switch to that now.
1174 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 1215 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
1175 browser->ToggleFullscreenMode(false); 1216 browser->ToggleFullscreenMode(false);
1176 #endif 1217 #endif
1177 1218
1178 bool first_tab = true;
1179 for (size_t i = 0; i < tabs.size(); ++i) { 1219 for (size_t i = 0; i < tabs.size(); ++i) {
1180 // We skip URLs that we'd have to launch an external protocol handler for. 1220 // We skip URLs that we'd have to launch an external protocol handler for.
1181 // This avoids us getting into an infinite loop asking ourselves to open 1221 // This avoids us getting into an infinite loop asking ourselves to open
1182 // a URL, should the handler be (incorrectly) configured to be us. Anyone 1222 // a URL, should the handler be (incorrectly) configured to be us. Anyone
1183 // asking us to open such a URL should really ask the handler directly. 1223 // asking us to open such a URL should really ask the handler directly.
1184 bool handled_by_chrome = ProfileIOData::IsHandledURL(tabs[i].url) || 1224 bool handled_by_chrome = ProfileIOData::IsHandledURL(tabs[i].url) ||
1185 (profile_ && profile_->GetProtocolHandlerRegistry()->IsHandledProtocol( 1225 (profile_ && profile_->GetProtocolHandlerRegistry()->IsHandledProtocol(
1186 tabs[i].url.scheme())); 1226 tabs[i].url.scheme()));
1187 if (!process_startup && !handled_by_chrome) 1227 if (!process_startup && !handled_by_chrome)
1188 continue; 1228 continue;
1189 1229
1190 int add_types = first_tab ? TabStripModel::ADD_ACTIVE : 1230 size_t index;
1191 TabStripModel::ADD_NONE; 1231 if (tabs[i].url.SchemeIs(chrome::kChromeUIScheme) &&
1232 tabs[i].url.host() == chrome::kChromeUISyncPromoHost) {
1233 index = 0;
sky 2012/01/30 18:13:41 Add a comment as to why you're forcing these to ap
sail 2012/01/30 21:00:39 Done.
1234 } else {
1235 index = browser->GetIndexForInsertionDuringRestore(i);
1236 }
1237
1238 int add_types = (first_tab || index == active_tab_index) ?
1239 TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE;
1192 add_types |= TabStripModel::ADD_FORCE_INDEX; 1240 add_types |= TabStripModel::ADD_FORCE_INDEX;
1193 if (tabs[i].is_pinned) 1241 if (tabs[i].is_pinned)
1194 add_types |= TabStripModel::ADD_PINNED; 1242 add_types |= TabStripModel::ADD_PINNED;
1195 int index = browser->GetIndexForInsertionDuringRestore(i);
1196 1243
1197 browser::NavigateParams params(browser, tabs[i].url, 1244 browser::NavigateParams params(browser, tabs[i].url,
1198 content::PAGE_TRANSITION_START_PAGE); 1245 content::PAGE_TRANSITION_START_PAGE);
1199 params.disposition = first_tab ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; 1246 params.disposition = (first_tab || index == active_tab_index) ?
1247 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB;
1200 params.tabstrip_index = index; 1248 params.tabstrip_index = index;
1201 params.tabstrip_add_types = add_types; 1249 params.tabstrip_add_types = add_types;
1202 params.extension_app_id = tabs[i].app_id; 1250 params.extension_app_id = tabs[i].app_id;
1203 browser::Navigate(&params); 1251 browser::Navigate(&params);
1204 1252
1205 first_tab = false; 1253 first_tab = false;
1206 } 1254 }
1207 browser->window()->Show(); 1255 browser->window()->Show();
1208 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial 1256 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial
1209 // focus explicitly. 1257 // focus explicitly.
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 1817
1770 Profile* profile = ProfileManager::GetLastUsedProfile(); 1818 Profile* profile = ProfileManager::GetLastUsedProfile();
1771 if (!profile) { 1819 if (!profile) {
1772 // We should only be able to get here if the profile already exists and 1820 // We should only be able to get here if the profile already exists and
1773 // has been created. 1821 // has been created.
1774 NOTREACHED(); 1822 NOTREACHED();
1775 return; 1823 return;
1776 } 1824 }
1777 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); 1825 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL);
1778 } 1826 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698