Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/devtools/global_confirm_info_bar.h" | 5 #include "chrome/browser/devtools/global_confirm_info_bar.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "components/infobars/core/infobar.h" | 13 #include "components/infobars/core/infobar.h" |
| 14 #include "ui/gfx/image/image.h" | 14 #include "ui/gfx/image/image.h" |
| 15 #include "ui/gfx/vector_icons_public.h" | |
| 15 | 16 |
| 16 // InfoBarDelegateProxy ------------------------------------------------------- | 17 // InfoBarDelegateProxy ------------------------------------------------------- |
| 17 | 18 |
| 18 class GlobalConfirmInfoBar::DelegateProxy : public ConfirmInfoBarDelegate { | 19 class GlobalConfirmInfoBar::DelegateProxy : public ConfirmInfoBarDelegate { |
| 19 public: | 20 public: |
| 20 explicit DelegateProxy(base::WeakPtr<GlobalConfirmInfoBar> global_info_bar); | 21 explicit DelegateProxy(base::WeakPtr<GlobalConfirmInfoBar> global_info_bar); |
| 21 ~DelegateProxy() override; | 22 ~DelegateProxy() override; |
| 22 void Detach(); | 23 void Detach(); |
| 23 | 24 |
| 24 private: | 25 private: |
| 25 friend class GlobalConfirmInfoBar; | 26 friend class GlobalConfirmInfoBar; |
| 26 | 27 |
| 27 // ConfirmInfoBarDelegate overrides | 28 // ConfirmInfoBarDelegate overrides |
| 28 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; | 29 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; |
| 29 base::string16 GetMessageText() const override; | 30 base::string16 GetMessageText() const override; |
| 30 int GetButtons() const override; | 31 int GetButtons() const override; |
| 31 base::string16 GetButtonLabel(InfoBarButton button) const override; | 32 base::string16 GetButtonLabel(InfoBarButton button) const override; |
| 32 bool Accept() override; | 33 bool Accept() override; |
| 33 bool Cancel() override; | 34 bool Cancel() override; |
| 34 base::string16 GetLinkText() const override; | 35 base::string16 GetLinkText() const override; |
| 35 GURL GetLinkURL() const override; | 36 GURL GetLinkURL() const override; |
| 36 bool LinkClicked(WindowOpenDisposition disposition) override; | 37 bool LinkClicked(WindowOpenDisposition disposition) override; |
| 37 bool EqualsDelegate(infobars::InfoBarDelegate* delegate) const override; | 38 bool EqualsDelegate(infobars::InfoBarDelegate* delegate) const override; |
| 38 void InfoBarDismissed() override; | 39 void InfoBarDismissed() override; |
| 40 infobars::InfoBarDelegate::Type GetInfoBarType() const override; | |
| 41 gfx::VectorIconId GetVectorIconId() const override; | |
|
Peter Kasting
2017/02/08 08:23:44
Nit: These last two go just above and just below G
| |
| 42 | |
| 43 void set_infobar(infobars::InfoBar* info_bar) { | |
| 44 info_bar_ = info_bar; | |
| 45 if (global_info_bar_) | |
| 46 global_info_bar_->delegate_->set_infobar(info_bar_); | |
|
Peter Kasting
2017/02/08 08:23:44
I'm worried about this.
It seems like |global_inf
| |
| 47 } | |
| 39 | 48 |
| 40 infobars::InfoBar* info_bar_; | 49 infobars::InfoBar* info_bar_; |
| 41 base::WeakPtr<GlobalConfirmInfoBar> global_info_bar_; | 50 base::WeakPtr<GlobalConfirmInfoBar> global_info_bar_; |
| 42 | 51 |
| 43 DISALLOW_COPY_AND_ASSIGN(DelegateProxy); | 52 DISALLOW_COPY_AND_ASSIGN(DelegateProxy); |
| 44 }; | 53 }; |
| 45 | 54 |
| 46 GlobalConfirmInfoBar::DelegateProxy::DelegateProxy( | 55 GlobalConfirmInfoBar::DelegateProxy::DelegateProxy( |
| 47 base::WeakPtr<GlobalConfirmInfoBar> global_info_bar) | 56 base::WeakPtr<GlobalConfirmInfoBar> global_info_bar) |
| 48 : info_bar_(nullptr), | 57 : info_bar_(nullptr), |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 | 126 |
| 118 void GlobalConfirmInfoBar::DelegateProxy::InfoBarDismissed() { | 127 void GlobalConfirmInfoBar::DelegateProxy::InfoBarDismissed() { |
| 119 base::WeakPtr<GlobalConfirmInfoBar> info_bar = global_info_bar_; | 128 base::WeakPtr<GlobalConfirmInfoBar> info_bar = global_info_bar_; |
| 120 if (info_bar) | 129 if (info_bar) |
| 121 info_bar->delegate_->InfoBarDismissed(); | 130 info_bar->delegate_->InfoBarDismissed(); |
| 122 // Could be destroyed after this point. | 131 // Could be destroyed after this point. |
| 123 if (info_bar) | 132 if (info_bar) |
| 124 info_bar->Close(); | 133 info_bar->Close(); |
| 125 } | 134 } |
| 126 | 135 |
| 136 infobars::InfoBarDelegate::Type | |
| 137 GlobalConfirmInfoBar::DelegateProxy::GetInfoBarType() const { | |
| 138 return global_info_bar_ ? global_info_bar_->delegate_->GetInfoBarType() | |
| 139 : WARNING_TYPE; | |
|
Peter Kasting
2017/02/08 08:23:44
Nit: Don't hardcode the fallback type; use Confirm
| |
| 140 } | |
| 141 | |
| 142 gfx::VectorIconId GlobalConfirmInfoBar::DelegateProxy::GetVectorIconId() const { | |
| 143 return global_info_bar_ ? global_info_bar_->delegate_->GetVectorIconId() | |
| 144 : gfx::VectorIconId::VECTOR_ICON_NONE; | |
|
Peter Kasting
2017/02/08 08:23:44
Nit: Same comment
| |
| 145 } | |
| 146 | |
| 127 void GlobalConfirmInfoBar::DelegateProxy::Detach() { | 147 void GlobalConfirmInfoBar::DelegateProxy::Detach() { |
| 128 global_info_bar_.reset(); | 148 global_info_bar_.reset(); |
| 129 } | 149 } |
| 130 | 150 |
| 131 // GlobalConfirmInfoBar ------------------------------------------------------- | 151 // GlobalConfirmInfoBar ------------------------------------------------------- |
| 132 | 152 |
| 133 // static | 153 // static |
| 134 base::WeakPtr<GlobalConfirmInfoBar> GlobalConfirmInfoBar::Show( | 154 base::WeakPtr<GlobalConfirmInfoBar> GlobalConfirmInfoBar::Show( |
| 135 std::unique_ptr<ConfirmInfoBarDelegate> delegate) { | 155 std::unique_ptr<ConfirmInfoBarDelegate> delegate) { |
| 136 GlobalConfirmInfoBar* info_bar = | 156 GlobalConfirmInfoBar* info_bar = |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 DCHECK(infobar_service); | 218 DCHECK(infobar_service); |
| 199 if (ContainsKey(proxies_, infobar_service)) | 219 if (ContainsKey(proxies_, infobar_service)) |
| 200 return; | 220 return; |
| 201 | 221 |
| 202 std::unique_ptr<GlobalConfirmInfoBar::DelegateProxy> proxy( | 222 std::unique_ptr<GlobalConfirmInfoBar::DelegateProxy> proxy( |
| 203 new GlobalConfirmInfoBar::DelegateProxy(weak_factory_.GetWeakPtr())); | 223 new GlobalConfirmInfoBar::DelegateProxy(weak_factory_.GetWeakPtr())); |
| 204 GlobalConfirmInfoBar::DelegateProxy* proxy_ptr = proxy.get(); | 224 GlobalConfirmInfoBar::DelegateProxy* proxy_ptr = proxy.get(); |
| 205 infobars::InfoBar* added_bar = infobar_service->AddInfoBar( | 225 infobars::InfoBar* added_bar = infobar_service->AddInfoBar( |
| 206 infobar_service->CreateConfirmInfoBar(std::move(proxy))); | 226 infobar_service->CreateConfirmInfoBar(std::move(proxy))); |
| 207 | 227 |
| 208 proxy_ptr->info_bar_ = added_bar; | 228 proxy_ptr->set_infobar(added_bar); |
| 209 DCHECK(added_bar); | 229 DCHECK(added_bar); |
|
Peter Kasting
2017/02/08 08:23:44
This DCHECK is unsafe; we can't guarantee |added_b
| |
| 210 proxies_[infobar_service] = proxy_ptr; | 230 proxies_[infobar_service] = proxy_ptr; |
| 211 infobar_service->AddObserver(this); | 231 infobar_service->AddObserver(this); |
| 212 } | 232 } |
| OLD | NEW |