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(error_message, |
bcwhite
2013/07/25 20:16:14
I think you should stick with multiple parameters
| |
64 toolbar_view->GetWebContents(), toolbar_view->app_menu(), | 64 string16(), |
65 error_message, string16(), start_sync, false); | 65 delegate.Pass(), |
66 anchor_view, | |
67 start_sync, | |
68 false); | |
66 break; | 69 break; |
67 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG: | 70 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG: |
68 bubble_view_ = new OneClickSigninBubbleView( | 71 bubble_view_ = new OneClickSigninBubbleView(string16(), |
69 toolbar_view->GetWebContents(), toolbar_view->location_bar(), | 72 string16(), |
70 string16(), string16(), start_sync, true); | 73 delegate.Pass(), |
74 anchor_view, | |
75 start_sync, | |
76 true); | |
71 break; | 77 break; |
72 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG: | 78 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG: |
73 bubble_view_ = new OneClickSigninBubbleView( | 79 bubble_view_ = new OneClickSigninBubbleView(string16(), |
74 toolbar_view->GetWebContents(), toolbar_view->location_bar(), | 80 email, |
75 string16(), email, start_sync, true); | 81 delegate.Pass(), |
82 anchor_view, | |
83 start_sync, | |
84 true); | |
76 break; | 85 break; |
77 } | 86 } |
78 | 87 |
79 views::BubbleDelegateView::CreateBubble(bubble_view_)->Show(); | 88 views::BubbleDelegateView::CreateBubble(bubble_view_)->Show(); |
80 } | 89 } |
81 | 90 |
82 // static | 91 // static |
83 bool OneClickSigninBubbleView::IsShowing() { | 92 bool OneClickSigninBubbleView::IsShowing() { |
84 return bubble_view_ != NULL; | 93 return bubble_view_ != NULL; |
85 } | 94 } |
86 | 95 |
87 // static | 96 // static |
88 void OneClickSigninBubbleView::Hide() { | 97 void OneClickSigninBubbleView::Hide() { |
89 if (IsShowing()) | 98 if (IsShowing()) |
90 bubble_view_->GetWidget()->Close(); | 99 bubble_view_->GetWidget()->Close(); |
91 } | 100 } |
92 | 101 |
93 OneClickSigninBubbleView::OneClickSigninBubbleView( | 102 OneClickSigninBubbleView::OneClickSigninBubbleView( |
94 content::WebContents* web_contents, | |
95 views::View* anchor_view, | |
96 const string16& error_message, | 103 const string16& error_message, |
97 const string16& email, | 104 const string16& email, |
105 scoped_ptr<OneClickSigninBubbleDelegate> delegate, | |
106 views::View* anchor_view, | |
98 const BrowserWindow::StartSyncCallback& start_sync_callback, | 107 const BrowserWindow::StartSyncCallback& start_sync_callback, |
99 bool is_sync_dialog) | 108 bool is_sync_dialog) |
100 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 109 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
101 web_contents_(web_contents), | 110 delegate_(delegate.Pass()), |
102 error_message_(error_message), | 111 error_message_(error_message), |
103 email_(email), | 112 email_(email), |
104 start_sync_callback_(start_sync_callback), | 113 start_sync_callback_(start_sync_callback), |
105 is_sync_dialog_(is_sync_dialog), | 114 is_sync_dialog_(is_sync_dialog), |
106 advanced_link_(NULL), | 115 advanced_link_(NULL), |
107 learn_more_link_(NULL), | 116 learn_more_link_(NULL), |
108 ok_button_(NULL), | 117 ok_button_(NULL), |
109 undo_button_(NULL), | 118 undo_button_(NULL), |
110 close_button_(NULL), | 119 close_button_(NULL), |
111 clicked_learn_more_(false), | 120 clicked_learn_more_(false), |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 } | 344 } |
336 | 345 |
337 void OneClickSigninBubbleView::LinkClicked(views::Link* source, | 346 void OneClickSigninBubbleView::LinkClicked(views::Link* source, |
338 int event_flags) { | 347 int event_flags) { |
339 if (source == learn_more_link_) { | 348 if (source == learn_more_link_) { |
340 if (is_sync_dialog_ && !clicked_learn_more_) { | 349 if (is_sync_dialog_ && !clicked_learn_more_) { |
341 OneClickSigninHelper::LogConfirmHistogramValue( | 350 OneClickSigninHelper::LogConfirmHistogramValue( |
342 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE); | 351 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE); |
343 clicked_learn_more_ = true; | 352 clicked_learn_more_ = true; |
344 } | 353 } |
345 | 354 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 | 355 |
354 // don't hide the modal dialog, as this is an informational link | 356 // don't hide the modal dialog, as this is an informational link |
355 if (is_sync_dialog_) | 357 if (is_sync_dialog_) |
356 return; | 358 return; |
357 } else if (advanced_link_ && source == advanced_link_) { | 359 } else if (advanced_link_ && source == advanced_link_) { |
358 if (is_sync_dialog_) { | 360 if (is_sync_dialog_) { |
359 OneClickSigninHelper::LogConfirmHistogramValue( | 361 OneClickSigninHelper::LogConfirmHistogramValue( |
360 clicked_learn_more_ ? | 362 clicked_learn_more_ ? |
361 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_ADVANCED : | 363 one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_ADVANCED : |
362 one_click_signin::HISTOGRAM_CONFIRM_ADVANCED); | 364 one_click_signin::HISTOGRAM_CONFIRM_ADVANCED); |
363 | 365 |
364 base::ResetAndReturn(&start_sync_callback_).Run( | 366 base::ResetAndReturn(&start_sync_callback_).Run( |
365 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 367 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
366 } else { | 368 } else { |
367 content::OpenURLParams params( | 369 delegate_->OnAdvancedLinkClicked(); |
368 GURL(chrome::kChromeUISettingsURL), content::Referrer(), | |
369 CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); | |
370 web_contents_->OpenURL(params); | |
371 } | 370 } |
372 } | 371 } |
373 | 372 |
374 Hide(); | 373 Hide(); |
375 } | 374 } |
376 | 375 |
377 void OneClickSigninBubbleView::ButtonPressed(views::Button* sender, | 376 void OneClickSigninBubbleView::ButtonPressed(views::Button* sender, |
378 const ui::Event& event) { | 377 const ui::Event& event) { |
379 Hide(); | 378 Hide(); |
380 | 379 |
(...skipping 27 matching lines...) Expand all Loading... | |
408 // we'll be destroyed asynchronously and the shown state will be checked | 407 // we'll be destroyed asynchronously and the shown state will be checked |
409 // before then. | 408 // before then. |
410 DCHECK_EQ(bubble_view_, this); | 409 DCHECK_EQ(bubble_view_, this); |
411 bubble_view_ = NULL; | 410 bubble_view_ = NULL; |
412 | 411 |
413 if (is_sync_dialog_ && !start_sync_callback_.is_null()) { | 412 if (is_sync_dialog_ && !start_sync_callback_.is_null()) { |
414 base::ResetAndReturn(&start_sync_callback_).Run( | 413 base::ResetAndReturn(&start_sync_callback_).Run( |
415 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | 414 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
416 } | 415 } |
417 } | 416 } |
OLD | NEW |