OLD | NEW |
1 // Copyright (c) 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" | 7 #include "base/metrics/histogram.h" |
8 #include "chrome/browser/content_settings/permission_queue_controller.h" | 8 #include "chrome/browser/content_settings/permission_queue_controller.h" |
9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
10 #include "components/google/core/browser/google_util.h" | 10 #include "components/google/core/browser/google_util.h" |
11 #include "components/infobars/core/infobar.h" | 11 #include "components/infobars/core/infobar.h" |
12 #include "content/public/browser/navigation_details.h" | 12 #include "content/public/browser/navigation_details.h" |
13 #include "content/public/browser/navigation_entry.h" | 13 #include "content/public/browser/navigation_entry.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "grit/locale_settings.h" | 16 #include "grit/locale_settings.h" |
17 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 | 20 |
21 #if defined(OS_ANDROID) | |
22 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" | |
23 typedef GeolocationInfoBarDelegateAndroid DelegateType; | |
24 #else | |
25 typedef GeolocationInfoBarDelegate DelegateType; | |
26 #endif | |
27 | 21 |
28 namespace { | 22 namespace { |
29 | 23 |
30 enum GeolocationInfoBarDelegateEvent { | 24 enum GeolocationInfoBarDelegateEvent { |
31 // NOTE: Do not renumber these as that would confuse interpretation of | 25 // NOTE: Do not renumber these as that would confuse interpretation of |
32 // previously logged data. When making changes, also update the enum list | 26 // previously logged data. When making changes, also update the enum list |
33 // in tools/metrics/histograms/histograms.xml to keep it in sync. | 27 // in tools/metrics/histograms/histograms.xml to keep it in sync. |
34 | 28 |
35 // The bar was created. | 29 // The bar was created. |
36 GEOLOCATION_INFO_BAR_DELEGATE_EVENT_CREATE = 0, | 30 GEOLOCATION_INFO_BAR_DELEGATE_EVENT_CREATE = 0, |
(...skipping 23 matching lines...) Expand all Loading... |
60 } | 54 } |
61 | 55 |
62 } // namespace | 56 } // namespace |
63 | 57 |
64 // static | 58 // static |
65 infobars::InfoBar* GeolocationInfoBarDelegate::Create( | 59 infobars::InfoBar* GeolocationInfoBarDelegate::Create( |
66 InfoBarService* infobar_service, | 60 InfoBarService* infobar_service, |
67 PermissionQueueController* controller, | 61 PermissionQueueController* controller, |
68 const PermissionRequestID& id, | 62 const PermissionRequestID& id, |
69 const GURL& requesting_frame, | 63 const GURL& requesting_frame, |
70 const std::string& display_languages, | 64 const std::string& display_languages) { |
71 const std::string& accept_button_label) { | |
72 RecordUmaEvent(GEOLOCATION_INFO_BAR_DELEGATE_EVENT_CREATE); | 65 RecordUmaEvent(GEOLOCATION_INFO_BAR_DELEGATE_EVENT_CREATE); |
73 const content::NavigationEntry* committed_entry = | 66 const content::NavigationEntry* committed_entry = |
74 infobar_service->web_contents()->GetController().GetLastCommittedEntry(); | 67 infobar_service->web_contents()->GetController().GetLastCommittedEntry(); |
75 GeolocationInfoBarDelegate* const delegate = new DelegateType( | 68 GeolocationInfoBarDelegate* const delegate = new GeolocationInfoBarDelegate( |
76 controller, id, requesting_frame, | 69 controller, id, requesting_frame, |
77 committed_entry ? committed_entry->GetUniqueID() : 0, | 70 committed_entry ? committed_entry->GetUniqueID() : 0, |
78 display_languages, accept_button_label); | 71 display_languages); |
79 | 72 |
80 infobars::InfoBar* infobar = ConfirmInfoBarDelegate::CreateInfoBar( | 73 infobars::InfoBar* infobar = ConfirmInfoBarDelegate::CreateInfoBar( |
81 scoped_ptr<ConfirmInfoBarDelegate>(delegate)).release(); | 74 scoped_ptr<ConfirmInfoBarDelegate>(delegate)).release(); |
82 return infobar_service->AddInfoBar(scoped_ptr<infobars::InfoBar>(infobar)); | 75 return infobar_service->AddInfoBar(scoped_ptr<infobars::InfoBar>(infobar)); |
83 } | 76 } |
84 | 77 |
85 GeolocationInfoBarDelegate::GeolocationInfoBarDelegate( | 78 GeolocationInfoBarDelegate::GeolocationInfoBarDelegate( |
86 PermissionQueueController* controller, | 79 PermissionQueueController* controller, |
87 const PermissionRequestID& id, | 80 const PermissionRequestID& id, |
88 const GURL& requesting_frame, | 81 const GURL& requesting_frame, |
89 int contents_unique_id, | 82 int contents_unique_id, |
90 const std::string& display_languages, | 83 const std::string& display_languages) |
91 const std::string& accept_button_label) | |
92 : ConfirmInfoBarDelegate(), | 84 : ConfirmInfoBarDelegate(), |
93 controller_(controller), | 85 controller_(controller), |
94 id_(id), | 86 id_(id), |
95 requesting_frame_(requesting_frame.GetOrigin()), | 87 requesting_frame_(requesting_frame.GetOrigin()), |
96 contents_unique_id_(contents_unique_id), | 88 contents_unique_id_(contents_unique_id), |
97 display_languages_(display_languages), | 89 display_languages_(display_languages), |
98 user_has_interacted_(false) { | 90 user_has_interacted_(false) { |
99 } | 91 } |
100 | 92 |
101 GeolocationInfoBarDelegate::~GeolocationInfoBarDelegate() { | 93 GeolocationInfoBarDelegate::~GeolocationInfoBarDelegate() { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 148 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
157 IDS_GEOLOCATION_ALLOW_BUTTON : IDS_GEOLOCATION_DENY_BUTTON); | 149 IDS_GEOLOCATION_ALLOW_BUTTON : IDS_GEOLOCATION_DENY_BUTTON); |
158 } | 150 } |
159 | 151 |
160 bool GeolocationInfoBarDelegate::Cancel() { | 152 bool GeolocationInfoBarDelegate::Cancel() { |
161 RecordUmaEvent(GEOLOCATION_INFO_BAR_DELEGATE_EVENT_DENY); | 153 RecordUmaEvent(GEOLOCATION_INFO_BAR_DELEGATE_EVENT_DENY); |
162 set_user_has_interacted(); | 154 set_user_has_interacted(); |
163 SetPermission(true, false); | 155 SetPermission(true, false); |
164 return true; | 156 return true; |
165 } | 157 } |
OLD | NEW |