Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/geolocation/geolocation_infobar_delegate.h" | 5 #include "chrome/browser/geolocation/geolocation_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | |
| 8 #include "chrome/browser/content_settings/permission_queue_controller.h" | 7 #include "chrome/browser/content_settings/permission_queue_controller.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 8 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "components/google/core/browser/google_util.h" | |
| 11 #include "components/infobars/core/infobar.h" | 9 #include "components/infobars/core/infobar.h" |
| 12 #include "content/public/browser/navigation_details.h" | |
| 13 #include "content/public/browser/navigation_entry.h" | 10 #include "content/public/browser/navigation_entry.h" |
| 14 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 15 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 16 #include "grit/locale_settings.h" | |
| 17 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 18 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 20 | 16 |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 enum GeolocationInfoBarDelegateEvent { | |
| 25 // NOTE: Do not renumber these as that would confuse interpretation of | |
| 26 // previously logged data. When making changes, also update the enum list | |
| 27 // in tools/metrics/histograms/histograms.xml to keep it in sync. | |
| 28 | |
| 29 // The bar was created. | |
| 30 GEOLOCATION_INFO_BAR_DELEGATE_EVENT_CREATE = 0, | |
| 31 | |
| 32 // User allowed use of geolocation. | |
| 33 GEOLOCATION_INFO_BAR_DELEGATE_EVENT_ALLOW = 1, | |
| 34 | |
| 35 // User denied use of geolocation. | |
| 36 GEOLOCATION_INFO_BAR_DELEGATE_EVENT_DENY = 2, | |
| 37 | |
| 38 // User dismissed the bar. | |
| 39 GEOLOCATION_INFO_BAR_DELEGATE_EVENT_DISMISS = 3, | |
| 40 | |
| 41 // User clicked on link. | |
| 42 DEPRECATED_GEOLOCATION_INFO_BAR_DELEGATE_EVENT_LINK_CLICK = 4, | |
| 43 | |
| 44 // User ignored the bar. | |
| 45 GEOLOCATION_INFO_BAR_DELEGATE_EVENT_IGNORED = 5, | |
| 46 | |
| 47 // NOTE: Add entries only immediately above this line. | |
| 48 GEOLOCATION_INFO_BAR_DELEGATE_EVENT_COUNT = 6 | |
| 49 }; | |
| 50 | |
| 51 void RecordUmaEvent(GeolocationInfoBarDelegateEvent event) { | |
|
Michael van Ouwerkerk
2014/08/13 10:01:10
Did you also deprecate the associated histograms?
Miguel Garcia
2014/08/13 13:18:13
Acknowledged.
| |
| 52 UMA_HISTOGRAM_ENUMERATION("Geolocation.InfoBarDelegate.Event", | |
| 53 event, GEOLOCATION_INFO_BAR_DELEGATE_EVENT_COUNT); | |
| 54 } | |
| 55 | |
| 56 } // namespace | |
| 57 | |
| 58 // static | 17 // static |
| 59 infobars::InfoBar* GeolocationInfoBarDelegate::Create( | 18 infobars::InfoBar* GeolocationInfoBarDelegate::Create( |
| 60 InfoBarService* infobar_service, | 19 InfoBarService* infobar_service, |
| 61 PermissionQueueController* controller, | 20 PermissionQueueController* controller, |
| 62 const PermissionRequestID& id, | 21 const PermissionRequestID& id, |
| 63 const GURL& requesting_frame, | 22 const GURL& requesting_frame, |
| 64 const std::string& display_languages) { | 23 const std::string& display_languages) { |
| 65 RecordUmaEvent(GEOLOCATION_INFO_BAR_DELEGATE_EVENT_CREATE); | |
| 66 const content::NavigationEntry* committed_entry = | 24 const content::NavigationEntry* committed_entry = |
| 67 infobar_service->web_contents()->GetController().GetLastCommittedEntry(); | 25 infobar_service->web_contents()->GetController().GetLastCommittedEntry(); |
| 68 GeolocationInfoBarDelegate* const delegate = new GeolocationInfoBarDelegate( | 26 GeolocationInfoBarDelegate* const delegate = new GeolocationInfoBarDelegate( |
| 69 controller, id, requesting_frame, | 27 controller, id, requesting_frame, |
| 70 committed_entry ? committed_entry->GetUniqueID() : 0, | 28 committed_entry ? committed_entry->GetUniqueID() : 0, |
| 71 display_languages); | 29 display_languages); |
| 72 | 30 |
| 73 infobars::InfoBar* infobar = ConfirmInfoBarDelegate::CreateInfoBar( | 31 infobars::InfoBar* infobar = ConfirmInfoBarDelegate::CreateInfoBar( |
| 74 scoped_ptr<ConfirmInfoBarDelegate>(delegate)).release(); | 32 scoped_ptr<ConfirmInfoBarDelegate>(delegate)).release(); |
| 75 return infobar_service->AddInfoBar(scoped_ptr<infobars::InfoBar>(infobar)); | 33 return infobar_service->AddInfoBar(scoped_ptr<infobars::InfoBar>(infobar)); |
| 76 } | 34 } |
| 77 | 35 |
| 78 GeolocationInfoBarDelegate::GeolocationInfoBarDelegate( | 36 GeolocationInfoBarDelegate::GeolocationInfoBarDelegate( |
| 79 PermissionQueueController* controller, | 37 PermissionQueueController* controller, |
| 80 const PermissionRequestID& id, | 38 const PermissionRequestID& id, |
| 81 const GURL& requesting_frame, | 39 const GURL& requesting_frame, |
| 82 int contents_unique_id, | 40 int contents_unique_id, |
| 83 const std::string& display_languages) | 41 const std::string& display_languages) |
| 84 : ConfirmInfoBarDelegate(), | 42 : PermissionInfobarDelegate(controller, id, requesting_frame, |
| 85 controller_(controller), | 43 CONTENT_SETTINGS_TYPE_GEOLOCATION), |
| 86 id_(id), | 44 requesting_frame_(requesting_frame), |
|
Michael van Ouwerkerk
2014/08/13 10:01:10
If we're not checking for origin here, we have to
Miguel Garcia
2014/08/13 13:18:13
The check is done in permission_context_base.cc al
| |
| 87 requesting_frame_(requesting_frame.GetOrigin()), | 45 display_languages_(display_languages) { |
| 88 contents_unique_id_(contents_unique_id), | |
| 89 display_languages_(display_languages), | |
| 90 user_has_interacted_(false) { | |
| 91 } | 46 } |
| 92 | 47 |
| 93 GeolocationInfoBarDelegate::~GeolocationInfoBarDelegate() { | 48 GeolocationInfoBarDelegate::~GeolocationInfoBarDelegate() { |
| 94 if (!user_has_interacted_) | |
| 95 RecordUmaEvent(GEOLOCATION_INFO_BAR_DELEGATE_EVENT_IGNORED); | |
| 96 } | |
| 97 | |
| 98 bool GeolocationInfoBarDelegate::Accept() { | |
| 99 RecordUmaEvent(GEOLOCATION_INFO_BAR_DELEGATE_EVENT_ALLOW); | |
| 100 set_user_has_interacted(); | |
| 101 SetPermission(true, true); | |
| 102 return true; | |
| 103 } | |
| 104 | |
| 105 void GeolocationInfoBarDelegate::SetPermission(bool update_content_setting, | |
| 106 bool allowed) { | |
| 107 content::WebContents* web_contents = | |
| 108 InfoBarService::WebContentsFromInfoBar(infobar()); | |
| 109 controller_->OnPermissionSet( | |
| 110 id_, requesting_frame_, | |
| 111 web_contents->GetLastCommittedURL().GetOrigin(), | |
| 112 update_content_setting, allowed); | |
| 113 } | |
| 114 | |
| 115 void GeolocationInfoBarDelegate::InfoBarDismissed() { | |
| 116 RecordUmaEvent(GEOLOCATION_INFO_BAR_DELEGATE_EVENT_DISMISS); | |
| 117 set_user_has_interacted(); | |
| 118 SetPermission(false, false); | |
| 119 } | 49 } |
| 120 | 50 |
| 121 int GeolocationInfoBarDelegate::GetIconID() const { | 51 int GeolocationInfoBarDelegate::GetIconID() const { |
| 122 return IDR_INFOBAR_GEOLOCATION; | 52 return IDR_INFOBAR_GEOLOCATION; |
| 123 } | 53 } |
| 124 | 54 |
| 125 infobars::InfoBarDelegate::Type GeolocationInfoBarDelegate::GetInfoBarType() | |
| 126 const { | |
| 127 return PAGE_ACTION_TYPE; | |
| 128 } | |
| 129 | |
| 130 bool GeolocationInfoBarDelegate::ShouldExpireInternal( | |
| 131 const NavigationDetails& details) const { | |
| 132 // This implementation matches InfoBarDelegate::ShouldExpireInternal(), but | |
| 133 // uses the unique ID we set in the constructor instead of that stored in the | |
| 134 // base class. | |
| 135 return (contents_unique_id_ != details.entry_id) || details.is_reload; | |
| 136 } | |
| 137 | |
| 138 base::string16 GeolocationInfoBarDelegate::GetMessageText() const { | 55 base::string16 GeolocationInfoBarDelegate::GetMessageText() const { |
| 139 return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION, | 56 return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION, |
| 140 net::FormatUrl(requesting_frame_, display_languages_, | 57 net::FormatUrl(requesting_frame_, display_languages_, |
| 141 net::kFormatUrlOmitUsernamePassword | | 58 net::kFormatUrlOmitUsernamePassword | |
| 142 net::kFormatUrlOmitTrailingSlashOnBareHostname, | 59 net::kFormatUrlOmitTrailingSlashOnBareHostname, |
| 143 net::UnescapeRule::SPACES, NULL, NULL, NULL)); | 60 net::UnescapeRule::SPACES, NULL, NULL, NULL)); |
| 144 } | 61 } |
| 145 | |
| 146 base::string16 GeolocationInfoBarDelegate::GetButtonLabel( | |
| 147 InfoBarButton button) const { | |
| 148 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | |
| 149 IDS_GEOLOCATION_ALLOW_BUTTON : IDS_GEOLOCATION_DENY_BUTTON); | |
| 150 } | |
| 151 | |
| 152 bool GeolocationInfoBarDelegate::Cancel() { | |
| 153 RecordUmaEvent(GEOLOCATION_INFO_BAR_DELEGATE_EVENT_DENY); | |
| 154 set_user_has_interacted(); | |
| 155 SetPermission(true, false); | |
| 156 return true; | |
| 157 } | |
| OLD | NEW |