OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 OwnPtr<protocol::DictionaryValue> headersObject = protocol::DictionaryValue:
:create(); | 114 OwnPtr<protocol::DictionaryValue> headersObject = protocol::DictionaryValue:
:create(); |
115 for (const auto& header : headers) | 115 for (const auto& header : headers) |
116 headersObject->setString(header.key.string(), header.value); | 116 headersObject->setString(header.key.string(), header.value); |
117 protocol::ErrorSupport errors; | 117 protocol::ErrorSupport errors; |
118 return protocol::Network::Headers::parse(headersObject.get(), &errors); | 118 return protocol::Network::Headers::parse(headersObject.get(), &errors); |
119 } | 119 } |
120 | 120 |
121 class InspectorFileReaderLoaderClient final : public FileReaderLoaderClient { | 121 class InspectorFileReaderLoaderClient final : public FileReaderLoaderClient { |
122 WTF_MAKE_NONCOPYABLE(InspectorFileReaderLoaderClient); | 122 WTF_MAKE_NONCOPYABLE(InspectorFileReaderLoaderClient); |
123 public: | 123 public: |
124 InspectorFileReaderLoaderClient(PassRefPtr<BlobDataHandle> blob, PassOwnPtr<
TextResourceDecoder> decoder, PassRefPtr<GetResponseBodyCallback> callback) | 124 InspectorFileReaderLoaderClient(PassRefPtr<BlobDataHandle> blob, PassOwnPtr<
TextResourceDecoder> decoder, PassOwnPtr<GetResponseBodyCallback> callback) |
125 : m_blob(blob) | 125 : m_blob(blob) |
126 , m_decoder(decoder) | 126 , m_decoder(decoder) |
127 , m_callback(callback) | 127 , m_callback(callback) |
128 { | 128 { |
129 m_loader = FileReaderLoader::create(FileReaderLoader::ReadByClient, this
); | 129 m_loader = FileReaderLoader::create(FileReaderLoader::ReadByClient, this
); |
130 } | 130 } |
131 | 131 |
132 ~InspectorFileReaderLoaderClient() override { } | 132 ~InspectorFileReaderLoaderClient() override { } |
133 | 133 |
134 void start(ExecutionContext* executionContext) | 134 void start(ExecutionContext* executionContext) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 175 |
176 private: | 176 private: |
177 void dispose() | 177 void dispose() |
178 { | 178 { |
179 m_rawData.clear(); | 179 m_rawData.clear(); |
180 delete this; | 180 delete this; |
181 } | 181 } |
182 | 182 |
183 RefPtr<BlobDataHandle> m_blob; | 183 RefPtr<BlobDataHandle> m_blob; |
184 OwnPtr<TextResourceDecoder> m_decoder; | 184 OwnPtr<TextResourceDecoder> m_decoder; |
185 RefPtr<GetResponseBodyCallback> m_callback; | 185 OwnPtr<GetResponseBodyCallback> m_callback; |
186 OwnPtr<FileReaderLoader> m_loader; | 186 OwnPtr<FileReaderLoader> m_loader; |
187 OwnPtr<ArrayBufferBuilder> m_rawData; | 187 OwnPtr<ArrayBufferBuilder> m_rawData; |
188 }; | 188 }; |
189 | 189 |
190 KURL urlWithoutFragment(const KURL& url) | 190 KURL urlWithoutFragment(const KURL& url) |
191 { | 191 { |
192 KURL result = url; | 192 KURL result = url; |
193 result.removeFragmentIdentifier(); | 193 result.removeFragmentIdentifier(); |
194 return result; | 194 return result; |
195 } | 195 } |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 void InspectorResourceAgent::setUserAgentOverride(ErrorString*, const String& us
erAgent) | 893 void InspectorResourceAgent::setUserAgentOverride(ErrorString*, const String& us
erAgent) |
894 { | 894 { |
895 m_state->setString(ResourceAgentState::userAgentOverride, userAgent); | 895 m_state->setString(ResourceAgentState::userAgentOverride, userAgent); |
896 } | 896 } |
897 | 897 |
898 void InspectorResourceAgent::setExtraHTTPHeaders(ErrorString*, const PassOwnPtr<
protocol::Network::Headers> headers) | 898 void InspectorResourceAgent::setExtraHTTPHeaders(ErrorString*, const PassOwnPtr<
protocol::Network::Headers> headers) |
899 { | 899 { |
900 m_state->setObject(ResourceAgentState::extraRequestHeaders, headers->seriali
ze()); | 900 m_state->setObject(ResourceAgentState::extraRequestHeaders, headers->seriali
ze()); |
901 } | 901 } |
902 | 902 |
903 bool InspectorResourceAgent::getResponseBodyBlob(const String& requestId, PassRe
fPtr<GetResponseBodyCallback> callback) | 903 bool InspectorResourceAgent::canGetResponseBodyBlob(const String& requestId) |
904 { | 904 { |
905 NetworkResourcesData::ResourceData const* resourceData = m_resourcesData->da
ta(requestId); | 905 NetworkResourcesData::ResourceData const* resourceData = m_resourcesData->da
ta(requestId); |
906 if (!resourceData) | 906 BlobDataHandle* blob = resourceData ? resourceData->downloadedFileBlob() : n
ullptr; |
| 907 if (!blob) |
907 return false; | 908 return false; |
908 if (BlobDataHandle* blob = resourceData->downloadedFileBlob()) { | 909 LocalFrame* frame = IdentifiersFactory::frameById(m_inspectedFrames, resourc
eData->frameId()); |
909 if (LocalFrame* frame = IdentifiersFactory::frameById(m_inspectedFrames,
resourceData->frameId())) { | 910 return frame && frame->document(); |
910 if (Document* document = frame->document()) { | |
911 InspectorFileReaderLoaderClient* client = new InspectorFileReade
rLoaderClient(blob, InspectorPageAgent::createResourceTextDecoder(resourceData->
mimeType(), resourceData->textEncodingName()), callback); | |
912 client->start(document); | |
913 return true; | |
914 } | |
915 } | |
916 } | |
917 return false; | |
918 } | 911 } |
919 | 912 |
| 913 void InspectorResourceAgent::getResponseBodyBlob(const String& requestId, PassOw
nPtr<GetResponseBodyCallback> callback) |
| 914 { |
| 915 NetworkResourcesData::ResourceData const* resourceData = m_resourcesData->da
ta(requestId); |
| 916 BlobDataHandle* blob = resourceData->downloadedFileBlob(); |
| 917 LocalFrame* frame = IdentifiersFactory::frameById(m_inspectedFrames, resourc
eData->frameId()); |
| 918 Document* document = frame->document(); |
| 919 InspectorFileReaderLoaderClient* client = new InspectorFileReaderLoaderClien
t(blob, InspectorPageAgent::createResourceTextDecoder(resourceData->mimeType(),
resourceData->textEncodingName()), callback); |
| 920 client->start(document); |
| 921 } |
920 | 922 |
921 void InspectorResourceAgent::getResponseBody(ErrorString* errorString, const Str
ing& requestId, PassRefPtr<GetResponseBodyCallback> passCallback) | 923 void InspectorResourceAgent::getResponseBody(ErrorString* errorString, const Str
ing& requestId, PassOwnPtr<GetResponseBodyCallback> passCallback) |
922 { | 924 { |
923 RefPtr<GetResponseBodyCallback> callback = passCallback; | 925 OwnPtr<GetResponseBodyCallback> callback = passCallback; |
924 NetworkResourcesData::ResourceData const* resourceData = m_resourcesData->da
ta(requestId); | 926 NetworkResourcesData::ResourceData const* resourceData = m_resourcesData->da
ta(requestId); |
925 if (!resourceData) { | 927 if (!resourceData) { |
926 callback->sendFailure("No resource with given identifier found"); | 928 callback->sendFailure("No resource with given identifier found"); |
927 return; | 929 return; |
928 } | 930 } |
929 | 931 |
930 // XHR with ResponseTypeBlob should be returned as blob. | 932 // XHR with ResponseTypeBlob should be returned as blob. |
931 if (resourceData->xhrReplayData() && getResponseBodyBlob(requestId, callback
)) | 933 if (resourceData->xhrReplayData() && canGetResponseBodyBlob(requestId)) { |
| 934 getResponseBodyBlob(requestId, callback.release()); |
932 return; | 935 return; |
| 936 } |
933 | 937 |
934 if (resourceData->hasContent()) { | 938 if (resourceData->hasContent()) { |
935 callback->sendSuccess(resourceData->content(), resourceData->base64Encod
ed()); | 939 callback->sendSuccess(resourceData->content(), resourceData->base64Encod
ed()); |
936 return; | 940 return; |
937 } | 941 } |
938 | 942 |
939 if (resourceData->isContentEvicted()) { | 943 if (resourceData->isContentEvicted()) { |
940 callback->sendFailure("Request content was evicted from inspector cache"
); | 944 callback->sendFailure("Request content was evicted from inspector cache"
); |
941 return; | 945 return; |
942 } | 946 } |
943 | 947 |
944 if (resourceData->buffer() && !resourceData->textEncodingName().isNull()) { | 948 if (resourceData->buffer() && !resourceData->textEncodingName().isNull()) { |
945 String content; | 949 String content; |
946 if (InspectorPageAgent::sharedBufferContent(resourceData->buffer(), reso
urceData->textEncodingName(), false, &content)) { | 950 if (InspectorPageAgent::sharedBufferContent(resourceData->buffer(), reso
urceData->textEncodingName(), false, &content)) { |
947 callback->sendSuccess(content, false); | 951 callback->sendSuccess(content, false); |
948 return; | 952 return; |
949 } | 953 } |
950 } | 954 } |
951 | 955 |
952 if (resourceData->cachedResource()) { | 956 if (resourceData->cachedResource()) { |
953 String content; | 957 String content; |
954 bool base64Encoded = false; | 958 bool base64Encoded = false; |
955 if (InspectorPageAgent::cachedResourceContent(resourceData->cachedResour
ce(), &content, &base64Encoded)) { | 959 if (InspectorPageAgent::cachedResourceContent(resourceData->cachedResour
ce(), &content, &base64Encoded)) { |
956 callback->sendSuccess(content, base64Encoded); | 960 callback->sendSuccess(content, base64Encoded); |
957 return; | 961 return; |
958 } | 962 } |
959 } | 963 } |
960 | 964 |
961 if (getResponseBodyBlob(requestId, callback)) | 965 if (canGetResponseBodyBlob(requestId)) { |
| 966 getResponseBodyBlob(requestId, callback.release()); |
962 return; | 967 return; |
| 968 } |
963 | 969 |
964 callback->sendFailure("No data found for resource with given identifier"); | 970 callback->sendFailure("No data found for resource with given identifier"); |
965 } | 971 } |
966 | 972 |
967 void InspectorResourceAgent::addBlockedURL(ErrorString*, const String& url) | 973 void InspectorResourceAgent::addBlockedURL(ErrorString*, const String& url) |
968 { | 974 { |
969 protocol::DictionaryValue* blockedURLs = m_state->getObject(ResourceAgentSta
te::blockedURLs); | 975 protocol::DictionaryValue* blockedURLs = m_state->getObject(ResourceAgentSta
te::blockedURLs); |
970 if (!blockedURLs) { | 976 if (!blockedURLs) { |
971 OwnPtr<protocol::DictionaryValue> newList = protocol::DictionaryValue::c
reate(); | 977 OwnPtr<protocol::DictionaryValue> newList = protocol::DictionaryValue::c
reate(); |
972 blockedURLs = newList.get(); | 978 blockedURLs = newList.get(); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish
edReplayXHRFired) | 1108 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish
edReplayXHRFired) |
1103 { | 1109 { |
1104 } | 1110 } |
1105 | 1111 |
1106 bool InspectorResourceAgent::shouldForceCORSPreflight() | 1112 bool InspectorResourceAgent::shouldForceCORSPreflight() |
1107 { | 1113 { |
1108 return m_state->booleanProperty(ResourceAgentState::cacheDisabled, false); | 1114 return m_state->booleanProperty(ResourceAgentState::cacheDisabled, false); |
1109 } | 1115 } |
1110 | 1116 |
1111 } // namespace blink | 1117 } // namespace blink |
OLD | NEW |