Implement unregisterProtocolHandler
authorArnaud Renevier <a.renevier@samsung.com>
Sat, 19 Sep 2015 00:20:41 +0000 (17:20 -0700)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
Now, unregisterProtocolHandler is a method of upstream
WebContentsDelegate.

The patch also fixes the protocal handler unittests. It doesn't assume
that resource files will be in /opt/resources anymore

Bug: http://web.sec.samsung.net/bugzilla/show_bug.cgi?id=13294

Reviewed by: a1.gomes, j.majnert

Change-Id: I34738f0bf08bddb4e467a9daf4f290810eedf9ef
Signed-off-by: Arnaud Renevier <a.renevier@samsung.com>
tizen_src/ewk/efl_integration/eweb_view_callbacks.h
tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc
tizen_src/ewk/efl_integration/web_contents_delegate_efl.h
tizen_src/ewk/unittest/resources/protocol_handler/register_protocol_handler.html
tizen_src/ewk/unittest/resources/protocol_handler/unregister_protocol_handler.html
tizen_src/ewk/unittest/utc_blink_cb_protocolhandler_registration_requested.cpp
tizen_src/ewk/unittest/utc_blink_cb_protocolhandler_unregistration_requested.cpp

index 3e3ebbe..13fb677 100644 (file)
@@ -90,6 +90,7 @@ enum CallbackType {
   ExitFullscreen,
   UserMediaPermission,
   RegisterProtocolHandler,
+  UnregisterProtocolHandler,
   IMEInputPanelShow,
   IMEInputPanelHide,
   IMECandidatePanelShow,
@@ -224,6 +225,7 @@ DECLARE_EWK_VIEW_CALLBACK(EnterFullscreen, "fullscreen,enterfullscreen", void);
 DECLARE_EWK_VIEW_CALLBACK(ExitFullscreen, "fullscreen,exitfullscreen", void);
 DECLARE_EWK_VIEW_CALLBACK(UserMediaPermission, "usermedia,permission,request", _Ewk_User_Media_Permission_Request*);
 DECLARE_EWK_VIEW_CALLBACK(RegisterProtocolHandler, "protocolhandler,registration,requested", Ewk_Custom_Handlers_Data*);
+DECLARE_EWK_VIEW_CALLBACK(UnregisterProtocolHandler, "protocolhandler,unregistration,requested", Ewk_Custom_Handlers_Data*);
 DECLARE_EWK_VIEW_CALLBACK(IMEInputPanelShow, "editorclient,ime,opened", void);
 DECLARE_EWK_VIEW_CALLBACK(IMEInputPanelHide, "editorclient,ime,closed", void);
 DECLARE_EWK_VIEW_CALLBACK(IMECandidatePanelShow, "editorclient,candidate,opened", void);
index 1b2878c..0fca8da 100644 (file)
@@ -204,10 +204,19 @@ bool WebContentsDelegateEfl::IsFullscreenForTabOrPending(
 
 void WebContentsDelegateEfl::RegisterProtocolHandler(WebContents* web_contents,
         const std::string& protocol, const GURL& url, bool user_gesture) {
-  scoped_ptr<Ewk_Custom_Handlers_Data> protocol_data(
-      new Ewk_Custom_Handlers_Data(protocol.c_str(),
-          url.host().c_str(), url.spec().c_str()));
-  web_view_->SmartCallback<EWebViewCallbacks::RegisterProtocolHandler>().call(protocol_data.get());
+  Ewk_Custom_Handlers_Data protocol_data(protocol.c_str(),
+          url.host().c_str(), url.spec().c_str());
+  web_view_->SmartCallback<EWebViewCallbacks::RegisterProtocolHandler>().call(&protocol_data);
+}
+
+void WebContentsDelegateEfl::UnregisterProtocolHandler(WebContents* web_contents,
+                                                       const std::string& protocol,
+                                                       const GURL& url,
+                                                       bool user_gesture) {
+  Ewk_Custom_Handlers_Data protocol_data(protocol.c_str(),
+          url.host().c_str(), url.spec().c_str());
+  web_view_->SmartCallback<EWebViewCallbacks::UnregisterProtocolHandler>()
+      .call(&protocol_data);
 }
 
 #if defined(TIZEN_MULTIMEDIA_SUPPORT)
index aceb13c..97182d3 100644 (file)
@@ -86,6 +86,11 @@ class WebContentsDelegateEfl
                                const GURL& url,
                                bool user_gesture) override;
 
+  void UnregisterProtocolHandler(WebContents* web_contents,
+                                 const std::string& protocol,
+                                 const GURL& url,
+                                 bool user_gesture) override;
+
   void FindReply(WebContents* web_contents,
                  int request_id,
                  int number_of_matches,
index f6a9a0b..802dbc8 100644 (file)
@@ -2,8 +2,9 @@
 <head>
   <script>
     window.onload = function() {
+      var url = location.protocol + '//' + location.host+location.pathname;
       navigator.registerProtocolHandler("mailto",
-                                        "file:///opt/usr/resources/protocol_handler/handler.html?url=%s",
+                                        url + '?url=%s',
                                         "EFL-Mail");
     }
   </script>
index fc87511..cfceab4 100644 (file)
@@ -2,8 +2,8 @@
 <head>
   <script>
     window.onload = function() {
-      navigator.unregisterProtocolHandler("mailto",
-                                          "file:///opt/usr/resources/protocol_handler/handler.html?url=%s");
+      var url = location.protocol + '//' + location.host+location.pathname;
+      navigator.unregisterProtocolHandler("mailto", url + '?url=%s');
     }
   </script>
 </head>
index 82ae0a3..c6c60ee 100644 (file)
@@ -11,7 +11,6 @@ protected:
     : handler_target_(NULL)
     , handler_base_url_(NULL)
     , handler_url_(NULL)
-    , handler_title_(NULL)
   {}
 
   ~utc_blink_cb_protocolhandler_registration_requested()
@@ -19,20 +18,19 @@ protected:
     if (handler_target_) free(handler_target_);
     if (handler_base_url_) free(handler_base_url_);
     if (handler_url_) free(handler_url_);
-    if (handler_title_) free(handler_title_);
   }
 
-  void LoadFinished(Evas_Object *)
+  void LoadFinished(Evas_Object *) override
   {
     EventLoopStop(Failure);
   }
 
-  void PostSetUp()
+  void PostSetUp() override
   {
     evas_object_smart_callback_add(GetEwkWebView(), "protocolhandler,registration,requested", cb_protocolhandler_registration_requested, this);
   }
 
-  void PreTearDown()
+  void PreTearDown() override
   {
     evas_object_smart_callback_del(GetEwkWebView(), "protocolhandler,registration,requested", cb_protocolhandler_registration_requested);
   }
@@ -48,7 +46,6 @@ protected:
     owner->handler_target_ = ewk_custom_handlers_data_target_get(handler_data_) ? strdup(ewk_custom_handlers_data_target_get(handler_data_)) : 0;
     owner->handler_base_url_ = ewk_custom_handlers_data_base_url_get(handler_data_) ? strdup(ewk_custom_handlers_data_base_url_get(handler_data_)) : 0;
     owner->handler_url_ = ewk_custom_handlers_data_url_get(handler_data_) ? strdup(ewk_custom_handlers_data_url_get(handler_data_)) : 0;
-    owner->handler_title_ = ewk_custom_handlers_data_title_get(handler_data_) ? strdup(ewk_custom_handlers_data_title_get(handler_data_)) : 0;
     owner->EventLoopStop(Success);
   }
 
