From 7d2bc4c97763bff6218813b289699ecee09c517d Mon Sep 17 00:00:00 2001 From: "surya.kumar7" Date: Tue, 20 Nov 2018 16:10:18 +0530 Subject: [PATCH] Add TizenWebContentsView component to JSWRT which resemebles EWebView 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 --- atom/browser/api/atom_api_web_contents.cc | 9 ++++ atom/browser/atom_browser_client.cc | 32 ++++++++++++- atom/browser/atom_browser_client.h | 22 +++++++++ tizen/browser/tizen_web_contents_view.cc | 24 ++++++++++ tizen/browser/tizen_web_contents_view.h | 44 +++++++++++++++++ .../tizen_web_contents_view_delegate.cc | 47 +++++++++++++++++++ .../tizen_web_contents_view_delegate.h | 47 +++++++++++++++++++ wrt.gyp | 4 ++ 8 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 tizen/browser/tizen_web_contents_view.cc create mode 100644 tizen/browser/tizen_web_contents_view.h create mode 100644 tizen/browser/tizen_web_contents_view_delegate.cc create mode 100644 tizen/browser/tizen_web_contents_view_delegate.h diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index e6d6b9317..2f685b54c 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -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); diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index d1ee230cc..dffa0c5c8 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -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" @@ -44,8 +43,12 @@ #include "v8/include/v8.h" #if defined(OS_TIZEN) +#include +#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 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& 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 diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index 4d6d3dfcc..efdf9577b 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -12,10 +12,16 @@ #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> 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& 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* 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> web_views_; +#endif + // pending_render_process => current_render_process. std::map 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 index 000000000..53a77c35e --- /dev/null +++ b/tizen/browser/tizen_web_contents_view.cc @@ -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 index 000000000..0b5999f93 --- /dev/null +++ b/tizen/browser/tizen_web_contents_view.h @@ -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 index 000000000..7f788b18c --- /dev/null +++ b/tizen/browser/tizen_web_contents_view_delegate.cc @@ -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 index 000000000..293bbd31e --- /dev/null +++ b/tizen/browser/tizen_web_contents_view_delegate.h @@ -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 89ca83312..39a59697b 100644 --- a/wrt.gyp +++ b/wrt.gyp @@ -144,6 +144,10 @@ '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', ], -- 2.34.1