| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/website_settings/permissions_bubble_view.h" | 5 #include "chrome/browser/ui/views/website_settings/permissions_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 8 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 9 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 public views::ButtonListener { | 22 public views::ButtonListener { |
| 23 public: | 23 public: |
| 24 explicit PermissionsBubbleDelegateView( | 24 explicit PermissionsBubbleDelegateView( |
| 25 views::View* anchor, | 25 views::View* anchor, |
| 26 PermissionBubbleViewViews* owner, | 26 PermissionBubbleViewViews* owner, |
| 27 const std::vector<PermissionBubbleRequest*>& requests, | 27 const std::vector<PermissionBubbleRequest*>& requests, |
| 28 const std::vector<bool>& accept_state, | 28 const std::vector<bool>& accept_state, |
| 29 bool customization_mode); | 29 bool customization_mode); |
| 30 virtual ~PermissionsBubbleDelegateView(); | 30 virtual ~PermissionsBubbleDelegateView(); |
| 31 | 31 |
| 32 void Close(); | 32 void ResetOwner(); |
| 33 void SizeToContents(); | 33 void SizeToContents(); |
| 34 | 34 |
| 35 // BubbleDelegateView: | 35 // BubbleDelegateView: |
| 36 virtual bool ShouldShowCloseButton() const OVERRIDE; | 36 virtual bool ShouldShowCloseButton() const OVERRIDE; |
| 37 virtual bool ShouldShowWindowTitle() const OVERRIDE; | 37 virtual bool ShouldShowWindowTitle() const OVERRIDE; |
| 38 virtual base::string16 GetWindowTitle() const OVERRIDE; | 38 virtual base::string16 GetWindowTitle() const OVERRIDE; |
| 39 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; | 39 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; |
| 40 | 40 |
| 41 // ButtonListener: | 41 // ButtonListener: |
| 42 virtual void ButtonPressed(views::Button* button, | 42 virtual void ButtonPressed(views::Button* button, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 allow_ = allow_button; | 171 allow_ = allow_button; |
| 172 | 172 |
| 173 button_layout->AddPaddingRow(0, 30); | 173 button_layout->AddPaddingRow(0, 30); |
| 174 } | 174 } |
| 175 | 175 |
| 176 PermissionsBubbleDelegateView::~PermissionsBubbleDelegateView() { | 176 PermissionsBubbleDelegateView::~PermissionsBubbleDelegateView() { |
| 177 if (owner_) | 177 if (owner_) |
| 178 owner_->Closing(); | 178 owner_->Closing(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void PermissionsBubbleDelegateView::Close() { | 181 void PermissionsBubbleDelegateView::ResetOwner() { |
| 182 owner_ = NULL; | 182 owner_ = NULL; |
| 183 GetWidget()->Close(); | |
| 184 } | 183 } |
| 185 | 184 |
| 186 bool PermissionsBubbleDelegateView::ShouldShowCloseButton() const { | 185 bool PermissionsBubbleDelegateView::ShouldShowCloseButton() const { |
| 187 return true; | 186 return true; |
| 188 } | 187 } |
| 189 | 188 |
| 190 bool PermissionsBubbleDelegateView::ShouldShowWindowTitle() const { | 189 bool PermissionsBubbleDelegateView::ShouldShowWindowTitle() const { |
| 191 return true; | 190 return true; |
| 192 } | 191 } |
| 193 | 192 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 222 owner_->Deny(); | 221 owner_->Deny(); |
| 223 else if (button == customize_) | 222 else if (button == customize_) |
| 224 owner_->SetCustomizationMode(); | 223 owner_->SetCustomizationMode(); |
| 225 } | 224 } |
| 226 | 225 |
| 227 PermissionBubbleViewViews::PermissionBubbleViewViews(views::View* anchor_view) | 226 PermissionBubbleViewViews::PermissionBubbleViewViews(views::View* anchor_view) |
| 228 : anchor_view_(anchor_view), | 227 : anchor_view_(anchor_view), |
| 229 delegate_(NULL), | 228 delegate_(NULL), |
| 230 bubble_delegate_(NULL) {} | 229 bubble_delegate_(NULL) {} |
| 231 | 230 |
| 232 PermissionBubbleViewViews::~PermissionBubbleViewViews() { | 231 PermissionBubbleViewViews::~PermissionBubbleViewViews() {} |
| 233 if (delegate_) | |
| 234 delegate_->SetView(NULL); | |
| 235 } | |
| 236 | 232 |
| 237 void PermissionBubbleViewViews::SetDelegate(Delegate* delegate) { | 233 void PermissionBubbleViewViews::SetDelegate(Delegate* delegate) { |
| 238 delegate_ = delegate; | 234 delegate_ = delegate; |
| 239 } | 235 } |
| 240 | 236 |
| 241 void PermissionBubbleViewViews::Show( | 237 void PermissionBubbleViewViews::Show( |
| 242 const std::vector<PermissionBubbleRequest*>& requests, | 238 const std::vector<PermissionBubbleRequest*>& requests, |
| 243 const std::vector<bool>& values, | 239 const std::vector<bool>& values, |
| 244 bool customization_mode) { | 240 bool customization_mode) { |
| 245 if (bubble_delegate_ != NULL) | 241 if (bubble_delegate_ != NULL) { |
| 246 bubble_delegate_->Close(); | 242 bubble_delegate_->ResetOwner(); |
| 243 bubble_delegate_->StartFade(false); |
| 244 } |
| 247 | 245 |
| 248 PermissionsBubbleDelegateView* bubble_delegate = | 246 PermissionsBubbleDelegateView* bubble_delegate = |
| 249 new PermissionsBubbleDelegateView(anchor_view_, this, | 247 new PermissionsBubbleDelegateView(anchor_view_, this, |
| 250 requests, values, customization_mode); | 248 requests, values, customization_mode); |
| 251 bubble_delegate_ = bubble_delegate; | 249 bubble_delegate_ = bubble_delegate; |
| 252 views::BubbleDelegateView::CreateBubble(bubble_delegate_); | 250 views::BubbleDelegateView::CreateBubble(bubble_delegate_); |
| 253 | 251 |
| 254 bubble_delegate_->StartFade(true); | 252 bubble_delegate_->StartFade(true); |
| 255 bubble_delegate->SizeToContents(); | 253 bubble_delegate->SizeToContents(); |
| 256 } | 254 } |
| 257 | 255 |
| 258 void PermissionBubbleViewViews::Hide() { | 256 void PermissionBubbleViewViews::Hide() { |
| 259 if (bubble_delegate_) { | 257 if (bubble_delegate_) { |
| 260 bubble_delegate_->Close(); | 258 bubble_delegate_->ResetOwner(); |
| 261 bubble_delegate_ = NULL; | 259 bubble_delegate_->StartFade(false); |
| 262 } | 260 } |
| 263 } | 261 } |
| 264 | 262 |
| 265 void PermissionBubbleViewViews::Closing() { | 263 void PermissionBubbleViewViews::Closing() { |
| 266 if (bubble_delegate_) | 264 if (bubble_delegate_) |
| 267 bubble_delegate_ = NULL; | 265 bubble_delegate_ = NULL; |
| 268 if (delegate_) | 266 if (delegate_) |
| 269 delegate_->Closing(); | 267 delegate_->Closing(); |
| 270 } | 268 } |
| 271 | 269 |
| 272 void PermissionBubbleViewViews::Toggle(int index, bool value) { | 270 void PermissionBubbleViewViews::Toggle(int index, bool value) { |
| 273 if (delegate_) | 271 if (delegate_) |
| 274 delegate_->ToggleAccept(index, value); | 272 delegate_->ToggleAccept(index, value); |
| 275 } | 273 } |
| 276 | 274 |
| 277 void PermissionBubbleViewViews::Accept() { | 275 void PermissionBubbleViewViews::Accept() { |
| 278 if (delegate_) | 276 if (delegate_) |
| 279 delegate_->Accept(); | 277 delegate_->Accept(); |
| 280 } | 278 } |
| 281 | 279 |
| 282 void PermissionBubbleViewViews::Deny() { | 280 void PermissionBubbleViewViews::Deny() { |
| 283 if (delegate_) | 281 if (delegate_) |
| 284 delegate_->Deny(); | 282 delegate_->Deny(); |
| 285 } | 283 } |
| 286 | 284 |
| 287 void PermissionBubbleViewViews::SetCustomizationMode() { | 285 void PermissionBubbleViewViews::SetCustomizationMode() { |
| 288 if (delegate_) | 286 if (delegate_) |
| 289 delegate_->SetCustomizationMode(); | 287 delegate_->SetCustomizationMode(); |
| 290 } | 288 } |
| OLD | NEW |