• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "content/renderer/shared_worker_repository.h"
6 
7 #include "content/child/child_thread.h"
8 #include "content/common/view_messages.h"
9 #include "content/renderer/render_view_impl.h"
10 #include "content/renderer/websharedworker_proxy.h"
11 #include "third_party/WebKit/public/web/WebView.h"
12 
13 namespace content {
14 
SharedWorkerRepository(RenderViewImpl * render_view)15 SharedWorkerRepository::SharedWorkerRepository(RenderViewImpl* render_view)
16     : RenderViewObserver(render_view) {
17   render_view->GetWebView()->setSharedWorkerRepositoryClient(this);
18 }
19 
~SharedWorkerRepository()20 SharedWorkerRepository::~SharedWorkerRepository() {}
21 
22 blink::WebSharedWorkerConnector*
createSharedWorkerConnector(const blink::WebURL & url,const blink::WebString & name,DocumentID document_id)23 SharedWorkerRepository::createSharedWorkerConnector(
24     const blink::WebURL& url,
25     const blink::WebString& name,
26     DocumentID document_id) {
27   int route_id = MSG_ROUTING_NONE;
28   bool exists = false;
29   bool url_mismatch = false;
30   ViewHostMsg_CreateWorker_Params params;
31   params.url = url;
32   params.name = name;
33   params.document_id = document_id;
34   params.render_view_route_id = render_view()->GetRoutingID();
35   params.route_id = MSG_ROUTING_NONE;
36   params.script_resource_appcache_id = 0;
37   Send(new ViewHostMsg_LookupSharedWorker(
38       params, &exists, &route_id, &url_mismatch));
39   if (url_mismatch)
40     return NULL;
41   documents_with_workers_.insert(document_id);
42   return new WebSharedWorkerProxy(ChildThread::current(),
43                                   document_id,
44                                   exists,
45                                   route_id,
46                                   render_view()->GetRoutingID());
47 }
48 
documentDetached(DocumentID document)49 void SharedWorkerRepository::documentDetached(DocumentID document) {
50   std::set<DocumentID>::iterator iter = documents_with_workers_.find(document);
51   if (iter != documents_with_workers_.end()) {
52     // Notify the browser process that the document has shut down.
53     Send(new ViewHostMsg_DocumentDetached(document));
54     documents_with_workers_.erase(iter);
55   }
56 }
57 
58 }  // namespace content
59