@@ -56,29 +53,17 @@ protected:
   char *handler_target_;
   char *handler_base_url_;
   char *handler_url_;
-  char *handler_title_;
-
-  static const char * const TARGET;
-  static const char * const BASE_URL;
-  static const char * const URL;
-  static const char * const TITLE;
 };
 
-const char * const utc_blink_cb_protocolhandler_registration_requested::TARGET = "mailto";
-const char * const utc_blink_cb_protocolhandler_registration_requested::BASE_URL = "file:///";
-const char * const utc_blink_cb_protocolhandler_registration_requested::URL = "file:///opt/usr/resources/protocol_handler/handler.html?url=%s";
-const char * const utc_blink_cb_protocolhandler_registration_requested::TITLE = "EFL-Mail";
-
 TEST_F(utc_blink_cb_protocolhandler_registration_requested, MAILTO_PROTOCOL_REGISTRATION)
 {
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl("protocol_handler/register_protocol_handler.html").c_str()));
+  std::string url = GetResourceUrl("protocol_handler/register_protocol_handler.html");
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), url.c_str()));
   ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_STREQ(TARGET, handler_target_);
-  ASSERT_STREQ(BASE_URL, handler_base_url_);
-  ASSERT_STREQ(URL, handler_url_);
-  ASSERT_STREQ(TITLE, handler_title_);
+  ASSERT_STREQ("mailto", handler_target_);
+  ASSERT_STREQ("", handler_base_url_);
+  ASSERT_STREQ((url + "?url=%s").c_str(), handler_url_);
   utc_message("target:   %s", handler_target_);
   utc_message("base url: %s", handler_base_url_);
   utc_message("url:      %s", handler_url_);
