| OLD | NEW |
| 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/views/sync/one_click_signin_bubble_view.h" | 5 #include "chrome/browser/ui/views/sync/one_click_signin_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "chrome/browser/google/google_util.h" | 10 #include "chrome/browser/google/google_util.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 12 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
| 13 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 13 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
| 14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 15 #include "content/public/browser/web_contents.h" | |
| 16 #include "grit/chromium_strings.h" | 15 #include "grit/chromium_strings.h" |
| 17 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 18 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 19 #include "grit/ui_resources.h" | 18 #include "grit/ui_resources.h" |
| 20 #include "ui/base/keycodes/keyboard_codes.h" | 19 #include "ui/base/keycodes/keyboard_codes.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/views/controls/button/image_button.h" | 22 #include "ui/views/controls/button/image_button.h" |
| 24 #include "ui/views/controls/button/label_button.h" | 23 #include "ui/views/controls/button/label_button.h" |
| 25 #include "ui/views/controls/image_view.h" | 24 #include "ui/views/controls/image_view.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 46 } // namespace | 45 } // namespace |
| 47 | 46 |
| 48 // static | 47 // static |
| 49 OneClickSigninBubbleView* OneClickSigninBubbleView::bubble_view_ = NULL; | 48 OneClickSigninBubbleView* OneClickSigninBubbleView::bubble_view_ = NULL; |
| 50 | 49 |
| 51 // static | 50 // static |
| 52 void OneClickSigninBubbleView::ShowBubble( | 51 void OneClickSigninBubbleView::ShowBubble( |
| 53 BrowserWindow::OneClickSigninBubbleType type, | 52 BrowserWindow::OneClickSigninBubbleType type, |
| 54 const string16& email, | 53 const string16& email, |
| 55 const string16& error_message, | 54 const string16& error_message, |
| 56 ToolbarView* toolbar_view, | 55 scoped_ptr<OneClickSigninBubbleDelegate> delegate, |
| 56 views::View* anchor_view, |
| 57 const BrowserWindow::StartSyncCallback& start_sync) { | 57 const BrowserWindow::StartSyncCallback& start_sync) { |
| 58 if (IsShowing()) | 58 if (IsShowing()) |
| 59 return; | 59 return; |
| 60 | 60 |
| 61 switch (type) { | 61 switch (type) { |
| 62 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE: | 62 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE: |
| 63 bubble_view_ = new OneClickSigninBubbleView( | 63 bubble_view_ = new OneClickSigninBubbleView( |
| 64 toolbar_view->GetWebContents(), toolbar_view->app_menu(), | 64 error_message, string16(), delegate.Pass(), |
| 65 error_message, string16(), start_sync, false); | 65 anchor_view, start_sync, false); |
| 66 break; | 66 break; |
| 67 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG: | 67 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG: |
| 68 bubble_view_ = new OneClickSigninBubbleView( | 68 bubble_view_ = new OneClickSigninBubbleView( |
| 69 toolbar_view->GetWebContents(), toolbar_view->location_bar(), | 69 string16(), string16(), delegate.Pass(), |
| 70 string16(), string16(), start_sync, true); | 70 anchor_view, start_sync, true); |
| 71 break; | 71 break; |
| 72 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG: | 72 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG: |
| 73 bubble_view_ = new OneClickSigninBubbleView( | 73 bubble_view_ = new OneClickSigninBubbleView( |
| 74 toolbar_view->GetWebContents(), toolbar_view->location_bar(), | 74 string16(), email, delegate.Pass(), |
| 75 string16(), email, start_sync, true); | 75 anchor_view, start_sync, true); |
| 76 break; | 76 break; |
| 77 } | 77 } |
| 78 | 78 |
| 79 views::BubbleDelegateView::CreateBubble(bubble_view_)->Show(); | 79 views::BubbleDelegateView::CreateBubble(bubble_view_)->Show(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // static | 82 // static |
| 83 bool OneClickSigninBubbleView::IsShowing() { | 83 bool OneClickSigninBubbleView::IsShowing() { |
| 84 return bubble_view_ != NULL; | 84 return bubble_view_ != NULL; |
| 85 } | 85 } |
| 86 | 86 |
| 87 // static | 87 // static |
| 88 void OneClickSigninBubbleView::Hide() { | 88 void OneClickSigninBubbleView::Hide() { |
| 89 if (IsShowing()) | 89 if (IsShowing()) |
| 90 bubble_view_->GetWidget()->Close(); | 90 bubble_view_->GetWidget()->Close(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 OneClickSigninBubbleView::OneClickSigninBubbleView( | 93 OneClickSigninBubbleView::OneClickSigninBubbleView( |
| 94 content::WebContents* web_contents, | |
| 95 views::View* anchor_view, | |
| 96 const string16& error_message, | 94 const string16& error_message, |
| 97 const string16& email, | 95 const string16& email, |
| 96 scoped_ptr<OneClickSigninBubbleDelegate> delegate, |
| 97 views::View* anchor_view, |
| 98 const BrowserWindow::StartSyncCallback& start_sync_callback, | 98 const BrowserWindow::StartSyncCallback& start_sync_callback, |
| 99 bool is_sync_dialog) | 99 bool is_sync_dialog) |
| 100 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 100 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| 101 web_contents_(web_contents), | 101 delegate_(delegate.Pass()), |
| 102 error_message_(error_message), | 102 error_message_(error_message), |
| 103 email_(email), | 103 email_(email), |
| 104 start_sync_callback_(start_sync_callback), | 104 start_sync_callback_(start_sync_callback), |
| 105 is_sync_dialog_(is_sync_dialog), | 105 is_sync_dialog_(is_sync_dialog), |
| 106 advanced_link_(NULL), | 106 advanced_link_(NULL), |
| 107 learn_more_link_(NULL), | 107 learn_more_link_(NULL), |
| 108 ok_button_(NULL), | 108 ok_button_(NULL), |
| 109 undo_button_(NULL), | 109 undo_button_(NULL), |
| 110 close_button_(NULL), | 110 close_button_(NULL), |
| 111 clicked_learn_more_(false), | 111 clicked_learn_more_(false), |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 } | 335 } |
| 336 | 336 |
| 337 void OneClickSigninBubbleView::LinkClicked(views::Link* source, | 337 void OneClickSigninBubbleView::LinkClicked(views::Link* source, |
| 338 int event_flags) { | 338 int event_flags) { |
| 339 if (source == learn_more_link_) { | 339 if (source == learn_more_link_) { |
| 340 if (is_sync_dialog_ && !clicked_learn_more_) { | 340 if (is_sync_dialog_ && !clicked_learn_more_) { |
| 341 OneClickSigninHelper::LogConfirmHistogramValue( | 341 OneClickSigninHelper::LogConfirmHistogramValue( |
| 342 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE); | 342 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE); |
| 343 clicked_learn_more_ = true; | 343 clicked_learn_more_ = true; |
| 344 } | 344 } |
| 345 | 345 delegate_->OnLearnMoreLinkClicked(is_sync_dialog_); |
| 346 WindowOpenDisposition location = | |
| 347 is_sync_dialog_ ? NEW_WINDOW : NEW_FOREGROUND_TAB; | |
| 348 | |
| 349 content::OpenURLParams params( | |
| 350 GURL(chrome::kChromeSyncLearnMoreURL), content::Referrer(), | |
| 351 location, content::PAGE_TRANSITION_LINK, false); | |
| 352 web_contents_->OpenURL(params); | |
| 353 | 346 |
| 354 // don't hide the modal dialog, as this is an informational link | 347 // don't hide the modal dialog, as this is an informational link |
| 355 if (is_sync_dialog_) | 348 if (is_sync_dialog_) |
| 356 return; | 349 return; |
| 357 } else if (advanced_link_ && source == advanced_link_) { | 350 } else if (advanced_link_ && source == advanced_link_) { |
| 358 if (is_sync_dialog_) { | 351 if (is_sync_dialog_) { |
| 359 OneClickSigninHelper::LogConfirmHistogramValue( | 352 OneClickSigninHelper::LogConfirmHistogramValue( |
| 360 clicked_learn_more_ ? | 353 clicked_learn_more_ ? |
| 361 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_ADVANCED : | 354 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_ADVANCED : |
| 362 one_click_signin::HISTOGRAM_CONFIRM_ADVANCED); | 355 one_click_signin::HISTOGRAM_CONFIRM_ADVANCED); |
| 363 | 356 |
| 364 base::ResetAndReturn(&start_sync_callback_).Run( | 357 base::ResetAndReturn(&start_sync_callback_).Run( |
| 365 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 358 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
| 366 } else { | 359 } else { |
| 367 content::OpenURLParams params( | 360 delegate_->OnAdvancedLinkClicked(); |
| 368 GURL(chrome::kChromeUISettingsURL), content::Referrer(), | |
| 369 CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); | |
| 370 web_contents_->OpenURL(params); | |
| 371 } | 361 } |
| 372 } | 362 } |
| 373 | 363 |
| 374 Hide(); | 364 Hide(); |
| 375 } | 365 } |
| 376 | 366 |
| 377 void OneClickSigninBubbleView::ButtonPressed(views::Button* sender, | 367 void OneClickSigninBubbleView::ButtonPressed(views::Button* sender, |
| 378 const ui::Event& event) { | 368 const ui::Event& event) { |
| 379 Hide(); | 369 Hide(); |
| 380 | 370 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 408 // we'll be destroyed asynchronously and the shown state will be checked | 398 // we'll be destroyed asynchronously and the shown state will be checked |
| 409 // before then. | 399 // before then. |
| 410 DCHECK_EQ(bubble_view_, this); | 400 DCHECK_EQ(bubble_view_, this); |
| 411 bubble_view_ = NULL; | 401 bubble_view_ = NULL; |
| 412 | 402 |
| 413 if (is_sync_dialog_ && !start_sync_callback_.is_null()) { | 403 if (is_sync_dialog_ && !start_sync_callback_.is_null()) { |
| 414 base::ResetAndReturn(&start_sync_callback_).Run( | 404 base::ResetAndReturn(&start_sync_callback_).Run( |
| 415 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | 405 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
| 416 } | 406 } |
| 417 } | 407 } |
| OLD | NEW |