Commit 820a1400 authored by motek@chromium.org's avatar motek@chromium.org

Hide the main window when Set-As-Default dialog is present.

This affect startup sequences only. 

BUG=134430
TEST=The dialog on win8 should appear without the main window.  If the user chooses not to make Chrome default, it should continue to desktop Chrome. 


Review URL: https://chromiumcodereview.appspot.com/10696093

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150936 0039d316-1c4b-4281-b951-d872f2087c98
parent e5354323
......@@ -1138,10 +1138,12 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
chrome::SetNewHomePagePrefs(profile_->GetPrefs());
browser_process_->profile_manager()->OnImportFinished(profile_);
if (!master_prefs_->suppress_first_run_default_browser_prompt)
chrome::ShowFirstRunDefaultBrowserPrompt(profile_);
else
if (!master_prefs_->suppress_first_run_default_browser_prompt) {
browser_creator_->set_show_main_browser_window(
!chrome::ShowFirstRunDefaultBrowserPrompt(profile_));
} else {
browser_creator_->set_is_default_browser_dialog_suppressed(true);
}
} // if (is_first_run_)
#if defined(OS_WIN)
......
......@@ -205,7 +205,8 @@ void ShowDefaultBrowserPrompt(Profile* profile) {
}
#if !defined(OS_WIN)
void ShowFirstRunDefaultBrowserPrompt(Profile* profile) {
bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) {
return false;
}
#endif
......
......@@ -13,8 +13,8 @@ namespace chrome {
void ShowDefaultBrowserPrompt(Profile* profile);
// Shows a prompt UI to set the default browser on first run
// (if necessary and permitted).
void ShowFirstRunDefaultBrowserPrompt(Profile* profile);
// (if necessary and permitted). Returns true if the dialog has been launched.
bool ShowFirstRunDefaultBrowserPrompt(Profile* profile);
} // namespace chrome
......
......@@ -69,15 +69,20 @@ void SetMetroBrowserFlowLauncher::Observe(
namespace chrome {
void ShowFirstRunDefaultBrowserPrompt(Profile* profile) {
if ((ShellIntegration::IsDefaultBrowser() ==
ShellIntegration::NOT_DEFAULT_WEB_CLIENT) &&
bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) {
// If the only available mode of setting the default browser requires
// user interaction, it means this couldn't have been done yet. Therefore,
// we launch the dialog and inform the caller of it.
bool show_status =
(ShellIntegration::CanSetAsDefaultBrowser() ==
ShellIntegration::SET_DEFAULT_INTERACTIVE)) {
// If the only available mode of setting the default browser requires
// user interaction, it means this couldn't have been done yet.
ShellIntegration::SET_DEFAULT_INTERACTIVE) &&
(ShellIntegration::IsDefaultBrowser() ==
ShellIntegration::NOT_DEFAULT_WEB_CLIENT);
if (show_status)
SetMetroBrowserFlowLauncher::LaunchSoon(profile);
}
return show_status;
}
} // namespace chrome
......@@ -155,7 +155,8 @@ base::LazyInstance<ProfileLaunchObserver> profile_launch_observer =
} // namespace
StartupBrowserCreator::StartupBrowserCreator()
: is_default_browser_dialog_suppressed_(false) {
: is_default_browser_dialog_suppressed_(false),
show_main_browser_window_(true) {
}
StartupBrowserCreator::~StartupBrowserCreator() {}
......
......@@ -91,6 +91,14 @@ class StartupBrowserCreator {
return is_default_browser_dialog_suppressed_;
}
void set_show_main_browser_window(bool show_main_browser_window) {
show_main_browser_window_ = show_main_browser_window;
}
bool show_main_browser_window() const {
return show_main_browser_window_;
}
private:
friend class CloudPrintProxyPolicyTest;
friend class CloudPrintProxyPolicyStartupTest;
......@@ -131,6 +139,10 @@ class StartupBrowserCreator {
// first-run when the dialog has been suppressed.
bool is_default_browser_dialog_suppressed_;
// Whether the browser window should be shown immediately after it has been
// created. Default is true.
bool show_main_browser_window_;
// True if we have already read and reset the preference kWasRestarted. (A
// member variable instead of a static variable inside WasRestarted because
// of testing.)
......
......@@ -790,10 +790,16 @@ Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser(Browser* browser,
chrome::ActivateTabAt(browser, 0, false);
}
browser->window()->Show();
// TODO(jcampan): http://crbug.com/8123 we should not need to set the initial
// focus explicitly.
chrome::GetActiveWebContents(browser)->GetView()->SetInitialFocus();
// The default behaviour is to show the window, as expressed by the default
// value of StartupBrowserCreated::show_main_browser_window_. If this was set
// to true ahead of this place, it means another task must have been spawned
// to take care of that.
if (!browser_creator_ || browser_creator_->show_main_browser_window()) {
browser->window()->Show();
// TODO(jcampan): http://crbug.com/8123 we should not need to set the
// initial focus explicitly.
chrome::GetActiveWebContents(browser)->GetView()->SetInitialFocus();
}
return browser;
}
......
......@@ -15,6 +15,7 @@
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/singleton_tabs.h"
......@@ -25,6 +26,7 @@
#include "chrome/installer/util/install_util.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "grit/browser_resources.h"
......@@ -59,6 +61,16 @@ ChromeWebUIDataSource* CreateSetAsDefaultBrowserUIHTMLSource() {
return data_source;
}
// A simple class serving as a delegate for passing down the result of the
// interaction.
class ResponseDelegate {
public:
virtual void SetChromeShutdownRequired(bool shutdown_chrome) = 0;
protected:
virtual ~ResponseDelegate() { }
};
// Event handler for SetAsDefaultBrowserUI. Capable of setting Chrome as the
// default browser on button click, closing itself and triggering Chrome
// restart.
......@@ -67,7 +79,7 @@ class SetAsDefaultBrowserHandler
public base::SupportsWeakPtr<SetAsDefaultBrowserHandler>,
public ShellIntegration::DefaultWebClientObserver {
public:
SetAsDefaultBrowserHandler();
explicit SetAsDefaultBrowserHandler(ResponseDelegate* response_delegate);
virtual ~SetAsDefaultBrowserHandler();
// WebUIMessageHandler implementation.
......@@ -76,7 +88,7 @@ class SetAsDefaultBrowserHandler
// ShellIntegration::DefaultWebClientObserver implementation.
virtual void SetDefaultWebClientUIState(
ShellIntegration::DefaultWebClientUIState state) OVERRIDE;
virtual void OnSetAsDefaultConcluded(bool call_result) OVERRIDE;
virtual void OnSetAsDefaultConcluded(bool close_chrome) OVERRIDE;
virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE;
private:
......@@ -84,7 +96,7 @@ class SetAsDefaultBrowserHandler
void HandleLaunchSetDefaultBrowserFlow(const ListValue* args);
// Close this web ui.
void ConcludeInteraction();
void ConcludeInteraction(bool mark_success);
// If required and possible, spawns a new Chrome in Metro mode and closes the
// current instance. Windows 8 only, on earlier systems it will simply close
......@@ -94,14 +106,17 @@ class SetAsDefaultBrowserHandler
scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
bool set_default_returned_;
bool set_default_result_;
ResponseDelegate* response_delegate_;
DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserHandler);
};
SetAsDefaultBrowserHandler::SetAsDefaultBrowserHandler()
SetAsDefaultBrowserHandler::SetAsDefaultBrowserHandler(
ResponseDelegate* response_delegate)
: ALLOW_THIS_IN_INITIALIZER_LIST(default_browser_worker_(
new ShellIntegration::DefaultBrowserWorker(this))),
set_default_returned_(false), set_default_result_(false) {
set_default_returned_(false), set_default_result_(false),
response_delegate_(response_delegate) {
}
SetAsDefaultBrowserHandler::~SetAsDefaultBrowserHandler() {
......@@ -126,7 +141,7 @@ void SetAsDefaultBrowserHandler::SetDefaultWebClientUIState(
// The operation concluded, but Chrome is still not the default.
// If the call has succeeded, this suggests user has decided not to make
// chrome the default. We fold this UI and move on.
ConcludeInteraction();
ConcludeInteraction(false);
} else if (state == ShellIntegration::STATE_IS_DEFAULT) {
if (!Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean(
prefs::kSuppressSwitchToMetroModeOnSetDefault)) {
......@@ -135,7 +150,7 @@ void SetAsDefaultBrowserHandler::SetDefaultWebClientUIState(
base::Bind(&SetAsDefaultBrowserHandler::ActivateMetroChrome,
base::Unretained(this)));
} else {
ConcludeInteraction();
ConcludeInteraction(false);
}
}
}
......@@ -156,9 +171,12 @@ void SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow(
default_browser_worker_->StartSetAsDefault();
}
void SetAsDefaultBrowserHandler::ConcludeInteraction() {
void SetAsDefaultBrowserHandler::ConcludeInteraction(bool close_chrome) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
WebContents* contents = web_ui()->GetWebContents();
if (response_delegate_)
response_delegate_->SetChromeShutdownRequired(close_chrome);
if (contents) {
content::WebContentsDelegate* delegate = contents->GetDelegate();
if (delegate)
......@@ -178,31 +196,23 @@ void SetAsDefaultBrowserHandler::ActivateMetroChrome() {
sentinel_removed = first_run::RemoveSentinel();
}
if (ShellIntegration::ActivateMetroChrome()) {
// If Metro Chrome has been activated, we should close this process.
// We are restarting as metro now.
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&BrowserList::CloseAllBrowsersWithProfile,
Profile::FromWebUI(web_ui())));
} else {
// This will return false if the operation failed for any reason,
// including invocation under a Windows version earlier than 8.
// In such case we simply close the window and carry on.
if (sentinel_removed)
bool metro_chrome_activated = ShellIntegration::ActivateMetroChrome();
if (!metro_chrome_activated && sentinel_removed)
first_run::CreateSentinel();
BrowserThread::PostTask(
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&SetAsDefaultBrowserHandler::ConcludeInteraction,
base::Unretained(this)));
}
base::Unretained(this), metro_chrome_activated));
}
// A web dialog delegate implementation for when 'Make Chrome Metro' UI
// is displayed on a dialog.
class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate {
class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate,
public ResponseDelegate {
public:
SetAsDefaultBrowserDialogImpl(Profile* profile, Browser* browser);
virtual ~SetAsDefaultBrowserDialogImpl();
// Show a modal web dialog with kChromeUIMetroFlowURL page.
void ShowDialog();
......@@ -222,16 +232,31 @@ class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate {
virtual bool HandleContextMenu(
const content::ContextMenuParams& params) OVERRIDE;
// Overridden from ResponseDelegate:
virtual void SetChromeShutdownRequired(bool shutdown_chrome);
private:
Profile* profile_;
Browser* browser_;
mutable bool owns_handler_;
SetAsDefaultBrowserHandler* handler_;
bool response_is_close_chrome_;
DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserDialogImpl);
};
SetAsDefaultBrowserDialogImpl::SetAsDefaultBrowserDialogImpl(Profile* profile,
Browser* browser)
: profile_(profile), browser_(browser) {
: profile_(profile),
browser_(browser),
owns_handler_(true),
handler_(new SetAsDefaultBrowserHandler(this)),
response_is_close_chrome_(false) {
}
SetAsDefaultBrowserDialogImpl::~SetAsDefaultBrowserDialogImpl() {
if (owns_handler_)
delete handler_;
}
void SetAsDefaultBrowserDialogImpl::ShowDialog() {
......@@ -254,6 +279,8 @@ GURL SetAsDefaultBrowserDialogImpl::GetDialogContentURL() const {
void SetAsDefaultBrowserDialogImpl::GetWebUIMessageHandlers(
std::vector<WebUIMessageHandler*>* handlers) const {
handlers->push_back(handler_);
owns_handler_ = false;
}
void SetAsDefaultBrowserDialogImpl::GetDialogSize(gfx::Size* size) const {
......@@ -273,6 +300,24 @@ std::string SetAsDefaultBrowserDialogImpl::GetDialogArgs() const {
void SetAsDefaultBrowserDialogImpl::OnDialogClosed(
const std::string& json_retval) {
if (response_is_close_chrome_) {
// If Metro Chrome has been activated, we should close this process.
// We are restarting as metro now.
BrowserList::CloseAllBrowsersWithProfile(profile_);
} else {
// This will be false if the user closed the dialog without doing anything
// or if operation failed for any reason (including invocation under a
// Windows version earlier than 8).
// In such case we just carry on with a normal chrome session. However, for
// the purpose of surfacing this dialog the actual browser window had to
// remain hidden. Now it's the time to show it.
BrowserWindow* window = browser_->window();
WebContents* contents = chrome::GetActiveWebContents(browser_);
window->Show();
if (contents)
contents->GetView()->SetInitialFocus();
}
delete this;
}
......@@ -290,11 +335,15 @@ bool SetAsDefaultBrowserDialogImpl::HandleContextMenu(
return true;
}
void SetAsDefaultBrowserDialogImpl::SetChromeShutdownRequired(
bool shutdown_chrome) {
response_is_close_chrome_ = shutdown_chrome;
}
} // namespace
SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui)
: WebUIController(web_ui) {
web_ui->AddMessageHandler(new SetAsDefaultBrowserHandler());
: ui::WebDialogUI(web_ui) {
ChromeURLDataManager::AddDataSource(Profile::FromWebUI(web_ui),
CreateSetAsDefaultBrowserUIHTMLSource());
}
......
......@@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_UI_WEBUI_SET_AS_DEFAULT_BROWSER_UI_H_
#define CHROME_BROWSER_UI_WEBUI_SET_AS_DEFAULT_BROWSER_UI_H_
#include "content/public/browser/web_ui_controller.h"
#include "ui/web_dialogs/web_dialog_ui.h"
class Browser;
class Profile;
......@@ -13,7 +13,7 @@ class Profile;
// The UI used in first-run flow to prompt the user to set Chrome as the
// default Windows browser and *the browser* of Metro mode. Intended for
// Windows 8 only.
class SetAsDefaultBrowserUI : public content::WebUIController {
class SetAsDefaultBrowserUI : public ui::WebDialogUI {
public:
explicit SetAsDefaultBrowserUI(content::WebUI* web_ui);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment