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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 #include "content/renderer/savable_resources.h" | 119 #include "content/renderer/savable_resources.h" |
120 #include "content/renderer/screen_orientation/screen_orientation_dispatcher.h" | 120 #include "content/renderer/screen_orientation/screen_orientation_dispatcher.h" |
121 #include "content/renderer/shared_worker_repository.h" | 121 #include "content/renderer/shared_worker_repository.h" |
122 #include "content/renderer/skia_benchmarking_extension.h" | 122 #include "content/renderer/skia_benchmarking_extension.h" |
123 #include "content/renderer/stats_collection_controller.h" | 123 #include "content/renderer/stats_collection_controller.h" |
124 #include "content/renderer/usb/web_usb_client_impl.h" | 124 #include "content/renderer/usb/web_usb_client_impl.h" |
125 #include "content/renderer/wake_lock/wake_lock_dispatcher.h" | 125 #include "content/renderer/wake_lock/wake_lock_dispatcher.h" |
126 #include "content/renderer/web_frame_utils.h" | 126 #include "content/renderer/web_frame_utils.h" |
127 #include "content/renderer/web_ui_extension.h" | 127 #include "content/renderer/web_ui_extension.h" |
128 #include "content/renderer/websharedworker_proxy.h" | 128 #include "content/renderer/websharedworker_proxy.h" |
129 #include "crypto/sha2.h" | |
129 #include "gin/modules/module_registry.h" | 130 #include "gin/modules/module_registry.h" |
130 #include "media/audio/audio_output_device.h" | 131 #include "media/audio/audio_output_device.h" |
131 #include "media/base/audio_renderer_mixer_input.h" | 132 #include "media/base/audio_renderer_mixer_input.h" |
132 #include "media/base/media_log.h" | 133 #include "media/base/media_log.h" |
133 #include "media/base/media_switches.h" | 134 #include "media/base/media_switches.h" |
134 #include "media/blink/url_index.h" | 135 #include "media/blink/url_index.h" |
135 #include "media/blink/webencryptedmediaclient_impl.h" | 136 #include "media/blink/webencryptedmediaclient_impl.h" |
136 #include "media/blink/webmediaplayer_impl.h" | 137 #include "media/blink/webmediaplayer_impl.h" |
137 #include "media/renderers/gpu_video_accelerator_factories.h" | 138 #include "media/renderers/gpu_video_accelerator_factories.h" |
138 #include "mojo/common/url_type_converters.h" | 139 #include "mojo/common/url_type_converters.h" |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 | 575 |
575 void OnGotContentHandlerID(uint32_t content_handler_id) {} | 576 void OnGotContentHandlerID(uint32_t content_handler_id) {} |
576 | 577 |
577 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { | 578 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { |
578 DCHECK(!path.IsAbsolute()); | 579 DCHECK(!path.IsAbsolute()); |
579 return WebString::fromUTF8( | 580 return WebString::fromUTF8( |
580 std::string("./") + | 581 std::string("./") + |
581 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); | 582 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); |
582 } | 583 } |
583 | 584 |
585 // Implementation of WebPageSerializer::MHTMLPartsGenerationDelegate that | |
586 // 1. Bases shouldSkipResource and getContentID responses on contents of | |
587 // FrameMsg_SerializeAsMHTML_Params. | |
588 // 2. Stores urls of serialized resources (reported via shouldSkipResource) | |
589 // into |uris_of_serialized_resources| passed to the constructor. | |
590 class MHTMLPartsGenerationDelegate | |
591 : public WebPageSerializer::MHTMLPartsGenerationDelegate { | |
592 public: | |
593 MHTMLPartsGenerationDelegate(const FrameMsg_SerializeAsMHTML_Params& params, | |
594 std::set<GURL>* uris_of_serialized_resources_) | |
595 : params_(params), | |
596 uris_of_serialized_resources_(uris_of_serialized_resources_) { | |
597 DCHECK(uris_of_serialized_resources_); | |
598 } | |
599 | |
600 bool shouldSkipResource(const WebURL& url) override { | |
601 std::string digest = | |
602 crypto::SHA256HashString(params_.salt + GURL(url).spec()); | |
603 | |
604 if (0 != params_.digests_of_uris_to_skip.count(digest)) | |
dcheng
2015/12/22 01:01:45
ContainsKey? Or find()? Either seems to be more co
Łukasz Anforowicz
2015/12/22 21:06:46
Thanks for pointing out ContainsKey. Done.
Side-
| |
605 return true; | |
606 | |
607 uris_of_serialized_resources_->insert(url); | |
dcheng
2015/12/22 01:01:45
Any particular reason not to just send the hashes
Łukasz Anforowicz
2015/12/22 21:06:46
Done - I changed the code to send digests (instead
| |
608 return false; | |
609 } | |
610 | |
611 WebString getContentID(const WebFrame& frame) override { | |
612 int routing_id = GetRoutingIdForFrameOrProxy(const_cast<WebFrame*>(&frame)); | |
613 auto it = params_.frame_routing_id_to_content_id.find(routing_id); | |
614 DCHECK(it != params_.frame_routing_id_to_content_id.end()); | |
615 const std::string& content_id = it->second; | |
616 return WebString::fromUTF8(content_id); | |
617 } | |
618 | |
619 private: | |
620 const FrameMsg_SerializeAsMHTML_Params& params_; | |
621 std::set<GURL>* uris_of_serialized_resources_; | |
622 }; | |
dcheng
2015/12/22 01:01:45
Nit: DISALLOW_COPY_AND_ASSIGN
Łukasz Anforowicz
2015/12/22 21:06:46
Oh, right. Done.
| |
623 | |
584 bool IsContentWithCertificateErrorsRelevantToUI( | 624 bool IsContentWithCertificateErrorsRelevantToUI( |
585 const blink::WebURL& url, | 625 const blink::WebURL& url, |
586 const blink::WebCString& security_info, | 626 const blink::WebCString& security_info, |
587 const blink::WebURL& main_resource_url, | 627 const blink::WebURL& main_resource_url, |
588 const blink::WebCString& main_resource_security_info) { | 628 const blink::WebCString& main_resource_security_info) { |
589 content::SSLStatus ssl_status; | 629 content::SSLStatus ssl_status; |
590 content::SSLStatus main_resource_ssl_status; | 630 content::SSLStatus main_resource_ssl_status; |
591 CHECK(DeserializeSecurityInfo(security_info, &ssl_status)); | 631 CHECK(DeserializeSecurityInfo(security_info, &ssl_status)); |
592 CHECK(DeserializeSecurityInfo(main_resource_security_info, | 632 CHECK(DeserializeSecurityInfo(main_resource_security_info, |
593 &main_resource_ssl_status)); | 633 &main_resource_ssl_status)); |
(...skipping 4177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4771 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path))); | 4811 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path))); |
4772 } | 4812 } |
4773 | 4813 |
4774 // Serialize the frame (without recursing into subframes). | 4814 // Serialize the frame (without recursing into subframes). |
4775 WebPageSerializer::serialize(GetWebFrame(), | 4815 WebPageSerializer::serialize(GetWebFrame(), |
4776 this, // WebPageSerializerClient. | 4816 this, // WebPageSerializerClient. |
4777 weburl_to_local_path); | 4817 weburl_to_local_path); |
4778 } | 4818 } |
4779 | 4819 |
4780 void RenderFrameImpl::OnSerializeAsMHTML( | 4820 void RenderFrameImpl::OnSerializeAsMHTML( |
4781 int job_id, | 4821 const FrameMsg_SerializeAsMHTML_Params& params) { |
4782 IPC::PlatformFileForTransit file_for_transit, | |
4783 const std::string& std_mhtml_boundary, | |
4784 const std::map<int, std::string>& frame_routing_id_to_content_id, | |
4785 bool is_last_frame) { | |
4786 // Unpack IPC payload. | 4822 // Unpack IPC payload. |
4787 base::File file = IPC::PlatformFileForTransitToFile(file_for_transit); | 4823 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); |
4788 const WebString mhtml_boundary = WebString::fromUTF8(std_mhtml_boundary); | 4824 const WebString mhtml_boundary = |
4825 WebString::fromUTF8(params.mhtml_boundary_marker); | |
4789 DCHECK(!mhtml_boundary.isEmpty()); | 4826 DCHECK(!mhtml_boundary.isEmpty()); |
4790 std::vector<std::pair<WebFrame*, WebString>> web_frame_to_content_id; | |
4791 for (const auto& it : frame_routing_id_to_content_id) { | |
4792 const std::string& content_id = it.second; | |
4793 WebFrame* web_frame = GetWebFrameFromRoutingIdForFrameOrProxy(it.first); | |
4794 if (!web_frame) | |
4795 continue; | |
4796 | |
4797 web_frame_to_content_id.push_back( | |
4798 std::make_pair(web_frame, WebString::fromUTF8(content_id))); | |
4799 } | |
4800 | 4827 |
4801 WebData data; | 4828 WebData data; |
4802 bool success = true; | 4829 bool success = true; |
4830 std::set<GURL> uris_of_serialized_resources; | |
4831 MHTMLPartsGenerationDelegate delegate(params, &uris_of_serialized_resources); | |
4803 | 4832 |
4804 // Generate MHTML header if needed. | 4833 // Generate MHTML header if needed. |
4805 if (IsMainFrame()) { | 4834 if (IsMainFrame()) { |
4806 data = | 4835 data = |
4807 WebPageSerializer::generateMHTMLHeader(mhtml_boundary, GetWebFrame()); | 4836 WebPageSerializer::generateMHTMLHeader(mhtml_boundary, GetWebFrame()); |
4808 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | 4837 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
4809 success = false; | 4838 success = false; |
4810 } | 4839 } |
4811 } | 4840 } |
4812 | 4841 |
4813 // Generate MHTML parts. | 4842 // Generate MHTML parts. |
4814 if (success) { | 4843 if (success) { |
4815 data = WebPageSerializer::generateMHTMLParts( | 4844 data = WebPageSerializer::generateMHTMLParts(mhtml_boundary, GetWebFrame(), |
4816 mhtml_boundary, GetWebFrame(), false, web_frame_to_content_id); | 4845 false, delegate); |
4817 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to | 4846 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to |
4818 // the message loop to process other events. | 4847 // the message loop to process other events. |
4819 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | 4848 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
4820 success = false; | 4849 success = false; |
4821 } | 4850 } |
4822 } | 4851 } |
4823 | 4852 |
4824 // Generate MHTML footer if needed. | 4853 // Generate MHTML footer if needed. |
4825 if (success && is_last_frame) { | 4854 if (success && params.is_last_frame) { |
4826 data = WebPageSerializer::generateMHTMLFooter(mhtml_boundary); | 4855 data = WebPageSerializer::generateMHTMLFooter(mhtml_boundary); |
4827 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | 4856 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
4828 success = false; | 4857 success = false; |
4829 } | 4858 } |
4830 } | 4859 } |
4831 | 4860 |
4832 // Cleanup and notify the browser process about completion. | 4861 // Cleanup and notify the browser process about completion. |
4833 file.Close(); // Need to flush file contents before sending IPC response. | 4862 file.Close(); // Need to flush file contents before sending IPC response. |
4834 Send(new FrameHostMsg_SerializeAsMHTMLResponse(routing_id_, job_id, success)); | 4863 Send(new FrameHostMsg_SerializeAsMHTMLResponse( |
4864 routing_id_, params.job_id, success, uris_of_serialized_resources)); | |
4835 } | 4865 } |
4836 | 4866 |
4837 void RenderFrameImpl::OpenURL(const GURL& url, | 4867 void RenderFrameImpl::OpenURL(const GURL& url, |
4838 const Referrer& referrer, | 4868 const Referrer& referrer, |
4839 WebNavigationPolicy policy, | 4869 WebNavigationPolicy policy, |
4840 bool should_replace_current_entry, | 4870 bool should_replace_current_entry, |
4841 bool is_history_navigation_in_new_child) { | 4871 bool is_history_navigation_in_new_child) { |
4842 FrameHostMsg_OpenURL_Params params; | 4872 FrameHostMsg_OpenURL_Params params; |
4843 params.url = url; | 4873 params.url = url; |
4844 params.referrer = referrer; | 4874 params.referrer = referrer; |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5637 media::ConvertToSwitchOutputDeviceCB(web_callbacks); | 5667 media::ConvertToSwitchOutputDeviceCB(web_callbacks); |
5638 scoped_refptr<media::AudioOutputDevice> device = | 5668 scoped_refptr<media::AudioOutputDevice> device = |
5639 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), | 5669 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), |
5640 security_origin); | 5670 security_origin); |
5641 media::OutputDeviceStatus status = device->GetDeviceStatus(); | 5671 media::OutputDeviceStatus status = device->GetDeviceStatus(); |
5642 device->Stop(); | 5672 device->Stop(); |
5643 callback.Run(status); | 5673 callback.Run(status); |
5644 } | 5674 } |
5645 | 5675 |
5646 } // namespace content | 5676 } // namespace content |
OLD | NEW |