Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: Source/core/workers/SharedWorker.cpp

Issue 40143003: Simplify SharedWorkerRepository code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 20 matching lines...) Expand all
31 31
32 #include "config.h" 32 #include "config.h"
33 #include "core/workers/SharedWorker.h" 33 #include "core/workers/SharedWorker.h"
34 34
35 #include "bindings/v8/ExceptionState.h" 35 #include "bindings/v8/ExceptionState.h"
36 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
37 #include "core/dom/ExecutionContext.h" 37 #include "core/dom/ExecutionContext.h"
38 #include "core/dom/MessageChannel.h" 38 #include "core/dom/MessageChannel.h"
39 #include "core/dom/MessagePort.h" 39 #include "core/dom/MessagePort.h"
40 #include "core/inspector/InspectorInstrumentation.h" 40 #include "core/inspector/InspectorInstrumentation.h"
41 #include "core/page/Page.h"
41 #include "core/page/UseCounter.h" 42 #include "core/page/UseCounter.h"
42 #include "core/workers/SharedWorkerRepository.h" 43 #include "core/workers/SharedWorkerRepositoryClient.h"
43 #include "weborigin/KURL.h" 44 #include "weborigin/KURL.h"
44 #include "weborigin/SecurityOrigin.h" 45 #include "weborigin/SecurityOrigin.h"
45 46
46 namespace WebCore { 47 namespace WebCore {
47 48
48 inline SharedWorker::SharedWorker(ExecutionContext* context) 49 inline SharedWorker::SharedWorker(ExecutionContext* context)
49 : AbstractWorker(context) 50 : AbstractWorker(context)
50 { 51 {
51 ScriptWrappable::init(this); 52 ScriptWrappable::init(this);
52 } 53 }
53 54
54 PassRefPtr<SharedWorker> SharedWorker::create(ExecutionContext* context, const S tring& url, const String& name, ExceptionState& es) 55 PassRefPtr<SharedWorker> SharedWorker::create(ExecutionContext* context, const S tring& url, const String& name, ExceptionState& es)
55 { 56 {
56 ASSERT(isMainThread()); 57 ASSERT(isMainThread());
58 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
59
57 UseCounter::count(toDocument(context)->domWindow(), UseCounter::SharedWorker Start); 60 UseCounter::count(toDocument(context)->domWindow(), UseCounter::SharedWorker Start);
58 61
59 RefPtr<SharedWorker> worker = adoptRef(new SharedWorker(context)); 62 RefPtr<SharedWorker> worker = adoptRef(new SharedWorker(context));
60 63
61 RefPtr<MessageChannel> channel = MessageChannel::create(context); 64 RefPtr<MessageChannel> channel = MessageChannel::create(context);
62 worker->m_port = channel->port1(); 65 worker->m_port = channel->port1();
63 RefPtr<MessagePortChannel> remotePort = channel->port2()->disentangle(); 66 RefPtr<MessagePortChannel> remotePort = channel->port2()->disentangle();
64 ASSERT(remotePort); 67 ASSERT(remotePort);
65 68
66 worker->suspendIfNeeded(); 69 worker->suspendIfNeeded();
67 70
68 // We don't currently support nested workers, so workers can only be created from documents. 71 // We don't currently support nested workers, so workers can only be created from documents.
69 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
70 Document* document = toDocument(context); 72 Document* document = toDocument(context);
71 if (!document->securityOrigin()->canAccessSharedWorkers()) { 73 if (!document->securityOrigin()->canAccessSharedWorkers()) {
72 es.throwSecurityError("Failed to create 'SharedWorker': access to shared workers is denied to origin '" + document->securityOrigin()->toString() + "'.") ; 74 es.throwSecurityError("Failed to create 'SharedWorker': access to shared workers is denied to origin '" + document->securityOrigin()->toString() + "'.") ;
73 return 0; 75 return 0;
74 } 76 }
75 77
76 KURL scriptURL = worker->resolveURL(url, es); 78 KURL scriptURL = worker->resolveURL(url, es);
77 if (scriptURL.isEmpty()) 79 if (scriptURL.isEmpty())
78 return 0; 80 return 0;
79 81
80 SharedWorkerRepository::connect(worker.get(), remotePort.release(), scriptUR L, name, es); 82 if (document->page() && document->page()->sharedWorkerRepositoryClient())
83 document->page()->sharedWorkerRepositoryClient()->connect(worker.get(), remotePort.release(), scriptURL, name, es);
81 84
82 return worker.release(); 85 return worker.release();
83 } 86 }
84 87
85 SharedWorker::~SharedWorker() 88 SharedWorker::~SharedWorker()
86 { 89 {
87 } 90 }
88 91
89 const AtomicString& SharedWorker::interfaceName() const 92 const AtomicString& SharedWorker::interfaceName() const
90 { 93 {
91 return EventTargetNames::SharedWorker; 94 return EventTargetNames::SharedWorker;
92 } 95 }
93 96
94 } // namespace WebCore 97 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/workers/DefaultSharedWorkerRepository.h ('k') | Source/core/workers/SharedWorkerRepository.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698