Changeset 81377 in webkit
- Timestamp:
- Mar 17, 2011 12:49:26 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 8 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r81340 r81377 1 2011-03-17 Jay Civelli <jcivelli@chromium.org> 2 3 Reviewed by David Levin. 4 5 Adding a contains method to Vector. 6 https://bugs.webkit.org/show_bug.cgi?id=55859 7 8 * wtf/Vector.h: 9 (WTF::::operator): 10 (WTF::::contains): 11 1 12 2011-03-17 Patrick Gansterer <paroga@webkit.org> 2 13 -
trunk/Source/JavaScriptCore/wtf/Vector.h
r79590 r81377 567 567 const T& last() const { return at(size() - 1); } 568 568 569 template<typename U> bool contains(const U&) const; 569 570 template<typename U> size_t find(const U&) const; 570 571 template<typename U> size_t reverseFind(const U&) const; … … 742 743 743 744 return *this; 745 } 746 747 template<typename T, size_t inlineCapacity> 748 template<typename U> 749 bool Vector<T, inlineCapacity>::contains(const U& value) const 750 { 751 return find(value) != notFound; 744 752 } 745 753 -
trunk/Source/WebKit/chromium/ChangeLog
r81365 r81377 1 2011-03-17 Jay Civelli <jcivelli@chromium.org> 2 3 Reviewed by David Levin. 4 5 Moving the method that is used to retrieve all the resources in 6 a page from the Chromium code (dom_operations.cc) to WebKit. 7 https://bugs.webkit.org/show_bug.cgi?id=55859 8 9 * WebKit.gyp: 10 * public/WebPageSerializer.h: 11 * public/WebURL.h: 12 (WebKit::operator==): 13 (WebKit::operator!=): 14 * public/WebVector.h: 15 (WebKit::WebVector::contains): 16 * src/WebDataSourceImpl.cpp: 17 (WebKit::WebDataSourceImpl::WebDataSourceImpl): 18 * src/WebPageSerializer.cpp: 19 (WebCore::getSubResourceURLFromElement): 20 (WebCore::retrieveResourcesForElement): 21 (WebCore::retrieveResourcesForFrame): 22 (WebKit::WebPageSerializer::retrieveAllResources): 23 * tests/WebFrameTest.cpp: 24 * tests/WebPageSerializerTest.cpp: Added. 25 * tests/data/pageserialization: Added. 26 * tests/data/pageserialization/awesome.png: Added. 27 * tests/data/pageserialization/embed_iframe.html: Added. 28 * tests/data/pageserialization/object_iframe.html: Added. 29 * tests/data/pageserialization/simple_iframe.html: Added. 30 * tests/data/pageserialization/simple_page.html: Added. 31 * tests/data/pageserialization/top_frame.html: Added. 32 1 33 2011-03-17 Tony Chang <tony@chromium.org> 2 34 -
trunk/Source/WebKit/chromium/WebKit.gyp
r81365 r81377 870 870 'tests/UniscribeHelperTest.cpp', 871 871 'tests/WebFrameTest.cpp', 872 'tests/WebPageSerializerTest.cpp', 872 873 ], 873 874 }], -
trunk/Source/WebKit/chromium/public/WebPageSerializer.h
r52268 r81377 35 35 36 36 namespace WebKit { 37 class WebCString; 37 38 class WebFrame; 38 39 class WebPageSerializerClient; 39 40 class WebString; 40 41 class WebURL; 42 class WebView; 41 43 template <typename T> class WebVector; 42 44 … … 70 72 const WebString& localDirectoryName); 71 73 74 // Retrieve all the resource for the passed view, including the main frame 75 // and sub-frames. Returns true if all resources were retrieved 76 // successfully. 77 WEBKIT_API static bool retrieveAllResources(WebView*, 78 const WebVector<WebCString>& supportedSchemes, 79 WebVector<WebURL>* resources, 80 WebVector<WebURL>* frames); 81 72 82 // FIXME: The following are here for unit testing purposes. Consider 73 83 // changing the unit tests instead. … … 81 91 }; 82 92 83 } 93 } // namespace WebKit 84 94 85 95 #endif -
trunk/Source/WebKit/chromium/public/WebURL.h
r61495 r81377 144 144 } 145 145 146 inline bool operator==(const WebURL& a, const WebURL& b) 147 { 148 return !a.spec().compare(b.spec()); 149 } 150 151 inline bool operator!=(const WebURL& a, const WebURL& b) 152 { 153 return !(a == b); 154 } 155 146 156 } // namespace WebKit 147 157 -
trunk/Source/WebKit/chromium/public/WebVector.h
r66820 r81377 126 126 return m_ptr[i]; 127 127 } 128 129 bool contains(const T& value) const 130 { 131 for (size_t i = 0; i < m_size; i++) { 132 if (m_ptr[i] == value) 133 return true; 134 } 135 return false; 136 } 128 137 129 138 T* data() { return m_ptr; } … … 173 182 }; 174 183 175 } 184 } // namespace WebKit 176 185 177 186 #endif -
trunk/Source/WebKit/chromium/src/WebDataSourceImpl.cpp
r71602 r81377 175 175 // to wait to attach the WebPluginLoadObserver to that data source. 176 176 if (!request.url().isEmpty()) { 177 ASSERT(m_nextPluginLoadObserver->url() == request.url());177 ASSERT(m_nextPluginLoadObserver->url() == WebURL(request.url())); 178 178 m_pluginLoadObserver.set(m_nextPluginLoadObserver); 179 179 m_nextPluginLoadObserver = 0; -
trunk/Source/WebKit/chromium/src/WebPageSerializer.cpp
r69850 r81377 32 32 #include "WebPageSerializer.h" 33 33 34 #include "DocumentLoader.h" 35 #include "Element.h" 36 #include "Frame.h" 37 #include "HTMLAllCollection.h" 38 #include "HTMLFrameOwnerElement.h" 39 #include "HTMLInputElement.h" 40 #include "HTMLNames.h" 34 41 #include "KURL.h" 35 42 #include "Vector.h" 43 44 #include "WebCString.h" 36 45 #include "WebFrame.h" 46 #include "WebFrameImpl.h" 37 47 #include "WebPageSerializerClient.h" 38 48 #include "WebPageSerializerImpl.h" … … 40 50 #include "WebURL.h" 41 51 #include "WebVector.h" 52 #include "WebView.h" 42 53 43 54 #include <wtf/text/StringConcatenate.h> 44 55 45 56 using namespace WebCore; 57 58 namespace { 59 60 KURL getSubResourceURLFromElement(Element* element) 61 { 62 ASSERT(element); 63 const QualifiedName* attributeName = 0; 64 if (element->hasTagName(HTMLNames::imgTag) || element->hasTagName(HTMLNames::scriptTag)) 65 attributeName = &HTMLNames::srcAttr; 66 else if (element->hasTagName(HTMLNames::inputTag)) { 67 HTMLInputElement* input = static_cast<HTMLInputElement*>(element); 68 if (input->isImageButton()) 69 attributeName = &HTMLNames::srcAttr; 70 } else if (element->hasTagName(HTMLNames::bodyTag) 71 || element->hasTagName(HTMLNames::tableTag) 72 || element->hasTagName(HTMLNames::trTag) 73 || element->hasTagName(HTMLNames::tdTag)) 74 attributeName = &HTMLNames::backgroundAttr; 75 else if (element->hasTagName(HTMLNames::blockquoteTag) 76 || element->hasTagName(HTMLNames::qTag) 77 || element->hasTagName(HTMLNames::delTag) 78 || element->hasTagName(HTMLNames::insTag)) 79 attributeName = &HTMLNames::citeAttr; 80 else if (element->hasTagName(HTMLNames::linkTag)) { 81 // If the link element is not css, ignore it. 82 if (equalIgnoringCase(element->getAttribute(HTMLNames::typeAttr), "text/css")) { 83 // FIXME: Add support for extracting links of sub-resources which 84 // are inside style-sheet such as @import, @font-face, url(), etc. 85 attributeName = &HTMLNames::hrefAttr; 86 } 87 } else if (element->hasTagName(HTMLNames::objectTag)) 88 attributeName = &HTMLNames::dataAttr; 89 else if (element->hasTagName(HTMLNames::embedTag)) 90 attributeName = &HTMLNames::srcAttr; 91 92 if (!attributeName) 93 return KURL(); 94 95 String value = element->getAttribute(*attributeName); 96 // Ignore javascript content. 97 if (value.isEmpty() || value.stripWhiteSpace().startsWith("javascript:", false)) 98 return KURL(); 99 100 return element->document()->completeURL(value); 101 } 102 103 void retrieveResourcesForElement(Element* element, 104 Vector<Frame*>* visitedFrames, 105 Vector<Frame*>* framesToVisit, 106 Vector<KURL>* frameURLs, 107 Vector<KURL>* resourceURLs) 108 { 109 // If the node is a frame, we'll process it later in retrieveResourcesForFrame. 110 if ((element->hasTagName(HTMLNames::iframeTag) || element->hasTagName(HTMLNames::frameTag) 111 || element->hasTagName(HTMLNames::objectTag) || element->hasTagName(HTMLNames::embedTag)) 112 && element->isFrameOwnerElement()) { 113 Frame* frame = static_cast<HTMLFrameOwnerElement*>(element)->contentFrame(); 114 if (frame) { 115 if (!visitedFrames->contains(frame)) 116 framesToVisit->append(frame); 117 return; 118 } 119 } 120 121 KURL url = getSubResourceURLFromElement(element); 122 if (url.isEmpty() || !url.isValid()) 123 return; // No subresource for this node. 124 125 // Ignore URLs that have a non-standard protocols. Since the FTP protocol 126 // does no have a cache mechanism, we skip it as well. 127 if (!url.protocolInHTTPFamily() && !url.isLocalFile()) 128 return; 129 130 if (!resourceURLs->contains(url)) 131 resourceURLs->append(url); 132 } 133 134 void retrieveResourcesForFrame(Frame* frame, 135 const WebKit::WebVector<WebKit::WebCString>& supportedSchemes, 136 Vector<Frame*>* visitedFrames, 137 Vector<Frame*>* framesToVisit, 138 Vector<KURL>* frameURLs, 139 Vector<KURL>* resourceURLs) 140 { 141 KURL frameURL = frame->loader()->documentLoader()->request().url(); 142 143 // If the frame's URL is invalid, ignore it, it is not retrievable. 144 if (!frameURL.isValid()) 145 return; 146 147 // Ignore frames from unsupported schemes. 148 bool isValidScheme = false; 149 for (size_t i = 0; i < supportedSchemes.size(); ++i) { 150 if (frameURL.protocolIs(static_cast<CString>(supportedSchemes[i]).data())) { 151 isValidScheme = true; 152 break; 153 } 154 } 155 if (!isValidScheme) 156 return; 157 158 // If we have already seen that frame, ignore it. 159 if (visitedFrames->contains(frame)) 160 return; 161 visitedFrames->append(frame); 162 if (!frameURLs->contains(frameURL)) 163 frameURLs->append(frameURL); 164 165 // Now get the resources associated with each node of the document. 166 RefPtr<HTMLAllCollection> allNodes = frame->document()->all(); 167 for (unsigned i = 0; i < allNodes->length(); ++i) { 168 Node* node = allNodes->item(i); 169 // We are only interested in HTML resources. 170 if (!node->isElementNode()) 171 continue; 172 retrieveResourcesForElement(static_cast<Element*>(node), 173 visitedFrames, framesToVisit, 174 frameURLs, resourceURLs); 175 } 176 } 177 178 } // namespace 46 179 47 180 namespace WebKit { … … 59 192 } 60 193 194 bool WebPageSerializer::retrieveAllResources(WebView* view, 195 const WebVector<WebCString>& supportedSchemes, 196 WebVector<WebURL>* resourceURLs, 197 WebVector<WebURL>* frameURLs) { 198 WebFrameImpl* mainFrame = static_cast<WebFrameImpl*>(view->mainFrame()); 199 if (!mainFrame) 200 return false; 201 202 Vector<Frame*> framesToVisit; 203 Vector<Frame*> visitedFrames; 204 Vector<KURL> frameKURLs; 205 Vector<KURL> resourceKURLs; 206 207 // Let's retrieve the resources from every frame in this page. 208 framesToVisit.append(mainFrame->frame()); 209 while (!framesToVisit.isEmpty()) { 210 Frame* frame = framesToVisit[0]; 211 framesToVisit.remove(0); 212 retrieveResourcesForFrame(frame, supportedSchemes, 213 &visitedFrames, &framesToVisit, 214 &frameKURLs, &resourceKURLs); 215 } 216 217 // Converts the results to WebURLs. 218 WebVector<WebURL> resultResourceURLs(resourceKURLs.size()); 219 for (size_t i = 0; i < resourceKURLs.size(); ++i) { 220 resultResourceURLs[i] = resourceKURLs[i]; 221 // A frame's src can point to the same URL as another resource, keep the 222 // resource URL only in such cases. 223 size_t index = frameKURLs.find(resourceKURLs[i]); 224 if (index != notFound) 225 frameKURLs.remove(index); 226 } 227 *resourceURLs = resultResourceURLs; 228 WebVector<WebURL> resultFrameURLs(frameKURLs.size()); 229 for (size_t i = 0; i < frameKURLs.size(); ++i) 230 resultFrameURLs[i] = frameKURLs[i]; 231 *frameURLs = resultFrameURLs; 232 233 return true; 234 } 235 61 236 WebString WebPageSerializer::generateMetaCharsetDeclaration(const WebString& charset) 62 237 { … … 78 253 } 79 254 80 } 255 } // namespace WebKit -
trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp
r75931 r81377 28 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 29 */ 30 31 #include "config.h" 30 32 31 33 #include <googleurl/src/gurl.h>
Note: See TracChangeset
for help on using the changeset viewer.