Changeset 85172 in webkit
- Timestamp:
- Apr 28, 2011 2:06:58 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r85171 r85172 1 2011-04-26 Alexander Pavlov <apavlov@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 Web Inspector: Use CachedResource to retrieve charset-decoded stylesheet text 6 https://bugs.webkit.org/show_bug.cgi?id=59326 7 8 Concrete CachedResource successors for stylesheets and scripts 9 can decode their content better than the generic approach we use. 10 11 * inspector/InspectorPageAgent.cpp: 12 (WebCore::decodeSharedBuffer): 13 (WebCore::prepareCachedResourceBuffer): 14 (WebCore::cachedResourceDecoded): 15 (WebCore::InspectorPageAgent::resourceContent): 16 (WebCore::InspectorPageAgent::resourceData): 17 * inspector/InspectorStyleSheet.cpp: 18 (WebCore::InspectorStyleSheet::originalStyleSheetText): 19 1 20 2011-04-28 Jon Lee <jonlee@apple.com> 2 21 -
trunk/Source/WebCore/inspector/InspectorPageAgent.cpp
r84904 r85172 36 36 37 37 #include "Base64.h" 38 #include "CachedCSSStyleSheet.h" 39 #include "CachedResource.h" 38 40 #include "CachedResourceLoader.h" 41 #include "CachedScript.h" 39 42 #include "Cookie.h" 40 43 #include "CookieJar.h" … … 62 65 namespace WebCore { 63 66 64 PassOwnPtr<InspectorPageAgent> InspectorPageAgent::create(InstrumentingAgents* instrumentingAgents, Page* page, InjectedScriptManager* injectedScriptManager) 65 { 66 return adoptPtr(new InspectorPageAgent(instrumentingAgents, page, injectedScriptManager)); 67 } 68 69 void InspectorPageAgent::resourceContent(ErrorString* errorString, Frame* frame, const KURL& url, String* result) 70 { 71 if (!frame) { 72 *errorString = "No frame to get resource content for"; 73 return; 74 } 75 76 String textEncodingName; 77 RefPtr<SharedBuffer> buffer = InspectorPageAgent::resourceData(frame, url, &textEncodingName); 78 67 static bool decodeSharedBuffer(PassRefPtr<SharedBuffer> buffer, const String& textEncodingName, String* result) 68 { 79 69 if (buffer) { 80 70 TextEncoding encoding(textEncodingName); … … 82 72 encoding = WindowsLatin1Encoding(); 83 73 *result = encoding.decode(buffer->data(), buffer->size()); 84 return; 85 } 86 *errorString = "No resource with given URL found"; 87 } 88 89 void InspectorPageAgent::resourceContentBase64(ErrorString* errorString, Frame* frame, const KURL& url, String* result) 90 { 91 String textEncodingName; 92 RefPtr<SharedBuffer> data = InspectorPageAgent::resourceData(frame, url, &textEncodingName); 93 if (!data) { 94 *result = String(); 95 *errorString = "No resource with given URL found"; 96 return; 97 } 98 99 *result = base64Encode(data->data(), data->size()); 100 } 101 102 PassRefPtr<SharedBuffer> InspectorPageAgent::resourceData(Frame* frame, const KURL& url, String* textEncodingName) 103 { 104 FrameLoader* frameLoader = frame->loader(); 105 DocumentLoader* loader = frameLoader->documentLoader(); 106 if (equalIgnoringFragmentIdentifier(url, loader->url())) { 107 *textEncodingName = frame->document()->inputEncoding(); 108 return frameLoader->documentLoader()->mainResourceData(); 109 } 110 111 CachedResource* cachedResource = InspectorPageAgent::cachedResource(frame, url); 74 return true; 75 } 76 return false; 77 } 78 79 static bool prepareCachedResourceBuffer(CachedResource* cachedResource, bool* hasZeroSize) 80 { 81 *hasZeroSize = false; 112 82 if (!cachedResource) 113 return 0; 114 115 // Zero-sized resources don't have data at all -- so fake the empty buffer, insted of indicating error by returning 0. 116 if (!cachedResource->encodedSize()) 117 return SharedBuffer::create(); 83 return false; 84 85 // Zero-sized resources don't have data at all -- so fake the empty buffer, instead of indicating error by returning 0. 86 if (!cachedResource->encodedSize()) { 87 *hasZeroSize = true; 88 return true; 89 } 118 90 119 91 if (cachedResource->isPurgeable()) { … … 125 97 // inspector? 126 98 if (!cachedResource->makePurgeable(false)) 127 return 0; 128 } 99 return false; 100 } 101 102 return true; 103 } 104 105 static bool decodeCachedResource(CachedResource* cachedResource, String* result) 106 { 107 bool hasZeroSize; 108 bool prepared = prepareCachedResourceBuffer(cachedResource, &hasZeroSize); 109 if (!prepared) 110 return false; 111 112 if (cachedResource) { 113 switch (cachedResource->type()) { 114 case CachedResource::CSSStyleSheet: 115 *result = static_cast<CachedCSSStyleSheet*>(cachedResource)->sheetText(); 116 return true; 117 case CachedResource::Script: 118 *result = static_cast<CachedScript*>(cachedResource)->script(); 119 return true; 120 default: 121 if (hasZeroSize) { 122 *result = ""; 123 return true; 124 } 125 return decodeSharedBuffer(cachedResource->data(), cachedResource->encoding(), result); 126 } 127 } 128 return false; 129 } 130 131 PassOwnPtr<InspectorPageAgent> InspectorPageAgent::create(InstrumentingAgents* instrumentingAgents, Page* page, InjectedScriptManager* injectedScriptManager) 132 { 133 return adoptPtr(new InspectorPageAgent(instrumentingAgents, page, injectedScriptManager)); 134 } 135 136 void InspectorPageAgent::resourceContent(ErrorString* errorString, Frame* frame, const KURL& url, String* result) 137 { 138 if (!frame) { 139 *errorString = "No frame to get resource content for"; 140 return; 141 } 142 143 FrameLoader* frameLoader = frame->loader(); 144 DocumentLoader* loader = frameLoader->documentLoader(); 145 RefPtr<SharedBuffer> buffer; 146 bool success = false; 147 if (equalIgnoringFragmentIdentifier(url, loader->url())) { 148 String textEncodingName = frame->document()->inputEncoding(); 149 buffer = frameLoader->documentLoader()->mainResourceData(); 150 success = decodeSharedBuffer(buffer, textEncodingName, result); 151 } 152 if (!success) 153 success = decodeCachedResource(cachedResource(frame, url), result); 154 155 if (!success) 156 *errorString = "No resource with given URL found"; 157 } 158 159 void InspectorPageAgent::resourceContentBase64(ErrorString* errorString, Frame* frame, const KURL& url, String* result) 160 { 161 String textEncodingName; 162 RefPtr<SharedBuffer> data = InspectorPageAgent::resourceData(frame, url, &textEncodingName); 163 if (!data) { 164 *result = String(); 165 *errorString = "No resource with given URL found"; 166 return; 167 } 168 169 *result = base64Encode(data->data(), data->size()); 170 } 171 172 PassRefPtr<SharedBuffer> InspectorPageAgent::resourceData(Frame* frame, const KURL& url, String* textEncodingName) 173 { 174 RefPtr<SharedBuffer> buffer; 175 FrameLoader* frameLoader = frame->loader(); 176 DocumentLoader* loader = frameLoader->documentLoader(); 177 if (equalIgnoringFragmentIdentifier(url, loader->url())) { 178 *textEncodingName = frame->document()->inputEncoding(); 179 buffer = frameLoader->documentLoader()->mainResourceData(); 180 if (buffer) 181 return buffer; 182 } 183 184 CachedResource* cachedResource = InspectorPageAgent::cachedResource(frame, url); 185 if (!cachedResource) 186 return 0; 187 188 bool hasZeroSize; 189 bool prepared = prepareCachedResourceBuffer(cachedResource, &hasZeroSize); 190 if (!prepared) 191 return 0; 129 192 130 193 *textEncodingName = cachedResource->encoding(); 131 return cachedResource->data();194 return hasZeroSize ? SharedBuffer::create() : cachedResource->data(); 132 195 } 133 196 -
trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp
r85162 r85172 46 46 #include "Node.h" 47 47 #include "StyleSheetList.h" 48 #include "TextResourceDecoder.h"49 48 #include "WebKitCSSKeyframesRule.h" 50 49 … … 1056 1055 bool InspectorStyleSheet::originalStyleSheetText(String* result) const 1057 1056 { 1058 String rawText; 1059 bool success = inlineStyleSheetText(&rawText); 1057 bool success = inlineStyleSheetText(result); 1060 1058 if (!success) 1061 success = resourceStyleSheetText(&rawText); 1062 if (success) { 1063 CString cString = rawText.utf8(); 1064 RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/css"); 1065 String sheetText = decoder->decode(cString.data(), cString.length()); 1066 sheetText += decoder->flush(); 1067 *result = sheetText; 1068 } 1059 success = resourceStyleSheetText(result); 1069 1060 return success; 1070 1061 }
Note: See TracChangeset
for help on using the changeset viewer.