Override requestPermission to make connection to EWK API for geolocation
authordayoung.shin <dayoung.shin@samsung.com>
Fri, 28 Nov 2014 16:40:19 +0000 (11:40 -0500)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
On M40, there are several changes regarding get permission from users
for HTML5's Geolocation feature. These set of changes cut the flow to
enter EWK API for Geolocation, so the feature failed to be used.
This patch fix the bug by doing following things.

  - Override requestPermission function to call
    GeolocationPermissionContextEfl's RequestPermission.
    It's callback connect to EWK API, so that the EWK API can ask user
    to use or not Geolocation feature.

  - Add privilege regarding location. This makes Geolocation feature can
    work on Tizen device.

* NOTE *
* Geolocation would work after applying following patch.
* http://165.213.202.130:8080/#/c/72765
*
* This patch is based on following patches.
* http://165.213.202.130:8080/#/c/72692/
* http://165.213.202.130:8080/#/c/71158/

Bug : http://107.108.218.239/bugzilla/show_bug.cgi?id=8610
Reviewed by: Antonio Gomes, SeungSeop Park

Change-Id: I013ae646577885ffc798c7eec5ad48c54ff9121f
Signed-off-by: dayoung.shin <dayoung.shin@samsung.com>
tizen_src/ewk/efl_webview_app/chromium-efl.xml
tizen_src/impl/browser/geolocation/geolocation_permission_context_efl.cc
tizen_src/impl/browser/geolocation/geolocation_permission_context_efl.h
tizen_src/impl/browser_context_efl.cc
tizen_src/impl/browser_context_efl.h
tizen_src/impl/chromium-efl.gyp
tizen_src/impl/content_browser_client_efl.cc
tizen_src/impl/content_browser_client_efl.h

index 89e2c19eb04692834d2f150e46e19345742b6328..f800904aa38f05f8408f565684ed455551e95d23 100644 (file)
@@ -8,4 +8,9 @@
         <label>Chromium-efl MiniBrowser</label>
         <label xml:lang="en-us">Chromium-efl MiniBrowser</label>
     </ui-application>
+    <privileges>
+      <privilege>http://tizen.org/privilege/location</privilege>
+      <privilege>http://tizen.org/privilege/internet</privilege>
+      <privilege>http://tizen.org/privilege/network.get</privilege>
+    </privileges>
 </manifest>
