Add TizenWebContentsView component to JSWRT which resemebles EWebView 33/193433/5
authorsurya.kumar7 <surya.kumar7@samsung.com>
Tue, 20 Nov 2018 10:40:18 +0000 (16:10 +0530)
committersurya.kumar7 <surya.kumar7@samsung.com>
Wed, 28 Nov 2018 11:50:45 +0000 (17:20 +0530)
A TizenWebContentsView is associated with every WebContents and is capable
of performing operations on it like handling Context Menu controller,
Selection Controller or Clipboard helper

Change-Id: Ib6ff95ce7395da40b99fd30d7e589129b9835b63
Signed-off-by: surya.kumar7 <surya.kumar7@samsung.com>
atom/browser/api/atom_api_web_contents.cc
atom/browser/atom_browser_client.cc
atom/browser/atom_browser_client.h
tizen/browser/tizen_web_contents_view.cc [new file with mode: 0644]
tizen/browser/tizen_web_contents_view.h [new file with mode: 0644]
tizen/browser/tizen_web_contents_view_delegate.cc [new file with mode: 0644]
tizen/browser/tizen_web_contents_view_delegate.h [new file with mode: 0644]
wrt.gyp

index e6d6b931761bbcb04d881d2cec9d265e81d7d269..2f685b54c6855618b510c686c624dda9b8ed2c2b 100644 (file)
@@ -417,6 +417,9 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate,
 }
 
 WebContents::~WebContents() {
+#if defined(OS_TIZEN)
+  atom::AtomBrowserClient::RemoveTizenWebContentsView(web_contents());
+#endif
   // The destroy() is called.
   if (managed_web_contents()) {
     // For webview we need to tell content module to do some cleanup work before
@@ -610,6 +613,12 @@ void WebContents::RendererResponsive(content::WebContents* source) {
 }
 
 bool WebContents::HandleContextMenu(const content::ContextMenuParams& params) {
+#if defined(OS_TIZEN)
+  // return false for Tizen web apps
+  auto app_data = common::ApplicationDataManager::GetCurrentAppData();
+  if (app_data && !app_data->IsElectronApp())
+    return false;
+#endif
   if (params.custom_context.is_pepper_menu) {
     Emit("pepper-context-menu", std::make_pair(params, web_contents()));
     web_contents()->NotifyContextMenuClosed(params.custom_context);
index d1ee230cc547cac8fad0d31d290e871fd97adf47..dffa0c5c81705e308bbe37d9b1941ad2b33ee892 100644 (file)
@@ -15,7 +15,6 @@
 #include "atom/browser/atom_quota_permission_context.h"
 #include "atom/browser/atom_resource_dispatcher_host_delegate.h"
 #include "atom/browser/atom_speech_recognition_manager_delegate.h"
-#include "atom/browser/native_window.h"
 #include "atom/browser/web_contents_permission_helper.h"
 #include "atom/browser/web_contents_preferences.h"
 #include "atom/browser/window_list.h"
 #include "v8/include/v8.h"
 
 #if defined(OS_TIZEN)
+#include <algorithm>
+#include "atom/browser/native_window_efl.h"
 #include "content/browser/speech/tts_message_filter_efl.h"
+#include "tizen/browser/tizen_web_contents_view_delegate.h"
 #else
+#include "atom/browser/native_window.h"
 #include "chrome/browser/speech/tts_message_filter.h"
 #endif
 
@@ -417,4 +420,31 @@ void AtomBrowserClient::RenderProcessHostDestroyed(
   RemoveSandboxedRendererId(process_id);
 }
 
+#if defined(OS_TIZEN)
+content::WebContentsViewDelegate* AtomBrowserClient::GetWebContentsViewDelegate(
+    content::WebContents* web_contents) {
+  auto tizen_view = new tizen::TizenWebContentsView(web_contents);
+  std::unique_ptr<tizen::TizenWebContentsView> p(tizen_view);
+  tizen_views_.push_back(std::move(p));
+  return new tizen::TizenWebContentsViewDelegate(tizen_view);
+}
+
+// static
+void AtomBrowserClient::RemoveTizenWebContentsView(content::WebContents* web_contents) {
+  tizen_views_.erase(std::remove_if(tizen_views_.begin(), tizen_views_.end(),
+      [web_contents] (std::unique_ptr<tizen::TizenWebContentsView>& wv) {
+        return wv->web_contents() == web_contents;
+      }),
+      tizen_views_.end());
+}
+
+tizen::TizenWebContentsView* AtomBrowserClient::GetTizenWebContentsView(content::WebContents* web_contents) {
+  for (auto& it: tizen_views_) {
+    if (it->web_contents() == web_contents)
+      return it.get();
+  }
+  return nullptr;
+}
+#endif
+
 }  // namespace atom
index 4d6d3dfccaec06af13c0b82894212ce2df6e35bd..efdf9577b0d9bc7818a6470ae3e4841e38a92714 100644 (file)
 
 #include "brightray/browser/browser_client.h"
 #include "content/public/browser/render_process_host_observer.h"
+#if defined (OS_TIZEN)
+#include "tizen/browser/tizen_web_contents_view.h"
+#endif
 
 namespace content {
 class QuotaPermissionContext;
 class ClientCertificateDelegate;
+#if defined(OS_TIZEN)
+class WebContentsViewDelegate;
+#endif
 }
 
 namespace net {
@@ -25,6 +31,9 @@ class SSLCertRequestInfo;
 namespace atom {
 
 class AtomResourceDispatcherHostDelegate;
+#if defined(OS_TIZEN)
+static std::vector<std::unique_ptr<tizen::TizenWebContentsView>> tizen_views_;
+#endif
 
 class AtomBrowserClient : public brightray::BrowserClient,
                           public content::RenderProcessHostObserver {
@@ -45,6 +54,11 @@ class AtomBrowserClient : public brightray::BrowserClient,
   static void SetCustomServiceWorkerSchemes(
       const std::vector<std::string>& schemes);
 
+#if defined(OS_TIZEN)
+  static tizen::TizenWebContentsView* GetTizenWebContentsView(content::WebContents* web_contents);
+  static void RemoveTizenWebContentsView(content::WebContents* web_contents);
+#endif
+
  protected:
   // content::ContentBrowserClient:
   void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
@@ -101,6 +115,10 @@ class AtomBrowserClient : public brightray::BrowserClient,
   void GetAdditionalAllowedSchemesForFileSystem(
       std::vector<std::string>* schemes) override;
   bool ShouldAllowOpenURL(content::SiteInstance* site_instance, const GURL& url) override;
+#if defined(OS_TIZEN)
+  content::WebContentsViewDelegate* GetWebContentsViewDelegate(
+      content::WebContents* web_contents) override;
+#endif
 
   // brightray::BrowserClient:
   brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
@@ -121,6 +139,10 @@ class AtomBrowserClient : public brightray::BrowserClient,
   void RemoveSandboxedRendererId(int process_id);
   bool IsRendererSandboxed(int process_id);
 
+#if defined(OS_TIZEN)
+  std::vector<std::unique_ptr<tizen::TizenWebContentsView>> web_views_;
+#endif
+
   // pending_render_process => current_render_process.
   std::map<int, int> pending_processes_;
   // Set that contains the process ids of all sandboxed renderers
diff --git a/tizen/browser/tizen_web_contents_view.cc b/tizen/browser/tizen_web_contents_view.cc
new file mode 100644 (file)
index 0000000..53a77c3
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#include "tizen_web_contents_view.h"
+
+namespace tizen {
+
+TizenWebContentsView::TizenWebContentsView(content::WebContents* web_contents)
+    : web_contents_(web_contents) {}
+
+} // namespace tizen
diff --git a/tizen/browser/tizen_web_contents_view.h b/tizen/browser/tizen_web_contents_view.h
new file mode 100644 (file)
index 0000000..0b5999f
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+
+// This class resembles EWebView
+// Empty functions will be replaced by full-fledged functions
+// in later patches
+
+#ifndef TIZEN_BROWSER_TIZEN_WEB_CONTENTS_VIEW_H_
+#define TIZEN_BROWSER_TIZEN_WEB_CONTENTS_VIEW_H_
+
+#include "content/public/common/context_menu_params.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/gfx/geometry/rect.h"
+
+namespace tizen {
+
+class TizenWebContentsView {
+ public:
+  TizenWebContentsView(content::WebContents* web_contents);
+  content::WebContents* web_contents() { return web_contents_; }
+  void HandleLongPressGesture(const content::ContextMenuParams&) {}
+  void ShowContextMenu(const content::ContextMenuParams&) {}
+  void OnSelectionRectReceived(const gfx::Rect& selection_rect) const {}
+
+ private:
+  content::WebContents* web_contents_;
+};
+
+} // namespace tizen
+
+#endif // TIZEN_BROWSER_TIZEN_WEB_CONTENTS_VIEW_H_
\ No newline at end of file
diff --git a/tizen/browser/tizen_web_contents_view_delegate.cc b/tizen/browser/tizen_web_contents_view_delegate.cc
new file mode 100644 (file)
index 0000000..7f788b1
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#include "tizen/browser/tizen_web_contents_view_delegate.h"
+
+namespace tizen {
+
+TizenWebContentsViewDelegate::TizenWebContentsViewDelegate(TizenWebContentsView* wv)
+    : web_view_(wv) {
+}
+
+// Note: WebContentsViewDelegate::ShowContextMenu is the hook called
+// by chromium in response to either a long press gesture (in case of
+// touch-based input event is the source) or a right button mouse click
+// (in case source is mouse-based).
+// For the former, JSWRT apps enter selection mode, whereas for the
+// later, context menu is shown right way.
+void TizenWebContentsViewDelegate::ShowContextMenu(
+    content::RenderFrameHost* render_frame_host,
+    const content::ContextMenuParams& params) {
+  if (params.source_type == ui::MENU_SOURCE_LONG_PRESS) {
+    // Touch events check is not needed as they're enabled by default
+    web_view_->HandleLongPressGesture(params);
+  } else {
+    web_view_->ShowContextMenu(params);
+  }
+}
+
+void TizenWebContentsViewDelegate::OnSelectionRectReceived(
+    const gfx::Rect& selection_rect) const {
+  web_view_->OnSelectionRectReceived(selection_rect);
+}
+
+} // namespace tizen
\ No newline at end of file
diff --git a/tizen/browser/tizen_web_contents_view_delegate.h b/tizen/browser/tizen_web_contents_view_delegate.h
new file mode 100644 (file)
index 0000000..293bbd3
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#ifndef TIZEN_BROWSER_TIZEN_WEB_CONTENTS_VIEW_DELEGATE_H_
+#define TIZEN_BROWSER_TIZEN_WEB_CONTENTS_VIEW_DELEGATE_H_
+
+#include "content/public/browser/web_contents_view_delegate.h"
+#include "content/public/common/menu_item.h"
+#include "tizen/browser/tizen_web_contents_view.h"
+
+namespace content {
+class RenderFrameHost;
+}
+
+namespace tizen {
+
+class TizenWebContentsViewDelegate
+    : public content::WebContentsViewDelegate {
+ public:
+  TizenWebContentsViewDelegate(TizenWebContentsView*);
+
+  void ShowContextMenu(
+      content::RenderFrameHost* render_frame_host,
+      const content::ContextMenuParams& params) override;
+
+ void OnSelectionRectReceived(const gfx::Rect& selection_rect) const override;
+
+ private:
+  TizenWebContentsView* web_view_;
+};
+
+} // namespace tizen
+
+#endif // TIZEN_BROWSER_TIZEN_WEB_CONTENTS_VIEW_DELEGATE_H_
\ No newline at end of file
diff --git a/wrt.gyp b/wrt.gyp
index 89ca83312d74ff6e6227f110ef418bcbee1e6b4b..39a59697bd6212766dc48d205a8ace4b802ce339 100644 (file)
--- a/wrt.gyp
+++ b/wrt.gyp
         'tizen/src/browser/wrt_service.h',
         'tizen/browser/tizen_browser_parts.cc',
         'tizen/browser/tizen_browser_parts.h',
+        'tizen/browser/tizen_web_contents_view_delegate.cc',
+        'tizen/browser/tizen_web_contents_view_delegate.h',
+        'tizen/browser/tizen_web_contents_view.cc',
+        'tizen/browser/tizen_web_contents_view.h',
         'tizen/browser/vibration_manager.cc',
         'tizen/browser/vibration_manager.h',
       ],