[M34-Merge]Add file:// protocol handler specific for WRT.
authorWojciech Wiśniewski <w.wisniewski@samsung.com>
Wed, 28 Jan 2015 13:59:57 +0000 (14:59 +0100)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
This patch is porting of following patches:
http://165.213.202.130:8080/#/c/70649/ by Zbigniew Kostrzewa
http://165.213.202.130:8080/#/c/70977/ by Marek Ruszczyński
http://165.213.202.130:8080/#/c/71786/ by Piotr Szawdyński
(second and third are fixups of the first)

Original commit message:

This commit extends file:// URI scheme to provide features
specific to WRT.
When Chromium launch originates from WRT then each reference
to a resource via file:// URI scheme results in an IPC message
sent from browser to renderer and back to give a chance to WRT
to modify the URI.

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=10412
Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=10405
Reviewed by: Jaesik Chang, Piotr Tworek, SeungSeop Park

Change-Id: Id875fd7b03a231a098f8277c6af5f2031da03861
Signed-off-by: Wojciech Wiśniewski <w.wisniewski@samsung.com>
tizen_src/impl/common/render_messages_efl.h
tizen_src/impl/renderer/content_renderer_client_efl.cc [changed mode: 0755->0644]
tizen_src/impl/renderer/content_renderer_client_efl.h [changed mode: 0755->0644]
tizen_src/impl/wrt/wrt_widget_host.cc
tizen_src/impl/wrt/wrt_widget_host.h
tizen_src/impl/wrt/wrtwidget.cc
tizen_src/impl/wrt/wrtwidget.h

index f71bca933bb6c563620bdc7b400fef0927e77ee7..1feae20aee753618bd41684f3f0b7f9d10f489ec 100644 (file)
@@ -177,9 +177,10 @@ IPC_MESSAGE_CONTROL4(WrtMsg_SetWidgetInfo,
 IPC_MESSAGE_CONTROL2(WrtMsg_ParseUrl,
                      int,            // result: request_id
                      GURL)           // result: url
+
 IPC_MESSAGE_CONTROL2(WrtMsg_ParseUrlResponse,
                      int,            // result: request_id
-                     GURL);          // result: url
+                     GURL)           // result: url
 
 IPC_MESSAGE_CONTROL1(WrtMsg_SendWrtMessage,
                      tizen_webview::WrtIpcMessageData /* data */);
old mode 100755 (executable)
new mode 100644 (file)
index 27ffc41..4f909ef
@@ -77,6 +77,7 @@ void ContentRendererClientEfl::RenderThreadStarted()
   content::RenderThread* thread = content::RenderThread::Get();
 
   wrt_widget_.reset(new WrtWidget);
+  thread->AddObserver(wrt_widget_->GetObserver());
 
   render_process_observer_.reset(new RenderProcessObserverEfl(this));
   thread->AddObserver(render_process_observer_.get());
@@ -147,6 +148,15 @@ bool ContentRendererClientEfl::HandleNavigation(content::RenderFrame* render_fra
   return result;
 }
 
+bool ContentRendererClientEfl::WillSendRequest(blink::WebFrame* frame,
+                                               ui::PageTransition transition_type,
+                                               const GURL& url,
+                                               const GURL& first_party_for_cookies,
+                                               GURL* new_url) {
+  wrt_widget_->ParseUrl(url, *new_url);
+  return true;
+}
+
 void ContentRendererClientEfl::DidCreateScriptContext(blink::WebFrame* frame,
                                                       v8::Handle<v8::Context> context,
                                                       int extension_group,
old mode 100755 (executable)
new mode 100644 (file)
index 9a07bf8..da36336
@@ -65,6 +65,12 @@ class ContentRendererClientEfl : public content::ContentRendererClient
                         blink::WebNavigationPolicy default_policy,
                         bool is_redirect) override;
 
+  virtual bool WillSendRequest(blink::WebFrame* frame,
+                               ui::PageTransition transition_type,
+                               const GURL& url,
+                               const GURL& first_party_for_cookies,
+                               GURL* new_url) override;
+
   virtual void GetNavigationErrorStrings(
       content::RenderView* render_view,
       blink::WebFrame* frame,
index 98a467fc91fb1bc7df4d662dcd41d0205ba5bb33..4189e093d0b147b7c62c8655fdeace0b203a7ff9 100644 (file)
@@ -38,6 +38,31 @@ bool SendToRenderer(int renderer_id, IPC::Message* message) {
 }
 }
 
