Replace PermissionManagerEfl with PermissionControllerDelegateEfl 63/246963/1
authorGajendra N <gajendra.n@samsung.com>
Wed, 4 Nov 2020 14:08:52 +0000 (19:38 +0530)
committerGajendra N <gajendra.n@samsung.com>
Thu, 5 Nov 2020 10:35:42 +0000 (16:05 +0530)
This patch applies necessary changes to Permissions related code,
so that it can be permanently applied to tizen.dev branch.
Also does some cleanup related to obsolete AccessTokerStoreEfl class.

(Cherry-picked from b1465410ee517f6badae82fa072d4b449df411e7)

Change-Id: Icf257bb843fb9e73c366c8ece040551e830cc132
Signed-off-by: Gajendra N <gajendra.n@samsung.com>
tizen_src/ewk/efl_integration/BUILD.gn
tizen_src/ewk/efl_integration/browser/geolocation/access_token_store_efl.cc [deleted file]
tizen_src/ewk/efl_integration/browser/geolocation/access_token_store_efl.h [deleted file]
tizen_src/ewk/efl_integration/browser/geolocation/geolocation_permission_context_efl.cc
tizen_src/ewk/efl_integration/browser/geolocation/geolocation_permission_context_efl.h
tizen_src/ewk/efl_integration/browser/permission_manager_efl.cc [deleted file]
tizen_src/ewk/efl_integration/browser/permission_manager_efl.h [deleted file]
tizen_src/ewk/efl_integration/browser_context_efl.cc
tizen_src/ewk/efl_integration/browser_context_efl.h
tizen_src/ewk/efl_integration/permission_controller_delegate_efl.cc [new file with mode: 0644]
tizen_src/ewk/efl_integration/permission_controller_delegate_efl.h [new file with mode: 0644]

