OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/render_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 | 592 |
593 void OnGotContentHandlerID(uint32_t content_handler_id) {} | 593 void OnGotContentHandlerID(uint32_t content_handler_id) {} |
594 | 594 |
595 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { | 595 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { |
596 DCHECK(!path.IsAbsolute()); | 596 DCHECK(!path.IsAbsolute()); |
597 return WebString::fromUTF8( | 597 return WebString::fromUTF8( |
598 std::string("./") + | 598 std::string("./") + |
599 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); | 599 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); |
600 } | 600 } |
601 | 601 |
| 602 // Implementation of WebFrameSerializer::LinkRewritingDelegate that responds |
| 603 // based on the payload of FrameMsg_GetSerializedHtmlWithLocalLinks. |
| 604 class LinkRewritingDelegate : public WebFrameSerializer::LinkRewritingDelegate { |
| 605 public: |
| 606 LinkRewritingDelegate( |
| 607 const std::map<GURL, base::FilePath>& url_to_local_path, |
| 608 const std::map<int, base::FilePath>& frame_routing_id_to_local_path) |
| 609 : url_to_local_path_(url_to_local_path), |
| 610 frame_routing_id_to_local_path_(frame_routing_id_to_local_path) {} |
| 611 |
| 612 bool rewriteFrameSource(WebFrame* frame, WebString* rewritten_link) override { |
| 613 int routing_id = GetRoutingIdForFrameOrProxy(frame); |
| 614 auto it = frame_routing_id_to_local_path_.find(routing_id); |
| 615 if (it == frame_routing_id_to_local_path_.end()) |
| 616 return false; // This can happen because of https://crbug.com/541354. |
| 617 |
| 618 const base::FilePath& local_path = it->second; |
| 619 *rewritten_link = ConvertRelativePathToHtmlAttribute(local_path); |
| 620 return true; |
| 621 } |
| 622 |
| 623 bool rewriteLink(const WebURL& url, WebString* rewritten_link) override { |
| 624 auto it = url_to_local_path_.find(url); |
| 625 if (it == url_to_local_path_.end()) |
| 626 return false; |
| 627 |
| 628 const base::FilePath& local_path = it->second; |
| 629 *rewritten_link = ConvertRelativePathToHtmlAttribute(local_path); |
| 630 return true; |
| 631 } |
| 632 |
| 633 private: |
| 634 const std::map<GURL, base::FilePath>& url_to_local_path_; |
| 635 const std::map<int, base::FilePath>& frame_routing_id_to_local_path_; |
| 636 }; |
| 637 |
602 // Implementation of WebFrameSerializer::MHTMLPartsGenerationDelegate that | 638 // Implementation of WebFrameSerializer::MHTMLPartsGenerationDelegate that |
603 // 1. Bases shouldSkipResource and getContentID responses on contents of | 639 // 1. Bases shouldSkipResource and getContentID responses on contents of |
604 // FrameMsg_SerializeAsMHTML_Params. | 640 // FrameMsg_SerializeAsMHTML_Params. |
605 // 2. Stores digests of urls of serialized resources (i.e. urls reported via | 641 // 2. Stores digests of urls of serialized resources (i.e. urls reported via |
606 // shouldSkipResource) into |digests_of_uris_of_serialized_resources| passed | 642 // shouldSkipResource) into |digests_of_uris_of_serialized_resources| passed |
607 // to the constructor. | 643 // to the constructor. |
608 class MHTMLPartsGenerationDelegate | 644 class MHTMLPartsGenerationDelegate |
609 : public WebFrameSerializer::MHTMLPartsGenerationDelegate { | 645 : public WebFrameSerializer::MHTMLPartsGenerationDelegate { |
610 public: | 646 public: |
611 MHTMLPartsGenerationDelegate( | 647 MHTMLPartsGenerationDelegate( |
(...skipping 14 matching lines...) Expand all Loading... |
626 return true; | 662 return true; |
627 | 663 |
628 // Let's record |url| as being serialized for the *current* frame. | 664 // Let's record |url| as being serialized for the *current* frame. |
629 auto pair = digests_of_uris_of_serialized_resources_->insert(digest); | 665 auto pair = digests_of_uris_of_serialized_resources_->insert(digest); |
630 bool insertion_took_place = pair.second; | 666 bool insertion_took_place = pair.second; |
631 DCHECK(insertion_took_place); // Blink should dedupe within a frame. | 667 DCHECK(insertion_took_place); // Blink should dedupe within a frame. |
632 | 668 |
633 return false; | 669 return false; |
634 } | 670 } |
635 | 671 |
636 WebString getContentID(const WebFrame& frame) override { | 672 WebString getContentID(WebFrame* frame) override { |
637 int routing_id = GetRoutingIdForFrameOrProxy(const_cast<WebFrame*>(&frame)); | 673 int routing_id = GetRoutingIdForFrameOrProxy(frame); |
638 | 674 |
639 auto it = params_.frame_routing_id_to_content_id.find(routing_id); | 675 auto it = params_.frame_routing_id_to_content_id.find(routing_id); |
640 if (it == params_.frame_routing_id_to_content_id.end()) | 676 if (it == params_.frame_routing_id_to_content_id.end()) |
641 return WebString(); | 677 return WebString(); |
642 | 678 |
643 const std::string& content_id = it->second; | 679 const std::string& content_id = it->second; |
644 return WebString::fromUTF8(content_id); | 680 return WebString::fromUTF8(content_id); |
645 } | 681 } |
646 | 682 |
647 private: | 683 private: |
(...skipping 4256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4904 } | 4940 } |
4905 | 4941 |
4906 Referrer referrer = | 4942 Referrer referrer = |
4907 Referrer(frame_->document().url(), frame_->document().referrerPolicy()); | 4943 Referrer(frame_->document().url(), frame_->document().referrerPolicy()); |
4908 | 4944 |
4909 Send(new FrameHostMsg_SavableResourceLinksResponse( | 4945 Send(new FrameHostMsg_SavableResourceLinksResponse( |
4910 routing_id_, resources_list, referrer, subframes)); | 4946 routing_id_, resources_list, referrer, subframes)); |
4911 } | 4947 } |
4912 | 4948 |
4913 void RenderFrameImpl::OnGetSerializedHtmlWithLocalLinks( | 4949 void RenderFrameImpl::OnGetSerializedHtmlWithLocalLinks( |
4914 const std::map<GURL, base::FilePath>& url_to_local_path) { | 4950 const std::map<GURL, base::FilePath>& url_to_local_path, |
| 4951 const std::map<int, base::FilePath>& frame_routing_id_to_local_path) { |
4915 // Convert input to the canonical way of passing a map into a Blink API. | 4952 // Convert input to the canonical way of passing a map into a Blink API. |
4916 std::vector<std::pair<WebURL, WebString>> weburl_to_local_path; | 4953 LinkRewritingDelegate delegate(url_to_local_path, |
4917 for (const auto& it : url_to_local_path) { | 4954 frame_routing_id_to_local_path); |
4918 const GURL& url = it.first; | |
4919 const base::FilePath& local_path = it.second; | |
4920 weburl_to_local_path.push_back(std::make_pair( | |
4921 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path))); | |
4922 } | |
4923 | 4955 |
4924 // Serialize the frame (without recursing into subframes). | 4956 // Serialize the frame (without recursing into subframes). |
4925 WebFrameSerializer::serialize(GetWebFrame(), | 4957 WebFrameSerializer::serialize(GetWebFrame(), |
4926 this, // WebFrameSerializerClient. | 4958 this, // WebFrameSerializerClient. |
4927 weburl_to_local_path); | 4959 &delegate); |
4928 } | 4960 } |
4929 | 4961 |
4930 void RenderFrameImpl::OnSerializeAsMHTML( | 4962 void RenderFrameImpl::OnSerializeAsMHTML( |
4931 const FrameMsg_SerializeAsMHTML_Params& params) { | 4963 const FrameMsg_SerializeAsMHTML_Params& params) { |
4932 // Unpack IPC payload. | 4964 // Unpack IPC payload. |
4933 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); | 4965 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); |
4934 const WebString mhtml_boundary = | 4966 const WebString mhtml_boundary = |
4935 WebString::fromUTF8(params.mhtml_boundary_marker); | 4967 WebString::fromUTF8(params.mhtml_boundary_marker); |
4936 DCHECK(!mhtml_boundary.isEmpty()); | 4968 DCHECK(!mhtml_boundary.isEmpty()); |
4937 | 4969 |
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6045 int match_count, | 6077 int match_count, |
6046 int ordinal, | 6078 int ordinal, |
6047 const WebRect& selection_rect, | 6079 const WebRect& selection_rect, |
6048 bool final_status_update) { | 6080 bool final_status_update) { |
6049 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count, | 6081 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count, |
6050 selection_rect, ordinal, | 6082 selection_rect, ordinal, |
6051 final_status_update)); | 6083 final_status_update)); |
6052 } | 6084 } |
6053 | 6085 |
6054 } // namespace content | 6086 } // namespace content |
OLD | NEW |