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 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 | 580 |
581 void OnGotContentHandlerID(uint32_t content_handler_id) {} | 581 void OnGotContentHandlerID(uint32_t content_handler_id) {} |
582 | 582 |
583 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { | 583 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { |
584 DCHECK(!path.IsAbsolute()); | 584 DCHECK(!path.IsAbsolute()); |
585 return WebString::fromUTF8( | 585 return WebString::fromUTF8( |
586 std::string("./") + | 586 std::string("./") + |
587 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); | 587 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); |
588 } | 588 } |
589 | 589 |
590 // Implementation of WebFrameSerializer::LinkRewritingDelegate that responds | |
591 // based on the payload of FrameMsg_GetSerializedHtmlWithLocalLinks. | |
592 class LinkRewritingDelegate : public WebFrameSerializer::LinkRewritingDelegate { | |
593 public: | |
594 LinkRewritingDelegate( | |
595 const std::map<GURL, base::FilePath>& url_to_local_path, | |
596 const std::map<int, base::FilePath>& frame_routing_id_to_local_path) | |
597 : url_to_local_path_(url_to_local_path), | |
598 frame_routing_id_to_local_path_(frame_routing_id_to_local_path) {} | |
599 | |
600 bool rewriteFrameSource(WebFrame* frame, WebString* rewritten_link) override { | |
601 int routing_id = GetRoutingIdForFrameOrProxy(frame); | |
602 auto it = frame_routing_id_to_local_path_.find(routing_id); | |
603 if (it == frame_routing_id_to_local_path_.end()) | |
604 return false; // This can happen because of crbug.com/541354. | |
nasko
2016/01/25 21:26:42
nit: https://
Łukasz Anforowicz
2016/01/25 23:11:37
Done.
| |
605 | |
606 const base::FilePath& local_path = it->second; | |
607 *rewritten_link = ConvertRelativePathToHtmlAttribute(local_path); | |
608 return true; | |
609 } | |
610 | |
611 bool rewriteLink(const WebURL& url, WebString* rewritten_link) override { | |
612 auto it = url_to_local_path_.find(url); | |
613 if (it == url_to_local_path_.end()) | |
614 return false; | |
615 | |
616 const base::FilePath& local_path = it->second; | |
617 *rewritten_link = ConvertRelativePathToHtmlAttribute(local_path); | |
618 return true; | |
619 } | |
620 | |
621 private: | |
622 const std::map<GURL, base::FilePath>& url_to_local_path_; | |
623 const std::map<int, base::FilePath>& frame_routing_id_to_local_path_; | |
624 }; | |
625 | |
590 // Implementation of WebFrameSerializer::MHTMLPartsGenerationDelegate that | 626 // Implementation of WebFrameSerializer::MHTMLPartsGenerationDelegate that |
591 // 1. Bases shouldSkipResource and getContentID responses on contents of | 627 // 1. Bases shouldSkipResource and getContentID responses on contents of |
592 // FrameMsg_SerializeAsMHTML_Params. | 628 // FrameMsg_SerializeAsMHTML_Params. |
593 // 2. Stores digests of urls of serialized resources (i.e. urls reported via | 629 // 2. Stores digests of urls of serialized resources (i.e. urls reported via |
594 // shouldSkipResource) into |digests_of_uris_of_serialized_resources| passed | 630 // shouldSkipResource) into |digests_of_uris_of_serialized_resources| passed |
595 // to the constructor. | 631 // to the constructor. |
596 class MHTMLPartsGenerationDelegate | 632 class MHTMLPartsGenerationDelegate |
597 : public WebFrameSerializer::MHTMLPartsGenerationDelegate { | 633 : public WebFrameSerializer::MHTMLPartsGenerationDelegate { |
598 public: | 634 public: |
599 MHTMLPartsGenerationDelegate( | 635 MHTMLPartsGenerationDelegate( |
(...skipping 14 matching lines...) Expand all Loading... | |
614 return true; | 650 return true; |
615 | 651 |
616 // Let's record |url| as being serialized for the *current* frame. | 652 // Let's record |url| as being serialized for the *current* frame. |
617 auto pair = digests_of_uris_of_serialized_resources_->insert(digest); | 653 auto pair = digests_of_uris_of_serialized_resources_->insert(digest); |
618 bool insertion_took_place = pair.second; | 654 bool insertion_took_place = pair.second; |
619 DCHECK(insertion_took_place); // Blink should dedupe within a frame. | 655 DCHECK(insertion_took_place); // Blink should dedupe within a frame. |
620 | 656 |
621 return false; | 657 return false; |
622 } | 658 } |
623 | 659 |
624 WebString getContentID(const WebFrame& frame) override { | 660 WebString getContentID(WebFrame* frame) override { |
625 int routing_id = GetRoutingIdForFrameOrProxy(const_cast<WebFrame*>(&frame)); | 661 int routing_id = GetRoutingIdForFrameOrProxy(frame); |
626 | 662 |
627 auto it = params_.frame_routing_id_to_content_id.find(routing_id); | 663 auto it = params_.frame_routing_id_to_content_id.find(routing_id); |
628 if (it == params_.frame_routing_id_to_content_id.end()) | 664 if (it == params_.frame_routing_id_to_content_id.end()) |
629 return WebString(); | 665 return WebString(); |
630 | 666 |
631 const std::string& content_id = it->second; | 667 const std::string& content_id = it->second; |
632 return WebString::fromUTF8(content_id); | 668 return WebString::fromUTF8(content_id); |
633 } | 669 } |
634 | 670 |
635 private: | 671 private: |
(...skipping 4273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4909 } | 4945 } |
4910 | 4946 |
4911 Referrer referrer = | 4947 Referrer referrer = |
4912 Referrer(frame_->document().url(), frame_->document().referrerPolicy()); | 4948 Referrer(frame_->document().url(), frame_->document().referrerPolicy()); |
4913 | 4949 |
4914 Send(new FrameHostMsg_SavableResourceLinksResponse( | 4950 Send(new FrameHostMsg_SavableResourceLinksResponse( |
4915 routing_id_, resources_list, referrer, subframes)); | 4951 routing_id_, resources_list, referrer, subframes)); |
4916 } | 4952 } |
4917 | 4953 |
4918 void RenderFrameImpl::OnGetSerializedHtmlWithLocalLinks( | 4954 void RenderFrameImpl::OnGetSerializedHtmlWithLocalLinks( |
4919 const std::map<GURL, base::FilePath>& url_to_local_path) { | 4955 const std::map<GURL, base::FilePath>& url_to_local_path, |
4956 const std::map<int, base::FilePath>& frame_routing_id_to_local_path) { | |
4920 // Convert input to the canonical way of passing a map into a Blink API. | 4957 // Convert input to the canonical way of passing a map into a Blink API. |
4921 std::vector<std::pair<WebURL, WebString>> weburl_to_local_path; | 4958 LinkRewritingDelegate delegate(url_to_local_path, |
4922 for (const auto& it : url_to_local_path) { | 4959 frame_routing_id_to_local_path); |
4923 const GURL& url = it.first; | |
4924 const base::FilePath& local_path = it.second; | |
4925 weburl_to_local_path.push_back(std::make_pair( | |
4926 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path))); | |
4927 } | |
4928 | 4960 |
4929 // Serialize the frame (without recursing into subframes). | 4961 // Serialize the frame (without recursing into subframes). |
4930 WebFrameSerializer::serialize(GetWebFrame(), | 4962 WebFrameSerializer::serialize(GetWebFrame(), |
4931 this, // WebFrameSerializerClient. | 4963 this, // WebFrameSerializerClient. |
4932 weburl_to_local_path); | 4964 &delegate); |
4933 } | 4965 } |
4934 | 4966 |
4935 void RenderFrameImpl::OnSerializeAsMHTML( | 4967 void RenderFrameImpl::OnSerializeAsMHTML( |
4936 const FrameMsg_SerializeAsMHTML_Params& params) { | 4968 const FrameMsg_SerializeAsMHTML_Params& params) { |
4937 // Unpack IPC payload. | 4969 // Unpack IPC payload. |
4938 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); | 4970 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); |
4939 const WebString mhtml_boundary = | 4971 const WebString mhtml_boundary = |
4940 WebString::fromUTF8(params.mhtml_boundary_marker); | 4972 WebString::fromUTF8(params.mhtml_boundary_marker); |
4941 DCHECK(!mhtml_boundary.isEmpty()); | 4973 DCHECK(!mhtml_boundary.isEmpty()); |
4942 | 4974 |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5800 media::ConvertToSwitchOutputDeviceCB(web_callbacks); | 5832 media::ConvertToSwitchOutputDeviceCB(web_callbacks); |
5801 scoped_refptr<media::AudioOutputDevice> device = | 5833 scoped_refptr<media::AudioOutputDevice> device = |
5802 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), | 5834 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), |
5803 security_origin); | 5835 security_origin); |
5804 media::OutputDeviceStatus status = device->GetDeviceStatus(); | 5836 media::OutputDeviceStatus status = device->GetDeviceStatus(); |
5805 device->Stop(); | 5837 device->Stop(); |
5806 callback.Run(status); | 5838 callback.Run(status); |
5807 } | 5839 } |
5808 | 5840 |
5809 } // namespace content | 5841 } // namespace content |
OLD | NEW |