Chromium Code Reviews| Index: content/browser/shared_worker/shared_worker_instance.cc |
| diff --git a/content/browser/shared_worker/shared_worker_service_impl.cc b/content/browser/shared_worker/shared_worker_instance.cc |
| similarity index 10% |
| copy from content/browser/shared_worker/shared_worker_service_impl.cc |
| copy to content/browser/shared_worker/shared_worker_instance.cc |
| index d1e245a4268825a414649040c9779c02e974ddd9..59f64f769dea5f490392678d70b3a587e60e7182 100644 |
| --- a/content/browser/shared_worker/shared_worker_service_impl.cc |
| +++ b/content/browser/shared_worker/shared_worker_instance.cc |
| @@ -2,143 +2,105 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "content/browser/shared_worker/shared_worker_service_impl.h" |
| +#include "content/browser/shared_worker/shared_worker_instance.h" |
| -#include "content/browser/shared_worker/shared_worker_message_filter.h" |
| -#include "content/common/worker_messages.h" |
| -#include "content/public/browser/browser_thread.h" |
| -#include "content/public/browser/worker_service_observer.h" |
| +#include "base/logging.h" |
| +#include "content/browser/worker_host/worker_document_set.h" |
| namespace content { |
| -SharedWorkerServiceImpl* SharedWorkerServiceImpl::GetInstance() { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - return Singleton<SharedWorkerServiceImpl>::get(); |
| -} |
| - |
| -SharedWorkerServiceImpl::SharedWorkerServiceImpl() { |
| -} |
| - |
| -SharedWorkerServiceImpl::~SharedWorkerServiceImpl() { |
| -} |
| - |
| -bool SharedWorkerServiceImpl::TerminateWorker(int process_id, int route_id) { |
| - // TODO(horo): implement this. |
| - return false; |
| -} |
| - |
| -std::vector<WorkerService::WorkerInfo> SharedWorkerServiceImpl::GetWorkers() { |
| - // TODO(horo): implement this. |
| - std::vector<WorkerService::WorkerInfo> results; |
| - return results; |
| -} |
| - |
| -void SharedWorkerServiceImpl::AddObserver(WorkerServiceObserver* observer) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - observers_.AddObserver(observer); |
| -} |
| - |
| -void SharedWorkerServiceImpl::RemoveObserver(WorkerServiceObserver* observer) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - observers_.RemoveObserver(observer); |
| -} |
| - |
| -void SharedWorkerServiceImpl::CreateWorker( |
| - const ViewHostMsg_CreateWorker_Params& params, |
| - int route_id, |
| - SharedWorkerMessageFilter* filter, |
| - ResourceContext* resource_context, |
| - const WorkerStoragePartition& partition, |
| - bool* url_mismatch) { |
| - // TODO(horo): implement this. |
| - NOTIMPLEMENTED(); |
| -} |
| - |
| -void SharedWorkerServiceImpl::ForwardToWorker( |
| - const IPC::Message& message, |
| - SharedWorkerMessageFilter* filter) { |
| - // TODO(horo): implement this. |
| - NOTIMPLEMENTED(); |
| -} |
| - |
| -void SharedWorkerServiceImpl::DocumentDetached( |
| - unsigned long long document_id, |
| - SharedWorkerMessageFilter* filter) { |
| - // TODO(horo): implement this. |
| - NOTIMPLEMENTED(); |
| -} |
| - |
| -void SharedWorkerServiceImpl::WorkerContextClosed( |
| - int worker_route_id, |
| - SharedWorkerMessageFilter* filter) { |
| - // TODO(horo): implement this. |
| - NOTIMPLEMENTED(); |
| -} |
| - |
| -void SharedWorkerServiceImpl::WorkerContextDestroyed( |
| - int worker_route_id, |
| - SharedWorkerMessageFilter* filter) { |
| - // TODO(horo): implement this. |
| - NOTIMPLEMENTED(); |
| -} |
| - |
| -void SharedWorkerServiceImpl::WorkerScriptLoaded( |
| - int worker_route_id, |
| - SharedWorkerMessageFilter* filter) { |
| - // TODO(horo): implement this. |
| - NOTIMPLEMENTED(); |
| -} |
| - |
| -void SharedWorkerServiceImpl::WorkerScriptLoadFailed( |
| - int worker_route_id, |
| - SharedWorkerMessageFilter* filter) { |
| - // TODO(horo): implement this. |
| - NOTIMPLEMENTED(); |
| -} |
| - |
| -void SharedWorkerServiceImpl::WorkerConnected( |
| - int message_port_id, |
| - int worker_route_id, |
| - SharedWorkerMessageFilter* filter) { |
| - // TODO(horo): implement this. |
| - NOTIMPLEMENTED(); |
| -} |
| - |
| -void SharedWorkerServiceImpl::AllowDatabase( |
| - int worker_route_id, |
| +SharedWorkerInstance::SharedWorkerInstance( |
| const GURL& url, |
| const base::string16& name, |
| - const base::string16& display_name, |
| - unsigned long estimated_size, |
| - bool* result, |
| - SharedWorkerMessageFilter* filter) { |
| - // TODO(horo): implement this. |
| - NOTIMPLEMENTED(); |
| -} |
| - |
| -void SharedWorkerServiceImpl::AllowFileSystem( |
| - int worker_route_id, |
| - const GURL& url, |
| - bool* result, |
| - SharedWorkerMessageFilter* filter) { |
| - // TODO(horo): implement this. |
| - NOTIMPLEMENTED(); |
| + const base::string16& content_security_policy, |
| + blink::WebContentSecurityPolicyType security_policy_type, |
| + ResourceContext* resource_context, |
| + const WorkerStoragePartition& partition) |
| + : url_(url), |
| + closed_(false), |
| + name_(name), |
| + content_security_policy_(content_security_policy), |
| + security_policy_type_(security_policy_type), |
| + worker_document_set_(new WorkerDocumentSet()), |
| + resource_context_(resource_context), |
| + partition_(partition), |
| + load_failed_(false) { |
| + DCHECK(resource_context_); |
| } |
| -void SharedWorkerServiceImpl::AllowIndexedDB( |
| - int worker_route_id, |
| - const GURL& url, |
| - const base::string16& name, |
| - bool* result, |
| - SharedWorkerMessageFilter* filter) { |
| - // TODO(horo): implement this. |
| - NOTIMPLEMENTED(); |
| +SharedWorkerInstance::~SharedWorkerInstance() { |
| } |
| -void SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing( |
| - SharedWorkerMessageFilter* filter) { |
| - // TODO(horo): implement this. |
| - NOTIMPLEMENTED(); |
| +void SharedWorkerInstance::SetMessagePortID( |
| + SharedWorkerMessageFilter* filter, |
| + int route_id, |
| + int message_port_id) { |
| + for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) { |
| + if (i->filter() == filter && i->route_id() == route_id) { |
| + i->set_message_port_id(message_port_id); |
| + return; |
| + } |
| + } |
| +} |
| + |
| +// Compares an instance based on the algorithm in the WebWorkers spec - an |
| +// instance matches if the origins of the URLs match, and: |
| +// a) the names are non-empty and equal |
| +// -or- |
| +// b) the names are both empty, and the urls are equal |
|
kinuko
2014/02/26 08:51:17
This comments can be probably moved to .h
horo
2014/02/26 10:36:19
Done.
|
| +bool SharedWorkerInstance::Matches(const GURL& match_url, |
| + const base::string16& match_name, |
| + const WorkerStoragePartition& partition, |
| + ResourceContext* resource_context) const { |
| + // Only match open shared workers. |
| + if (closed_) |
| + return false; |
| + |
| + // ResourceContext equivalence is being used as a proxy to ensure we only |
| + // matched shared workers within the same BrowserContext. |
| + if (resource_context_ != resource_context) |
| + return false; |
| + |
| + // We must be in the same storage partition otherwise sharing will violate |
| + // isolation. |
| + if (!partition_.Equals(partition)) |
| + return false; |
| + |
| + if (url_.GetOrigin() != match_url.GetOrigin()) |
| + return false; |
| + |
| + if (name_.empty() && match_name.empty()) |
| + return url_ == match_url; |
| + |
| + return name_ == match_name; |
| +} |
| + |
| +void SharedWorkerInstance::AddFilter(SharedWorkerMessageFilter* filter, |
| + int route_id) { |
| + CHECK(filter); |
| + if (!HasFilter(filter, route_id)) { |
| + FilterInfo info(filter, route_id); |
| + filters_.push_back(info); |
| + } |
| +} |
| + |
| +void SharedWorkerInstance::RemoveFilters(SharedWorkerMessageFilter* filter) { |
| + for (FilterList::iterator i = filters_.begin(); i != filters_.end();) { |
| + if (i->filter() == filter) |
| + i = filters_.erase(i); |
| + else |
| + ++i; |
| + } |
| +} |
| + |
| +bool SharedWorkerInstance::HasFilter(SharedWorkerMessageFilter* filter, |
| + int route_id) const { |
| + for (FilterList::const_iterator i = filters_.begin(); i != filters_.end(); |
| + ++i) { |
| + if (i->filter() == filter && i->route_id() == route_id) |
| + return true; |
| + } |
| + return false; |
| } |
| } // namespace content |