index ad628456ac197902804672587f0183eb60956b1e..07f54eb3328d69dabf51969b8584c68b3071c65f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2013 Samsung Electronics. All rights reserved.
+// Copyright 2014 Samsung Electronics. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -15,12 +15,16 @@ using web_contents_utils::WebContentsFromViewID;
 
 namespace content {
 
-void GeolocationPermissionContextEfl::RequestGeolocationPermissionOnUIThread(int render_process_id,
-                                                                             int render_view_id,
-                                                                             int /*bridge_id*/,
-                                                                             const GURL& requesting_frame,
-                                                                             base::Callback<void(bool)> callback) {
-  CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+GeolocationPermissionContextEfl::GeolocationPermissionContextEfl()
+    : weak_ptr_factory_(this) {
+}
+
+void GeolocationPermissionContextEfl::RequestPermissionOnUIThread(
+    int render_process_id,
+    int render_view_id,
+    const GURL& requesting_frame,
+    base::Callback<void(bool)> callback) const {
+  DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
   WebContents* web_contents = WebContentsFromViewID(render_process_id, render_view_id);
   if (!web_contents)
     return;
@@ -75,28 +79,31 @@ void GeolocationPermissionContextEfl::RequestGeolocationPermissionOnUIThread(int
   callback.Run(false);
 }
 
-void GeolocationPermissionContextEfl::RequestGeolocationPermission(int render_process_id,
-                                                                   int render_view_id,
-                                                                   int bridge_id,
-                                                                   const GURL& requesting_frame,
-                                                                   base::Callback<void(bool)> callback) {
-  content::BrowserThread::PostTask(content::BrowserThread::UI,
-                                   FROM_HERE,
-                                   base::Bind(&GeolocationPermissionContextEfl::RequestGeolocationPermissionOnUIThread,
-                                              base::Unretained(this),
-                                              render_process_id,
-                                              render_view_id,
-                                              bridge_id,
-                                              requesting_frame,
-                                              callback));
+void GeolocationPermissionContextEfl::RequestPermission(
+    int render_process_id,
+    int render_view_id,
+    const GURL& requesting_frame,
+    base::Callback<void(bool)> callback) const {
+  content::BrowserThread::PostTask(
+      content::BrowserThread::UI,
+      FROM_HERE,
+      base::Bind(
+          &GeolocationPermissionContextEfl::RequestPermissionOnUIThread,
+          weak_ptr_factory_.GetWeakPtr(),
+          render_process_id,
+          render_view_id,
+          requesting_frame,
+          callback));
 }
 
-void GeolocationPermissionContextEfl::CancelGeolocationPermissionRequest(int /*render_process_id*/,
-                                                                         int /*render_view_id*/,
-                                                                         int /*bridge_id*/,
-                                                                         const GURL& /*requesting_frame*/) {
-  // There is currently no mechanism to inform the application that a permission request should be canceled.
+void GeolocationPermissionContextEfl::CancelPermissionRequest(
+    int /*render_process_id*/,
+    int /*render_view_id*/,
+    int /*bridge_id*/,
+    const GURL& /*requesting_frame*/) const {
+  // There is currently no mechanism to inform the application
+  // that a permission request should be canceled.
   // To be implemented in the future.
 }
 
-}//namespace
+}  // namespace content
index d01612641d30b14358d9b451ae427be4991e046d..f5d07c88879e395b8ce09ac76233c67b07d559c9 100644 (file)
@@ -1,28 +1,45 @@
-// Copyright 2013 Samsung Electronics. All rights reserved.
+// Copyright 2014 Samsung Electronics. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 #ifndef GEOLOCATION_PERMISSION_CONTEXT_EFL_H
 #define GEOLOCATION_PERMISSION_CONTEXT_EFL_H
 
-#include "content/public/browser/geolocation_permission_context.h"
+#include "base/callback.h"
+#include "base/memory/weak_ptr.h"
 
-namespace content {
-
-class BrowserContext;
-
-class GeolocationPermissionContextEfl : public GeolocationPermissionContext {
-public:
-    GeolocationPermissionContextEfl() { }
+class GURL;
 
-    virtual void RequestGeolocationPermission(int, int, int, const GURL&, base::Callback<void(bool)>) override;
-
-    // The renderer is cancelling a pending permission request.
-    virtual void CancelGeolocationPermissionRequest(int, int, int, const GURL&) override;
+namespace content {
 
-private:
-    void RequestGeolocationPermissionOnUIThread(int, int, int, const GURL&, base::Callback<void(bool)>);
+// This includes both prompting the user and persisting results, as required.
+class GeolocationPermissionContextEfl final {
+ public:
+  GeolocationPermissionContextEfl();
+
+  // The renderer is requesting permission to use Geolocation.
+  // When the answer to a permission request has been determined, |callback|
+  // should be called with the result.
+  void RequestPermission(int render_process_id,
+                         int render_view_id,
+                         const GURL& requesting_frame,
+                         base::Callback<void(bool)> callback) const;
+
+  // The renderer is cancelling a pending permission request.
+  void CancelPermissionRequest(int render_process_id,
+                               int render_view_id,
+                               int bridge_id,
+                               const GURL& requesting_frame) const;
+
+ private:
+  void RequestPermissionOnUIThread(int render_process_id,
+                                   int render_view_id,
+                                   const GURL& requesting_frame,
+                                   base::Callback<void(bool)> callback) const;
+
+  mutable base::WeakPtrFactory<GeolocationPermissionContextEfl>
+      weak_ptr_factory_;
 };
 
-} // namespace
+}  // namespace content
 #endif // GEOLOCATION_PERMISSION_CONTEXT_EFL_H
index ecd083294a5481ac0869ca2c152c310185d4728e..a97f52c084a50aced651a082d90b69f7975dddbc 100644 (file)
@@ -7,6 +7,7 @@
 #include "base/bind.h"
 #include "base/files/file_util.h"
 #include "base/path_service.h"
+#include "browser/geolocation/geolocation_permission_context_efl.h"
 #include "components/visitedlink/browser/visitedlink_master.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/render_view_host.h"
@@ -172,4 +173,14 @@ SSLHostStateDelegate* BrowserContextEfl::GetSSLHostStateDelegate() {
   return NULL;
 }
 
+const GeolocationPermissionContextEfl&
+    BrowserContextEfl::GetGeolocationPermissionContext() const {
+  if (!geolocation_permission_context_.get()) {
+    geolocation_permission_context_.reset(
+        new GeolocationPermissionContextEfl());
+  }
+
+  return *(geolocation_permission_context_.get());
+}
+
 }
index 575477859a5adb4965125af111d8a4e65dd18293..dbe62188d63e85c1795d0e509a5da3b1b4c8bbc9 100644 (file)
@@ -9,6 +9,9 @@
 
 #include "base/memory/scoped_ptr.h"
 #include "base/files/scoped_temp_dir.h"
+#include "browser/download_manager_delegate_efl.h"
+#include "browser/geolocation/geolocation_permission_context_efl.h"
+#include "browser/notification/notification_controller_efl.h"
 #include "components/visitedlink/browser/visitedlink_delegate.h"
 #include "components/visitedlink/browser/visitedlink_master.h"
 #include "content/public/browser/content_browser_client.h"
@@ -16,8 +19,7 @@
 #include "content/public/browser/storage_partition.h"
 #include "content/public/browser/resource_context.h"
 #include "url_request_context_getter_efl.h"
-#include "browser/notification/notification_controller_efl.h"
-#include "browser/download_manager_delegate_efl.h"
+
 #include "net/url_request/url_request_context.h"
 
 class EWebContext;
@@ -67,6 +69,9 @@ class BrowserContextEfl
   virtual PushMessagingService* GetPushMessagingService() override
   { return 0; }
 
+  virtual const GeolocationPermissionContextEfl&
+      GetGeolocationPermissionContext() const;
+
   virtual base::FilePath GetPath() const override;
 
   net::URLRequestContextGetter* CreateRequestContext(
@@ -98,7 +103,8 @@ class BrowserContextEfl
  private:
   static void ReadCertificateAndAdd(base::FilePath* file_path);
   virtual SSLHostStateDelegate* GetSSLHostStateDelegate() override;
-
+  mutable scoped_ptr<GeolocationPermissionContextEfl>
+      geolocation_permission_context_;
   scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
   ResourceContextEfl* resource_context_;
   scoped_refptr<URLRequestContextGetterEfl> request_context_getter_;
index fa1db3a3fa635029fa76102b214e9871964fa125..a88610847e56faf2e542db5e994bc6c07082b3b1 100644 (file)
       'browser/favicon/favicon_service.h',
       'browser/geolocation/access_token_store_efl.cc',
       'browser/geolocation/access_token_store_efl.h',
-      # [M37] Geolocation related code changed. Figure out how to fix it.
-      #'browser/geolocation/geolocation_permission_context_efl.cc',
-      #'browser/geolocation/geolocation_permission_context_efl.h',
+      'browser/geolocation/geolocation_permission_context_efl.cc',
+      'browser/geolocation/geolocation_permission_context_efl.h',
       'browser/geolocation/location_provider_efl.cc',
       'browser/geolocation/location_provider_efl.h',
       'browser/inputpicker/InputPicker.cc',
index d5df97d320659d0fd42a5dec1be6681ec389e3df..216d058b81d9cc83fa689e65f538372d1ccd77f3 100644 (file)
@@ -11,6 +11,7 @@
 #include "devtools_manager_delegate_efl.h"
 #include "browser/web_contents/web_contents_view_efl.h"
 #include "browser/geolocation/access_token_store_efl.h"
+#include "browser/geolocation/geolocation_permission_context_efl.h"
 #include "browser/renderer_host/render_message_filter_efl.h"
 #include "browser/resource_dispatcher_host_delegate_efl.h"
 #include "browser/vibration/vibration_message_filter.h"
@@ -224,6 +225,47 @@ void ContentBrowserClientEfl::RenderProcessWillLaunch(
   host->AddFilter(new editing::EditorClientObserver(host->GetID()));
 }
 
+void ContentBrowserClientEfl::RequestPermission(
+    content::PermissionType permission,
+    content::WebContents* web_contents,
+    int bridge_id,
+    const GURL& requesting_frame,
+    bool user_gesture,
+    const base::Callback<void(bool)>& result_callback) {
+  int render_process_id = web_contents->GetRenderProcessHost()->GetID();
+  int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
+
+  GURL origin = requesting_frame.GetOrigin();
+  BrowserContextEfl* browser_context =
+      static_cast<BrowserContextEfl*>(web_contents->GetBrowserContext());
+  const GeolocationPermissionContextEfl& geolocation_permission_context =
+      browser_context->GetGeolocationPermissionContext();
+
+  switch (permission) {
+    case content::PERMISSION_GEOLOCATION:
+      if (!browser_context) {
+        LOG(ERROR) << "Dropping GeolocationPermission request";
+        result_callback.Run(false);
+        return;
+      }
+
+      geolocation_permission_context.RequestPermission(render_process_id,
+                                                       render_view_id,
+                                                       requesting_frame,
+                                                       result_callback);
+      break;
+    case content::PERMISSION_PROTECTED_MEDIA:
+    case content::PERMISSION_MIDI_SYSEX:
+    case content::PERMISSION_NOTIFICATIONS:
+    case content::PERMISSION_PUSH_MESSAGING:
+      NOTIMPLEMENTED() << "RequestPermission not implemented for "
+                       << permission;
+      break;
+    default:
+      NOTREACHED() << "Invalid RequestPermission for " << permission;
+  }
+}
+
 content::DevToolsManagerDelegate* ContentBrowserClientEfl::GetDevToolsManagerDelegate() {
   return new DevToolsManagerDelegateEfl();
 }
index 6db6d142dff885846e2d56c4ced02881dd0ff19a..ce900083fe07141564fbb8b0bb381c566ff17e7a 100644 (file)
@@ -87,6 +87,14 @@ class ContentBrowserClientEfl: public ContentBrowserClient {
 
   virtual void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
 
+  void RequestPermission(
+      content::PermissionType permission,
+      content::WebContents* web_contents,
+      int bridge_id,
+      const GURL& requesting_frame,
+      bool user_gesture,
+      const base::Callback<void(bool)>& result_callback) override;
+
   content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override;
 
  private: