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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/browser_init.h ('k') | chrome/browser/ui/cocoa/html_dialog_window_controller.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/browser_init.cc
diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc
index 640bbe7c1e47ece28285d8730db758a7ecc81fad..7cbd53d0e8f5072d6bda1862f91ac6d3c4d04ae5 100644
--- a/chrome/browser/ui/browser_init.cc
+++ b/chrome/browser/ui/browser_init.cc
@@ -63,12 +63,16 @@
#include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h"
#include "chrome/browser/tabs/pinned_tab_codec.h"
#include "chrome/browser/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/dialog_style.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/browser/ui/webui/sync_promo/sync_promo_dialog.h"
#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_result_codes.h"
#include "chrome/common/chrome_switches.h"
@@ -1150,14 +1154,20 @@ Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser(
Browser* BrowserInit::LaunchWithProfile::OpenTabsInBrowser(
Browser* browser,
bool process_startup,
- const std::vector<Tab>& tabs) {
- DCHECK(!tabs.empty());
+ const std::vector<Tab>& in_tabs) {
+ DCHECK(!in_tabs.empty());
+
// If we don't yet have a profile, try to use the one we're given from
// |browser|. While we may not end up actually using |browser| (since it
// could be a popup window), we can at least use the profile.
if (!profile_ && browser)
profile_ = browser->profile();
+ std::vector<Tab> tabs(in_tabs);
+ size_t active_tab_index =
+ ShowSyncPromoDialog(process_startup, &browser, &tabs);
+ bool first_tab = active_tab_index == std::string::npos;
+
if (!browser || !browser->is_type_tabbed()) {
browser = Browser::Create(profile_);
} else {
@@ -1175,7 +1185,6 @@ Browser* BrowserInit::LaunchWithProfile::OpenTabsInBrowser(
browser->ToggleFullscreenMode(false);
#endif
- bool first_tab = true;
for (size_t i = 0; i < tabs.size(); ++i) {
// We skip URLs that we'd have to launch an external protocol handler for.
// This avoids us getting into an infinite loop asking ourselves to open
@@ -1187,16 +1196,27 @@ Browser* BrowserInit::LaunchWithProfile::OpenTabsInBrowser(
if (!process_startup && !handled_by_chrome)
continue;
- int add_types = first_tab ? TabStripModel::ADD_ACTIVE :
- TabStripModel::ADD_NONE;
+ size_t index;
+ if (tabs[i].url.SchemeIs(chrome::kChromeUIScheme) &&
+ tabs[i].url.host() == chrome::kChromeUISyncPromoHost) {
+ // The sync promo must always be the first tab. If the browser window
+ // was spawned from the sync promo dialog then it might have other tabs
+ // in it already. Explicilty set it to 0 to ensure that it's first.
+ index = 0;
+ } else {
+ index = browser->GetIndexForInsertionDuringRestore(i);
+ }
+
+ int add_types = (first_tab || index == active_tab_index) ?
+ TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE;
add_types |= TabStripModel::ADD_FORCE_INDEX;
if (tabs[i].is_pinned)
add_types |= TabStripModel::ADD_PINNED;
- int index = browser->GetIndexForInsertionDuringRestore(i);
browser::NavigateParams params(browser, tabs[i].url,
content::PAGE_TRANSITION_START_PAGE);
- params.disposition = first_tab ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB;
+ params.disposition = (first_tab || index == active_tab_index) ?
+ NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB;
params.tabstrip_index = index;
params.tabstrip_add_types = add_types;
params.extension_app_id = tabs[i].app_id;
@@ -1481,6 +1501,44 @@ bool BrowserInit::LaunchWithProfile::CheckIfAutoLaunched(Profile* profile) {
return false;
}
+size_t BrowserInit::LaunchWithProfile::ShowSyncPromoDialog(
+ bool process_startup,
+ Browser** browser,
+ std::vector<Tab>* tabs) {
+ DCHECK(browser);
+ DCHECK(tabs);
+
+ // The dialog is only shown on process startup if no browser window is already
+ // being displayed.
+ if (!profile_ || *browser || !process_startup ||
+ SyncPromoUI::GetSyncPromoVersion() != SyncPromoUI::VERSION_DIALOG) {
+ return std::string::npos;
+ }
+
+ for (size_t i = 0; i < tabs->size(); ++i) {
+ GURL url((*tabs)[i].url);
+ if (url.SchemeIs(chrome::kChromeUIScheme) &&
+ url.host() == chrome::kChromeUISyncPromoHost) {
+ SyncPromoDialog dialog(profile_, url);
+ dialog.ShowDialog();
+ *browser = dialog.spawned_browser();
+ if (dialog.sync_promo_was_closed()) {
+ tabs->erase(tabs->begin() + i);
+ // The tab spawned by the dialog is at tab index 0 so return 0 to make
+ // it the active tab.
+ return 0;
+ } else {
+ // Since the sync promo is not closed it will be inserted at tab
+ // index 0. The tab spawned by the dialog will be at index 1 so return
+ // 0 to make it the active tab.
+ return 1;
+ }
+ }
+ }
+
+ return std::string::npos;
+}
+
std::vector<GURL> BrowserInit::GetURLsFromCommandLine(
const CommandLine& command_line,
const FilePath& cur_dir,
« no previous file with comments | « chrome/browser/ui/browser_init.h ('k') | chrome/browser/ui/cocoa/html_dialog_window_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698