+class WrtWidgetHostMessageFilter : public content::BrowserMessageFilter {
+ public:
+  explicit WrtWidgetHostMessageFilter(WrtWidgetHost* wrt_widget_host);
+
+ private:
+  bool OnMessageReceived(const IPC::Message& message) override;
+
+  WrtWidgetHost* wrt_widget_host_;
+};
+
+WrtWidgetHostMessageFilter::WrtWidgetHostMessageFilter(
+    WrtWidgetHost* wrt_widget_host)
+    : content::BrowserMessageFilter(ChromeMsgStart),
+      wrt_widget_host_(wrt_widget_host) {
+}
+
+bool WrtWidgetHostMessageFilter::OnMessageReceived(const IPC::Message& message) {
+  bool handled = true;
+  IPC_BEGIN_MESSAGE_MAP(WrtWidgetHostMessageFilter, message)
+    IPC_MESSAGE_FORWARD(WrtMsg_ParseUrlResponse, wrt_widget_host_, WrtWidgetHost::OnUrlRetrieved)
+    IPC_MESSAGE_UNHANDLED(handled = false)
+  IPC_END_MESSAGE_MAP()
+  return handled;
+}
+
 WrtWidgetHost* WrtWidgetHost::Get() {
   // TODO(z.kostrzewa) LazyInstance is thread-safe but creating
   // WrtWidgetHost is not - make it thread-safe.
@@ -47,7 +72,8 @@ WrtWidgetHost* WrtWidgetHost::Get() {
 }
 
 WrtWidgetHost::WrtWidgetHost()
-    : in_wrt_(false),
+    : message_filter_(new WrtWidgetHostMessageFilter(this)),
+      in_wrt_(false),
       widget_id_(0) {
 }
 
index 61c18baa88a63980f0c54c08346affc2e27d33c6..3fb0211c9a4d6018311b99c45fcda1528afac2e9 100644 (file)
@@ -22,12 +22,12 @@ class WrtIpcMessageData;
 
 class GURL;
 
+class WrtWidgetHostMessageFilter;
+
 class WrtWidgetHost {
  public:
   static WrtWidgetHost* Get();
 
-  content::BrowserMessageFilter* GetMessageFilter() const;
-
   void GetUrlForRequest(net::URLRequest* request,
                         base::Callback<void(const GURL&)> callback);
 
@@ -41,18 +41,21 @@ class WrtWidgetHost {
   int WidgetId() const;
 
  private:
+  friend class WrtWidgetHostMessageFilter;
+
   typedef std::map<int, base::Callback<void(const GURL&)> > callbacks_type;
 
   WrtWidgetHost();
 
-  DISALLOW_COPY_AND_ASSIGN(WrtWidgetHost);
-
   void OnUrlRetrieved(int callback_id, const GURL& url);
 
+  scoped_refptr<WrtWidgetHostMessageFilter> message_filter_;
   base::AtomicSequenceNumber callback_id_generator_;
   callbacks_type callbacks_;
   bool in_wrt_;
   int widget_id_;
+
+  DISALLOW_COPY_AND_ASSIGN(WrtWidgetHost);
 };
 
 
index 63c27322c73f2deafac77883c564a66851d92c9e..692c7344a6be9dd5d232fedbddf700b65f0dddeb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2014,2015 Samsung Electronics. All rights reserved.
+// Copyright 2014, 2015 Samsung Electronics. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 // TODO(z.kostrzewa) Why it can't be implemented as IPC::ChannelProxy::MessageFilter (?)
 // Tried that and it seems that Observer starts receiving messages earlier than
 // MessageFilter what is crucial for message that sets widget handle
+class WrtRenderThreadObserver : public content::RenderProcessObserver {
+ public:
+  explicit WrtRenderThreadObserver(WrtWidget* wrt_widget)
+    : wrt_widget_(wrt_widget),
+      channel_(content::RenderThread::Get()->GetChannel())
+  { }
+
+  bool OnControlMessageReceived(const IPC::Message& message) {
+    bool handled = true;
+    IPC_BEGIN_MESSAGE_MAP(WrtRenderThreadObserver, message)
+      IPC_MESSAGE_FORWARD(WrtMsg_SetWidgetInfo, wrt_widget_, WrtWidget::SetWidgetInfo)
+      IPC_MESSAGE_FORWARD(WrtMsg_SendWrtMessage, wrt_widget_, WrtWidget::MessageReceived)
+      IPC_MESSAGE_HANDLER(WrtMsg_ParseUrl, ParseUrl)
+      IPC_MESSAGE_UNHANDLED(handled = false)
+    IPC_END_MESSAGE_MAP()
+    return handled;
+  }
+
+ private:
+  void ParseUrl(int request_id, const GURL& url) {
+    GURL response;
+    wrt_widget_->ParseUrl(url, response);
+    Send(new WrtMsg_ParseUrlResponse(request_id, response));
+  }
+
+  void Send(IPC::Message* message) {
+    if (channel_)
+      channel_->Send(message);
+    else
+      delete message;
+  }
+
+  WrtWidget* wrt_widget_;
+  IPC::SyncChannel* channel_;
+};
+
 WrtWidget::WrtWidget()
- : widgetHandle_(-1) {
+    : widgetHandle_(-1),
+      observer_(new WrtRenderThreadObserver(this)) {
 }
 
 WrtWidget::~WrtWidget() {
+  delete observer_;
+}
+
+content::RenderProcessObserver* WrtWidget::GetObserver() {
+  return observer_;
 }
 
 void WrtWidget::SetWidgetInfo(int widgetHandle,
@@ -63,7 +105,7 @@ void WrtWidget::StopSession(v8::Handle<v8::Context> context) {
   //TODO: stop session
 }
 
-void WrtWidget::messageReceived(const tizen_webview::WrtIpcMessageData& data) {
+void WrtWidget::MessageReceived(const tizen_webview::WrtIpcMessageData& data) {
   if (widgetHandle_ != -1)
     DynamicPlugin::instance().messageReceived(data);
 }
index 714cb13757dfa81b8a60b99053306cf31e3aace8..aaeed7f427ae1336b77e5e8e5b975c68da92279d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2014,2015 Samsung Electronics. All rights reserved.
+// Copyright 2014, 2015 Samsung Electronics. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -23,6 +23,8 @@ class WrtWidget {
   WrtWidget();
   ~WrtWidget();
 
+  content::RenderProcessObserver* GetObserver();
+
   void SetWidgetInfo(int widgetHandle,
                      double scaleFactor,
                      const std::string& encodedBundle,
@@ -30,7 +32,7 @@ class WrtWidget {
 
   bool IsWidgetInfoSet() const;
 
-  void messageReceived(const tizen_webview::WrtIpcMessageData& data);
+  void MessageReceived(const tizen_webview::WrtIpcMessageData& data);
 
   void ParseUrl(const GURL& url, GURL& new_url);