index ee7a55d..c048742 100644 (file)
@@ -195,8 +195,6 @@ shared_library("chromium-ewk") {
     "browser/mime_override_manager_efl.h",
     "browser/navigation_policy_handler_efl.cc",
     "browser/navigation_policy_handler_efl.h",
-    "browser/permission_manager_efl.cc",
-    "browser/permission_manager_efl.h",
     "browser/policy_response_delegate_efl.cc",
     "browser/policy_response_delegate_efl.h",
     "browser/quota_permission_context_efl.cc",
@@ -251,6 +249,8 @@ shared_library("chromium-ewk") {
     "network_delegate_efl.h",
     "notification_permission_popup.cc",
     "notification_permission_popup.h",
+    "permission_controller_delegate_efl.cc",
+    "permission_controller_delegate_efl.h",
     "permission_popup.h",
     "permission_popup_manager.cc",
     "permission_popup_manager.h",
@@ -288,8 +288,6 @@ shared_library("chromium-ewk") {
     "browser/favicon/favicon_database_p.h",
     "browser/favicon/favicon_downloader.cc",
     "browser/favicon/favicon_downloader.h",
-    "browser/geolocation/access_token_store_efl.cc",
-    "browser/geolocation/access_token_store_efl.h",
     "browser/geolocation/geolocation_permission_context_efl.cc",
     "browser/geolocation/geolocation_permission_context_efl.h",
     "browser/geolocation/location_provider_efl.cc",
@@ -562,10 +560,6 @@ shared_library("chromium-ewk") {
   # FIXME: Followings are guarded just for bringup.
   if (ewk_bringup) {
     sources -= [
-      "browser/geolocation/access_token_store_efl.cc",
-      "browser/geolocation/access_token_store_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/vibration/vibration_provider_client.cc",
diff --git a/tizen_src/ewk/efl_integration/browser/geolocation/access_token_store_efl.cc b/tizen_src/ewk/efl_integration/browser/geolocation/access_token_store_efl.cc
deleted file mode 100644 (file)
index 0139d18..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2013 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.
-
-#include "browser/geolocation/access_token_store_efl.h"
-
-#include "base/bind.h"
-#include "base/message_loop/message_loop.h"
-#include "base/strings/utf_string_conversions.h"
-#include "content/public/browser/browser_thread.h"
-#include "eweb_context.h"
-#include "ewk_global_data.h"
-#include "private/ewk_context_private.h"
-
-namespace device {
-
-AccessTokenStoreEfl::AccessTokenStoreEfl()
-    : system_request_context_(NULL)
-{
-}
-
-AccessTokenStoreEfl::~AccessTokenStoreEfl()
-{
-}
-
-void AccessTokenStoreEfl::LoadAccessTokens(const LoadAccessTokensCallback& callback)
-{
-  content::BrowserThread::PostTaskAndReply(
-      content::BrowserThread::UI, FROM_HERE,
-      base::Bind(&AccessTokenStoreEfl::GetRequestContextOnUIThread, this),
-      base::Bind(&AccessTokenStoreEfl::RespondOnOriginatingThread, this,
-                 callback));
-}
-
-void AccessTokenStoreEfl::GetRequestContextOnUIThread()
-{
-  system_request_context_ = EwkGlobalData::GetInstance()->GetSystemRequestContextGetter();
-}
-
-void AccessTokenStoreEfl::RespondOnOriginatingThread(const LoadAccessTokensCallback& callback)
-{
-  AccessTokenMap access_token_map;
-  callback.Run(access_token_map, system_request_context_);
-}
-
-void AccessTokenStoreEfl::SaveAccessToken(const GURL& /*server_url*/, const base::string16& /*access_token*/)
-{
-}
-
-}  // namespace device
diff --git a/tizen_src/ewk/efl_integration/browser/geolocation/access_token_store_efl.h b/tizen_src/ewk/efl_integration/browser/geolocation/access_token_store_efl.h
deleted file mode 100644 (file)
index 87f7768..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2013 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 ACCESS_TOKEN_STORE_EFL_H_
-#define ACCESS_TOKEN_STORE_EFL_H_
-
-#include "browser_context_efl.h"
-#include "device/geolocation/access_token_store.h"
-
-namespace content {
-class BrowserContextEfl;
-}
-
-namespace device {
-
-class AccessTokenStoreEfl : public device::AccessTokenStore {
- public:
-  AccessTokenStoreEfl();
-
-  // AccessTokenStore
-  virtual void LoadAccessTokens(const LoadAccessTokensCallback& callback) override;
-  virtual void SaveAccessToken(const GURL& server_url, const base::string16& access_token) override;
-
- private:
-  virtual ~AccessTokenStoreEfl();
-
-  void GetRequestContextOnUIThread();
-  void RespondOnOriginatingThread(const LoadAccessTokensCallback& callback);
-
-  net::URLRequestContextGetter* system_request_context_;
-
-  DISALLOW_COPY_AND_ASSIGN(AccessTokenStoreEfl);
-};
-
-}  // namespace device
-
-#endif  // ACCESS_TOKEN_STORE_EFL_H_
-
index b878e38..e952ad4 100644 (file)
@@ -21,6 +21,8 @@ GeolocationPermissionContextEfl::GeolocationPermissionContextEfl()
     : weak_ptr_factory_(this) {
 }
 
+GeolocationPermissionContextEfl::~GeolocationPermissionContextEfl() {}
+
 void GeolocationPermissionContextEfl::RequestPermissionOnUIThread(
     int render_process_id,
     int render_frame_id,
@@ -28,8 +30,10 @@ void GeolocationPermissionContextEfl::RequestPermissionOnUIThread(
     base::Callback<void(PermissionStatus)> callback) const {
   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
   WebContents* web_contents = WebContentsFromFrameID(render_process_id, render_frame_id);
-  if (!web_contents)
+  if (!web_contents) {
+    callback.Run(PermissionStatus::DENIED);
     return;
+  }
 
   EWebView* web_view = WebViewFromWebContents(web_contents);
 
@@ -69,7 +73,7 @@ void GeolocationPermissionContextEfl::RequestPermission(
     int render_frame_id,
     const GURL& requesting_frame,
     base::Callback<void(PermissionStatus)> callback) const {
-  base::PostTaskWithTraits(
+  base::PostTask(
       FROM_HERE, {BrowserThread::UI},
       base::Bind(&GeolocationPermissionContextEfl::RequestPermissionOnUIThread,
                  weak_ptr_factory_.GetWeakPtr(), render_process_id,
index 67a47a5..0da4868 100644 (file)
@@ -17,6 +17,7 @@ namespace content {
 class GeolocationPermissionContextEfl final {
  public:
   GeolocationPermissionContextEfl();
+  ~GeolocationPermissionContextEfl();
 
   // The renderer is requesting permission to use Geolocation.
   // When the answer to a permission request has been determined, |callback|
diff --git a/tizen_src/ewk/efl_integration/browser/permission_manager_efl.cc b/tizen_src/ewk/efl_integration/browser/permission_manager_efl.cc
deleted file mode 100644 (file)
index 2f721c0..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright 2015 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.
-
-#include "permission_manager_efl.h"
-
-#include "base/callback.h"
-#include "browser/geolocation/geolocation_permission_context_efl.h"
-#include "browser/notification/notification_controller_efl.h"
-#include "browser_context_efl.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/permission_controller.h"
-#include "content/public/browser/permission_type.h"
-#include "content/public/browser/render_frame_host.h"
-#include "content/public/browser/render_process_host.h"
-#include "content/public/browser/web_contents.h"
-#include "content_browser_client_efl.h"
-#include "content_main_delegate_efl.h"
-#include "ewk_global_data.h"
-
-using namespace blink::mojom;
-
-namespace content {
-
-PermissionManagerEfl::PermissionManagerEfl() {
-}
-
-PermissionManagerEfl::~PermissionManagerEfl() {
-}
-
-int PermissionManagerEfl::RequestPermission(
-    PermissionType permission,
-    content::RenderFrameHost* render_frame_host,
-    const GURL& requesting_origin,
-    bool user_gesture,
-    base::OnceCallback<void(PermissionStatus)> callback) {
-#if !defined(EWK_BRINGUP)  // FIXME: m67 bringup
-  // [M48_2564] Temporary disabling the codes for switching to new chromium
-  //            FIXME: http://web.sec.samsung.net/bugzilla/show_bug.cgi?id=15387
-  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
-  content::WebContents* web_contents =
-      content::WebContents::FromRenderFrameHost(render_frame_host);
-
-  switch (permission) {
-    case PermissionType::GEOLOCATION: {
-      BrowserContextEfl* browser_context =
-          static_cast<BrowserContextEfl*>(web_contents->GetBrowserContext());
-      if (!browser_context) {
-        LOG(ERROR) << "Dropping GeolocationPermission request";
-        callback.Run(PermissionStatus::PERMISSION_STATUS_DENIED);
-        return;
-      }
-
-      const GeolocationPermissionContextEfl& geolocation_permission_context =
-          browser_context->GetGeolocationPermissionContext();
-
-      int render_process_id = render_frame_host->GetProcess()->GetID();
-      int render_frame_id = render_frame_host->GetRoutingID();
-
-      geolocation_permission_context.RequestPermission(render_process_id,
-                                                       render_frame_id,
-                                                       requesting_origin,
-                                                       callback);
-      break;
-    }
-    case PermissionType::NOTIFICATIONS:
-    {
-#if defined(ENABLE_NOTIFICATIONS)
-      ContentMainDelegateEfl& cmde =
-          EwkGlobalData::GetInstance()->GetContentMainDelegateEfl();
-      ContentBrowserClientEfl* cbce =
-        static_cast<ContentBrowserClientEfl*>(cmde.GetContentBrowserClient());
-      if (!cbce) {
-        LOG(ERROR) << "Dropping NotificationPermission request";
-        callback.Run(PermissionStatus::PERMISSION_STATUS_DENIED);
-        return;
-      }
-
-      cbce->GetNotificationController()->RequestPermission(web_contents,
-                                                           requesting_origin,
-                                                           callback);
-
-#else
-      callback.Run(PermissionStatus::PERMISSION_STATUS_DENIED);
-#endif
-      break;
-    }
-    case PermissionType::PROTECTED_MEDIA_IDENTIFIER:
-    case PermissionType::MIDI_SYSEX:
-    case PermissionType::PUSH_MESSAGING: {
-      NOTIMPLEMENTED() << "RequestPermission not implemented for "
-                       << static_cast<int>(permission);
-      callback.Run(PermissionStatus::PERMISSION_STATUS_DENIED);
-      break;
-    }
-    default: {
-      NOTREACHED() << "Invalid RequestPermission for "
-                   << static_cast<int>(permission);
-    }
-  }
-#else
-  NOTIMPLEMENTED();
-  return PermissionController::kNoPendingOperation;
-#endif
-}
-
-int PermissionManagerEfl::RequestPermissions(
-    const std::vector<PermissionType>& permission,
-    RenderFrameHost* render_frame_host,
-    const GURL& requesting_origin,
-    bool user_gesture,
-    base::OnceCallback<void(const std::vector<PermissionStatus>&)> callback) {
-  NOTIMPLEMENTED();
-  return PermissionController::kNoPendingOperation;
-}
-
-PermissionStatus PermissionManagerEfl::GetPermissionStatus(
-                                                 PermissionType permission,
-                                                 const GURL& requesting_origin,
-                                                 const GURL& embedding_origin) {
-  return PermissionStatus::DENIED;
-}
-
-blink::mojom::PermissionStatus
-PermissionManagerEfl::GetPermissionStatusForFrame(
-    PermissionType permission,
-    content::RenderFrameHost* render_frame_host,
-    const GURL& requesting_origin) {
-  return GetPermissionStatus(
-      permission, requesting_origin,
-      content::WebContents::FromRenderFrameHost(render_frame_host)
-          ->GetLastCommittedURL()
-          .GetOrigin());
-}
-
-void PermissionManagerEfl::ResetPermission(PermissionType permission,
-                                           const GURL& requesting_origin,
-                                           const GURL& embedding_origin) {
-}
-
-int PermissionManagerEfl::SubscribePermissionStatusChange(
-    PermissionType permission,
-    content::RenderFrameHost* render_frame_host,
-    const GURL& requesting_origin,
-    base::RepeatingCallback<void(PermissionStatus)> callback) {
-  return -1;
-}
-
-void PermissionManagerEfl::UnsubscribePermissionStatusChange(
-                                              int subscription_id) {
-}
-
-}
diff --git a/tizen_src/ewk/efl_integration/browser/permission_manager_efl.h b/tizen_src/ewk/efl_integration/browser/permission_manager_efl.h
deleted file mode 100644 (file)
index e0a85b7..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2015 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.
-
-#ifndef PERMISSION_MANAGER_EFL_H_
-#define PERMISSION_MANAGER_EFL_H_
-
-#include "base/callback_forward.h"
-#include "base/macros.h"
-#include "content/public/browser/permission_controller_delegate.h"
-
-namespace content {
-
-class CONTENT_EXPORT PermissionManagerEfl
-    : public PermissionControllerDelegate {
- public:
-
-  PermissionManagerEfl();
-  ~PermissionManagerEfl() override;
-
-  int RequestPermission(PermissionType permission,
-                        RenderFrameHost* render_frame_host,
-                        const GURL& requesting_origin,
-                        bool user_gesture,
-                        base::OnceCallback<void(blink::mojom::PermissionStatus)>
-                            callback) override;
-
-  int RequestPermissions(
-      const std::vector<PermissionType>& permission,
-      RenderFrameHost* render_frame_host,
-      const GURL& requesting_origin,
-      bool user_gesture,
-      base::OnceCallback<
-          void(const std::vector<blink::mojom::PermissionStatus>&)> callback)
-      override;
-
-  blink::mojom::PermissionStatus GetPermissionStatus(
-      PermissionType permission,
-      const GURL& requesting_origin,
-      const GURL& embedding_origin) override;
-
-  blink::mojom::PermissionStatus GetPermissionStatusForFrame(
-      PermissionType permission,
-      RenderFrameHost* render_frame_host,
-      const GURL& requesting_origin) override;
-
-  void ResetPermission(PermissionType permission,
-                       const GURL& requesting_origin,
-                       const GURL& embedding_origin) override;
-
-  // Runs the given |callback| whenever the |permission| associated with the
-  // pair { requesting_origin, embedding_origin } changes.
-  // Returns the subscription_id to be used to unsubscribe.
-  int SubscribePermissionStatusChange(
-      PermissionType permission,
-      content::RenderFrameHost* render_frame_host,
-      const GURL& requesting_origin,
-      base::RepeatingCallback<void(blink::mojom::PermissionStatus)> callback)
-      override;
-
-  void UnsubscribePermissionStatusChange(int subscription_id) override;
-
- private:
-  DISALLOW_COPY_AND_ASSIGN(PermissionManagerEfl);
-};
-
-}
-
-#endif // PERMISSION_MANAGER_EFL_H_
index 6563b9d..6389bc1 100644 (file)
@@ -10,7 +10,6 @@
 #include "base/synchronization/waitable_event.h"
 #include "browser/autofill/personal_data_manager_factory.h"
 #include "browser/geolocation/geolocation_permission_context_efl.h"
-#include "browser/permission_manager_efl.h"
 #include "browser/webdata/web_data_service_factory.h"
 #include "components/autofill/core/browser/personal_data_manager.h"
 #include "components/password_manager/core/common/password_manager_pref_names.h"
@@ -27,6 +26,7 @@
 #include "content/public/browser/web_contents.h"
 #include "eweb_context.h"
 #include "network_delegate_efl.h"
+#include "permission_controller_delegate_efl.h"
 
 using namespace prefs;
 using namespace password_manager::prefs;
@@ -317,7 +317,10 @@ SSLHostStateDelegate* BrowserContextEfl::GetSSLHostStateDelegate() {
 
 PermissionControllerDelegate*
 BrowserContextEfl::GetPermissionControllerDelegate() {
-  return nullptr;
+  if (!permission_controller_delegate_.get())
+    permission_controller_delegate_.reset(new PermissionControllerDelegateEfl());
+
+  return permission_controller_delegate_.get();
 }
 
 const GeolocationPermissionContextEfl&
index 2f8f8fb..b5b9405 100644 (file)
@@ -142,6 +142,7 @@ class BrowserContextEfl : public BrowserContext,
   const bool incognito_;
   std::unique_ptr<net::NetworkDelegate> network_delegate_for_getter_;
   std::unique_ptr<SSLHostStateDelegateEfl> ssl_host_state_delegate_;
+  std::unique_ptr<PermissionControllerDelegate> permission_controller_delegate_;
 
   DISALLOW_COPY_AND_ASSIGN(BrowserContextEfl);
 };
diff --git a/tizen_src/ewk/efl_integration/permission_controller_delegate_efl.cc b/tizen_src/ewk/efl_integration/permission_controller_delegate_efl.cc
new file mode 100644 (file)
index 0000000..ddafca7
--- /dev/null
@@ -0,0 +1,258 @@
+// Copyright 2015 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.
+
+#include "permission_controller_delegate_efl.h"
+
+#include "base/callback.h"
+#include "browser_context_efl.h"
+#include "browser/geolocation/geolocation_permission_context_efl.h"
+#include "browser/notification/notification_controller_efl.h"
+#include "content_browser_client_efl.h"
+#include "content_main_delegate_efl.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/permission_controller.h"
+#include "content/public/browser/permission_type.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/web_contents.h"
+#include "ewk_global_data.h"
+
+using namespace blink::mojom;
+
+namespace content {
+
+struct PermissionControllerDelegateEfl::PendingRequest {
+  PendingRequest(const std::vector<PermissionType>& permission_types,
+                 content::RenderFrameHost* render_frame_host,
+                 PermissionStatusVectorCallback callback)
+      : permission_types_(permission_types),
+        render_process_id_(render_frame_host->GetProcess()->GetID()),
+        render_frame_id_(render_frame_host->GetRoutingID()),
+        callback_(std::move(callback)),
+        results_(permission_types.size(), PermissionStatus::DENIED),
+        remaining_results_(permission_types.size()) {}
+
+  void SetPermissionStatus(int permission_id,
+                           PermissionStatus permission_status) {
+    DCHECK(!IsComplete());
+
+    results_[permission_id] = permission_status;
+    --remaining_results_;
+  }
+
+  bool IsComplete() const { return remaining_results_ == 0; }
+
+  PermissionStatusVectorCallback callback() { return std::move(callback_); }
+
+  std::vector<PermissionStatus> results() const { return results_; }
+
+  std::vector<PermissionType> permission_types_;
+  int render_process_id_;
+  int render_frame_id_;
+  PermissionStatusVectorCallback callback_;
+  std::vector<PermissionStatus> results_;
+  size_t remaining_results_;
+};
+
+PermissionControllerDelegateEfl::PermissionControllerDelegateEfl() : weak_ptr_factory_(this) {
+}
+
+PermissionControllerDelegateEfl::~PermissionControllerDelegateEfl() {
+}
+
+void PermissionStatusCallbackWrapper(
+    PermissionStatusCallback callback,
+    const std::vector<PermissionStatus>& permission_status_list) {
+  DCHECK_EQ(1ul, permission_status_list.size());
+  std::move(callback).Run(permission_status_list[0]);
+}
+
+int PermissionControllerDelegateEfl::RequestPermission(
+    PermissionType permission,
+    content::RenderFrameHost* render_frame_host,
+    const GURL& requesting_origin,
+    bool user_gesture,
+    PermissionStatusCallback callback) {
+  return RequestPermissions(
+      std::vector<PermissionType>(1, permission), render_frame_host,
+      requesting_origin, user_gesture,
+      base::BindOnce(&PermissionStatusCallbackWrapper, std::move(callback)));
+}
+
+int PermissionControllerDelegateEfl::RequestPermissions(
+    const std::vector<PermissionType>& permissions,
+    RenderFrameHost* render_frame_host,
+    const GURL& requesting_origin,
+    bool user_gesture,
+    PermissionStatusVectorCallback callback) {
+  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+  if (permissions.empty()) {
+    std::move(callback).Run(std::vector<PermissionStatus>());
+    return content::PermissionController::kNoPendingOperation;
+  }
+
+  content::WebContents* web_contents =
+      content::WebContents::FromRenderFrameHost(render_frame_host);
+
+  PendingRequest* pending_request =
+      new PendingRequest(permissions, render_frame_host, std::move(callback));
+  int request_id = pending_requests_.Add(pending_request);
+
+  for (auto i = 0; i < permissions.size(); ++i) {
+    const auto& permission = permissions[i];
+    switch (permission) {
+      case PermissionType::GEOLOCATION: {
+        BrowserContextEfl* browser_context =
+            static_cast<BrowserContextEfl*>(web_contents->GetBrowserContext());
+        if (!browser_context) {
+          LOG(ERROR) << "Dropping GeolocationPermission request";
+          OnPermissionRequestResponse(request_id, i, PermissionStatus::DENIED);
+          continue;
+        }
+
+        const GeolocationPermissionContextEfl& geolocation_permission_context =
+            browser_context->GetGeolocationPermissionContext();
+
+        geolocation_permission_context.RequestPermission(
+            pending_request->render_process_id_,
+            pending_request->render_frame_id_, requesting_origin,
+            base::Bind(&PermissionControllerDelegateEfl::OnPermissionRequestResponse,
+                       weak_ptr_factory_.GetWeakPtr(), request_id, i));
+        break;
+      }
+#if defined(ENABLE_NOTIFICATIONS)
+      case PermissionType::NOTIFICATIONS: {
+        ContentMainDelegateEfl& cmde =
+            EwkGlobalData::GetInstance()->GetContentMainDelegatEfl();
+        ContentBrowserClientEfl* cbce = static_cast<ContentBrowserClientEfl*>(
+            cmde.GetContentBrowserClient());
+        if (!cbce) {
+          LOG(ERROR) << "Dropping NotificationPermission request";
+          OnPermissionRequestResponse(request_id, i, PermissionStatus::DENIED);
+          continue;
+        }
+
+        cbce->GetNotificationController()->RequestPermission(
+            web_contents, requesting_origin,
+            base::Bind(&PermissionControllerDelegateEfl::OnPermissionRequestResponse,
+                       weak_ptr_factory_.GetWeakPtr(), request_id, i));
+        break;
+      }
+#endif
+      case PermissionType::PROTECTED_MEDIA_IDENTIFIER:
+      case PermissionType::MIDI_SYSEX: {
+        NOTIMPLEMENTED() << "RequestPermission not implemented for "
+                         << static_cast<int>(permission);
+        OnPermissionRequestResponse(request_id, i, PermissionStatus::DENIED);
+        break;
+      }
+      case PermissionType::SENSORS: {
+        NOTIMPLEMENTED() << "RequestPermission not implemented for "
+                         << static_cast<int>(permission);
+        // TODO(gajendra.n): Implement SensorPermissionContextEfl similar to
+        // GeolocationPermissionContextEfl. For now, by default permission is
+        // set as GRANTED to enable the feature funtionality working.
+        OnPermissionRequestResponse(request_id, i, PermissionStatus::GRANTED);
+        break;
+      }
+      default: {
+        NOTREACHED() << "Invalid RequestPermission for "
+                     << static_cast<int>(permission);
+      }
+    }
+  }
+
+  return request_id;
+}
+
+void PermissionControllerDelegateEfl::OnPermissionRequestResponse(
+    int request_id,
+    int permission_id,
+    PermissionStatus permission_status) {
+  PendingRequest* pending_request = pending_requests_.Lookup(request_id);
+  if (!pending_request)
+    return;
+
+  pending_request->SetPermissionStatus(permission_id, permission_status);
+
+  if (!pending_request->IsComplete())
+    return;
+
+  pending_requests_.Remove(request_id);
+  pending_request->callback().Run(pending_request->results());
+}
+
+PermissionStatus PermissionControllerDelegateEfl::GetPermissionStatus(
+                                                 PermissionType permission,
+                                                 const GURL& requesting_origin,
+                                                 const GURL& embedding_origin) {
+  switch (permission) {
+#if defined(ENABLE_NOTIFICATIONS)
+    case PermissionType::NOTIFICATIONS: {
+      // requesting_origin should be the same as embedding_origin
+      // using push API from iframes are not allowed
+      if (requesting_origin != embedding_origin)
+        return PermissionStatus::DENIED;
+
+      ContentMainDelegateEfl& cmde =
+          EwkGlobalData::GetInstance()->GetContentMainDelegatEfl();
+      ContentBrowserClientEfl* cbce =
+          static_cast<ContentBrowserClientEfl*>(cmde.GetContentBrowserClient());
+      if (!cbce) {
+        LOG(ERROR) << "Dropping NotificationPermission request";
+        return PermissionStatus::DENIED;
+      }
+
+      PermissionStatus notification_status =
+          cbce->GetNotificationController()->CheckPermissionOnIOThread(
+              nullptr, requesting_origin, 0);
+
+      LOG(INFO) << "GetPermissionStatus() type:" << static_cast<int>(permission)
+                << ", status: " << notification_status;
+
+      return notification_status;
+    }
+#endif
+    case PermissionType::PROTECTED_MEDIA_IDENTIFIER:
+      return PermissionStatus::GRANTED;
+    default:
+      return PermissionStatus::DENIED;
+  }
+}
+
+blink::mojom::PermissionStatus
+PermissionControllerDelegateEfl::GetPermissionStatusForFrame(
+    PermissionType permission,
+   content::RenderFrameHost* render_frame_host,
+    const GURL& requesting_origin) {
+  return GetPermissionStatus(
+      permission, requesting_origin,
+      content::WebContents::FromRenderFrameHost(render_frame_host)
+          ->GetLastCommittedURL()
+          .GetOrigin());
+}
+
+void PermissionControllerDelegateEfl::ResetPermission(PermissionType permission,
+                                           const GURL& requesting_origin,
+                                           const GURL& embedding_origin) {
+  NOTIMPLEMENTED();
+}
+
+int PermissionControllerDelegateEfl::SubscribePermissionStatusChange(
+    PermissionType permission,
+    content::RenderFrameHost* render_frame_host,
+    const GURL& embedding_origin,
+    base::RepeatingCallback<void(blink::mojom::PermissionStatus)>
+          callback) {
+  NOTIMPLEMENTED();
+  return -1;
+}
+
+void PermissionControllerDelegateEfl::UnsubscribePermissionStatusChange(
+                                              int subscription_id) {
+  NOTIMPLEMENTED();
+}
+
+}  // namespace content
diff --git a/tizen_src/ewk/efl_integration/permission_controller_delegate_efl.h b/tizen_src/ewk/efl_integration/permission_controller_delegate_efl.h
new file mode 100644 (file)
index 0000000..2fd4bfc
--- /dev/null
@@ -0,0 +1,81 @@
+// Copyright 2015 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.
+
+#ifndef PERMISSION_CONTROLLER_DELEGATE_EFL_H_
+#define PERMISSION_CONTROLLER_DELEGATE_EFL_H_
+
+#include "base/callback_forward.h"
+#include "base/containers/id_map.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "content/public/browser/permission_controller_delegate.h"
+
+namespace content {
+
+using PermissionStatusCallback = base::OnceCallback<void(blink::mojom::PermissionStatus)>;
+using PermissionStatusVectorCallback =
+    base::OnceCallback<void(const std::vector<blink::mojom::PermissionStatus>&)>;
+
+class CONTENT_EXPORT PermissionControllerDelegateEfl : public PermissionControllerDelegate {
+ public:
+
+  PermissionControllerDelegateEfl();
+  ~PermissionControllerDelegateEfl() override;
+
+  int RequestPermission(PermissionType permission,
+                        content::RenderFrameHost* render_frame_host,
+                        const GURL& requesting_origin,
+                        bool user_gesture,
+                        PermissionStatusCallback callback) override;
+
+  int RequestPermissions(
+      const std::vector<PermissionType>& permissions,
+      RenderFrameHost* render_frame_host,
+      const GURL& requesting_origin,
+      bool user_gesture,
+      PermissionStatusVectorCallback callback) override;
+
+  blink::mojom::PermissionStatus GetPermissionStatus(PermissionType permission,
+                                       const GURL& requesting_origin,
+                                       const GURL& embedding_origin) override;
+
+  blink::mojom::PermissionStatus GetPermissionStatusForFrame(
+      PermissionType permission,
+      RenderFrameHost* render_frame_host,
+      const GURL& requesting_origin) override;
+
+  void ResetPermission(PermissionType permission,
+                       const GURL& requesting_origin,
+                       const GURL& embedding_origin) override;
+
+  // Runs the given |callback| whenever the |permission| associated with the
+  // pair { requesting_origin, embedding_origin } changes.
+  // Returns the subscription_id to be used to unsubscribe.
+  int SubscribePermissionStatusChange(
+      PermissionType permission,
+      RenderFrameHost* render_frame_host,
+      const GURL& embedding_origin,
+      base::RepeatingCallback<void(blink::mojom::PermissionStatus)>
+          callback) override;
+
+  void UnsubscribePermissionStatusChange(int subscription_id) override;
+
+ private:
+  struct PendingRequest;
+  using PendingRequestsMap = base::IDMap<PendingRequest*>;
+
+  void OnPermissionRequestResponse(int request_id,
+                                   int permission_id,
+                                   blink::mojom::PermissionStatus permission_status);
+
+  PendingRequestsMap pending_requests_;
+  base::WeakPtrFactory<PermissionControllerDelegateEfl> weak_ptr_factory_;
+
+  DISALLOW_COPY_AND_ASSIGN(PermissionControllerDelegateEfl);
+};
+
+}
+
+#endif // PERMISSION_CONTROLLER_DELEGATE_EFL_H_
+