Implement ewk_view_web_application_capable_get
authorFilip Piechocki <f.piechocki@samsung.com>
Thu, 19 Jun 2014 22:28:36 +0000 (15:28 -0700)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
Issue: CBWEBVIEW-577
Change-Id: I1d0eb5bd81ad883f11040d130722ce02d3d4b737

tizen_src/impl/browser/renderer_host/render_widget_host_view_efl.cc
tizen_src/impl/browser/renderer_host/render_widget_host_view_efl.h
tizen_src/impl/common/render_messages_efl.h
tizen_src/impl/eweb_view.cc
tizen_src/impl/eweb_view.h
tizen_src/impl/renderer/render_view_observer_efl.cc
tizen_src/impl/renderer/render_view_observer_efl.h

index b044fc8..6fb6cd1 100644 (file)
@@ -298,6 +298,7 @@ bool RenderWidgetHostViewEfl::OnMessageReceived(const IPC::Message& message) {
     IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyLayout, OnDidFirstVisuallyNonEmptyLayout)
     IPC_MESSAGE_HANDLER(EwkHostMsg_PlainTextGetContents, OnPlainTextGetContents)
     IPC_MESSAGE_HANDLER(EwkHostMsg_WebAppIconUrlGet, OnWebAppIconUrlGet)
+    IPC_MESSAGE_HANDLER(EwkHostMsg_WebAppCapableGet, OnWebAppCapableGet)
     IPC_MESSAGE_HANDLER(EwkHostMsg_DidChangeContentsSize, OnDidChangeContentsSize)
     IPC_MESSAGE_HANDLER(EwkHostMsg_OrientationChangeEvent, OnOrientationChangeEvent)
     IPC_MESSAGE_HANDLER(EwkViewMsg_SelectionTextStyleState, OnSelectionTextStyleState)
@@ -1229,6 +1230,11 @@ void RenderWidgetHostViewEfl::OnPlainTextGetContents(const std::string& content_
   eweb_view()->InvokePlainTextGetCallback(content_text, plain_text_get_callback_id);
 }
 
+void RenderWidgetHostViewEfl::OnWebAppCapableGet(bool capable, int callback_id) {
+  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+  eweb_view()->InvokeWebAppCapableGetCallback(capable, callback_id);
+}
+
 void RenderWidgetHostViewEfl::OnWebAppIconUrlGet(const std::string &icon_url, int callback_id) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
   eweb_view()->InvokeWebAppIconUrlGetCallback(icon_url, callback_id);
index ea98c15..3be5843 100755 (executable)
@@ -204,6 +204,7 @@ class RenderWidgetHostViewEfl
   void HandleGesture(ui::GestureEvent*);
   void HandleTouchEvent(ui::TouchEvent*);
   void OnPlainTextGetContents(const std::string&, int);
+  void OnWebAppCapableGet(bool capable, int callback_id);
   void OnWebAppIconUrlGet(const std::string &icon_url, int callback_id);
   void SelectRange(const gfx::Point&, const gfx::Point&);
   void MoveCaret(const gfx::Point&);
index ffe99d4..69646e5 100644 (file)
@@ -240,3 +240,9 @@ IPC_MESSAGE_ROUTED2(EwkHostMsg_WebAppIconUrlGet,
                     std::string, /* icon url */
                     int /* callback id */)
 
+IPC_MESSAGE_ROUTED1(EwkViewMsg_WebAppCapableGet,
+                    int /* calback id */)
+
+IPC_MESSAGE_ROUTED2(EwkHostMsg_WebAppCapableGet,
+                    bool, /* capable */
+                    int /* calback id */)
index b816920..746239e 100644 (file)
@@ -1423,6 +1423,16 @@ void EWebView::InvokeBackForwardListChangedCallback() {
   SmartCallback<EWebViewCallbacks::BackForwardListChange>().call();
 }
 
