From 6e80936f617d1e571ced94751ab6e1008bc4df7c Mon Sep 17 00:00:00 2001 From: "surya.kumar7" Date: Wed, 20 Jun 2018 22:57:22 +0530 Subject: [PATCH] Implementation of Appcontrol functionalities Added a few functionalities performed during AppControl in crosswalk-tizen 1. Added CSP support 2. Added Long polling support 3. Added TizenBrowserParts class to remove bloating atom's Browser Change-Id: Ifc2d40aa011beee881adf55cbfaca30e78df9bf7 Signed-off-by: surya.kumar7 --- atom/browser/api/atom_api_web_contents.cc | 10 +++ atom/browser/api/atom_api_web_contents.h | 2 + atom/browser/browser.cc | 7 -- atom/browser/browser.h | 11 ++-- atom/common/api/api_messages.h | 8 +++ atom/renderer/atom_render_view_observer.cc | 31 +++++++++ atom/renderer/atom_render_view_observer.h | 3 + tizen/browser/tizen_browser_parts.cc | 75 ++++++++++++++++++++++ tizen/browser/tizen_browser_parts.h | 54 ++++++++++++++++ wrt.gyp | 2 + 10 files changed, 190 insertions(+), 13 deletions(-) create mode 100644 tizen/browser/tizen_browser_parts.cc create mode 100644 tizen/browser/tizen_browser_parts.h diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 7e3e1764c..43b1940b6 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -685,6 +685,7 @@ void WebContents::RenderViewCreated(content::RenderViewHost* render_view_host) { render_view_host->GetRoutingID()); if (impl) impl->disable_hidden_ = !background_throttling_; + atom::Browser::Get()->RenderViewCreated(render_view_host); } void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) { @@ -954,6 +955,7 @@ void WebContents::HandleWrtPluginMessage(Ewk_Wrt_Message_Data* msg) { bool WebContents::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(WebContents, message) + IPC_MESSAGE_HANDLER_DELAY_REPLY(WrtViewMsg_GetCSP, OnGetContentSecurityPolicy) IPC_MESSAGE_HANDLER(AtomViewHostMsg_Message, OnRendererMessage) IPC_MESSAGE_HANDLER_DELAY_REPLY(AtomViewHostMsg_Message_Sync, OnRendererMessageSync) @@ -1701,6 +1703,14 @@ void WebContents::OnGetZoomLevel(IPC::Message* reply_msg) { Send(reply_msg); } +void WebContents::OnGetContentSecurityPolicy(IPC::Message* reply_msg) { + std::string csp_rule; + std::string csp_report_rule; + atom::Browser::Get()->GetCSP(csp_rule, csp_report_rule); + WrtViewMsg_GetCSP::WriteReplyParams(reply_msg, csp_rule, csp_report_rule); + Send(reply_msg); +} + v8::Local WebContents::GetWebPreferences(v8::Isolate* isolate) { WebContentsPreferences* web_preferences = WebContentsPreferences::FromWebContents(web_contents()); diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index ef1578c22..6d5069484 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -387,6 +387,8 @@ class WebContents : public mate::TrackableObject, // get the zoom level. void OnGetZoomLevel(IPC::Message* reply_msg); + void OnGetContentSecurityPolicy(IPC::Message* reply_msg); + v8::Global session_; v8::Global devtools_web_contents_; v8::Global debugger_; diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index aca2f6832..dcfc6bc6b 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -30,7 +30,6 @@ namespace atom { Browser::Browser() : is_quiting_(false), #if defined(OS_TIZEN) - locale_manager_(new common::LocaleManager()), launched_(false), is_electron_launch_(false), #endif @@ -275,12 +274,6 @@ void Browser::Show() { last_window->NotifyResume(); } -void Browser::Initialize() { - auto appdata = common::ApplicationDataManager::GetCurrentAppData(); - resource_manager_.reset(new common::ResourceManager(appdata, locale_manager_.get())); - resource_manager_->set_base_resource_path(appdata->application_path()); -} - void Browser::AppControl(std::unique_ptr appcontrol) { std::unique_ptr res = resource_manager_->GetStartResource(appcontrol.get()); diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 48365b868..358bcb982 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -18,6 +18,7 @@ #include "native_mate/arguments.h" #if defined(OS_TIZEN) #include "atom/browser/splash_screen.h" +#include "tizen/browser/tizen_browser_parts.h" #include "tizen/common/app_control.h" #include "tizen/common/application_data.h" #include "tizen/common/resource_manager.h" @@ -43,14 +44,14 @@ class AtomMenuModel; class LoginHandler; // This class is used for control application-wide operations. -class Browser : public WindowListObserver { +class Browser : public WindowListObserver, + public tizen::TizenBrowserParts { public: Browser(); ~Browser(); static Browser* Get(); - void Initialize(); // Try to close all windows and quit the application. void Quit(); @@ -117,8 +118,8 @@ class Browser : public WindowListObserver { #if defined(OS_TIZEN) void Hide(); void Show(); - void AppControl(std::unique_ptr appcontrol); - void Launch(std::unique_ptr appcontrol); + void AppControl(std::unique_ptr appcontrol) override; + void Launch(std::unique_ptr appcontrol) override; void SendAppControlEvent(); void SetSplashScreen(); void HideSplashScreen(int reason); @@ -262,8 +263,6 @@ class Browser : public WindowListObserver { base::ObserverList observers_; #if defined(OS_TIZEN) - std::unique_ptr resource_manager_; - std::unique_ptr locale_manager_; std::unique_ptr splash_screen_; std::string start_url_; bool launched_; diff --git a/atom/common/api/api_messages.h b/atom/common/api/api_messages.h index 5052c4086..44e8ad61c 100644 --- a/atom/common/api/api_messages.h +++ b/atom/common/api/api_messages.h @@ -64,3 +64,11 @@ IPC_MESSAGE_ROUTED1(AtomHostMsg_WrtMessage, IPC_SYNC_MESSAGE_ROUTED1_1(AtomHostMsg_WrtSyncMessage, Ewk_Wrt_Message_Data /* data */, std::string /*result*/) + +// Wrt related messages +IPC_SYNC_MESSAGE_ROUTED0_2(WrtViewMsg_GetCSP, + std::string, + std::string) + +IPC_MESSAGE_ROUTED1(WrtViewMsg_SetLongPolling, + unsigned long) \ No newline at end of file diff --git a/atom/renderer/atom_render_view_observer.cc b/atom/renderer/atom_render_view_observer.cc index a68238ba4..8923fdfd0 100644 --- a/atom/renderer/atom_render_view_observer.cc +++ b/atom/renderer/atom_render_view_observer.cc @@ -23,6 +23,7 @@ #include "native_mate/dictionary.h" #include "net/base/net_module.h" #include "net/grit/net_resources.h" +#include "third_party/WebKit/public/web/WebContentSecurityPolicy.h" #include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebDraggableRegion.h" #include "third_party/WebKit/public/web/WebFrame.h" @@ -116,6 +117,7 @@ void AtomRenderViewObserver::EmitIPCEvent(blink::WebFrame* frame, void AtomRenderViewObserver::DidCreateDocumentElement( blink::WebLocalFrame* frame) { document_created_ = true; + SetContentSecurityPolicy(frame); } void AtomRenderViewObserver::DraggableRegionsChanged(blink::WebFrame* frame) { @@ -136,6 +138,7 @@ bool AtomRenderViewObserver::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(AtomRenderViewObserver, message) IPC_MESSAGE_HANDLER(AtomViewMsg_Message, OnBrowserMessage) + IPC_MESSAGE_HANDLER(WrtViewMsg_SetLongPolling, OnSetLongPolling) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -169,4 +172,32 @@ void AtomRenderViewObserver::OnBrowserMessage(bool send_to_all, } } +void AtomRenderViewObserver::SetContentSecurityPolicy(blink::WebLocalFrame* frame) { + std::string csp_rule; + std::string csp_report_rule; + Send(new WrtViewMsg_GetCSP(render_view()->GetRoutingID(), &csp_rule, &csp_report_rule)); + + if (!csp_rule.empty()) { + frame->document().setContentSecurityPolicyUsingHeader( + blink::WebString::fromUTF8(csp_rule), + blink::WebContentSecurityPolicyType::WebContentSecurityPolicyTypeEnforce); + } + + if (!csp_report_rule.empty()) { + frame->document().setContentSecurityPolicyUsingHeader( + blink::WebString::fromUTF8(csp_report_rule), + blink::WebContentSecurityPolicyType::WebContentSecurityPolicyTypeReport); + } +} + +void AtomRenderViewObserver::OnSetLongPolling(unsigned long timeout) { + if (!document_created_) + return; + + blink::WebView* view = render_view()->GetWebView(); + if (!view) + return; + view->setLongPollingGlobalTimeout(timeout); +} + } // namespace atom diff --git a/atom/renderer/atom_render_view_observer.h b/atom/renderer/atom_render_view_observer.h index e642bbe94..cd69e2a72 100644 --- a/atom/renderer/atom_render_view_observer.h +++ b/atom/renderer/atom_render_view_observer.h @@ -40,6 +40,9 @@ class AtomRenderViewObserver : public content::RenderViewObserver { const base::string16& channel, const base::ListValue& args); + void SetContentSecurityPolicy(blink::WebLocalFrame* frame); + void OnSetLongPolling(unsigned long); + AtomRendererClient* renderer_client_; // Whether the document object has been created. diff --git a/tizen/browser/tizen_browser_parts.cc b/tizen/browser/tizen_browser_parts.cc new file mode 100644 index 000000000..231a9b317 --- /dev/null +++ b/tizen/browser/tizen_browser_parts.cc @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2015 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 "atom/common/api/api_messages.h" +#include "base/logging.h" +#include "tizen/browser/tizen_browser_parts.h" + +namespace tizen { + +namespace { + +const char* kDefaultCSPRule = + "default-src *; script-src 'self'; style-src 'self'; object-src 'none';"; + +} // namespace + +TizenBrowserParts::TizenBrowserParts() + : locale_manager_(new common::LocaleManager()) { +} + +void TizenBrowserParts::Initialize() { + app_data_ = common::ApplicationDataManager::GetCurrentAppData(); + resource_manager_.reset(new common::ResourceManager(app_data_, locale_manager_.get())); + resource_manager_->set_base_resource_path(app_data_->application_path()); + + if (app_data_->csp_info() != NULL || app_data_->csp_report_info() != NULL || + app_data_->allowed_navigation_info() != NULL) { + security_model_version_ = 2; + if (app_data_->csp_info() == NULL || + app_data_->csp_info()->security_rules().empty()) { + csp_rule_ = kDefaultCSPRule; + } else { + csp_rule_ = app_data_->csp_info()->security_rules(); + } + if (app_data_->csp_report_info() != NULL && + !app_data_->csp_report_info()->security_rules().empty()) { + csp_report_rule_ = app_data_->csp_report_info()->security_rules(); + } + } else { + security_model_version_ = 1; + } +} + +void TizenBrowserParts::GetCSP(std::string &csp_rule, std::string &csp_report_rule) { + csp_rule = csp_rule_; + csp_report_rule = csp_report_rule_; +} + +void TizenBrowserParts::SetLongPollingTimeout(content::RenderViewHost* rvh) { + if (app_data_->setting_info() != NULL && + app_data_->setting_info()->long_polling()) { + boost::optional polling_val(app_data_->setting_info()->long_polling()); + unsigned long *ptr = reinterpret_cast (&polling_val.get()); + rvh->Send(new WrtViewMsg_SetLongPolling(rvh->GetRoutingID(), *ptr)); + } +} + +void TizenBrowserParts::RenderViewCreated(content::RenderViewHost* render_view_host) { + SetLongPollingTimeout(render_view_host); +} + +} \ No newline at end of file diff --git a/tizen/browser/tizen_browser_parts.h b/tizen/browser/tizen_browser_parts.h new file mode 100644 index 000000000..4f6d552b5 --- /dev/null +++ b/tizen/browser/tizen_browser_parts.h @@ -0,0 +1,54 @@ +/* + * 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_BROWSER_PARTS_H_ +#define TIZEN_BROWSER_TIZEN_BROWSER_PARTS_H_ + +#include "content/public/browser/render_view_host.h" +#include "tizen/common/app_control.h" +#include "tizen/common/application_data.h" +#include "tizen/common/resource_manager.h" +#include "tizen/common/locale_manager.h" + +namespace tizen { + +class TizenBrowserParts { + public: + TizenBrowserParts(); + virtual void AppControl(std::unique_ptr appcontrol) = 0; + virtual void Launch(std::unique_ptr appcontrol) = 0; + virtual bool launched() const = 0; + void RenderViewCreated(content::RenderViewHost* render_view_host); + void GetCSP(std::string &csp_rule, std::string &csp_report_rule); + void Initialize(); + + protected: + std::unique_ptr locale_manager_; + std::unique_ptr resource_manager_; + virtual ~TizenBrowserParts() {} + + private: + void SetLongPollingTimeout(content::RenderViewHost* render_view_host); + + common::ApplicationData* app_data_; + int security_model_version_; + std::string csp_rule_; + std::string csp_report_rule_; +}; + +} // namespace tizen + +#endif // TIZEN_BROWSER_TIZEN_BROWSER_PARTS_H_ \ No newline at end of file diff --git a/wrt.gyp b/wrt.gyp index 32f0a97f8..2410d1c27 100644 --- a/wrt.gyp +++ b/wrt.gyp @@ -122,6 +122,8 @@ 'tizen/src/browser/wrt_ipc.h', 'tizen/src/browser/wrt_service.cc', 'tizen/src/browser/wrt_service.h', + 'tizen/browser/tizen_browser_parts.cc', + 'tizen/browser/tizen_browser_parts.h', ], 'sources/': [ # chromium-efl supports only tizen webrtc using CAPI -- 2.34.1