Implement ask popup for usermedia permission
authorJihoon Chung <jihoon.chung@samsung.com>
Thu, 20 Dec 2012 08:36:36 +0000 (17:36 +0900)
committerJihoon Chung <jihoon.chung@samsung.com>
Thu, 20 Dec 2012 08:59:21 +0000 (17:59 +0900)
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] Support asking user permission for media
[SCMRequest] N/A

Change-Id: Iab7fb57366c7e10f7cafd6bab706a4eb763cf4ae

src/view/webkit/CMakeLists.txt
src/view/webkit/view_logic.cpp
src/view/webkit/view_logic.h
src/view/webkit/view_logic_usermedia_support.cpp [new file with mode: 0644]
src/view/webkit/view_logic_usermedia_support.h [new file with mode: 0644]

index 90c0f32..78b3904 100644 (file)
@@ -44,6 +44,7 @@ SET(VIEW_MODULE_SOURCES
     ${PROJECT_SOURCE_DIR}/src/view/webkit/view_logic_filesystem_support.cpp
     ${PROJECT_SOURCE_DIR}/src/view/webkit/view_logic_scheme_support.cpp
     ${PROJECT_SOURCE_DIR}/src/view/webkit/view_logic_geolocation_support_webkit2.cpp
+    ${PROJECT_SOURCE_DIR}/src/view/webkit/view_logic_usermedia_support.cpp
     ${PROJECT_SOURCE_DIR}/src/view/webkit/view_logic_web_storage_support.cpp
     ${PROJECT_SOURCE_DIR}/src/view/webkit/bundles/plugin_module_support.cpp
     ${VIEW_MODULE_SOURCES}
index 19ecef1..55fa930 100644 (file)
@@ -53,6 +53,7 @@
 #include <view_logic_scheme_support.h>
 #include <view_logic_filesystem_support.h>
 #include <view_logic_geolocation_support_webkit2.h>
+#include <view_logic_usermedia_support.h>
 #include <view_logic_web_storage_support.h>
 #include "bundles/plugin_module_support.h"
 #include <popup-runner/PopupInvoker.h>
@@ -122,6 +123,9 @@ const char * const EWK_INPUTMETHOD_CHANGED = "inputmethod,changed";
 const char * const EWK_EDITORCLIENT_IME_OPENED = "editorclient,ime,opened";
 const char * const EWK_EDITORCLIENT_IME_CLOSED = "editorclient,ime,closed";
 
+// EWK Usermedia Callback
+const char * const EWK_USERMEDIA_PERMISSION_REQUEST = "usermedia,permission,request";
+
 // Custom handlers
 const char * const EWK_PROTOCOLHANDLER_REGISTRATION = "protocolhandler,registration,requested";
 const char * const EWK_PROTOCOLHANDLER_ISREGISTERED = "protocolhandler,isregistered";
@@ -691,6 +695,13 @@ void ViewLogic::ewkClientInit(Evas_Object *wkView) {
         imeClosedCallback,
         this);
 
+    // usermedia callback
+    evas_object_smart_callback_add(
+        wkView,
+        EWK_USERMEDIA_PERMISSION_REQUEST,
+        usermediaPermissionRequestCallback,
+        this);
+
     // custom content/scheme handlers
     evas_object_smart_callback_add(
         wkView,
@@ -850,6 +861,12 @@ void ViewLogic::ewkClientDeinit(Evas_Object *wkView) {
         EWK_EDITORCLIENT_IME_CLOSED,
         imeClosedCallback);
 
+    // usermedia callback
+    evas_object_smart_callback_del(
+        wkView,
+        EWK_USERMEDIA_PERMISSION_REQUEST,
+        usermediaPermissionRequestCallback);
+
     // custom content/scheme handlers
     evas_object_smart_callback_del(
         wkView,
@@ -1707,6 +1724,19 @@ void ViewLogic::imeClosedCallback(
             &args);
 }
 
+void ViewLogic::usermediaPermissionRequestCallback(
+        void* data,
+        Evas_Object* /*obj*/,
+        void* eventInfo)
+{
+    LogDebug("usermediaPermissionRequestCallback called");
+    Assert(data);
+    ViewLogic* This = static_cast<ViewLogic*>(data);
+    ViewModule::UsermediaSupport::usermediaPermissionRequest(This->m_window,
+                                                             eventInfo);
+}
+
+
 // helper method
 CustomHandlerDB::CustomHandlerPtr getCustomHandlerFromData(void* data)
 {
index f604f82..56df489 100644 (file)
@@ -219,6 +219,12 @@ class ViewLogic : public ViewModule::IViewModule
             Evas_Object* obj,
             void* eventInfo);
 
+    // EWK Usermedia Callback
+    static void usermediaPermissionRequestCallback(
+            void* data,
+            Evas_Object* obj,
+            void* eventInfo);
+
     // custom content/scheme handlers
     void attachToCustomHandlersDao();
     void detachFromCustomHandlersDao();
diff --git a/src/view/webkit/view_logic_usermedia_support.cpp b/src/view/webkit/view_logic_usermedia_support.cpp
new file mode 100644 (file)
index 0000000..cfb9364
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file    view_logic_usermedia_support.cpp
+ * @author  Jihoon Chung (jihoon.chung@samsung.com)
+ */
+
+#include "view_logic_usermedia_support.h"
+
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <Elementary.h>
+#include <EWebKit2.h>
+
+namespace ViewModule {
+
+namespace {
+const char* const USERMEDIA_USE_ASK_BODY =
+    "This application wants to use your media";
+
+// function declare
+void askUserForUsermediaPermission(Evas_Object* window, void* data);
+Evas_Object* getPopup(Evas_Object* button);
+static void popupCallback(void* data, Evas_Object* obj, void* eventInfo);
+
+void askUserForUsermediaPermission(Evas_Object* window, void* data)
+{
+    LogDebug("askUserForUsermediaPermission called");
+
+    Evas_Object* popup = elm_popup_add(window);
+    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+    elm_object_text_set(popup, USERMEDIA_USE_ASK_BODY);
+
+    Evas_Object* lButton = elm_button_add(popup);
+    elm_object_text_set(lButton, "Allow");
+    elm_object_part_content_set(popup, "button1", lButton);
+    evas_object_smart_callback_add(lButton, "clicked", popupCallback, popup);
+
+    Evas_Object* rButton = elm_button_add(popup);
+    elm_object_text_set(rButton, "Deny");
+    elm_object_part_content_set(popup, "button2", rButton);
+    evas_object_smart_callback_add(rButton, "clicked", popupCallback, popup);
+    evas_object_show(popup);
+}
+
+Evas_Object* getPopup(Evas_Object* button)
+{
+    Assert(button);
+
+    Evas_Object* popup = button;
+    while (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
+        popup = elm_object_parent_widget_get(popup);
+        if (!popup) {
+            return NULL;
+        }
+    }
+    return popup;
+}
+
+void popupCallback(void* data, Evas_Object* obj, void* /*eventInfo*/)
+{
+    LogDebug("popupCallback");
+    Assert(data);
+    Ewk_User_Media_Permission* usermediaPermission =
+        static_cast<Ewk_User_Media_Permission*>(data);
+
+    Assert(obj);
+    Evas_Object* popup = getPopup(obj);
+    Assert(popup);
+    bool allow = !strcmp("Allow", elm_object_text_get(obj));
+
+    Eina_Bool ret = allow ? EINA_TRUE : EINA_FALSE;
+    ewk_user_media_permission_set(usermediaPermission, ret);
+
+    evas_object_hide(popup);
+    evas_object_del(popup);
+}
+} // namespace
+
+void UsermediaSupport::usermediaPermissionRequest(Evas_Object* window,
+                                                   void* data)
+{
+    LogDebug("usermediaPermissionRequest called");
+    Assert(window);
+    Assert(data);
+    // ask to user
+    askUserForUsermediaPermission(window, data);
+    return;
+}
+} // namespace ViewModule
diff --git a/src/view/webkit/view_logic_usermedia_support.h b/src/view/webkit/view_logic_usermedia_support.h
new file mode 100644 (file)
index 0000000..27f5e70
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file    view_logic_usermedia_support.h
+ * @author  Jihoon Chung (jihoon.chung@samsung.com)
+ */
+
+#ifndef VIEW_LOGIC_USERMEDIA_SUPPORT_H_
+#define VIEW_LOGIC_USERMEDIA_SUPPORT_H_
+
+#include <Elementary.h>
+
+namespace ViewModule {
+namespace UsermediaSupport {
+
+void usermediaPermissionRequest(
+        Evas_Object* window,
+        void* data);
+
+} // namespace UsermediaSupport
+} // namespace ViewModule
+
+#endif // VIEW_LOGIC_USERMEDIA_SUPPORT_H_
\ No newline at end of file