Handle ewk ipc messages in WebViewBrowserMessageFilter
authorArnaud Renevier <a.renevier@samsung.com>
Mon, 16 Mar 2015 23:03:08 +0000 (16:03 -0700)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
Many ipc messages were sent from RenderViewObserverEfl, and received in
RenderWidgetHostViewEfl. From them, some actions were performed on
EWebView.

But now, that ewk is isolated from chromium-efl, we need to receive
those messages in ewk layer. We use WebViewBrowserMessageFilter for
that.

This patch also removes WebViewBrowserMessageFilter class which was
defined in eweb_view.cc but never used.

Change-Id: Ia85f699b8a32ecd9e4907549fcc01478f784244a
Signed-off-by: Arnaud Renevier <a.renevier@samsung.com>
tizen_src/chromium_impl/content/browser/renderer_host/render_widget_host_view_efl.cc
tizen_src/chromium_impl/content/browser/renderer_host/render_widget_host_view_efl.h
tizen_src/ewk/efl_integration/browser/web_view_browser_message_filter.cc
tizen_src/ewk/efl_integration/browser/web_view_browser_message_filter.h
tizen_src/ewk/efl_integration/content_browser_client_efl.cc
tizen_src/ewk/efl_integration/eweb_view.cc
tizen_src/ewk/efl_integration/eweb_view.h

index b86c4e9..a01ac70 100644 (file)
@@ -497,9 +497,6 @@ bool RenderWidgetHostViewEfl::OnMessageReceived(const IPC::Message& message) {
   bool handled = true;
   IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewEfl, message)
     IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, OnTextInputStateChanged)
-#if 0 //defined(OS_TIZEN)
-    IPC_MESSAGE_HANDLER(ViewHostMsg_SnapshotDataReceived, OnSnapshot)
-#endif
     IPC_MESSAGE_UNHANDLED(handled = false)
   IPC_END_MESSAGE_MAP()
   return handled;
@@ -565,16 +562,6 @@ gfx::NativeView RenderWidgetHostViewEfl::GetNativeView() const {
   return content_image_elm_host_;
 }
 
-void RenderWidgetHostViewEfl::OnSnapshot(const std::vector<unsigned char> pixData, int snapshotId, const gfx::Size& size) {
-  NOTIMPLEMENTED();
-#if 0
-  Evas_Object* image = evas_object_image_filled_add(evas_);
-  evas_object_image_size_set(image, size.width(), size.height());
-  evas_object_image_data_copy_set(image, const_cast<unsigned char*>(&pixData[0]));
-  web_view_->FindAndRunSnapshotCallback(image, snapshotId);
-#endif
-}
-
 gfx::NativeViewId RenderWidgetHostViewEfl::GetNativeViewId() const {
   DCHECK(evas_gl_initialized_);
   Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_);
index 577f21c..c21b53b 100644 (file)
@@ -220,7 +220,6 @@ class RenderWidgetHostViewEfl
   void ProcessTouchEvents();
 
   void OnOrientationChangeEvent(int);
-  void OnSnapshot(const std::vector<unsigned char> pixData, int snapshotId, const gfx::Size& size);
 
 #if 0
   SelectionControllerEfl* GetSelectionController();
index 4f43487..0be9d7d 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "common/web_contents_utils.h"
 #include "common/render_messages_ewk.h"
+#include "content/common/view_messages.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/notification_observer.h"
 #include "content/public/browser/notification_registrar.h"
@@ -21,8 +22,6 @@ using content::RenderViewHost;
 using content::WebContents;
 using namespace web_contents_utils;
 
-namespace tizen_webview {
-
 class WebViewBrowserMessageFilterPrivate
     : public content::NotificationObserver {
  public:
@@ -76,6 +75,79 @@ class WebViewBrowserMessageFilterPrivate
     }
   }
 
