Commit f4058d68 authored by beidson@apple.com's avatar beidson@apple.com

WebCore:

2008-03-28  Brady Eidson  <beidson@apple.com>

        Reviewed by Darin

        "Yet another transitional step" to empty out WebKit-based code for archiving.

        With this patch, the key operation of "Creating a WebArchive rooted at a single Node" takes place
        entirely within WebCore, and opens the door to saving WebArchives on Windows.

        This is another "zero behavior change" patch, and current editing/ and webarchive/ layout tests
        covered the relevant code

        * WebCore.base.exp:
        * loader/archive/cf/LegacyWebArchive.cpp:
        (WebCore::LegacyWebArchive::create):
        * loader/archive/cf/LegacyWebArchive.h:

WebKit/mac:

2008-03-28  Brady Eidson  <beidson@apple.com>

        Reviewed by Darin

        "Yet another transitional step" to empty out WebKit-based code for archiving.

        With this patch, the key operation of "Creating a WebArchive rooted at a single Node" takes place
        entirely within WebCore, and opens the door to saving WebArchives on Windows.

        * DOM/WebDOMOperations.mm:
        * WebView/WebArchiver.mm:
        (+[WebArchiver _archiveWithMarkupString:fromFrame:nodes:]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31400 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9df404ab
2008-03-28 Brady Eidson <beidson@apple.com>
Reviewed by Darin
"Yet another transitional step" to empty out WebKit-based code for archiving.
With this patch, the key operation of "Creating a WebArchive rooted at a single Node" takes place
entirely within WebCore, and opens the door to saving WebArchives on Windows.
This is another "zero behavior change" patch, and current editing/ and webarchive/ layout tests
covered the relevant code
* WebCore.base.exp:
* loader/archive/cf/LegacyWebArchive.cpp:
(WebCore::LegacyWebArchive::create):
* loader/archive/cf/LegacyWebArchive.h:
2008-03-28 Jasper Bryant-Greene <jasper@unix.geek.nz>
Reviewed by Alp Toker.
......@@ -341,6 +341,9 @@ __ZN7WebCore16FontPlatformDataD1Ev
__ZN7WebCore16LegacyWebArchive21rawDataRepresentationEv
__ZN7WebCore16LegacyWebArchive6createEN3WTF10PassRefPtrINS_15ArchiveResourceEEERNS1_6VectorIS4_Lm0EEERNS5_INS2_IS0_EELm0EEE
__ZN7WebCore16LegacyWebArchive6createEPNS_12SharedBufferE
__ZN7WebCore16LegacyWebArchive6createEPNS_4NodeE
__ZN7WebCore16LegacyWebArchive6createEPNS_5FrameE
__ZN7WebCore16LegacyWebArchive6createERKNS_6StringEPNS_5FrameERN3WTF6VectorIPNS_4NodeELm0EEE
__ZN7WebCore16LegacyWebArchive6createEv
__ZN7WebCore16MIMETypeRegistry24isSupportedImageMIMETypeERKNS_6StringE
__ZN7WebCore16MIMETypeRegistry26getSupportedImageMIMETypesEv
......
......@@ -29,8 +29,18 @@
#include "config.h"
#include "LegacyWebArchive.h"
#include "CString.h"
#include "Document.h"
#include "DocumentLoader.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameTree.h"
#include "HTMLFrameOwnerElement.h"
#include "HTMLNames.h"
#include "KURL.h"
#include "Logging.h"
#include "markup.h"
#include "Node.h"
#include "SharedBuffer.h"
#include <wtf/RetainPtr.h>
......@@ -391,4 +401,102 @@ RetainPtr<CFDataRef> propertyListDataFromResourceResponse(const ResourceResponse
}
#endif
PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(Node* node)
{
ASSERT(node);
if (!node)
return create();
Document* document = node->document();
Frame* frame = document ? document->frame() : 0;
if (!frame)
return create();
Vector<Node*> nodeList;
String markupString = frame->documentTypeString() + createMarkup(node, IncludeNode, &nodeList);
return create(markupString, frame, nodeList);
}
PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(Frame* frame)
{
ASSERT(frame);
DocumentLoader* documentLoader = frame->loader()->documentLoader();
if (!documentLoader)
return 0;
Vector<PassRefPtr<LegacyWebArchive> > subframeArchives;
unsigned children = frame->tree()->childCount();
for (unsigned i = 0; i < children; ++i) {
RefPtr<LegacyWebArchive> childFrameArchive = create(frame->tree()->child(i));
if (childFrameArchive)
subframeArchives.append(childFrameArchive.release());
}
Vector<PassRefPtr<ArchiveResource> > subresources;
documentLoader->getSubresources(subresources);
return LegacyWebArchive::create(documentLoader->mainResource(), subresources, subframeArchives);
}
PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(const String& markupString, Frame* frame, Vector<Node*>& nodes)
{
ASSERT(frame);
const ResourceResponse& response = frame->loader()->documentLoader()->response();
KURL responseURL = response.url();
// it's possible to have a response without a URL here
// <rdar://problem/5454935>
if (responseURL.isNull())
responseURL = KURL("");
PassRefPtr<ArchiveResource> mainResource = ArchiveResource::create(utf8Buffer(markupString), responseURL, response.mimeType(), "UTF-8", frame->tree()->name());
Vector<PassRefPtr<LegacyWebArchive> > subframeArchives;
Vector<PassRefPtr<ArchiveResource> > subresources;
HashSet<String> uniqueSubresources;
Vector<Node*>::iterator it = nodes.begin();
Vector<Node*>::iterator end = nodes.end();
for (; it != end; ++it) {
Frame* childFrame;
if (((*it)->hasTagName(HTMLNames::frameTag) || (*it)->hasTagName(HTMLNames::iframeTag) || (*it)->hasTagName(HTMLNames::objectTag)) &&
(childFrame = static_cast<HTMLFrameOwnerElement*>(*it)->contentFrame())) {
RefPtr<LegacyWebArchive> subframeArchive;
if (Document* document = childFrame->document())
subframeArchive = LegacyWebArchive::create(document);
else
subframeArchive = create(childFrame);
if (subframeArchive)
subframeArchives.append(subframeArchive);
else
LOG_ERROR("Unabled to archive subframe %s", childFrame->tree()->name().string().utf8().data());
} else {
Vector<KURL> subresourceURLs;
(*it)->getSubresourceURLs(subresourceURLs);
DocumentLoader* documentLoader = frame->loader()->documentLoader();
for (unsigned i = 0; i < subresourceURLs.size(); ++i) {
if (uniqueSubresources.contains(subresourceURLs[i].string()))
continue;
uniqueSubresources.add(subresourceURLs[i].string());
RefPtr<ArchiveResource> resource = documentLoader->subresource(subresourceURLs[i]);
if (resource)
subresources.append(resource.release());
else
// FIXME: should do something better than spew to console here
LOG_ERROR("Failed to archive subresource for %s", subresourceURLs[i].string().utf8().data());
}
}
}
return create(mainResource, subresources, subframeArchives);
}
}
......@@ -35,11 +35,17 @@
namespace WebCore {
class Frame;
class Node;
class LegacyWebArchive : public Archive {
public:
static PassRefPtr<LegacyWebArchive> create();
static PassRefPtr<LegacyWebArchive> create(SharedBuffer*);
static PassRefPtr<LegacyWebArchive> create(PassRefPtr<ArchiveResource> mainResource, Vector<PassRefPtr<ArchiveResource> >& subresources, Vector<PassRefPtr<LegacyWebArchive> >& subframeArchives);
static PassRefPtr<LegacyWebArchive> create(Node*);
static PassRefPtr<LegacyWebArchive> create(Frame*);
static PassRefPtr<LegacyWebArchive> create(const String& markupString, Frame*, Vector<Node*>& nodes);
RetainPtr<CFDataRef> rawDataRepresentation();
......
2008-03-28 Brady Eidson <beidson@apple.com>
Reviewed by Darin
"Yet another transitional step" to empty out WebKit-based code for archiving.
With this patch, the key operation of "Creating a WebArchive rooted at a single Node" takes place
entirely within WebCore, and opens the door to saving WebArchives on Windows.
* DOM/WebDOMOperations.mm:
* WebView/WebArchiver.mm:
(+[WebArchiver _archiveWithMarkupString:fromFrame:nodes:]):
2008-03-27 Brady Eidson <beidson@apple.com>
Reviewed by Adam Roben
......
......@@ -52,7 +52,7 @@ using namespace WebCore;
- (WebArchive *)webArchive
{
return [WebArchiver archiveNode:self];
return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create([self _node])] autorelease];
}
- (NSString *)markupString
......
......@@ -28,7 +28,9 @@
#import "WebArchiver.h"
#import "DOMNodeInternal.h"
#import "WebArchive.h"
#import "WebArchiveInternal.h"
#import "WebDOMOperationsPrivate.h"
#import "WebDataSource.h"
#import "WebDocument.h"
......@@ -37,6 +39,7 @@
#import "WebResource.h"
#import <JavaScriptCore/Assertions.h>
#import <WebCore/Frame.h>
#import <WebCore/LegacyWebArchive.h>
#import <WebCore/SelectionController.h>
#import <WebKit/DOM.h>
......@@ -44,87 +47,21 @@ using namespace WebCore;
@implementation WebArchiver
+ (NSArray *)_subframeArchivesForFrame:(WebFrame *)frame
{
NSEnumerator *enumerator = [[frame childFrames] objectEnumerator];
NSMutableArray *subframeArchives = [NSMutableArray array];
WebFrame *childFrame;
while ((childFrame = [enumerator nextObject])) {
WebArchive *childFrameArchive = [self archiveFrame:childFrame];
if (childFrameArchive)
[subframeArchives addObject:childFrameArchive];
}
return subframeArchives;
}
+ (WebArchive *)archiveFrame:(WebFrame *)frame;
{
return [[[WebArchive alloc] initWithMainResource:[[frame _dataSource] mainResource]
subresources:[[frame _dataSource] subresources]
subframeArchives:[self _subframeArchivesForFrame:frame]] autorelease];
}
+ (WebArchive *)_archiveCurrentStateForFrame:(WebFrame *)frame
{
if ([frame DOMDocument])
return [self archiveNode:[frame DOMDocument]];
return [self archiveFrame:frame];
return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create(core(frame))] autorelease];
}
+ (WebArchive *)_archiveWithMarkupString:(NSString *)markupString fromFrame:(WebFrame *)frame nodes:(NSArray *)nodes
{
NSURLResponse *response = [[frame _dataSource] response];
NSURL *responseURL = [response URL];
// it's possible to have a response without a URL here
// <rdar://problem/5454935>
if (!responseURL)
responseURL = [NSURL URLWithString:@""];
WebResource *mainResource = [[WebResource alloc] initWithData:[markupString dataUsingEncoding:NSUTF8StringEncoding]
URL:responseURL
MIMEType:[response MIMEType]
textEncodingName:@"UTF-8"
frameName:[frame name]];
NSMutableArray *subframeArchives = [[NSMutableArray alloc] init];
NSMutableArray *subresources = [[NSMutableArray alloc] init];
NSMutableSet *uniqueSubresources = [[NSMutableSet alloc] init];
NSEnumerator *enumerator = [nodes objectEnumerator];
DOMNode *node;
while ((node = [enumerator nextObject]) != nil) {
WebFrame *childFrame;
if (([node isKindOfClass:[DOMHTMLFrameElement class]] ||
[node isKindOfClass:[DOMHTMLIFrameElement class]] ||
[node isKindOfClass:[DOMHTMLObjectElement class]]) &&
((childFrame = [(DOMHTMLFrameElement *)node contentFrame]) != nil)) {
[subframeArchives addObject:[self _archiveCurrentStateForFrame:childFrame]];
} else {
NSEnumerator *enumerator = [[node _subresourceURLs] objectEnumerator];
NSURL *URL;
while ((URL = [enumerator nextObject]) != nil) {
if ([uniqueSubresources containsObject:URL])
continue;
[uniqueSubresources addObject:URL];
WebResource *subresource = [[frame _dataSource] subresourceForURL:URL];
if (subresource)
[subresources addObject:subresource];
else
// FIXME: should do something better than spew to console here
LOG_ERROR("Failed to archive subresource for %@", URL);
}
}
}
WebArchive *archive = [[[WebArchive alloc] initWithMainResource:mainResource subresources:subresources subframeArchives:subframeArchives] autorelease];
[mainResource release];
[uniqueSubresources release];
[subresources release];
[subframeArchives release];
Vector<Node*> coreNodes;
unsigned count = [nodes count];
coreNodes.reserveCapacity(count);
return archive;
for (unsigned i = 0; i < count; ++i)
coreNodes.append([[nodes objectAtIndex:i] _node]);
return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create(markupString, core(frame), coreNodes)] autorelease];
}
+ (WebArchive *)archiveRange:(DOMRange *)range
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment