OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/passwords/manage_passwords_bubble_view.h" | 5 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
13 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" | |
13 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
15 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h" | 16 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h" |
16 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" | 17 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" |
17 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
18 #include "content/public/browser/web_contents_view.h" | 19 #include "content/public/browser/web_contents_view.h" |
19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/models/combobox_model.h" | 22 #include "ui/base/models/combobox_model.h" |
22 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 virtual int GetDefaultIndex() const OVERRIDE { return 0; } | 69 virtual int GetDefaultIndex() const OVERRIDE { return 0; } |
69 | 70 |
70 std::vector<base::string16> items_; | 71 std::vector<base::string16> items_; |
71 | 72 |
72 DISALLOW_COPY_AND_ASSIGN(SavePasswordRefusalComboboxModel); | 73 DISALLOW_COPY_AND_ASSIGN(SavePasswordRefusalComboboxModel); |
73 }; | 74 }; |
74 | 75 |
75 } // namespace | 76 } // namespace |
76 | 77 |
77 | 78 |
79 // Globals -------------------------------------------------------------------- | |
80 | |
81 namespace chrome { | |
82 | |
83 void ShowManagePasswordsBubble(content::WebContents* web_contents) { | |
84 ManagePasswordsBubbleUIController* controller = | |
85 ManagePasswordsBubbleUIController::FromWebContents(web_contents); | |
86 ManagePasswordsBubbleView::ShowBubble( | |
87 web_contents, | |
88 controller->manage_passwords_bubble_needs_showing() ? | |
89 ManagePasswordsBubbleView::AUTOMATIC : | |
90 ManagePasswordsBubbleView::USER_ACTION); | |
91 } | |
92 | |
93 } // namespace chrome | |
94 | |
95 | |
78 // ManagePasswordsBubbleView -------------------------------------------------- | 96 // ManagePasswordsBubbleView -------------------------------------------------- |
79 | 97 |
80 // static | 98 // static |
81 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 99 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
82 NULL; | 100 NULL; |
83 | 101 |
84 // static | 102 // static |
85 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, | 103 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, |
86 DisplayReason reason) { | 104 DisplayReason reason) { |
87 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 105 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 DisplayReason reason) | 152 DisplayReason reason) |
135 : ManagePasswordsBubble(web_contents, reason), | 153 : ManagePasswordsBubble(web_contents, reason), |
136 BubbleDelegateView(anchor_view, | 154 BubbleDelegateView(anchor_view, |
137 anchor_view ? views::BubbleBorder::TOP_RIGHT | 155 anchor_view ? views::BubbleBorder::TOP_RIGHT |
138 : views::BubbleBorder::NONE) { | 156 : views::BubbleBorder::NONE) { |
139 // Compensate for built-in vertical padding in the anchor view's image. | 157 // Compensate for built-in vertical padding in the anchor view's image. |
140 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 158 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
141 set_notify_enter_exit_on_child(true); | 159 set_notify_enter_exit_on_child(true); |
142 } | 160 } |
143 | 161 |
144 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {} | 162 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { |
163 // The combobox doesn't take ownership of it's model. If we created a combobox | |
vabr (Chromium)
2014/04/30 07:56:07
The explanation in the comment is very helpful.
Ho
| |
164 // we need to ensure that we delete the model here, and because the combobox | |
165 // uses the model in it's destructor, we need to make sure we delete the model | |
166 // _after_ the combobox itself is deleted. | |
167 if (refuse_combobox_) { | |
168 SavePasswordRefusalComboboxModel* model = | |
169 static_cast<SavePasswordRefusalComboboxModel*>( | |
170 refuse_combobox_->model()); | |
171 delete refuse_combobox_; | |
172 delete model; | |
173 } | |
174 } | |
145 | 175 |
146 void ManagePasswordsBubbleView::BuildColumnSet(views::GridLayout* layout, | 176 void ManagePasswordsBubbleView::BuildColumnSet(views::GridLayout* layout, |
147 ColumnSetType type) { | 177 ColumnSetType type) { |
148 views::ColumnSet* column_set = layout->AddColumnSet(type); | 178 views::ColumnSet* column_set = layout->AddColumnSet(type); |
149 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); | 179 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); |
150 switch (type) { | 180 switch (type) { |
151 case SINGLE_VIEW_COLUMN_SET: | 181 case SINGLE_VIEW_COLUMN_SET: |
152 column_set->AddColumn(views::GridLayout::FILL, | 182 column_set->AddColumn(views::GridLayout::FILL, |
153 views::GridLayout::FILL, | 183 views::GridLayout::FILL, |
154 0, | 184 0, |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 break; | 392 break; |
363 case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: | 393 case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: |
364 model()->OnNeverForThisSiteClicked(); | 394 model()->OnNeverForThisSiteClicked(); |
365 break; | 395 break; |
366 default: | 396 default: |
367 NOTREACHED(); | 397 NOTREACHED(); |
368 break; | 398 break; |
369 } | 399 } |
370 Close(); | 400 Close(); |
371 } | 401 } |
OLD | NEW |