+  void OnPlainTextGetContents(const std::string& content_text, int plain_text_get_callback_id) {
+    DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+    if (web_view_)
+      web_view_->InvokePlainTextGetCallback(content_text, plain_text_get_callback_id);
+  }
+
+  void OnWebAppIconUrlGet(const std::string &icon_url, int callback_id) {
+    DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+    if (web_view_)
+      web_view_->InvokeWebAppIconUrlGetCallback(icon_url, callback_id);
+  }
+
+  void OnWebAppIconUrlsGet(const std::map<std::string, std::string> &icon_urls, int callback_id) {
+    DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+    if (web_view_)
+      web_view_->InvokeWebAppIconUrlsGetCallback(icon_urls, callback_id);
+  }
+
+  void OnWebAppCapableGet(bool capable, int callback_id) {
+    DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+    if (web_view_)
+      web_view_->InvokeWebAppCapableGetCallback(capable, callback_id);
+  }
+
+  void OnDidChangeContentsSize(int width, int height) {
+    DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+    if (web_view_)
+      web_view_->DidChangeContentsSize(width, height);
+  }
+
+  void OnSelectionTextStyleState(const SelectionStylePrams& params) {
+    if (web_view_)
+      web_view_->OnQuerySelectionStyleReply(params);
+  }
+
+  void OnDidChangePageScaleFactor(double scale_factor) {
+    if (web_view_)
+      web_view_->DidChangePageScaleFactor(scale_factor);
+  }
+
+  void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id) {
+    if (web_view_)
+      web_view_->OnMHTMLContentGet(mhtml_content, callback_id);
+  }
+
+  void OnDidChangePageScaleRange(double min_scale, double max_scale) {
+    if (web_view_)
+      web_view_->DidChangePageScaleRange(min_scale, max_scale);
+  }
+
+  void OnSnapshot(const std::vector<unsigned char> pixData, int snapshotId, const gfx::Size& size) {
+    if (web_view_)
+      web_view_->OnSnapshot(pixData, size.width(), size.height(), snapshotId);
+  }
+
+  void OnGetTextAtPositionReply(const std::string& text) {
+#ifdef TIZEN_CONTENTS_DETECTION
+    if (web_view_) {
+      base::string16 content = base::UTF8ToUTF16(text);
+
+      std::string message;
+      if (autofill::IsValidEmailAddress(content))
+        message = std::string("mailto:").append(text);
+      else if (autofill::IsValidPhoneNumber(content))
+        message = std::string("tel:").append(text);
+      else
+        return;
+
+      web_view_->ShowContentsDetectedPopup(message.c_str());
+    }
+#endif
+  }
+
   void Observe(int type, const content::NotificationSource& source,
       const content::NotificationDetails& details) override {
     DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type);
@@ -120,9 +192,32 @@ bool WebViewBrowserMessageFilter::OnMessageReceived(
         WebViewBrowserMessageFilterPrivate::OnReceivedHitTestAsyncData)
     IPC_MESSAGE_FORWARD(EwkViewMsg_DidFailLoadWithError, private_,
         WebViewBrowserMessageFilterPrivate::OnReceivedDidFailLoadWithError)
+    IPC_MESSAGE_FORWARD(EwkHostMsg_PlainTextGetContents, private_,
+        WebViewBrowserMessageFilterPrivate::OnPlainTextGetContents)
+    IPC_MESSAGE_FORWARD(EwkHostMsg_WebAppIconUrlGet, private_,
+        WebViewBrowserMessageFilterPrivate::OnWebAppIconUrlGet)
+    IPC_MESSAGE_FORWARD(EwkHostMsg_WebAppIconUrlsGet, private_,
+        WebViewBrowserMessageFilterPrivate::OnWebAppIconUrlsGet)
+    IPC_MESSAGE_FORWARD(EwkHostMsg_WebAppCapableGet, private_,
+        WebViewBrowserMessageFilterPrivate::OnWebAppCapableGet)
+    IPC_MESSAGE_FORWARD(EwkHostMsg_DidChangeContentsSize, private_,
+        WebViewBrowserMessageFilterPrivate::OnDidChangeContentsSize)
+    IPC_MESSAGE_FORWARD(EwkViewMsg_SelectionTextStyleState, private_,
+        WebViewBrowserMessageFilterPrivate::OnSelectionTextStyleState)
+    IPC_MESSAGE_FORWARD(EwkHostMsg_ReadMHTMLData, private_,
+        WebViewBrowserMessageFilterPrivate::OnMHTMLContentGet)
+    IPC_MESSAGE_FORWARD(EwkHostMsg_DidChangePageScaleFactor, private_,
+        WebViewBrowserMessageFilterPrivate::OnDidChangePageScaleFactor)
+    IPC_MESSAGE_FORWARD(EwkHostMsg_DidChangePageScaleRange, private_,
+        WebViewBrowserMessageFilterPrivate::OnDidChangePageScaleRange)
+#if defined(OS_TIZEN)
+    IPC_MESSAGE_FORWARD(ViewHostMsg_SnapshotDataReceived, private_,
+        WebViewBrowserMessageFilterPrivate::OnSnapshot)
+    IPC_MESSAGE_FORWARD(ViewHostMsg_GetTextAtPositionReply, private_,
+        WebViewBrowserMessageFilterPrivate::OnGetTextAtPositionReply)
+#endif
+
     IPC_MESSAGE_UNHANDLED(handled = false)
   IPC_END_MESSAGE_MAP()
   return handled;
 }
-
-} // namespace tizen_webview
index c2a617a..ccb9e78 100644 (file)
@@ -11,8 +11,6 @@ namespace content {
 class WebContents;
 }
 