-  utc_message("title:    %s", handler_title_);
 }
index f097f51..049740f 100644 (file)
@@ -22,17 +22,17 @@ protected:
     if (handler_title_) free(handler_title_);
   }
 
-  void LoadFinished(Evas_Object *)
+  void LoadFinished(Evas_Object *) override
   {
     EventLoopStop(Failure);
   }
 
-  void PostSetUp()
+  void PostSetUp() override
   {
     evas_object_smart_callback_add(GetEwkWebView(), "protocolhandler,unregistration,requested", cb_protocolhandler_unregistration_requested, this);
   }
 
-  void PreTearDown()
+  void PreTearDown() override
   {
     evas_object_smart_callback_del(GetEwkWebView(), "protocolhandler,unregistration,requested", cb_protocolhandler_unregistration_requested);
   }
@@ -57,25 +57,14 @@ protected:
   char *handler_base_url_;
   char *handler_url_;
   char *handler_title_;
-
-  static const char * const TARGET;
-  static const char * const BASE_URL;
-  static const char * const URL;
 };
 
-const char * const utc_blink_cb_protocolhandler_unregistration_requested::TARGET = "mailto";
-const char * const utc_blink_cb_protocolhandler_unregistration_requested::BASE_URL = "file:///";
-const char * const utc_blink_cb_protocolhandler_unregistration_requested::URL = "file:///opt/usr/resources/protocol_handler/handler.html?url=%s";
-
 TEST_F(utc_blink_cb_protocolhandler_unregistration_requested, MAILTO_PROTOCOL_UNREGISTRATION)
 {
-  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl("protocol_handler/unregister_protocol_handler.html").c_str()));
+  std::string url = GetResourceUrl("protocol_handler/unregister_protocol_handler.html");
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), url.c_str()));
   ASSERT_EQ(Success, EventLoopStart());
-  ASSERT_STREQ(TARGET, handler_target_);
-  ASSERT_STREQ(BASE_URL, handler_base_url_);
-  ASSERT_STREQ(URL, handler_url_);
-  utc_message("target:   %s", handler_target_);
-  utc_message("base url: %s", handler_base_url_);
-  utc_message("url:      %s", handler_url_);
-  utc_message("title:    %s", handler_title_);
+  ASSERT_STREQ("mailto", handler_target_);
+  ASSERT_STREQ("", handler_base_url_);
+  ASSERT_STREQ((url + "?url=%s").c_str(), handler_url_);
 }