summaryrefslogtreecommitdiffstats
path: root/content/renderer/shared_worker_repository.cc
blob: e39fa379d1d9bb1324163341376f50bfb3ccfc5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/renderer/shared_worker_repository.h"

#include "content/child/child_thread.h"
#include "content/common/view_messages.h"
#include "content/renderer/render_view_impl.h"
#include "content/renderer/websharedworker_proxy.h"
#include "third_party/WebKit/public/web/WebView.h"

namespace content {

SharedWorkerRepository::SharedWorkerRepository(RenderViewImpl* render_view)
    : RenderViewObserver(render_view) {
  render_view->GetWebView()->setSharedWorkerRepositoryClient(this);
}

SharedWorkerRepository::~SharedWorkerRepository() {}

WebKit::WebSharedWorker* SharedWorkerRepository::createSharedWorker(
    const WebKit::WebURL& url,
    const WebKit::WebString& name,
    DocumentID document_id) {
  int route_id = MSG_ROUTING_NONE;
  bool exists = false;
  bool url_mismatch = false;
  ViewHostMsg_CreateWorker_Params params;
  params.url = url;
  params.name = name;
  params.document_id = document_id;
  params.render_view_route_id = render_view()->GetRoutingID();
  params.route_id = MSG_ROUTING_NONE;
  params.script_resource_appcache_id = 0;
  Send(new ViewHostMsg_LookupSharedWorker(
      params, &exists, &route_id, &url_mismatch));
  if (url_mismatch)
    return NULL;
  documents_with_workers_.insert(document_id);
  return new WebSharedWorkerProxy(ChildThread::current(),
                                  document_id,
                                  exists,
                                  route_id,
                                  render_view()->GetRoutingID());
}

void SharedWorkerRepository::documentDetached(DocumentID document) {
  std::set<DocumentID>::iterator iter = documents_with_workers_.find(document);
  if (iter != documents_with_workers_.end()) {
    // Notify the browser process that the document has shut down.
    Send(new ViewHostMsg_DocumentDetached(document));
    documents_with_workers_.erase(iter);
  }
}

}  // namespace content