#include "content/public/browser/shared_worker_instance.h"
#include "base/check.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_client.h"
namespace content {
SharedWorkerInstance::SharedWorkerInstance(
const GURL& url,
blink::mojom::ScriptType script_type,
network::mojom::CredentialsMode credentials_mode,
const std::string& name,
const blink::StorageKey& storage_key,
blink::mojom::SharedWorkerCreationContextType creation_context_type)
: url_(url),
script_type_(script_type),
credentials_mode_(credentials_mode),
name_(name),
storage_key_(storage_key),
creation_context_type_(creation_context_type) {
DCHECK(url.SchemeIs(url::kDataScheme) ||
GetContentClient()->browser()->DoesSchemeAllowCrossOriginSharedWorker(
storage_key.origin().scheme()) ||
storage_key.origin().IsSameOriginWith(url));
}
SharedWorkerInstance::SharedWorkerInstance(const SharedWorkerInstance& other) =
default;
SharedWorkerInstance::SharedWorkerInstance(SharedWorkerInstance&& other) =
default;
SharedWorkerInstance::~SharedWorkerInstance() = default;
bool SharedWorkerInstance::Matches(const GURL& url,
const std::string& name,
const blink::StorageKey& storage_key) const {
if (storage_key_ != storage_key || url_ != url || name_ != name) {
return false;
}
if (url.SchemeIsFile() || storage_key.origin().scheme() == url::kFileScheme)
return false;
return true;
}
}