| 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/permissions/permission_infobar_delegate.h" | 5 #include "chrome/browser/permissions/permission_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "chrome/browser/permissions/permission_uma_util.h" | 7 #include "chrome/browser/permissions/permission_uma_util.h" |
| 8 #include "chrome/grit/generated_resources.h" | 8 #include "chrome/grit/generated_resources.h" |
| 9 #include "components/infobars/core/infobar.h" | 9 #include "components/infobars/core/infobar.h" |
| 10 #include "components/url_formatter/elide_url.h" | 10 #include "components/url_formatter/elide_url.h" |
| 11 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
| 12 #include "chrome/browser/permissions/permission_request.h" |
| 12 | 13 |
| 13 PermissionInfobarDelegate::~PermissionInfobarDelegate() { | 14 PermissionInfobarDelegate::~PermissionInfobarDelegate() { |
| 14 if (!action_taken_) | 15 // if (!action_taken_) |
| 15 PermissionUmaUtil::PermissionIgnored(permission_type_, requesting_origin_); | 16 // PermissionUmaUtil::PermissionIgnored(permission_type_, requesting_origin_
); |
| 17 } |
| 18 |
| 19 PermissionInfobarDelegate::PermissionInfobarDelegate(PermissionRequest* request) |
| 20 : request_(request) { |
| 16 } | 21 } |
| 17 | 22 |
| 18 PermissionInfobarDelegate::PermissionInfobarDelegate( | 23 PermissionInfobarDelegate::PermissionInfobarDelegate( |
| 19 const GURL& requesting_origin, | 24 const GURL& requesting_origin, |
| 20 content::PermissionType permission_type, | 25 content::PermissionType permission_type, |
| 21 ContentSettingsType content_settings_type, | 26 ContentSettingsType content_settings_type, |
| 22 const base::Callback<void(bool, bool)>& callback) | 27 const base::Callback<void(bool, bool)>& callback) |
| 23 : requesting_origin_(requesting_origin), | 28 : requesting_origin_(requesting_origin), |
| 24 action_taken_(false), | 29 action_taken_(false), |
| 30 // TODO: remove |
| 25 permission_type_(permission_type), | 31 permission_type_(permission_type), |
| 32 // TODO: remove |
| 26 content_settings_type_(content_settings_type), | 33 content_settings_type_(content_settings_type), |
| 27 callback_(callback) {} | 34 callback_(callback) {} |
| 28 | 35 |
| 29 base::string16 PermissionInfobarDelegate::GetMessageText() const { | 36 base::string16 PermissionInfobarDelegate::GetMessageText() const { |
| 37 // TODO: |
| 38 // return request_->GetMessageText(); |
| 30 return l10n_util::GetStringFUTF16( | 39 return l10n_util::GetStringFUTF16( |
| 31 GetMessageResourceId(), | 40 GetMessageResourceId(), |
| 32 url_formatter::FormatUrlForSecurityDisplay( | 41 url_formatter::FormatUrlForSecurityDisplay( |
| 33 requesting_origin_, | 42 requesting_origin_, |
| 34 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | 43 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); |
| 35 } | 44 } |
| 36 | 45 |
| 46 int PermissionInfobarDelegate::GetMessageResourceId() const { |
| 47 return IDS_GEOLOCATION_INFOBAR_QUESTION; |
| 48 } |
| 49 |
| 37 infobars::InfoBarDelegate::Type PermissionInfobarDelegate::GetInfoBarType() | 50 infobars::InfoBarDelegate::Type PermissionInfobarDelegate::GetInfoBarType() |
| 38 const { | 51 const { |
| 39 return PAGE_ACTION_TYPE; | 52 return PAGE_ACTION_TYPE; |
| 40 } | 53 } |
| 41 | 54 |
| 42 void PermissionInfobarDelegate::InfoBarDismissed() { | 55 void PermissionInfobarDelegate::InfoBarDismissed() { |
| 43 SetPermission(false, false); | 56 // SetPermission(false, false); |
| 57 request_->Cancelled(); |
| 44 } | 58 } |
| 45 | 59 |
| 46 PermissionInfobarDelegate* | 60 PermissionInfobarDelegate* |
| 47 PermissionInfobarDelegate::AsPermissionInfobarDelegate() { | 61 PermissionInfobarDelegate::AsPermissionInfobarDelegate() { |
| 48 return this; | 62 return this; |
| 49 } | 63 } |
| 50 | 64 |
| 51 base::string16 PermissionInfobarDelegate::GetButtonLabel( | 65 base::string16 PermissionInfobarDelegate::GetButtonLabel( |
| 52 InfoBarButton button) const { | 66 InfoBarButton button) const { |
| 53 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 67 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 54 IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY); | 68 IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY); |
| 55 } | 69 } |
| 56 | 70 |
| 57 bool PermissionInfobarDelegate::Accept() { | 71 bool PermissionInfobarDelegate::Accept() { |
| 58 SetPermission(true, true); | 72 request_->PermissionGranted(); |
| 59 return true; | 73 return true; |
| 60 } | 74 } |
| 61 | 75 |
| 62 bool PermissionInfobarDelegate::Cancel() { | 76 bool PermissionInfobarDelegate::Cancel() { |
| 63 SetPermission(true, false); | 77 request_->PermissionDenied(); |
| 64 return true; | 78 return true; |
| 65 } | 79 } |
| 66 | 80 |
| 81 infobars::InfoBarDelegate::InfoBarIdentifier |
| 82 PermissionInfobarDelegate::GetIdentifier() const { |
| 83 // TODO |
| 84 return GEOLOCATION_INFOBAR_DELEGATE_ANDROID; |
| 85 } |
| 86 |
| 87 int PermissionInfobarDelegate::GetIconId() const { |
| 88 return request_->GetIconId(); |
| 89 } |
| 90 |
| 67 void PermissionInfobarDelegate::SetPermission(bool update_content_setting, | 91 void PermissionInfobarDelegate::SetPermission(bool update_content_setting, |
| 68 bool allowed) { | 92 bool allowed) { |
| 69 action_taken_ = true; | 93 action_taken_ = true; |
| 70 callback_.Run(update_content_setting, allowed); | 94 callback_.Run(update_content_setting, allowed); |
| 71 } | 95 } |
| OLD | NEW |