Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / geolocation / geolocation_permission_context.cc
index ca97bfa..496b500 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -33,6 +33,7 @@ class GeolocationPermissionRequest : public PermissionBubbleRequest {
   GeolocationPermissionRequest(GeolocationPermissionContext* context,
                                const PermissionRequestID& id,
                                const GURL& requesting_frame,
+                               const GURL& embedder,
                                bool user_gesture,
                                base::Callback<void(bool)> callback,
                                const std::string& display_languages);
@@ -53,6 +54,7 @@ class GeolocationPermissionRequest : public PermissionBubbleRequest {
   GeolocationPermissionContext* context_;
   PermissionRequestID id_;
   GURL requesting_frame_;
+  GURL embedder_;
   bool user_gesture_;
   base::Callback<void(bool)> callback_;
   std::string display_languages_;
@@ -62,12 +64,14 @@ GeolocationPermissionRequest::GeolocationPermissionRequest(
     GeolocationPermissionContext* context,
     const PermissionRequestID& id,
     const GURL& requesting_frame,
+    const GURL& embedder,
     bool user_gesture,
     base::Callback<void(bool)> callback,
     const std::string& display_languages)
     : context_(context),
       id_(id),
       requesting_frame_(requesting_frame),
+      embedder_(embedder),
       user_gesture_(user_gesture),
       callback_(callback),
       display_languages_(display_languages) {}
@@ -79,8 +83,12 @@ int GeolocationPermissionRequest::GetIconID() const {
 }
 
 base::string16 GeolocationPermissionRequest::GetMessageText() const {
-  return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION,
-      net::FormatUrl(requesting_frame_, display_languages_));
+  return l10n_util::GetStringFUTF16(
+      IDS_GEOLOCATION_INFOBAR_QUESTION,
+      net::FormatUrl(requesting_frame_.GetOrigin(), display_languages_,
+                     net::kFormatUrlOmitUsernamePassword |
+                     net::kFormatUrlOmitTrailingSlashOnBareHostname,
+                     net::UnescapeRule::SPACES, NULL, NULL, NULL));
 }
 
 base::string16 GeolocationPermissionRequest::GetMessageTextFragment() const {
@@ -96,10 +104,14 @@ GURL GeolocationPermissionRequest::GetRequestingHostname() const {
 }
 
 void GeolocationPermissionRequest::PermissionGranted() {
+  context_->QueueController()->UpdateContentSetting(
+      requesting_frame_, embedder_, true);
   context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true);
 }
 
 void GeolocationPermissionRequest::PermissionDenied() {
+  context_->QueueController()->UpdateContentSetting(
+      requesting_frame_, embedder_, false);
   context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false);
 }
 
@@ -170,7 +182,7 @@ void GeolocationPermissionContext::RequestGeolocationPermission(
   }
 
   DecidePermission(web_contents, id, requesting_frame_origin, user_gesture,
-                   embedder, "", result_callback);
+                   embedder, result_callback);
 }
 
 void GeolocationPermissionContext::CancelGeolocationPermissionRequest(
@@ -192,14 +204,16 @@ void GeolocationPermissionContext::DecidePermission(
     const GURL& requesting_frame,
     bool user_gesture,
     const GURL& embedder,
-    const std::string& accept_button_label,
     base::Callback<void(bool)> callback) {
   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
 
   ContentSetting content_setting =
-     profile_->GetHostContentSettingsMap()->GetContentSetting(
-          requesting_frame, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION,
-          std::string());
+      profile_->GetHostContentSettingsMap()
+          ->GetContentSettingAndMaybeUpdateLastUsage(
+              requesting_frame,
+              embedder,
+              CONTENT_SETTINGS_TYPE_GEOLOCATION,
+              std::string());
   switch (content_setting) {
     case CONTENT_SETTING_BLOCK:
       PermissionDecided(id, requesting_frame, embedder, callback, false);
@@ -214,7 +228,7 @@ void GeolocationPermissionContext::DecidePermission(
         if (mgr) {
           scoped_ptr<GeolocationPermissionRequest> request_ptr(
               new GeolocationPermissionRequest(
-                  this, id, requesting_frame, user_gesture, callback,
+                  this, id, requesting_frame, embedder, user_gesture, callback,
                   profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)));
           GeolocationPermissionRequest* request = request_ptr.get();
           pending_requests_.add(id.ToString(), request_ptr.Pass());
@@ -223,7 +237,7 @@ void GeolocationPermissionContext::DecidePermission(
       } else {
         // setting == ask. Prompt the user.
         QueueController()->CreateInfoBarRequest(
-            id, requesting_frame, embedder, accept_button_label,
+            id, requesting_frame, embedder,
                 base::Bind(
                     &GeolocationPermissionContext::NotifyPermissionSet,
                 base::Unretained(this), id, requesting_frame, callback));
@@ -235,10 +249,9 @@ void GeolocationPermissionContext::CreateInfoBarRequest(
     const PermissionRequestID& id,
     const GURL& requesting_frame,
     const GURL& embedder,
-    const std::string accept_button_label,
     base::Callback<void(bool)> callback) {
     QueueController()->CreateInfoBarRequest(
-        id, requesting_frame, embedder, accept_button_label, base::Bind(
+        id, requesting_frame, embedder, base::Bind(
             &GeolocationPermissionContext::NotifyPermissionSet,
             base::Unretained(this), id, requesting_frame, callback));
 }