-namespace tizen_webview {
-
 class WebViewBrowserMessageFilterPrivate;
 
 class WebViewBrowserMessageFilter: public content::BrowserMessageFilter {
@@ -27,6 +25,5 @@ class WebViewBrowserMessageFilter: public content::BrowserMessageFilter {
  private:
   WebViewBrowserMessageFilterPrivate* private_;
 };
-} // namespace tizen_webview
 
 #endif // WEB_VIEW_BROWSER_MESSAGE_FILTER_H_
index 9c23e13..b58b013 100644 (file)
@@ -307,7 +307,7 @@ void ContentBrowserClientEfl::RenderProcessWillLaunch(
       WebContents* content = WebContents::FromRenderViewHost(vh);
       DCHECK(content);
       if (content)
-        host->AddFilter(new tizen_webview::WebViewBrowserMessageFilter(content));
+        host->AddFilter(new WebViewBrowserMessageFilter(content));
     }
   }
 }
index 768feb7..35432f8 100644 (file)
@@ -198,70 +198,6 @@ class WebViewAsyncRequestHitTestDataInternalCallback: public WebViewAsyncRequest
   Callback callback_;
 };
 
-class WebViewBrowserMessageFilter: public content::BrowserMessageFilter
-{
- public:
-  WebViewBrowserMessageFilter(EWebView* web_view)
-      : BrowserMessageFilter(EwkMsgStart)
-      , web_view_(web_view) {
-    WebContents* web_contents = GetWebContents();
-    DCHECK(web_contents);
-
-    if (web_contents && web_contents->GetRenderProcessHost())
-      web_contents->GetRenderProcessHost()->AddFilter(this);
-  }
-
-  virtual void OverrideThreadForMessage(const IPC::Message& message,
-      BrowserThread::ID* thread) override {
-    if (message.type() == EwkViewHostMsg_HitTestAsyncReply::ID)
-      *thread = BrowserThread::UI;
-  }
-
-  virtual bool OnMessageReceived(const IPC::Message& message) override {
-    bool handled = true;
-    IPC_BEGIN_MESSAGE_MAP(WebViewBrowserMessageFilter, message)
-      IPC_MESSAGE_HANDLER(EwkViewHostMsg_HitTestReply, OnReceivedHitTestData)
-      IPC_MESSAGE_HANDLER(EwkViewHostMsg_HitTestAsyncReply, OnReceivedHitTestAsyncData)
-      IPC_MESSAGE_UNHANDLED(handled = false)
-    IPC_END_MESSAGE_MAP()
-    return handled;
-  }
-
- private:
-  void OnReceivedHitTestData(int render_view, const _Ewk_Hit_Test& hit_test_data,
-      const NodeAttributesMap& node_attributes) {
-    DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
-    RenderViewHost* render_view_host= web_view_->web_contents().GetRenderViewHost();
-    CHECK(render_view_host);
-
-    if (render_view_host && render_view_host->GetRoutingID() == render_view)
-      web_view_->UpdateHitTestData(hit_test_data, node_attributes);
-  }
-
-  void OnReceivedHitTestAsyncData(int render_view, const _Ewk_Hit_Test& hit_test_data,
-      const NodeAttributesMap& node_attributes, int64_t request_id) {
-    DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-    WebContents* contents = GetWebContents();
-    CHECK(contents);
-
-    RenderViewHost* render_view_host= contents->GetRenderViewHost();
-    CHECK(render_view_host);
-    if (render_view_host && render_view_host->GetRoutingID() == render_view)
-      web_view_->DispatchAsyncHitTestData(hit_test_data, node_attributes, request_id);
-  }
-
-  WebContents* GetWebContents() const {
-    if (web_view_)
-      return &(web_view_->web_contents());
-
-    return NULL;
-  }
-
- private:
-  EWebView* web_view_;
-};
-
 class AsyncHitTestRequest
 {
  public:
@@ -1676,11 +1612,16 @@ void EWebView::SetLinkMagnifierEnabled(bool enabled) {
   web_contents_->GetRenderViewHost()->SyncRendererPrefs();
 }
 
-void EWebView::FindAndRunSnapshotCallback(Evas_Object* image, int snapshotId) {
+void EWebView::OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId) {
   WebAppScreenshotCapturedCallback* callback = screen_capture_cb_map_.Lookup(snapshotId);
   if (!callback) {
     return;
   }
+
+  Evas_Object* image = evas_object_image_filled_add(rwhv()->evas());
+  evas_object_image_size_set(image, width, height);
+  evas_object_image_data_copy_set(image, const_cast<unsigned char*>(&pixData[0]));
+
   callback->Run(image);
   screen_capture_cb_map_.Remove(snapshotId);
 }
index 71ad4f3..6e5871d 100644 (file)
@@ -438,7 +438,7 @@ class EWebView {
 #else
   void InputPickerShow(ui::TextInputType input_type, double input_value);
 #endif
-  void FindAndRunSnapshotCallback(Evas_Object* image, int snapshotId);
+  void OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId);
 
 #ifdef TIZEN_EDGE_EFFECT
   scoped_refptr<EdgeEffect> edgeEffect() { return edge_effect_; }