This source file includes following definitions.
- created_
- Disconnect
- Send
- SendQueuedMessages
- connect
- OnMessageReceived
- OnWorkerCreated
- OnWorkerScriptLoadFailed
- OnWorkerConnected
#include "content/renderer/websharedworker_proxy.h"
#include "content/child/webmessageportchannel_impl.h"
#include "content/common/message_router.h"
#include "content/common/view_messages.h"
#include "content/common/worker_messages.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/web/WebSharedWorkerClient.h"
namespace content {
WebSharedWorkerProxy::WebSharedWorkerProxy(MessageRouter* router,
unsigned long long document_id,
int route_id,
int render_frame_route_id)
: route_id_(route_id),
render_frame_route_id_(render_frame_route_id),
router_(router),
document_id_(document_id),
pending_route_id_(route_id),
connect_listener_(NULL),
created_(false) {
router_->AddRoute(route_id_, this);
}
WebSharedWorkerProxy::~WebSharedWorkerProxy() {
Disconnect();
for (size_t i = 0; i < queued_messages_.size(); ++i)
delete queued_messages_[i];
}
void WebSharedWorkerProxy::Disconnect() {
if (route_id_ == MSG_ROUTING_NONE)
return;
router_->RemoveRoute(route_id_);
route_id_ = MSG_ROUTING_NONE;
}
bool WebSharedWorkerProxy::Send(IPC::Message* message) {
if (!created_) {
queued_messages_.push_back(message);
return true;
}
IPC::Message* wrapped_msg = new ViewHostMsg_ForwardToWorker(*message);
delete message;
return router_->Send(wrapped_msg);
}
void WebSharedWorkerProxy::SendQueuedMessages() {
DCHECK(queued_messages_.size());
std::vector<IPC::Message*> queued_messages = queued_messages_;
queued_messages_.clear();
for (size_t i = 0; i < queued_messages.size(); ++i) {
queued_messages[i]->set_routing_id(route_id_);
Send(queued_messages[i]);
}
}
void WebSharedWorkerProxy::connect(blink::WebMessagePortChannel* channel,
ConnectListener* listener) {
WebMessagePortChannelImpl* webchannel =
static_cast<WebMessagePortChannelImpl*>(channel);
int message_port_id = webchannel->message_port_id();
DCHECK(message_port_id != MSG_ROUTING_NONE);
webchannel->QueueMessages();
Send(new WorkerMsg_Connect(route_id_, message_port_id, MSG_ROUTING_NONE));
connect_listener_ = listener;
}
bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message)
IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated)
IPC_MESSAGE_HANDLER(ViewMsg_WorkerScriptLoadFailed,
OnWorkerScriptLoadFailed)
IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected,
OnWorkerConnected)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void WebSharedWorkerProxy::OnWorkerCreated() {
created_ = true;
SendQueuedMessages();
}
void WebSharedWorkerProxy::OnWorkerScriptLoadFailed() {
if (connect_listener_) {
connect_listener_->scriptLoadFailed();
}
}
void WebSharedWorkerProxy::OnWorkerConnected() {
if (connect_listener_) {
connect_listener_->connected();
}
}
}