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

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: Rebasing... 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
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | third_party/WebKit/Source/web/WebFrameSerializer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_frame_impl.cc
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
index 9e059675510bfae4e210991066bde776368991e0..8cb0638738400b0885b82f37067418dd767f312e 100644
--- a/content/renderer/render_frame_impl.cc
+++ b/content/renderer/render_frame_impl.cc
@@ -599,6 +599,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 rewriteFrameSource(WebFrame* frame, WebString* rewritten_link) override {
+ int routing_id = GetRoutingIdForFrameOrProxy(frame);
+ 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 https://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.
@@ -633,8 +669,8 @@ class MHTMLPartsGenerationDelegate
return false;
}
- WebString getContentID(const WebFrame& frame) override {
- int routing_id = GetRoutingIdForFrameOrProxy(const_cast<WebFrame*>(&frame));
+ WebString getContentID(WebFrame* frame) override {
+ int routing_id = GetRoutingIdForFrameOrProxy(frame);
auto it = params_.frame_routing_id_to_content_id.find(routing_id);
if (it == params_.frame_routing_id_to_content_id.end())
@@ -4911,20 +4947,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(
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | third_party/WebKit/Source/web/WebFrameSerializer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698