Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: content/renderer/dom_serializer_browsertest.cc

Issue 1502563004: Save-Page-As-Complete-Html: Each frame links to a distinct local file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no-url-deduping-for-frame-and-adding-save-item-id
Patch Set: Addressed feedback from Randy (and apparently accidentally rebased as well...). Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 WebFrame* web_frame = GetMainFrame(); 151 WebFrame* web_frame = GetMainFrame();
152 152
153 ASSERT_TRUE(web_frame != NULL); 153 ASSERT_TRUE(web_frame != NULL);
154 154
155 web_frame->loadData(data, "text/html", encoding_info, base_url); 155 web_frame->loadData(data, "text/html", encoding_info, base_url);
156 } 156 }
157 157
158 runner->Run(); 158 runner->Run();
159 } 159 }
160 160
161 class SingleLinkRewritingDelegate
162 : public WebFrameSerializer::LinkRewritingDelegate {
163 public:
164 SingleLinkRewritingDelegate(const WebURL& url, const WebString& localPath)
165 : url_(url), local_path_(localPath) {}
166
167 bool rewriteFrameSource(WebFrame* frame,
168 WebString* rewritten_link) override {
nasko 2016/01/25 21:26:42 The indentation on this looks wrong. Have you done
Łukasz Anforowicz 2016/01/25 23:11:37 Done (I must have missed this step after changing
169 return false;
170 }
171
172 bool rewriteLink(const WebURL& url, WebString* rewritten_link) override {
173 if (url != url_)
174 return false;
175
176 *rewritten_link = local_path_;
177 return true;
178 }
179
180 private:
181 const WebURL url_;
182 const WebString local_path_;
183 };
184
161 // Serialize DOM belonging to a frame with the specified |frame_url|. 185 // Serialize DOM belonging to a frame with the specified |frame_url|.
162 void SerializeDomForURL(const GURL& frame_url) { 186 void SerializeDomForURL(const GURL& frame_url) {
163 // Find corresponding WebFrame according to frame_url. 187 // Find corresponding WebFrame according to frame_url.
164 WebFrame* web_frame = FindSubFrameByURL(frame_url); 188 WebFrame* web_frame = FindSubFrameByURL(frame_url);
165 ASSERT_TRUE(web_frame != NULL); 189 ASSERT_TRUE(web_frame != NULL);
166 WebString file_path = 190 WebString file_path =
167 base::FilePath(FILE_PATH_LITERAL("c:\\dummy.htm")).AsUTF16Unsafe(); 191 base::FilePath(FILE_PATH_LITERAL("c:\\dummy.htm")).AsUTF16Unsafe();
168 std::vector<std::pair<WebURL, WebString>> url_to_local_path; 192 SingleLinkRewritingDelegate delegate(frame_url, file_path);
169 url_to_local_path.push_back(std::make_pair(WebURL(frame_url), file_path));
170 // Start serializing DOM. 193 // Start serializing DOM.
171 bool result = WebFrameSerializer::serialize( 194 bool result = WebFrameSerializer::serialize(web_frame->toWebLocalFrame(),
172 web_frame->toWebLocalFrame(), 195 this, &delegate);
173 static_cast<WebFrameSerializerClient*>(this), url_to_local_path);
174 ASSERT_TRUE(result); 196 ASSERT_TRUE(result);
175 } 197 }
176 198
177 void SerializeHTMLDOMWithDocTypeOnRenderer(const GURL& file_url) { 199 void SerializeHTMLDOMWithDocTypeOnRenderer(const GURL& file_url) {
178 // Make sure original contents have document type. 200 // Make sure original contents have document type.
179 WebFrame* web_frame = FindSubFrameByURL(file_url); 201 WebFrame* web_frame = FindSubFrameByURL(file_url);
180 ASSERT_TRUE(web_frame != NULL); 202 ASSERT_TRUE(web_frame != NULL);
181 WebDocument doc = web_frame->document(); 203 WebDocument doc = web_frame->document();
182 ASSERT_TRUE(HasDocType(doc)); 204 ASSERT_TRUE(HasDocType(doc));
183 // Do serialization. 205 // Do serialization.
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 NavigateToURL(shell(), file_url); 864 NavigateToURL(shell(), file_url);
843 865
844 PostTaskToInProcessRendererAndWait( 866 PostTaskToInProcessRendererAndWait(
845 base::Bind( 867 base::Bind(
846 &DomSerializerTests:: 868 &DomSerializerTests::
847 SubResourceForElementsInNonHTMLNamespaceOnRenderer, 869 SubResourceForElementsInNonHTMLNamespaceOnRenderer,
848 base::Unretained(this), file_url)); 870 base::Unretained(this), file_url));
849 } 871 }
850 872
851 } // namespace content 873 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698