1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "FileChannelParent.h"
8 #include "mozilla/Assertions.h"
9 #include "mozilla/dom/ContentParent.h"
10 #include "mozilla/net/NeckoParent.h"
11 #include "nsNetUtil.h"
12 #include "nsIChannel.h"
13 
14 namespace mozilla {
15 namespace net {
16 
NS_IMPL_ISUPPORTS(FileChannelParent,nsIParentChannel,nsIStreamListener)17 NS_IMPL_ISUPPORTS(FileChannelParent, nsIParentChannel, nsIStreamListener)
18 
19 bool FileChannelParent::Init(const uint64_t& aChannelId) {
20   nsCOMPtr<nsIChannel> channel;
21   MOZ_ALWAYS_SUCCEEDS(
22       NS_LinkRedirectChannels(aChannelId, this, getter_AddRefs(channel)));
23 
24   return true;
25 }
26 
27 NS_IMETHODIMP
SetParentListener(ParentChannelListener * aListener)28 FileChannelParent::SetParentListener(ParentChannelListener* aListener) {
29   // Nothing to do.
30   return NS_OK;
31 }
32 
33 NS_IMETHODIMP
NotifyClassificationFlags(uint32_t aClassificationFlags,bool aIsThirdParty)34 FileChannelParent::NotifyClassificationFlags(uint32_t aClassificationFlags,
35                                              bool aIsThirdParty) {
36   // Nothing to do.
37   return NS_OK;
38 }
39 
40 NS_IMETHODIMP
NotifyFlashPluginStateChanged(nsIHttpChannel::FlashPluginState aState)41 FileChannelParent::NotifyFlashPluginStateChanged(
42     nsIHttpChannel::FlashPluginState aState) {
43   // Nothing to do.
44   return NS_OK;
45 }
46 
47 NS_IMETHODIMP
SetClassifierMatchedInfo(const nsACString & aList,const nsACString & aProvider,const nsACString & aFullHash)48 FileChannelParent::SetClassifierMatchedInfo(const nsACString& aList,
49                                             const nsACString& aProvider,
50                                             const nsACString& aFullHash) {
51   // nothing to do
52   return NS_OK;
53 }
54 
55 NS_IMETHODIMP
SetClassifierMatchedTrackingInfo(const nsACString & aLists,const nsACString & aFullHashes)56 FileChannelParent::SetClassifierMatchedTrackingInfo(
57     const nsACString& aLists, const nsACString& aFullHashes) {
58   // nothing to do
59   return NS_OK;
60 }
61 
62 NS_IMETHODIMP
Delete()63 FileChannelParent::Delete() {
64   // Nothing to do.
65   return NS_OK;
66 }
67 
68 NS_IMETHODIMP
GetRemoteType(nsACString & aRemoteType)69 FileChannelParent::GetRemoteType(nsACString& aRemoteType) {
70   if (!CanSend()) {
71     return NS_ERROR_UNEXPECTED;
72   }
73 
74   dom::PContentParent* pcp = Manager()->Manager();
75   aRemoteType = static_cast<dom::ContentParent*>(pcp)->GetRemoteType();
76   return NS_OK;
77 }
78 
ActorDestroy(ActorDestroyReason why)79 void FileChannelParent::ActorDestroy(ActorDestroyReason why) {}
80 
81 NS_IMETHODIMP
OnStartRequest(nsIRequest * aRequest)82 FileChannelParent::OnStartRequest(nsIRequest* aRequest) {
83   // We don't have a way to prevent nsBaseChannel from calling AsyncOpen on
84   // the created nsDataChannel. We don't have anywhere to send the data in the
85   // parent, so abort the binding.
86   return NS_BINDING_ABORTED;
87 }
88 
89 NS_IMETHODIMP
OnStopRequest(nsIRequest * aRequest,nsresult aStatusCode)90 FileChannelParent::OnStopRequest(nsIRequest* aRequest, nsresult aStatusCode) {
91   // See above.
92   MOZ_ASSERT(NS_FAILED(aStatusCode));
93   return NS_OK;
94 }
95 
96 NS_IMETHODIMP
OnDataAvailable(nsIRequest * aRequest,nsIInputStream * aInputStream,uint64_t aOffset,uint32_t aCount)97 FileChannelParent::OnDataAvailable(nsIRequest* aRequest,
98                                    nsIInputStream* aInputStream,
99                                    uint64_t aOffset, uint32_t aCount) {
100   // See above.
101   MOZ_CRASH("Should never be called");
102 }
103 
104 }  // namespace net
105 }  // namespace mozilla
106