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