Implementation of Appcontrol functionalities 83/178883/8
authorsurya.kumar7 <surya.kumar7@samsung.com>
Wed, 20 Jun 2018 17:27:22 +0000 (22:57 +0530)
committerjaekuk lee <juku1999@samsung.com>
Mon, 2 Jul 2018 11:36:29 +0000 (11:36 +0000)
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 <surya.kumar7@samsung.com>
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/browser.cc
atom/browser/browser.h
atom/common/api/api_messages.h
atom/renderer/atom_render_view_observer.cc
atom/renderer/atom_render_view_observer.h
tizen/browser/tizen_browser_parts.cc [new file with mode: 0644]
tizen/browser/tizen_browser_parts.h [new file with mode: 0644]
wrt.gyp

index 7e3e176..43b1940 100644 (file)
@@ -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<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
   WebContentsPreferences* web_preferences =
       WebContentsPreferences::FromWebContents(web_contents());
index ef1578c..6d50694 100644 (file)
@@ -387,6 +387,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
   // get the zoom level.
   void OnGetZoomLevel(IPC::Message* reply_msg);
 
+  void OnGetContentSecurityPolicy(IPC::Message* reply_msg);
+
   v8::Global<v8::Value> session_;
   v8::Global<v8::Value> devtools_web_contents_;
   v8::Global<v8::Value> debugger_;
index aca2f68..dcfc6bc 100644 (file)
@@ -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<common::AppControl> appcontrol) {
   std::unique_ptr<common::ResourceManager::Resource> res =
       resource_manager_->GetStartResource(appcontrol.get());
index 48365b8..358bcb9 100644 (file)
@@ -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<common::AppControl> appcontrol);
-  void Launch(std::unique_ptr<common::AppControl> appcontrol);
+  void AppControl(std::unique_ptr<common::AppControl> appcontrol) override;
+  void Launch(std::unique_ptr<common::AppControl> appcontrol) override;
   void SendAppControlEvent();
   void SetSplashScreen();
   void HideSplashScreen(int reason);
@@ -262,8 +263,6 @@ class Browser : public WindowListObserver {
   base::ObserverList<BrowserObserver> observers_;
 
 #if defined(OS_TIZEN)
-  std::unique_ptr<common::ResourceManager> resource_manager_;
-  std::unique_ptr<common::LocaleManager> locale_manager_;
   std::unique_ptr<SplashScreen> splash_screen_;
   std::string start_url_;
   bool launched_;
index 5052c40..44e8ad6 100644 (file)
@@ -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
index a68238b..8923fdf 100644 (file)
@@ -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
index e642bbe..cd69e2a 100644 (file)
@@ -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 (file)
index 0000000..231a9b3
--- /dev/null
@@ -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 <unsigned int> polling_val(app_data_->setting_info()->long_polling());
+    unsigned long *ptr =  reinterpret_cast <unsigned long *> (&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 (file)
index 0000000..4f6d552
--- /dev/null
@@ -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<common::AppControl> appcontrol) = 0;
+  virtual void Launch(std::unique_ptr<common::AppControl> 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<common::LocaleManager> locale_manager_;
+  std::unique_ptr<common::ResourceManager> 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 32f0a97..2410d1c 100644 (file)
--- a/wrt.gyp
+++ b/wrt.gyp
         '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