| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_confirm_infobar_delegate.h" | 5 #include "chrome/browser/geolocation/geolocation_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "chrome/browser/api/infobars/infobar_service.h" | |
| 8 #include "chrome/browser/geolocation/geolocation_infobar_queue_controller.h" | 7 #include "chrome/browser/geolocation/geolocation_infobar_queue_controller.h" |
| 9 #include "chrome/browser/google/google_util.h" | 8 #include "chrome/browser/google/google_util.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "content/public/browser/navigation_details.h" | 10 #include "content/public/browser/navigation_details.h" |
| 11 #include "content/public/browser/navigation_entry.h" | 11 #include "content/public/browser/navigation_entry.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 14 #include "grit/locale_settings.h" | 14 #include "grit/locale_settings.h" |
| 15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 | 19 |
| 20 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
| 21 #include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate_androi
d.h" | 21 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" |
| 22 typedef GeolocationConfirmInfoBarDelegateAndroid DelegateType; | 22 typedef GeolocationInfoBarDelegateAndroid DelegateType; |
| 23 #else | 23 #else |
| 24 typedef GeolocationConfirmInfoBarDelegate DelegateType; | 24 typedef GeolocationInfoBarDelegate DelegateType; |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 | 27 |
| 28 // static | 28 // static |
| 29 InfoBarDelegate* GeolocationConfirmInfoBarDelegate::Create( | 29 InfoBarDelegate* GeolocationInfoBarDelegate::Create( |
| 30 InfoBarService* infobar_service, | 30 InfoBarService* infobar_service, |
| 31 GeolocationInfoBarQueueController* controller, | 31 GeolocationInfoBarQueueController* controller, |
| 32 const GeolocationPermissionRequestID& id, | 32 const GeolocationPermissionRequestID& id, |
| 33 const GURL& requesting_frame, | 33 const GURL& requesting_frame, |
| 34 const std::string& display_languages) { | 34 const std::string& display_languages) { |
| 35 return infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 35 return infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 36 new DelegateType(infobar_service, controller, id, requesting_frame, | 36 new DelegateType(infobar_service, controller, id, requesting_frame, |
| 37 display_languages))); | 37 display_languages))); |
| 38 } | 38 } |
| 39 | 39 |
| 40 GeolocationConfirmInfoBarDelegate::GeolocationConfirmInfoBarDelegate( | 40 GeolocationInfoBarDelegate::GeolocationInfoBarDelegate( |
| 41 InfoBarService* infobar_service, | 41 InfoBarService* infobar_service, |
| 42 GeolocationInfoBarQueueController* controller, | 42 GeolocationInfoBarQueueController* controller, |
| 43 const GeolocationPermissionRequestID& id, | 43 const GeolocationPermissionRequestID& id, |
| 44 const GURL& requesting_frame, | 44 const GURL& requesting_frame, |
| 45 const std::string& display_languages) | 45 const std::string& display_languages) |
| 46 : ConfirmInfoBarDelegate(infobar_service), | 46 : ConfirmInfoBarDelegate(infobar_service), |
| 47 controller_(controller), | 47 controller_(controller), |
| 48 id_(id), | 48 id_(id), |
| 49 requesting_frame_(requesting_frame), | 49 requesting_frame_(requesting_frame), |
| 50 display_languages_(display_languages) { | 50 display_languages_(display_languages) { |
| 51 const content::NavigationEntry* committed_entry = infobar_service-> | 51 const content::NavigationEntry* committed_entry = infobar_service-> |
| 52 GetWebContents()->GetController().GetLastCommittedEntry(); | 52 GetWebContents()->GetController().GetLastCommittedEntry(); |
| 53 contents_unique_id_ = committed_entry ? committed_entry->GetUniqueID() : 0; | 53 contents_unique_id_ = committed_entry ? committed_entry->GetUniqueID() : 0; |
| 54 } | 54 } |
| 55 | 55 |
| 56 gfx::Image* GeolocationConfirmInfoBarDelegate::GetIcon() const { | 56 gfx::Image* GeolocationInfoBarDelegate::GetIcon() const { |
| 57 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 57 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 58 IDR_GEOLOCATION_INFOBAR_ICON); | 58 IDR_GEOLOCATION_INFOBAR_ICON); |
| 59 } | 59 } |
| 60 | 60 |
| 61 InfoBarDelegate::Type | 61 InfoBarDelegate::Type GeolocationInfoBarDelegate::GetInfoBarType() const { |
| 62 GeolocationConfirmInfoBarDelegate::GetInfoBarType() const { | |
| 63 return PAGE_ACTION_TYPE; | 62 return PAGE_ACTION_TYPE; |
| 64 } | 63 } |
| 65 | 64 |
| 66 bool GeolocationConfirmInfoBarDelegate::ShouldExpireInternal( | 65 bool GeolocationInfoBarDelegate::ShouldExpireInternal( |
| 67 const content::LoadCommittedDetails& details) const { | 66 const content::LoadCommittedDetails& details) const { |
| 68 // This implementation matches InfoBarDelegate::ShouldExpireInternal(), but | 67 // This implementation matches InfoBarDelegate::ShouldExpireInternal(), but |
| 69 // uses the unique ID we set in the constructor instead of that stored in the | 68 // uses the unique ID we set in the constructor instead of that stored in the |
| 70 // base class. | 69 // base class. |
| 71 return (contents_unique_id_ != details.entry->GetUniqueID()) || | 70 return (contents_unique_id_ != details.entry->GetUniqueID()) || |
| 72 (content::PageTransitionStripQualifier( | 71 (content::PageTransitionStripQualifier( |
| 73 details.entry->GetTransitionType()) == | 72 details.entry->GetTransitionType()) == |
| 74 content::PAGE_TRANSITION_RELOAD); | 73 content::PAGE_TRANSITION_RELOAD); |
| 75 } | 74 } |
| 76 | 75 |
| 77 string16 GeolocationConfirmInfoBarDelegate::GetMessageText() const { | 76 string16 GeolocationInfoBarDelegate::GetMessageText() const { |
| 78 return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION, | 77 return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION, |
| 79 net::FormatUrl(requesting_frame_.GetOrigin(), display_languages_)); | 78 net::FormatUrl(requesting_frame_.GetOrigin(), display_languages_)); |
| 80 } | 79 } |
| 81 | 80 |
| 82 string16 GeolocationConfirmInfoBarDelegate::GetButtonLabel( | 81 string16 GeolocationInfoBarDelegate::GetButtonLabel( |
| 83 InfoBarButton button) const { | 82 InfoBarButton button) const { |
| 84 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 83 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 85 IDS_GEOLOCATION_ALLOW_BUTTON : IDS_GEOLOCATION_DENY_BUTTON); | 84 IDS_GEOLOCATION_ALLOW_BUTTON : IDS_GEOLOCATION_DENY_BUTTON); |
| 86 } | 85 } |
| 87 | 86 |
| 88 void GeolocationConfirmInfoBarDelegate::SetPermission( | 87 void GeolocationInfoBarDelegate::SetPermission(bool update_content_setting, |
| 89 bool update_content_setting, bool allowed) { | 88 bool allowed) { |
| 90 controller_->OnPermissionSet(id_, requesting_frame_, | 89 controller_->OnPermissionSet(id_, requesting_frame_, |
| 91 owner()->GetWebContents()->GetURL(), | 90 owner()->GetWebContents()->GetURL(), |
| 92 update_content_setting, allowed); | 91 update_content_setting, allowed); |
| 93 } | 92 } |
| 94 | 93 |
| 95 bool GeolocationConfirmInfoBarDelegate::Accept() { | 94 bool GeolocationInfoBarDelegate::Accept() { |
| 96 SetPermission(true, true); | 95 SetPermission(true, true); |
| 97 return true; | 96 return true; |
| 98 } | 97 } |
| 99 | 98 |
| 100 bool GeolocationConfirmInfoBarDelegate::Cancel() { | 99 bool GeolocationInfoBarDelegate::Cancel() { |
| 101 SetPermission(true, false); | 100 SetPermission(true, false); |
| 102 return true; | 101 return true; |
| 103 } | 102 } |
| 104 | 103 |
| 105 string16 GeolocationConfirmInfoBarDelegate::GetLinkText() const { | 104 string16 GeolocationInfoBarDelegate::GetLinkText() const { |
| 106 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 105 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 107 } | 106 } |
| 108 | 107 |
| 109 bool GeolocationConfirmInfoBarDelegate::LinkClicked( | 108 bool GeolocationInfoBarDelegate::LinkClicked( |
| 110 WindowOpenDisposition disposition) { | 109 WindowOpenDisposition disposition) { |
| 111 const char kGeolocationLearnMoreUrl[] = | 110 const char kGeolocationLearnMoreUrl[] = |
| 112 #if defined(OS_CHROMEOS) | 111 #if defined(OS_CHROMEOS) |
| 113 "https://www.google.com/support/chromeos/bin/answer.py?answer=142065"; | 112 "https://www.google.com/support/chromeos/bin/answer.py?answer=142065"; |
| 114 #else | 113 #else |
| 115 "https://www.google.com/support/chrome/bin/answer.py?answer=142065"; | 114 "https://www.google.com/support/chrome/bin/answer.py?answer=142065"; |
| 116 #endif | 115 #endif |
| 117 | 116 |
| 118 content::OpenURLParams params( | 117 content::OpenURLParams params( |
| 119 google_util::AppendGoogleLocaleParam(GURL(kGeolocationLearnMoreUrl)), | 118 google_util::AppendGoogleLocaleParam(GURL(kGeolocationLearnMoreUrl)), |
| 120 content::Referrer(), | 119 content::Referrer(), |
| 121 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 120 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
| 122 content::PAGE_TRANSITION_LINK, false); | 121 content::PAGE_TRANSITION_LINK, false); |
| 123 owner()->GetWebContents()->OpenURL(params); | 122 owner()->GetWebContents()->OpenURL(params); |
| 124 return false; // Do not dismiss the info bar. | 123 return false; // Do not dismiss the info bar. |
| 125 } | 124 } |
| OLD | NEW |