+bool EWebView::WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback, void *userData) {
+  RenderViewHost *renderViewHost = web_contents_delegate()->web_contents()->GetRenderViewHost();
+  if (!renderViewHost) {
+    return false;
+  }
+  WebApplicationCapableGetCallback *cb = new WebApplicationCapableGetCallback(callback, userData);
+  int callbackId = web_app_capable_get_callback_map_.Add(cb);
+  return renderViewHost->Send(new EwkViewMsg_WebAppCapableGet(renderViewHost->GetRoutingID(), callbackId));
+}
+
 bool EWebView::WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback, void* userData) {
   RenderViewHost* renderViewHost = web_contents_delegate()->web_contents()->GetRenderViewHost();
   if (!renderViewHost) {
@@ -1433,6 +1443,13 @@ bool EWebView::WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback, void
   return renderViewHost->Send(new EwkViewMsg_WebAppIconUrlGet(renderViewHost->GetRoutingID(), callbackId));
 }
 
+void EWebView::InvokeWebAppCapableGetCallback(bool capable, int callbackId) {
+  WebApplicationCapableGetCallback *callback = web_app_capable_get_callback_map_.Lookup(callbackId);
+  if (!callback)
+    return;
+  callback->Run(capable);
+}
+
 void EWebView::InvokeWebAppIconUrlGetCallback(const std::string& iconUrl, int callbackId) {
   WebApplicationIconUrlGetCallback *callback = web_app_icon_url_get_callback_map_.Lookup(callbackId);
   if (!callback)
index 3845e11..dff0707 100644 (file)
@@ -132,6 +132,22 @@ class WebApplicationIconUrlGetCallback {
   void *user_data_;
 };
 
+class WebApplicationCapableGetCallback {
+ public:
+  WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func, void *user_data)
+    : func_(func), user_data_(user_data)
+  {}
+  void Run(bool capable) {
+    if (func_) {
+      (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
+    }
+  }
+
+ private:
+  Ewk_Web_App_Capable_Get_Callback func_;
+  void *user_data_;
+};
+
 class JavaScriptDialogManagerEfl;
 
 class EWebView
@@ -257,7 +273,9 @@ class EWebView
   bool SaveAsPdf(int width, int height, const std::string& file_name);
   void BackForwardListClear();
   void InvokeBackForwardListChangedCallback();
+  bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback, void *userData);
   bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback, void *userData);
+  void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
   void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
 
   bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
@@ -421,6 +439,7 @@ class EWebView
   scoped_ptr<OrientationLockCallback> orientation_lock_callback_;
   scoped_ptr<content::InputPicker> inputPicker_;
   IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
+  IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
 #ifdef TIZEN_EDGE_EFFECT
   scoped_refptr<EdgeEffect> edge_effect_;
 #endif
index 253fb7a..a686c94 100644 (file)
@@ -137,6 +137,7 @@ bool RenderViewObserverEfl::OnMessageReceived(const IPC::Message& message)
     IPC_MESSAGE_HANDLER(EwkViewMsg_PrintToPdf, OnPrintToPdf)
     IPC_MESSAGE_HANDLER(EwkViewMsg_GetMHTMLData, OnGetMHTMLData);
     IPC_MESSAGE_HANDLER(EwkViewMsg_WebAppIconUrlGet, OnWebAppIconUrlGet);
+    IPC_MESSAGE_HANDLER(EwkViewMsg_WebAppCapableGet, OnWebAppCapableGet);
     IPC_MESSAGE_HANDLER(EwkViewMsg_SetDrawsTransparentBackground, OnSetDrawsTransparentBackground);
     IPC_MESSAGE_HANDLER(EwkViewMsg_SetBrowserFont, OnSetBrowserFont);
     IPC_MESSAGE_UNHANDLED(handled = false)
@@ -384,6 +385,40 @@ void RenderViewObserverEfl::OnWebAppIconUrlGet(int callback_id)
   Send(new EwkHostMsg_WebAppIconUrlGet(render_view()->GetRoutingID(), appleIconUrl.empty() ? iconUrl : appleIconUrl, callback_id));
 }
 
+void RenderViewObserverEfl::OnWebAppCapableGet(int callback_id) {
+  blink::WebFrame *frame = render_view()->GetWebView()->mainFrame();
+  if (!frame)
+    return;
+
+  blink::WebDocument document = frame->document();
+  blink::WebElement head = document.head();
+  if (head.isNull())
+    return;
+
+  bool capable = false;
+  blink::WebNodeList nodes = head.childNodes();
+  for (int i = 0; i < nodes.length(); ++i) {
+    blink::WebNode node = nodes.item(i);
+    if (!node.isElementNode())
+      continue;
+
+    blink::WebElement elem = node.to<blink::WebElement>();
+    if (!elem.hasTagName("meta"))
+      continue;
+
+    std::string name = elem.getAttribute("name").utf8();
+    if (LowerCaseEqualsASCII(name, "apple-mobile-web-app-capable") ||   // Apple's way
+        LowerCaseEqualsASCII(name, "mobile-web-app-capable")) {         // Google's way
+      std::string content = elem.getAttribute("content").utf8();
+      if (LowerCaseEqualsASCII(content, "yes")) {
+        capable = true;
+      }
+      break;
+    }
+  }
+  Send(new EwkHostMsg_WebAppCapableGet(render_view()->GetRoutingID(), capable, callback_id));
+}
+
 void RenderViewObserverEfl::OrientationChangeEvent(int orientation)
 {
   Send(new EwkHostMsg_OrientationChangeEvent(render_view()->GetRoutingID(), orientation));
index f0edd97..e6a14a9 100644 (file)
@@ -53,6 +53,7 @@ class RenderViewObserverEfl: public content::RenderViewObserver {
   void OnGetMHTMLData(int callback_id);
   void OnSetDrawsTransparentBackground(bool enabled);
   void OnWebAppIconUrlGet(int callback_id);
+  void OnWebAppCapableGet(int callback_id);
   void WillSubmitForm(blink::WebFrame* frame, const blink::WebFormElement& form);
   void OnSetBrowserFont();