| Index: content/renderer/service_worker/worker_fetch_context_info_impl.cc
 | 
| diff --git a/content/renderer/service_worker/worker_fetch_context_info_impl.cc b/content/renderer/service_worker/worker_fetch_context_info_impl.cc
 | 
| new file mode 100644
 | 
| index 0000000000000000000000000000000000000000..a9ef52e8f858a318e1dd90b58494b93ff6da40f6
 | 
| --- /dev/null
 | 
| +++ b/content/renderer/service_worker/worker_fetch_context_info_impl.cc
 | 
| @@ -0,0 +1,146 @@
 | 
| +// Copyright 2017 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/service_worker/worker_fetch_context_info_impl.h"
 | 
| +
 | 
| +#include "content/child/child_thread_impl.h"
 | 
| +#include "content/child/request_extra_data.h"
 | 
| +#include "content/child/resource_dispatcher.h"
 | 
| +#include "content/child/web_url_loader_impl.h"
 | 
| +#include "content/common/frame_messages.h"
 | 
| +#include "mojo/public/cpp/bindings/associated_binding.h"
 | 
| +
 | 
| +namespace content {
 | 
| +
 | 
| +namespace {
 | 
| +
 | 
| +class WorkerFetchContextImpl : public blink::WebWorkerFetchContext,
 | 
| +                               public mojom::ServiceWorkerClient {
 | 
| + public:
 | 
| +  WorkerFetchContextImpl(mojom::WorkerFetchContextFactoryPtrInfo factory_info,
 | 
| +                         int service_worker_provider_id,
 | 
| +                         int appcache_host_id,
 | 
| +                         int parent_frame_id,
 | 
| +                         bool parent_is_secure_context,
 | 
| +                         bool parent_is_controlled_by_service_worker,
 | 
| +                         base::SingleThreadTaskRunner* loading_task_runner,
 | 
| +                         scoped_refptr<ThreadSafeSender> thread_safe_sender)
 | 
| +      : binding_(this),
 | 
| +        service_worker_provider_id_(service_worker_provider_id),
 | 
| +        appcache_host_id_(appcache_host_id),
 | 
| +        parent_frame_id_(parent_frame_id),
 | 
| +        parent_is_secure_context_(parent_is_secure_context),
 | 
| +        parent_is_controlled_by_service_worker_(
 | 
| +            parent_is_controlled_by_service_worker),
 | 
| +        resource_dispatcher_(
 | 
| +            base::MakeUnique<ResourceDispatcher>(nullptr, loading_task_runner)),
 | 
| +        thread_safe_sender_(std::move(thread_safe_sender)) {
 | 
| +    factory_.Bind(std::move(factory_info));
 | 
| +    mojom::ServiceWorkerClientAssociatedPtrInfo ptr_info;
 | 
| +    binding_.Bind(&ptr_info);
 | 
| +    factory_->CreateWorkerFetchContext(mojo::MakeRequest(&url_loader_factory_),
 | 
| +                                       std::move(ptr_info),
 | 
| +                                       service_worker_provider_id_);
 | 
| +  }
 | 
| +  ~WorkerFetchContextImpl() override {}
 | 
| +
 | 
| +  void SetControllerServiceWorker(int64_t controller_version_id) override {
 | 
| +    controller_version_id_ = controller_version_id;
 | 
| +  }
 | 
| +
 | 
| +  bool IsControlledByServiceWorker() const override {
 | 
| +    return parent_is_controlled_by_service_worker_ ||
 | 
| +           (controller_version_id_ != kInvalidServiceWorkerVersionId);
 | 
| +  }
 | 
| +
 | 
| +  int64_t serviceWorkerID() const override { return controller_version_id_; }
 | 
| +
 | 
| +  blink::WebURLLoader* createURLLoader() override {
 | 
| +    return new content::WebURLLoaderImpl(resource_dispatcher_.get(),
 | 
| +                                         url_loader_factory_.get());
 | 
| +  }
 | 
| +  void willSendRequest(blink::WebURLRequest& request) override {
 | 
| +    RequestExtraData* extra_data = new RequestExtraData();
 | 
| +    extra_data->set_service_worker_provider_id(service_worker_provider_id_);
 | 
| +    extra_data->set_render_frame_id(parent_frame_id_);
 | 
| +    // TODO(horo): Just checking the worker's origin is enough?
 | 
| +    extra_data->set_initiated_in_secure_context(parent_is_secure_context_);
 | 
| +    request.setExtraData(extra_data);
 | 
| +    request.setAppCacheHostID(appcache_host_id_);
 | 
| +
 | 
| +    if (!IsControlledByServiceWorker() &&
 | 
| +        request.getServiceWorkerMode() !=
 | 
| +            blink::WebURLRequest::ServiceWorkerMode::None) {
 | 
| +      request.setServiceWorkerMode(
 | 
| +          blink::WebURLRequest::ServiceWorkerMode::Foreign);
 | 
| +    }
 | 
| +    // request.addHTTPOriginIfNeeded(blink::WebSecurityOrigin::createUnique());
 | 
| +  }
 | 
| +  void didRunContentWithCertificateErrors(const blink::WebURL& url) override {
 | 
| +    Send(new FrameHostMsg_DidRunContentWithCertificateErrors(parent_frame_id_,
 | 
| +                                                             url));
 | 
| +  }
 | 
| +  void didDisplayContentWithCertificateErrors(
 | 
| +      const blink::WebURL& url) override {
 | 
| +    Send(new FrameHostMsg_DidDisplayContentWithCertificateErrors(
 | 
| +        parent_frame_id_, url));
 | 
| +  }
 | 
| +  bool Send(IPC::Message* message) {
 | 
| +    return thread_safe_sender_->Send(message);
 | 
| +  }
 | 
| +
 | 
| + private:
 | 
| +  mojo::AssociatedBinding<mojom::ServiceWorkerClient> binding_;
 | 
| +  const int service_worker_provider_id_;
 | 
| +  const int appcache_host_id_;
 | 
| +  const int parent_frame_id_;
 | 
| +  const int parent_is_secure_context_;
 | 
| +  const bool parent_is_controlled_by_service_worker_;
 | 
| +  std::unique_ptr<ResourceDispatcher> resource_dispatcher_;
 | 
| +  scoped_refptr<ThreadSafeSender> thread_safe_sender_;
 | 
| +  int controller_version_id_ = kInvalidServiceWorkerVersionId;
 | 
| +  mojom::WorkerFetchContextFactoryPtr factory_;
 | 
| +  mojom::URLLoaderFactoryAssociatedPtr url_loader_factory_;
 | 
| +};
 | 
| +
 | 
| +}  // namespace
 | 
| +
 | 
| +WorkerFetchContextInfoImpl::WorkerFetchContextInfoImpl(
 | 
| +    mojom::WorkerFetchContextFactoryPtrInfo factory_info)
 | 
| +    : factory_info_(std::move(factory_info)),
 | 
| +      thread_safe_sender_(ChildThreadImpl::current()->thread_safe_sender()) {}
 | 
| +
 | 
| +WorkerFetchContextInfoImpl::~WorkerFetchContextInfoImpl() {}
 | 
| +
 | 
| +std::unique_ptr<blink::WebWorkerFetchContext>
 | 
| +WorkerFetchContextInfoImpl::CreateContext(
 | 
| +    base::SingleThreadTaskRunner* loading_task_runner) {
 | 
| +  DCHECK(factory_info_.is_valid());
 | 
| +  return base::MakeUnique<WorkerFetchContextImpl>(
 | 
| +      std::move(factory_info_), service_worker_provider_id_, appcache_host_id_,
 | 
| +      parent_frame_id_, is_secure_context_, is_controlled_by_service_worker_,
 | 
| +      loading_task_runner, std::move(thread_safe_sender_));
 | 
| +}
 | 
| +void WorkerFetchContextInfoImpl::setAppCacheHostID(int appcache_host_id) {
 | 
| +  appcache_host_id_ = appcache_host_id;
 | 
| +}
 | 
| +void WorkerFetchContextInfoImpl::setParentFrameID(int parent_frame_id) {
 | 
| +  parent_frame_id_ = parent_frame_id;
 | 
| +}
 | 
| +void WorkerFetchContextInfoImpl::setServiceWorkerProviderID(
 | 
| +    int service_worker_provider_id) {
 | 
| +  service_worker_provider_id_ = service_worker_provider_id;
 | 
| +}
 | 
| +void WorkerFetchContextInfoImpl::setIsSecureContext(bool is_secure_context) {
 | 
| +  is_secure_context_ = is_secure_context;
 | 
| +}
 | 
| +void WorkerFetchContextInfoImpl::setIsControlledByServiceWorker(
 | 
| +    bool contolled) {
 | 
| +  is_controlled_by_service_worker_ = contolled;
 | 
| +}
 | 
| +void WorkerFetchContextInfoImpl::willSendRequest(blink::WebURLRequest&) {
 | 
| +  NOTREACHED();
 | 
| +}
 | 
| +
 | 
| +}  // namespace content
 | 
| 
 |