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 */);
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());
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,
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,
}
}
+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.
}
WrtWidgetHost::WrtWidgetHost()
- : in_wrt_(false),
+ : message_filter_(new WrtWidgetHostMessageFilter(this)),
+ in_wrt_(false),
widget_id_(0) {
}
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);
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);
};
-// 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,
//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);
}
-// 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.
WrtWidget();
~WrtWidget();
+ content::RenderProcessObserver* GetObserver();
+
void SetWidgetInfo(int widgetHandle,
double scaleFactor,
const std::string& encodedBundle,
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);