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

Unified Diff: content/renderer/render_frame_impl.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: Fixing building of dom_serializer_browsertest.cc :-/ 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/render_frame_impl.cc
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
index 03908b3983d27a456c495235dfba36e09b532f3f..28564f69526c9f99283b4dfcb619451702267247 100644
--- a/content/renderer/render_frame_impl.cc
+++ b/content/renderer/render_frame_impl.cc
@@ -584,6 +584,42 @@ WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) {
path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe());
}
+// Implementation of WebFrameSerializer::LinkRewritingDelegate that responds
+// based on the payload of FrameMsg_GetSerializedHtmlWithLocalLinks.
+class LinkRewritingDelegate : public WebFrameSerializer::LinkRewritingDelegate {
+ public:
+ LinkRewritingDelegate(
+ const std::map<GURL, base::FilePath>& url_to_local_path,
+ const std::map<int, base::FilePath>& frame_routing_id_to_local_path)
+ : url_to_local_path_(url_to_local_path),
+ frame_routing_id_to_local_path_(frame_routing_id_to_local_path) {}
+
+ bool rewriteLink(const WebFrame& frame, WebString* rewritten_link) override {
+ int routing_id = GetRoutingIdForFrameOrProxy(const_cast<WebFrame*>(&frame));
dcheng 2016/01/12 00:10:47 I wonder if we'd be better off just passing these
Łukasz Anforowicz 2016/01/13 22:32:23 Done (= s/const WebFrame&/WebFrame*/ in both LinkR
+ auto it = frame_routing_id_to_local_path_.find(routing_id);
+ if (it == frame_routing_id_to_local_path_.end())
+ return false; // This can happen because of crbug.com/541354.
+
+ const base::FilePath& local_path = it->second;
+ *rewritten_link = ConvertRelativePathToHtmlAttribute(local_path);
+ return true;
+ }
+
+ bool rewriteLink(const WebURL& url, WebString* rewritten_link) override {
+ auto it = url_to_local_path_.find(url);
+ if (it == url_to_local_path_.end())
+ return false;
+
+ const base::FilePath& local_path = it->second;
+ *rewritten_link = ConvertRelativePathToHtmlAttribute(local_path);
+ return true;
+ }
+
+ private:
+ const std::map<GURL, base::FilePath>& url_to_local_path_;
+ const std::map<int, base::FilePath>& frame_routing_id_to_local_path_;
+};
+
// Implementation of WebFrameSerializer::MHTMLPartsGenerationDelegate that
// 1. Bases shouldSkipResource and getContentID responses on contents of
// FrameMsg_SerializeAsMHTML_Params.
@@ -4806,20 +4842,16 @@ void RenderFrameImpl::OnGetSavableResourceLinks() {
}
void RenderFrameImpl::OnGetSerializedHtmlWithLocalLinks(
- const std::map<GURL, base::FilePath>& url_to_local_path) {
+ const std::map<GURL, base::FilePath>& url_to_local_path,
+ const std::map<int, base::FilePath>& frame_routing_id_to_local_path) {
// Convert input to the canonical way of passing a map into a Blink API.
- std::vector<std::pair<WebURL, WebString>> weburl_to_local_path;
- for (const auto& it : url_to_local_path) {
- const GURL& url = it.first;
- const base::FilePath& local_path = it.second;
- weburl_to_local_path.push_back(std::make_pair(
- WebURL(url), ConvertRelativePathToHtmlAttribute(local_path)));
- }
+ LinkRewritingDelegate delegate(url_to_local_path,
+ frame_routing_id_to_local_path);
// Serialize the frame (without recursing into subframes).
WebFrameSerializer::serialize(GetWebFrame(),
this, // WebFrameSerializerClient.
- weburl_to_local_path);
+ &delegate);
}
void RenderFrameImpl::OnSerializeAsMHTML(

Powered by Google App Engine
This is Rietveld 408576698