diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/cocoa/html_dialog_window_controller.h | 11 | ||||
-rw-r--r-- | chrome/browser/cocoa/html_dialog_window_controller.mm | 10 | ||||
-rw-r--r-- | chrome/browser/cocoa/html_dialog_window_controller_cppsafe.h | 10 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service.cc | 13 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service.h | 3 | ||||
-rw-r--r-- | chrome/browser/sync/sync_setup_flow.cc | 31 | ||||
-rw-r--r-- | chrome/browser/sync/sync_setup_flow.h | 17 | ||||
-rw-r--r-- | chrome/browser/sync/sync_setup_wizard_unittest.cc | 19 |
8 files changed, 72 insertions, 42 deletions
diff --git a/chrome/browser/cocoa/html_dialog_window_controller.h b/chrome/browser/cocoa/html_dialog_window_controller.h index c8e3884..9c871b1 100644 --- a/chrome/browser/cocoa/html_dialog_window_controller.h +++ b/chrome/browser/cocoa/html_dialog_window_controller.h @@ -29,10 +29,13 @@ class TabContents; } // Creates and shows an HtmlDialogWindowController with the given -// delegate and profile. The window is automatically destroyed when it is -// closed. -+ (void)showHtmlDialog:(HtmlDialogUIDelegate*)delegate - profile:(Profile*)profile; +// delegate and profile. The window is automatically destroyed when +// it is closed. Returns the created window. +// +// Make sure to use the returned window only when you know it is safe +// to do so, i.e. before OnDialogClosed() is called on the delegate. ++ (NSWindow*)showHtmlDialog:(HtmlDialogUIDelegate*)delegate + profile:(Profile*)profile; @end diff --git a/chrome/browser/cocoa/html_dialog_window_controller.mm b/chrome/browser/cocoa/html_dialog_window_controller.mm index f2b79ea..32b2096 100644 --- a/chrome/browser/cocoa/html_dialog_window_controller.mm +++ b/chrome/browser/cocoa/html_dialog_window_controller.mm @@ -72,8 +72,9 @@ private: namespace html_dialog_window_controller { -void ShowHtmlDialog(HtmlDialogUIDelegate* delegate, Profile* profile) { - [HtmlDialogWindowController showHtmlDialog:delegate profile:profile]; +gfx::NativeWindow ShowHtmlDialog( + HtmlDialogUIDelegate* delegate, Profile* profile) { + return [HtmlDialogWindowController showHtmlDialog:delegate profile:profile]; } } // namespace html_dialog_window_controller @@ -217,13 +218,14 @@ void HtmlDialogWindowDelegateBridge::HandleKeyboardEvent( // NOTE(akalin): We'll probably have to add the parentWindow parameter back // in once we implement modal dialogs. -+ (void)showHtmlDialog:(HtmlDialogUIDelegate*)delegate - profile:(Profile*)profile { ++ (NSWindow*)showHtmlDialog:(HtmlDialogUIDelegate*)delegate + profile:(Profile*)profile { HtmlDialogWindowController* htmlDialogWindowController = [[HtmlDialogWindowController alloc] initWithDelegate:delegate profile:profile]; [htmlDialogWindowController loadDialogContents]; [htmlDialogWindowController showWindow:nil]; + return [htmlDialogWindowController window]; } - (id)initWithDelegate:(HtmlDialogUIDelegate*)delegate diff --git a/chrome/browser/cocoa/html_dialog_window_controller_cppsafe.h b/chrome/browser/cocoa/html_dialog_window_controller_cppsafe.h index 15c4576..9bcd975 100644 --- a/chrome/browser/cocoa/html_dialog_window_controller_cppsafe.h +++ b/chrome/browser/cocoa/html_dialog_window_controller_cppsafe.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_COCOA_HTML_DIALOG_WINDOW_CONTROLLER_CPPSAFE_H_ #define CHROME_BROWSER_COCOA_HTML_DIALOG_WINDOW_CONTROLLER_CPPSAFE_H_ +#include "gfx/native_widget_types.h" + // We declare this in a separate file that is safe for including in C++ code. // TODO(akalin): It would be nice if there were a platform-agnostic way to @@ -16,8 +18,12 @@ namespace html_dialog_window_controller { // Creates and shows an HtmlDialogWindowController with the given // delegate and profile. The window is automatically destroyed when it is -// closed. -void ShowHtmlDialog(HtmlDialogUIDelegate* delegate, Profile* profile); +// closed. Returns the created window. +// +// Make sure to use the returned window only when you know it is safe +// to do so, i.e. before OnDialogClosed() is called on the delegate. +gfx::NativeWindow ShowHtmlDialog( + HtmlDialogUIDelegate* delegate, Profile* profile); } // namespace html_dialog_window_controller diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index da9c1d3..5c502a4 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -23,11 +23,6 @@ #include "chrome/browser/sync/glue/data_type_controller.h" #include "chrome/browser/sync/glue/data_type_manager.h" #include "chrome/browser/sync/profile_sync_factory.h" -#if defined(OS_WIN) -#include "chrome/browser/views/options/customize_sync_window_view.h" -#elif defined(OS_LINUX) -#include "chrome/browser/gtk/options/customize_sync_window_gtk.h" -#endif #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_service.h" @@ -449,14 +444,6 @@ string16 ProfileSyncService::GetAuthenticatedUsername() const { return backend_->GetAuthenticatedUsername(); } -void ProfileSyncService::OnUserClickedCustomize() { -#if defined(OS_WIN) - CustomizeSyncWindowView::Show(NULL, profile_); -#elif defined(OS_LINUX) - ShowCustomizeSyncWindow(profile_); -#endif -} - void ProfileSyncService::OnUserSubmittedAuth( const std::string& username, const std::string& password, const std::string& captcha) { diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index ceacc59..7777e1a 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -150,9 +150,6 @@ class ProfileSyncService : public browser_sync::SyncFrontend, virtual void OnSyncCycleCompleted(); virtual void OnAuthError(); - // Called when a user clicks the "customize" button while setting up sync. - virtual void OnUserClickedCustomize(); - // Called when a user enters credentials through UI. virtual void OnUserSubmittedAuth(const std::string& username, const std::string& password, diff --git a/chrome/browser/sync/sync_setup_flow.cc b/chrome/browser/sync/sync_setup_flow.cc index 1ccc8a3..595b3a3 100644 --- a/chrome/browser/sync/sync_setup_flow.cc +++ b/chrome/browser/sync/sync_setup_flow.cc @@ -55,9 +55,11 @@ static std::string GetJsonResponse(const Value* content) { } void FlowHandler::RegisterMessages() { -#if defined(OS_WIN) || defined(OS_LINUX) dom_ui_->RegisterMessageCallback("ShowCustomize", NewCallback(this, &FlowHandler::HandleUserClickedCustomize)); + // On OS X, the customize dialog is modal to the HTML window so we + // don't need to hook up the two functions below. +#if defined(OS_WIN) || defined(OS_LINUX) dom_ui_->RegisterMessageCallback("ClickCustomizeOk", NewCallback(this, &FlowHandler::ClickCustomizeOk)); dom_ui_->RegisterMessageCallback("ClickCustomizeCancel", @@ -177,7 +179,8 @@ SyncSetupFlow::SyncSetupFlow(SyncSetupWizard::State start_state, login_start_time_(base::TimeTicks::Now()), flow_handler_(new FlowHandler()), owns_flow_handler_(true), - service_(service) { + service_(service), + html_dialog_window_(NULL) { flow_handler_->set_flow(this); } @@ -261,11 +264,7 @@ void SyncSetupFlow::GetArgsForGaiaLogin(const ProfileSyncService* service, args->SetString(L"captchaUrl", error.captcha().image_url.spec()); -#if defined(OS_WIN) || defined(OS_LINUX) args->SetBoolean(L"showCustomize", true); -#else - args->SetBoolean(L"showCustomize", false); -#endif } void SyncSetupFlow::GetDOMMessageHandlers( @@ -338,21 +337,23 @@ SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service, SyncSetupFlow* flow = new SyncSetupFlow(start, end, json_args, container, service); +#if defined(OS_MACOSX) + // TODO(akalin): Figure out a cleaner way to do this than to have this + // gross per-OS behavior, i.e. have a cross-platform ShowHtmlDialog() + // function that is not tied to a browser instance. Note that if we do + // that, we'll have to fix sync_setup_wizard_unittest.cc as it relies on + // being able to intercept ShowHtmlDialog() calls. + flow->html_dialog_window_ = + html_dialog_window_controller::ShowHtmlDialog( + flow, service->profile()); +#else Browser* b = BrowserList::GetLastActive(); if (b) { b->BrowserShowHtmlDialog(flow, NULL); } else { - // TODO(akalin): Figure out a cleaner way to do this than to have this - // gross per-OS behavior, i.e. have a cross-platform ShowHtmlDialog() - // function that is not tied to a browser instance. Note that if we do - // that, we'll have to fix sync_setup_wizard_unittest.cc as it relies on - // being able to intercept ShowHtmlDialog() calls. -#if defined(OS_MACOSX) - html_dialog_window_controller::ShowHtmlDialog(flow, service->profile()); -#else delete flow; return NULL; -#endif } +#endif // defined(OS_MACOSX) return flow; } diff --git a/chrome/browser/sync/sync_setup_flow.h b/chrome/browser/sync/sync_setup_flow.h index 3a711a9..35ac55e 100644 --- a/chrome/browser/sync/sync_setup_flow.h +++ b/chrome/browser/sync/sync_setup_flow.h @@ -17,7 +17,10 @@ #include "chrome/browser/views/options/customize_sync_window_view.h" #elif defined(OS_LINUX) #include "chrome/browser/gtk/options/customize_sync_window_gtk.h" +#elif defined(OS_MACOSX) +#include "chrome/browser/cocoa/sync_customize_controller_cppsafe.h" #endif +#include "gfx/native_widget_types.h" #include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest_prod.h" @@ -82,7 +85,14 @@ class SyncSetupFlow : public HtmlDialogUIDelegate { } void OnUserClickedCustomize() { - service_->OnUserClickedCustomize(); +#if defined(OS_WIN) + CustomizeSyncWindowView::Show(NULL, service_->profile()); +#elif defined(OS_LINUX) + ShowCustomizeSyncWindow(service_->profile()); +#elif defined(OS_MACOSX) + DCHECK(html_dialog_window_); + ShowSyncCustomizeDialog(html_dialog_window_, service_); +#endif } void ClickCustomizeOk() { @@ -143,6 +153,11 @@ class SyncSetupFlow : public HtmlDialogUIDelegate { // We need this to write the sentinel "setup completed" pref. ProfileSyncService* service_; + // Currently used only on OS X + // TODO(akalin): Add the necessary support to the other OSes and use + // this for them. + gfx::NativeWindow html_dialog_window_; + DISALLOW_COPY_AND_ASSIGN(SyncSetupFlow); }; diff --git a/chrome/browser/sync/sync_setup_wizard_unittest.cc b/chrome/browser/sync/sync_setup_wizard_unittest.cc index 645f365..f47036a 100644 --- a/chrome/browser/sync/sync_setup_wizard_unittest.cc +++ b/chrome/browser/sync/sync_setup_wizard_unittest.cc @@ -189,7 +189,19 @@ class SyncSetupWizardTest : public BrowserWithTestWindowTest { ProfileSyncServiceForWizardTest* service_; }; +// See http://code.google.com/p/chromium/issues/detail?id=40715 for +// why we skip the below tests on OS X. We don't use DISABLED_ as we +// would have to change the corresponding FRIEND_TEST() declarations. + +#if defined(OS_MACOSX) +#define SKIP_TEST_ON_MACOSX() \ + do { LOG(WARNING) << "Test skipped on OS X"; return; } while (0) +#else +#define SKIP_TEST_ON_MACOSX() do {} while (0) +#endif + TEST_F(SyncSetupWizardTest, InitialStepLogin) { + SKIP_TEST_ON_MACOSX(); DictionaryValue dialog_args; SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); std::string json_start_args; @@ -269,6 +281,7 @@ TEST_F(SyncSetupWizardTest, InitialStepLogin) { } TEST_F(SyncSetupWizardTest, DialogCancelled) { + SKIP_TEST_ON_MACOSX(); wizard_->Step(SyncSetupWizard::GAIA_LOGIN); // Simulate the user closing the dialog. test_window_->CloseDialog(); @@ -293,6 +306,7 @@ TEST_F(SyncSetupWizardTest, DialogCancelled) { } TEST_F(SyncSetupWizardTest, InvalidTransitions) { + SKIP_TEST_ON_MACOSX(); wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); EXPECT_FALSE(wizard_->IsVisible()); EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); @@ -319,6 +333,7 @@ TEST_F(SyncSetupWizardTest, InvalidTransitions) { } TEST_F(SyncSetupWizardTest, FullSuccessfulRunSetsPref) { + SKIP_TEST_ON_MACOSX(); wizard_->Step(SyncSetupWizard::GAIA_LOGIN); wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); wizard_->Step(SyncSetupWizard::DONE); @@ -329,6 +344,7 @@ TEST_F(SyncSetupWizardTest, FullSuccessfulRunSetsPref) { } TEST_F(SyncSetupWizardTest, FirstFullSuccessfulRunSetsPref) { + SKIP_TEST_ON_MACOSX(); wizard_->Step(SyncSetupWizard::GAIA_LOGIN); wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); wizard_->Step(SyncSetupWizard::DONE_FIRST_TIME); @@ -339,6 +355,7 @@ TEST_F(SyncSetupWizardTest, FirstFullSuccessfulRunSetsPref) { } TEST_F(SyncSetupWizardTest, DiscreteRun) { + SKIP_TEST_ON_MACOSX(); DictionaryValue dialog_args; // For a discrete run, we need to have ran through setup once. wizard_->Step(SyncSetupWizard::GAIA_LOGIN); @@ -367,3 +384,5 @@ TEST_F(SyncSetupWizardTest, DiscreteRun) { wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); } + +#undef SKIP_TEST_ON_MACOSX |