| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_permission_context.h" | 5 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| 11 #include "chrome/browser/browser_list.h" | 11 #include "chrome/browser/browser_list.h" |
| 12 #include "chrome/browser/chrome_thread.h" | 12 #include "chrome/browser/chrome_thread.h" |
| 13 #include "chrome/browser/geolocation/geolocation_dispatcher_host.h" | 13 #include "chrome/browser/geolocation/geolocation_dispatcher_host.h" |
| 14 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/renderer_host/render_process_host.h" | 15 #include "chrome/browser/renderer_host/render_process_host.h" |
| 16 #include "chrome/browser/renderer_host/render_view_host.h" | 16 #include "chrome/browser/renderer_host/render_view_host.h" |
| 17 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" | 17 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" |
| 18 #include "chrome/browser/tab_contents/infobar_delegate.h" | 18 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 19 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
| 20 #include "chrome/browser/tab_contents/tab_util.h" | 20 #include "chrome/browser/tab_contents/tab_util.h" |
| 21 #include "chrome/common/json_value_serializer.h" | 21 #include "chrome/common/json_value_serializer.h" |
| 22 #include "chrome/common/render_messages.h" | 22 #include "chrome/common/render_messages.h" |
| 23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 24 #include "grit/locale_settings.h" |
| 24 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 const FilePath::CharType kGeolocationPermissionPath[] = | 29 const FilePath::CharType kGeolocationPermissionPath[] = |
| 29 FILE_PATH_LITERAL("Geolocation"); | 30 FILE_PATH_LITERAL("Geolocation"); |
| 30 | 31 |
| 31 const wchar_t kAllowedDictionaryKey[] = L"allowed"; | 32 const wchar_t kAllowedDictionaryKey[] = L"allowed"; |
| 32 | 33 |
| 33 // This is the delegate used to display the confirmation info bar. | 34 // This is the delegate used to display the confirmation info bar. |
| 34 class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { | 35 class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 35 public: | 36 public: |
| 36 GeolocationConfirmInfoBarDelegate( | 37 GeolocationConfirmInfoBarDelegate( |
| 37 TabContents* tab_contents, GeolocationPermissionContext* context, | 38 TabContents* tab_contents, GeolocationPermissionContext* context, |
| 38 int render_process_id, int render_view_id, int bridge_id, | 39 int render_process_id, int render_view_id, int bridge_id, |
| 39 const std::string& host) | 40 const std::string& host) |
| 40 : ConfirmInfoBarDelegate(tab_contents), context_(context), | 41 : ConfirmInfoBarDelegate(tab_contents), |
| 41 render_process_id_(render_process_id), render_view_id_(render_view_id), | 42 tab_contents_(tab_contents), |
| 42 bridge_id_(bridge_id), host_(host) { | 43 context_(context), |
| 44 render_process_id_(render_process_id), |
| 45 render_view_id_(render_view_id), |
| 46 bridge_id_(bridge_id), |
| 47 host_(host) { |
| 43 } | 48 } |
| 44 | 49 |
| 45 // ConfirmInfoBarDelegate | 50 // ConfirmInfoBarDelegate |
| 51 virtual void InfoBarClosed() { delete this; } |
| 46 virtual Type GetInfoBarType() { return INFO_TYPE; } | 52 virtual Type GetInfoBarType() { return INFO_TYPE; } |
| 47 virtual bool Accept() { return SetPermission(true); } | 53 virtual bool Accept() { return SetPermission(true); } |
| 48 virtual bool Cancel() { return SetPermission(false); } | 54 virtual bool Cancel() { return SetPermission(false); } |
| 49 virtual int GetButtons() const { return BUTTON_OK | BUTTON_CANCEL; } | 55 virtual int GetButtons() const { return BUTTON_OK | BUTTON_CANCEL; } |
| 50 | |
| 51 virtual std::wstring GetButtonLabel(InfoBarButton button) const { | 56 virtual std::wstring GetButtonLabel(InfoBarButton button) const { |
| 52 switch (button) { | 57 switch (button) { |
| 53 case BUTTON_OK: | 58 case BUTTON_OK: |
| 54 return l10n_util::GetString(IDS_GEOLOCATION_ALLOW_BUTTON); | 59 return l10n_util::GetString(IDS_GEOLOCATION_ALLOW_BUTTON); |
| 55 case BUTTON_CANCEL: | 60 case BUTTON_CANCEL: |
| 56 return l10n_util::GetString(IDS_GEOLOCATION_DENY_BUTTON); | 61 return l10n_util::GetString(IDS_GEOLOCATION_DENY_BUTTON); |
| 57 default: | 62 default: |
| 58 // All buttons are labeled above. | 63 // All buttons are labeled above. |
| 59 NOTREACHED() << "Bad button id " << button; | 64 NOTREACHED() << "Bad button id " << button; |
| 60 return L""; | 65 return L""; |
| 61 } | 66 } |
| 62 } | 67 } |
| 63 | |
| 64 virtual std::wstring GetMessageText() const { | 68 virtual std::wstring GetMessageText() const { |
| 65 return l10n_util::GetStringF( | 69 return l10n_util::GetStringF( |
| 66 IDS_GEOLOCATION_INFOBAR_QUESTION, UTF8ToWide(host_)); | 70 IDS_GEOLOCATION_INFOBAR_QUESTION, UTF8ToWide(host_)); |
| 67 } | 71 } |
| 68 | |
| 69 virtual SkBitmap* GetIcon() const { | 72 virtual SkBitmap* GetIcon() const { |
| 70 return ResourceBundle::GetSharedInstance().GetBitmapNamed( | 73 return ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 71 IDR_GEOLOCATION_INFOBAR_ICON); | 74 IDR_GEOLOCATION_INFOBAR_ICON); |
| 72 } | 75 } |
| 76 virtual std::wstring GetLinkText() { |
| 77 return l10n_util::GetString(IDS_LEARN_MORE); |
| 78 } |
| 79 virtual bool LinkClicked(WindowOpenDisposition disposition) { |
| 80 // Ignore the click dispostion and always open in a new top level tab. |
| 81 tab_contents_->OpenURL( |
| 82 GURL(l10n_util::GetStringUTF8(IDS_LEARN_MORE_GEOLOCATION_URL)), GURL(), |
| 83 NEW_FOREGROUND_TAB, PageTransition::LINK); |
| 84 return false; // Do not dismiss the info bar. |
| 85 } |
| 73 | 86 |
| 74 private: | 87 private: |
| 75 bool SetPermission(bool confirm) { | 88 bool SetPermission(bool confirm) { |
| 76 context_->SetPermission( | 89 context_->SetPermission( |
| 77 render_process_id_, render_view_id_, bridge_id_, host_, confirm); | 90 render_process_id_, render_view_id_, bridge_id_, host_, confirm); |
| 78 return true; | 91 return true; |
| 79 } | 92 } |
| 80 | 93 |
| 94 TabContents* tab_contents_; |
| 81 scoped_refptr<GeolocationPermissionContext> context_; | 95 scoped_refptr<GeolocationPermissionContext> context_; |
| 82 int render_process_id_; | 96 int render_process_id_; |
| 83 int render_view_id_; | 97 int render_view_id_; |
| 84 int bridge_id_; | 98 int bridge_id_; |
| 85 std::string host_; | 99 std::string host_; |
| 100 |
| 101 DISALLOW_IMPLICIT_CONSTRUCTORS(GeolocationConfirmInfoBarDelegate); |
| 86 }; | 102 }; |
| 87 | 103 |
| 88 // TODO(bulach): use HostContentSettingsMap instead! | 104 // TODO(bulach): use HostContentSettingsMap instead! |
| 89 FilePath::StringType StdStringToFilePathString(const std::string& std_string) { | 105 FilePath::StringType StdStringToFilePathString(const std::string& std_string) { |
| 90 #if defined(OS_WIN) | 106 #if defined(OS_WIN) |
| 91 return UTF8ToWide(std_string); | 107 return UTF8ToWide(std_string); |
| 92 #else | 108 #else |
| 93 return std_string; | 109 return std_string; |
| 94 #endif | 110 #endif |
| 95 } | 111 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 293 } |
| 278 | 294 |
| 279 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 295 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 280 | 296 |
| 281 // TODO(bulach): should we save a file per host or have some smarter | 297 // TODO(bulach): should we save a file per host or have some smarter |
| 282 // storage? Use HostContentSettingsMap instead. | 298 // storage? Use HostContentSettingsMap instead. |
| 283 #if 0 | 299 #if 0 |
| 284 SavePermissionToFile(host, permissions_path_, allowed); | 300 SavePermissionToFile(host, permissions_path_, allowed); |
| 285 #endif | 301 #endif |
| 286 } | 302 } |
| OLD | NEW |