OLD | NEW |
| (Empty) |
1 // Copyright 2013 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/autofill/autocheckout_bubble_controller.h" | |
6 | |
7 #include "components/autofill/core/browser/autofill_metrics.h" | |
8 #include "grit/generated_resources.h" | |
9 #include "grit/ui_resources.h" | |
10 #include "ui/base/l10n/l10n_util.h" | |
11 #include "ui/base/resource/resource_bundle.h" | |
12 #include "ui/gfx/image/image.h" | |
13 #include "ui/gfx/rect_conversions.h" | |
14 | |
15 namespace autofill { | |
16 | |
17 AutocheckoutBubbleController::AutocheckoutBubbleController( | |
18 const gfx::RectF& anchor_rect, | |
19 const gfx::NativeWindow& native_window, | |
20 bool is_google_user, | |
21 const base::Callback<void(AutocheckoutBubbleState)>& callback) | |
22 : anchor_rect_(gfx::ToEnclosingRect(anchor_rect)), | |
23 native_window_(native_window), | |
24 is_google_user_(is_google_user), | |
25 callback_(callback), | |
26 metric_logger_(new AutofillMetrics), | |
27 had_user_interaction_(false) {} | |
28 | |
29 AutocheckoutBubbleController::~AutocheckoutBubbleController() {} | |
30 | |
31 // static | |
32 base::string16 AutocheckoutBubbleController::AcceptText() { | |
33 return l10n_util::GetStringUTF16(IDS_AUTOCHECKOUT_BUBBLE_ACCEPT); | |
34 } | |
35 | |
36 // static | |
37 base::string16 AutocheckoutBubbleController::CancelText() { | |
38 return l10n_util::GetStringUTF16(IDS_AUTOCHECKOUT_BUBBLE_CANCEL); | |
39 } | |
40 | |
41 base::string16 AutocheckoutBubbleController::PromptText() { | |
42 return l10n_util::GetStringUTF16( | |
43 is_google_user_ ? IDS_AUTOCHECKOUT_BUBBLE_PROMPT_SIGNED_IN : | |
44 IDS_AUTOCHECKOUT_BUBBLE_PROMPT_NOT_SIGNED_IN); | |
45 } | |
46 | |
47 // TODO(ahutter): Change these functions back to not returning a "Buy With | |
48 // Google" button after UX has finalized the non-Google user experience. See | |
49 // http://crbug.com/253681. | |
50 gfx::Image AutocheckoutBubbleController::NormalImage() { | |
51 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
52 return rb.GetImageNamed(IDR_BUY_WITH_GOOGLE_BUTTON); | |
53 } | |
54 | |
55 gfx::Image AutocheckoutBubbleController::HoverImage() { | |
56 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
57 return rb.GetImageNamed(IDR_BUY_WITH_GOOGLE_BUTTON_H); | |
58 } | |
59 | |
60 gfx::Image AutocheckoutBubbleController::PressedImage() { | |
61 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
62 return rb.GetImageNamed(IDR_BUY_WITH_GOOGLE_BUTTON_P); | |
63 } | |
64 | |
65 void AutocheckoutBubbleController::BubbleAccepted() { | |
66 had_user_interaction_ = true; | |
67 metric_logger_->LogAutocheckoutBubbleMetric(AutofillMetrics::BUBBLE_ACCEPTED); | |
68 callback_.Run(AUTOCHECKOUT_BUBBLE_ACCEPTED); | |
69 } | |
70 | |
71 void AutocheckoutBubbleController::BubbleCanceled() { | |
72 had_user_interaction_ = true; | |
73 metric_logger_->LogAutocheckoutBubbleMetric( | |
74 AutofillMetrics::BUBBLE_DISMISSED); | |
75 callback_.Run(AUTOCHECKOUT_BUBBLE_CANCELED); | |
76 } | |
77 | |
78 void AutocheckoutBubbleController::BubbleCreated() const { | |
79 metric_logger_->LogAutocheckoutBubbleMetric(AutofillMetrics::BUBBLE_CREATED); | |
80 } | |
81 | |
82 void AutocheckoutBubbleController::BubbleDestroyed() const { | |
83 if (!had_user_interaction_) { | |
84 metric_logger_->LogAutocheckoutBubbleMetric( | |
85 AutofillMetrics::BUBBLE_IGNORED); | |
86 callback_.Run(AUTOCHECKOUT_BUBBLE_IGNORED); | |
87 } | |
88 } | |
89 | |
90 void AutocheckoutBubbleController::set_metric_logger( | |
91 AutofillMetrics* metric_logger) { | |
92 metric_logger_.reset(metric_logger); | |
93 } | |
94 | |
95 } // namespace autofill | |
OLD | NEW |