| 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 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 | 577 |
| 578 void OnGotContentHandlerID(uint32_t content_handler_id) {} | 578 void OnGotContentHandlerID(uint32_t content_handler_id) {} |
| 579 | 579 |
| 580 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { | 580 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { |
| 581 DCHECK(!path.IsAbsolute()); | 581 DCHECK(!path.IsAbsolute()); |
| 582 return WebString::fromUTF8( | 582 return WebString::fromUTF8( |
| 583 std::string("./") + | 583 std::string("./") + |
| 584 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); | 584 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); |
| 585 } | 585 } |
| 586 | 586 |
| 587 // Implementation of WebFrameSerializer::LinkRewritingDelegate that responds |
| 588 // based on the payload of FrameMsg_GetSerializedHtmlWithLocalLinks. |
| 589 class LinkRewritingDelegate : public WebFrameSerializer::LinkRewritingDelegate { |
| 590 public: |
| 591 LinkRewritingDelegate( |
| 592 const std::map<GURL, base::FilePath>& url_to_local_path, |
| 593 const std::map<int, base::FilePath>& frame_routing_id_to_local_path) |
| 594 : url_to_local_path_(url_to_local_path), |
| 595 frame_routing_id_to_local_path_(frame_routing_id_to_local_path) {} |
| 596 |
| 597 bool rewriteFrameSource(WebFrame* frame, WebString* rewritten_link) override { |
| 598 int routing_id = GetRoutingIdForFrameOrProxy(frame); |
| 599 auto it = frame_routing_id_to_local_path_.find(routing_id); |
| 600 if (it == frame_routing_id_to_local_path_.end()) |
| 601 return false; // This can happen because of crbug.com/541354. |
| 602 |
| 603 const base::FilePath& local_path = it->second; |
| 604 *rewritten_link = ConvertRelativePathToHtmlAttribute(local_path); |
| 605 return true; |
| 606 } |
| 607 |
| 608 bool rewriteLink(const WebURL& url, WebString* rewritten_link) override { |
| 609 auto it = url_to_local_path_.find(url); |
| 610 if (it == url_to_local_path_.end()) |
| 611 return false; |
| 612 |
| 613 const base::FilePath& local_path = it->second; |
| 614 *rewritten_link = ConvertRelativePathToHtmlAttribute(local_path); |
| 615 return true; |
| 616 } |
| 617 |
| 618 private: |
| 619 const std::map<GURL, base::FilePath>& url_to_local_path_; |
| 620 const std::map<int, base::FilePath>& frame_routing_id_to_local_path_; |
| 621 }; |
| 622 |
| 587 // Implementation of WebFrameSerializer::MHTMLPartsGenerationDelegate that | 623 // Implementation of WebFrameSerializer::MHTMLPartsGenerationDelegate that |
| 588 // 1. Bases shouldSkipResource and getContentID responses on contents of | 624 // 1. Bases shouldSkipResource and getContentID responses on contents of |
| 589 // FrameMsg_SerializeAsMHTML_Params. | 625 // FrameMsg_SerializeAsMHTML_Params. |
| 590 // 2. Stores digests of urls of serialized resources (i.e. urls reported via | 626 // 2. Stores digests of urls of serialized resources (i.e. urls reported via |
| 591 // shouldSkipResource) into |digests_of_uris_of_serialized_resources| passed | 627 // shouldSkipResource) into |digests_of_uris_of_serialized_resources| passed |
| 592 // to the constructor. | 628 // to the constructor. |
| 593 class MHTMLPartsGenerationDelegate | 629 class MHTMLPartsGenerationDelegate |
| 594 : public WebFrameSerializer::MHTMLPartsGenerationDelegate { | 630 : public WebFrameSerializer::MHTMLPartsGenerationDelegate { |
| 595 public: | 631 public: |
| 596 MHTMLPartsGenerationDelegate( | 632 MHTMLPartsGenerationDelegate( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 611 return true; | 647 return true; |
| 612 | 648 |
| 613 // Let's record |url| as being serialized for the *current* frame. | 649 // Let's record |url| as being serialized for the *current* frame. |
| 614 auto pair = digests_of_uris_of_serialized_resources_->insert(digest); | 650 auto pair = digests_of_uris_of_serialized_resources_->insert(digest); |
| 615 bool insertion_took_place = pair.second; | 651 bool insertion_took_place = pair.second; |
| 616 DCHECK(insertion_took_place); // Blink should dedupe within a frame. | 652 DCHECK(insertion_took_place); // Blink should dedupe within a frame. |
| 617 | 653 |
| 618 return false; | 654 return false; |
| 619 } | 655 } |
| 620 | 656 |
| 621 WebString getContentID(const WebFrame& frame) override { | 657 WebString getContentID(WebFrame* frame) override { |
| 622 int routing_id = GetRoutingIdForFrameOrProxy(const_cast<WebFrame*>(&frame)); | 658 int routing_id = GetRoutingIdForFrameOrProxy(frame); |
| 623 auto it = params_.frame_routing_id_to_content_id.find(routing_id); | 659 auto it = params_.frame_routing_id_to_content_id.find(routing_id); |
| 624 DCHECK(it != params_.frame_routing_id_to_content_id.end()); | 660 DCHECK(it != params_.frame_routing_id_to_content_id.end()); |
| 625 const std::string& content_id = it->second; | 661 const std::string& content_id = it->second; |
| 626 return WebString::fromUTF8(content_id); | 662 return WebString::fromUTF8(content_id); |
| 627 } | 663 } |
| 628 | 664 |
| 629 private: | 665 private: |
| 630 const FrameMsg_SerializeAsMHTML_Params& params_; | 666 const FrameMsg_SerializeAsMHTML_Params& params_; |
| 631 std::set<std::string>* digests_of_uris_of_serialized_resources_; | 667 std::set<std::string>* digests_of_uris_of_serialized_resources_; |
| 632 | 668 |
| (...skipping 4166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4799 } | 4835 } |
| 4800 | 4836 |
| 4801 Referrer referrer = | 4837 Referrer referrer = |
| 4802 Referrer(frame_->document().url(), frame_->document().referrerPolicy()); | 4838 Referrer(frame_->document().url(), frame_->document().referrerPolicy()); |
| 4803 | 4839 |
| 4804 Send(new FrameHostMsg_SavableResourceLinksResponse( | 4840 Send(new FrameHostMsg_SavableResourceLinksResponse( |
| 4805 routing_id_, resources_list, referrer, subframes)); | 4841 routing_id_, resources_list, referrer, subframes)); |
| 4806 } | 4842 } |
| 4807 | 4843 |
| 4808 void RenderFrameImpl::OnGetSerializedHtmlWithLocalLinks( | 4844 void RenderFrameImpl::OnGetSerializedHtmlWithLocalLinks( |
| 4809 const std::map<GURL, base::FilePath>& url_to_local_path) { | 4845 const std::map<GURL, base::FilePath>& url_to_local_path, |
| 4846 const std::map<int, base::FilePath>& frame_routing_id_to_local_path) { |
| 4810 // Convert input to the canonical way of passing a map into a Blink API. | 4847 // Convert input to the canonical way of passing a map into a Blink API. |
| 4811 std::vector<std::pair<WebURL, WebString>> weburl_to_local_path; | 4848 LinkRewritingDelegate delegate(url_to_local_path, |
| 4812 for (const auto& it : url_to_local_path) { | 4849 frame_routing_id_to_local_path); |
| 4813 const GURL& url = it.first; | |
| 4814 const base::FilePath& local_path = it.second; | |
| 4815 weburl_to_local_path.push_back(std::make_pair( | |
| 4816 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path))); | |
| 4817 } | |
| 4818 | 4850 |
| 4819 // Serialize the frame (without recursing into subframes). | 4851 // Serialize the frame (without recursing into subframes). |
| 4820 WebFrameSerializer::serialize(GetWebFrame(), | 4852 WebFrameSerializer::serialize(GetWebFrame(), |
| 4821 this, // WebFrameSerializerClient. | 4853 this, // WebFrameSerializerClient. |
| 4822 weburl_to_local_path); | 4854 &delegate); |
| 4823 } | 4855 } |
| 4824 | 4856 |
| 4825 void RenderFrameImpl::OnSerializeAsMHTML( | 4857 void RenderFrameImpl::OnSerializeAsMHTML( |
| 4826 const FrameMsg_SerializeAsMHTML_Params& params) { | 4858 const FrameMsg_SerializeAsMHTML_Params& params) { |
| 4827 // Unpack IPC payload. | 4859 // Unpack IPC payload. |
| 4828 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); | 4860 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); |
| 4829 const WebString mhtml_boundary = | 4861 const WebString mhtml_boundary = |
| 4830 WebString::fromUTF8(params.mhtml_boundary_marker); | 4862 WebString::fromUTF8(params.mhtml_boundary_marker); |
| 4831 DCHECK(!mhtml_boundary.isEmpty()); | 4863 DCHECK(!mhtml_boundary.isEmpty()); |
| 4832 | 4864 |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5689 media::ConvertToSwitchOutputDeviceCB(web_callbacks); | 5721 media::ConvertToSwitchOutputDeviceCB(web_callbacks); |
| 5690 scoped_refptr<media::AudioOutputDevice> device = | 5722 scoped_refptr<media::AudioOutputDevice> device = |
| 5691 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), | 5723 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), |
| 5692 security_origin); | 5724 security_origin); |
| 5693 media::OutputDeviceStatus status = device->GetDeviceStatus(); | 5725 media::OutputDeviceStatus status = device->GetDeviceStatus(); |
| 5694 device->Stop(); | 5726 device->Stop(); |
| 5695 callback.Run(status); | 5727 callback.Run(status); |
| 5696 } | 5728 } |
| 5697 | 5729 |
| 5698 } // namespace content | 5730 } // namespace content |
| OLD | NEW |