OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/sync_promo/sync_promo_dialog.h" |
| 6 |
| 7 #include "base/message_loop.h" |
| 8 #include "chrome/browser/ui/browser_dialogs.h" |
| 9 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" |
| 10 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
| 11 #include "content/public/browser/page_navigator.h" |
| 12 #include "grit/chromium_strings.h" |
| 13 #include "grit/generated_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/gfx/size.h" |
| 16 |
| 17 SyncPromoDialog::SyncPromoDialog(Profile* profile, GURL url) |
| 18 : profile_(profile), |
| 19 spawned_browser_(NULL), |
| 20 sync_promo_was_closed_(false), |
| 21 url_(url), |
| 22 window_(NULL) { |
| 23 } |
| 24 |
| 25 SyncPromoDialog::~SyncPromoDialog() { |
| 26 } |
| 27 |
| 28 void SyncPromoDialog::ShowDialog() { |
| 29 window_ = browser::ShowHtmlDialog(NULL, profile_, NULL, this, STYLE_GENERIC); |
| 30 |
| 31 // Wait for the dialog to close. |
| 32 MessageLoop::current()->Run(); |
| 33 } |
| 34 |
| 35 ui::ModalType SyncPromoDialog::GetDialogModalType() const { |
| 36 return ui::MODAL_TYPE_SYSTEM; |
| 37 } |
| 38 |
| 39 string16 SyncPromoDialog::GetDialogTitle() const { |
| 40 return l10n_util::GetStringFUTF16( |
| 41 IDS_SYNC_PROMO_TITLE, |
| 42 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 43 } |
| 44 |
| 45 GURL SyncPromoDialog::GetDialogContentURL() const { |
| 46 return url_; |
| 47 } |
| 48 |
| 49 void SyncPromoDialog::GetWebUIMessageHandlers( |
| 50 std::vector<content::WebUIMessageHandler*>* handlers) const { |
| 51 } |
| 52 |
| 53 void SyncPromoDialog::GetDialogSize(gfx::Size* size) const { |
| 54 DCHECK(size); |
| 55 const int kDialogWidth = 500; |
| 56 const int kDialogHeight = 540; |
| 57 *size = gfx::Size(kDialogWidth, kDialogHeight); |
| 58 } |
| 59 |
| 60 std::string SyncPromoDialog::GetDialogArgs() const { |
| 61 return std::string(); |
| 62 } |
| 63 |
| 64 void SyncPromoDialog::OnDialogClosed(const std::string& json_retval) { |
| 65 MessageLoop::current()->Quit(); |
| 66 } |
| 67 |
| 68 void SyncPromoDialog::OnCloseContents(content::WebContents* source, |
| 69 bool* out_close_dialog) { |
| 70 } |
| 71 |
| 72 bool SyncPromoDialog::ShouldShowDialogTitle() const { |
| 73 return true; |
| 74 } |
| 75 |
| 76 bool SyncPromoDialog::HandleContextMenu(const ContextMenuParams& params) { |
| 77 return true; |
| 78 } |
| 79 |
| 80 bool SyncPromoDialog::HandleOpenURLFromTab( |
| 81 content::WebContents* source, |
| 82 const content::OpenURLParams& params, |
| 83 content::WebContents** out_new_contents) { |
| 84 spawned_browser_ = HtmlDialogTabContentsDelegate::StaticOpenURLFromTab( |
| 85 profile_, source, params, out_new_contents); |
| 86 // If the open URL request is for the current tab then that means the sync |
| 87 // promo page will be closed. |
| 88 sync_promo_was_closed_ = params.disposition == CURRENT_TAB; |
| 89 browser::CloseHtmlDialog(window_); |
| 90 return true; |
| 91 } |
| 92 |
| 93 bool SyncPromoDialog::HandleAddNewContents( |
| 94 content::WebContents* source, |
| 95 content::WebContents* new_contents, |
| 96 WindowOpenDisposition disposition, |
| 97 const gfx::Rect& initial_pos, |
| 98 bool user_gesture) { |
| 99 spawned_browser_ = HtmlDialogTabContentsDelegate::StaticAddNewContents( |
| 100 profile_, source, new_contents, disposition, initial_pos, user_gesture); |
| 101 browser::CloseHtmlDialog(window_); |
| 102 return true; |
| 103 } |
OLD | NEW |