Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4564)

Unified Diff: chrome/browser/geolocation/chrome_geolocation_permission_context.cc

Issue 147543004: [Geolocation] Add permission bubble client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/geolocation/chrome_geolocation_permission_context.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/geolocation/chrome_geolocation_permission_context.cc
diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc
index 01e69ee839d8b4f69ad92b41f9a99e5b9ff9ece3..1aee529fbb715cc56aadf886fb4004594de41c80 100644
--- a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc
+++ b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc
@@ -9,6 +9,7 @@
#include <vector>
#include "base/bind.h"
+#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/content_settings/permission_request_id.h"
@@ -16,6 +17,9 @@
#include "chrome/browser/extensions/suggest_permission_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/tab_util.h"
+#include "chrome/browser/ui/website_settings/permission_bubble_delegate.h"
+#include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
+#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
@@ -23,10 +27,92 @@
#include "extensions/browser/process_map.h"
#include "extensions/browser/view_type_utils.h"
#include "extensions/common/extension.h"
+#include "grit/generated_resources.h"
+#include "net/base/net_util.h"
+#include "ui/base/l10n/l10n_util.h"
using extensions::APIPermission;
using extensions::ExtensionRegistry;
+class GeolocationPermissionBubbleDelegate : public PermissionBubbleDelegate {
+ public:
+ GeolocationPermissionBubbleDelegate(
+ ChromeGeolocationPermissionContext* context,
timvolodine 2014/02/05 12:26:15 indent 4 spaces
Greg Billock 2014/02/05 16:46:38 Done.
+ const PermissionRequestID& id,
+ const GURL& requesting_frame,
+ base::Callback<void(bool)> callback,
+ const std::string& display_languages);
+ virtual ~GeolocationPermissionBubbleDelegate();
+
+ // PermissionBubbleDelegate:
+ virtual base::string16 GetMessageText() const OVERRIDE;
+ virtual base::string16 GetMessageTextFragment() const OVERRIDE;
+ virtual base::string16 GetAlternateAcceptButtonText() const OVERRIDE;
+ virtual base::string16 GetAlternateDenyButtonText() const OVERRIDE;
+ virtual void PermissionGranted() OVERRIDE;
+ virtual void PermissionDenied() OVERRIDE;
+ virtual void Cancelled() OVERRIDE;
+ virtual void RequestFinished() OVERRIDE;
+
+ private:
+ ChromeGeolocationPermissionContext* context_;
+ PermissionRequestID id_;
+ GURL requesting_frame_;
+ base::Callback<void(bool)> callback_;
+ std::string display_languages_;
+};
+
+GeolocationPermissionBubbleDelegate::GeolocationPermissionBubbleDelegate(
+ ChromeGeolocationPermissionContext* context,
+ const PermissionRequestID& id,
+ const GURL& requesting_frame,
+ base::Callback<void(bool)> callback,
+ const std::string& display_languages)
+ : context_(context),
+ id_(id),
+ requesting_frame_(requesting_frame),
+ callback_(callback),
+ display_languages_(display_languages) {}
+
+GeolocationPermissionBubbleDelegate::~GeolocationPermissionBubbleDelegate() {}
+
+base::string16 GeolocationPermissionBubbleDelegate::GetMessageText() const {
+ return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION,
+ net::FormatUrl(requesting_frame_, display_languages_));
+}
+
+base::string16
+GeolocationPermissionBubbleDelegate::GetMessageTextFragment() const {
+ return l10n_util::GetStringUTF16(IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT);
+}
+
+base::string16
+GeolocationPermissionBubbleDelegate::GetAlternateAcceptButtonText() const {
+ return l10n_util::GetStringUTF16(IDS_GEOLOCATION_ALLOW_BUTTON);
+}
+
+base::string16
+GeolocationPermissionBubbleDelegate::GetAlternateDenyButtonText() const {
+ return l10n_util::GetStringUTF16(IDS_GEOLOCATION_DENY_BUTTON);
+}
+
+void GeolocationPermissionBubbleDelegate::PermissionGranted() {
+ context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true);
+}
+
+void GeolocationPermissionBubbleDelegate::PermissionDenied() {
+ context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false);
+}
+
+void GeolocationPermissionBubbleDelegate::Cancelled() {
+ context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false);
+}
+
+void GeolocationPermissionBubbleDelegate::RequestFinished() {
+ delete this;
+}
+
+
ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext(
Profile* profile)
: profile_(profile),
@@ -103,7 +189,8 @@ void ChromeGeolocationPermissionContext::RequestGeolocationPermission(
return;
}
- DecidePermission(id, requesting_frame_origin, embedder, callback);
+ DecidePermission(web_contents, id, requesting_frame_origin,
+ embedder, callback);
}
void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest(
@@ -116,6 +203,7 @@ void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest(
}
void ChromeGeolocationPermissionContext::DecidePermission(
+ content::WebContents* web_contents,
const PermissionRequestID& id,
const GURL& requesting_frame,
const GURL& embedder,
@@ -134,11 +222,20 @@ void ChromeGeolocationPermissionContext::DecidePermission(
PermissionDecided(id, requesting_frame, embedder, callback, true);
break;
default:
- // setting == ask. Prompt the user.
- QueueController()->CreateInfoBarRequest(
- id, requesting_frame, embedder, base::Bind(
- &ChromeGeolocationPermissionContext::NotifyPermissionSet,
- base::Unretained(this), id, requesting_frame, callback));
+ if (PermissionBubbleManager::Enabled()) {
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents);
+ mgr->AddPermissionBubbleDelegate(
+ new GeolocationPermissionBubbleDelegate(
+ this, id, requesting_frame, callback,
+ profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)));
+ } else {
+ // setting == ask. Prompt the user.
+ QueueController()->CreateInfoBarRequest(
+ id, requesting_frame, embedder, base::Bind(
+ &ChromeGeolocationPermissionContext::NotifyPermissionSet,
+ base::Unretained(this), id, requesting_frame, callback));
+ }
}
}
« no previous file with comments | « chrome/browser/geolocation/chrome_geolocation_permission_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698