Chromium Code Reviews| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 #include "content/renderer/savable_resources.h" | 118 #include "content/renderer/savable_resources.h" |
| 119 #include "content/renderer/screen_orientation/screen_orientation_dispatcher.h" | 119 #include "content/renderer/screen_orientation/screen_orientation_dispatcher.h" |
| 120 #include "content/renderer/shared_worker_repository.h" | 120 #include "content/renderer/shared_worker_repository.h" |
| 121 #include "content/renderer/skia_benchmarking_extension.h" | 121 #include "content/renderer/skia_benchmarking_extension.h" |
| 122 #include "content/renderer/stats_collection_controller.h" | 122 #include "content/renderer/stats_collection_controller.h" |
| 123 #include "content/renderer/usb/web_usb_client_impl.h" | 123 #include "content/renderer/usb/web_usb_client_impl.h" |
| 124 #include "content/renderer/wake_lock/wake_lock_dispatcher.h" | 124 #include "content/renderer/wake_lock/wake_lock_dispatcher.h" |
| 125 #include "content/renderer/web_frame_utils.h" | 125 #include "content/renderer/web_frame_utils.h" |
| 126 #include "content/renderer/web_ui_extension.h" | 126 #include "content/renderer/web_ui_extension.h" |
| 127 #include "content/renderer/websharedworker_proxy.h" | 127 #include "content/renderer/websharedworker_proxy.h" |
| 128 #include "crypto/sha2.h" | |
| 128 #include "gin/modules/module_registry.h" | 129 #include "gin/modules/module_registry.h" |
| 129 #include "media/audio/audio_output_device.h" | 130 #include "media/audio/audio_output_device.h" |
| 130 #include "media/base/audio_renderer_mixer_input.h" | 131 #include "media/base/audio_renderer_mixer_input.h" |
| 131 #include "media/base/media_log.h" | 132 #include "media/base/media_log.h" |
| 132 #include "media/base/media_switches.h" | 133 #include "media/base/media_switches.h" |
| 133 #include "media/blink/webencryptedmediaclient_impl.h" | 134 #include "media/blink/webencryptedmediaclient_impl.h" |
| 134 #include "media/blink/webmediaplayer_impl.h" | 135 #include "media/blink/webmediaplayer_impl.h" |
| 135 #include "media/renderers/gpu_video_accelerator_factories.h" | 136 #include "media/renderers/gpu_video_accelerator_factories.h" |
| 136 #include "mojo/common/url_type_converters.h" | 137 #include "mojo/common/url_type_converters.h" |
| 137 #include "net/base/data_url.h" | 138 #include "net/base/data_url.h" |
| (...skipping 4515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4653 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path))); | 4654 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path))); |
| 4654 } | 4655 } |
| 4655 | 4656 |
| 4656 // Serialize the frame (without recursing into subframes). | 4657 // Serialize the frame (without recursing into subframes). |
| 4657 WebPageSerializer::serialize(GetWebFrame(), | 4658 WebPageSerializer::serialize(GetWebFrame(), |
| 4658 this, // WebPageSerializerClient. | 4659 this, // WebPageSerializerClient. |
| 4659 weburl_to_local_path); | 4660 weburl_to_local_path); |
| 4660 } | 4661 } |
| 4661 | 4662 |
| 4662 void RenderFrameImpl::OnSerializeAsMHTML( | 4663 void RenderFrameImpl::OnSerializeAsMHTML( |
| 4663 int job_id, | 4664 const FrameMsg_SerializeAsMHTML_Params& params) { |
| 4664 IPC::PlatformFileForTransit file_for_transit, | |
| 4665 const std::string& std_mhtml_boundary, | |
| 4666 const std::map<int, std::string>& frame_routing_id_to_content_id, | |
| 4667 bool is_last_frame) { | |
| 4668 // Unpack IPC payload. | 4665 // Unpack IPC payload. |
| 4669 base::File file = IPC::PlatformFileForTransitToFile(file_for_transit); | 4666 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); |
| 4670 const WebString mhtml_boundary = WebString::fromUTF8(std_mhtml_boundary); | 4667 WebString mhtml_boundary = WebString::fromUTF8(params.mhtml_boundary_marker); |
| 4671 DCHECK(!mhtml_boundary.isEmpty()); | |
| 4672 std::vector<std::pair<WebFrame*, WebString>> web_frame_to_content_id; | 4668 std::vector<std::pair<WebFrame*, WebString>> web_frame_to_content_id; |
| 4673 for (const auto& it : frame_routing_id_to_content_id) { | 4669 for (const auto& it : params.frame_routing_id_to_content_id) { |
| 4674 const std::string& content_id = it.second; | 4670 const std::string& content_id = it.second; |
| 4675 WebFrame* web_frame = GetWebFrameFromRoutingIdForFrameOrProxy(it.first); | 4671 WebFrame* web_frame = GetWebFrameFromRoutingIdForFrameOrProxy(it.first); |
| 4676 if (!web_frame) | 4672 if (!web_frame) |
| 4677 continue; | 4673 continue; |
| 4678 | 4674 |
| 4679 web_frame_to_content_id.push_back( | 4675 web_frame_to_content_id.push_back( |
| 4680 std::make_pair(web_frame, WebString::fromUTF8(content_id))); | 4676 std::make_pair(web_frame, WebString::fromUTF8(content_id))); |
| 4681 } | 4677 } |
| 4678 const std::string& salt = params.salt; | |
| 4682 | 4679 |
| 4683 WebData data; | 4680 WebData data; |
| 4684 bool success = true; | 4681 bool success = true; |
| 4682 std::set<GURL> uris_of_generated_mhtml_parts; | |
| 4685 | 4683 |
| 4686 // Generate MHTML header if needed. | 4684 // Generate MHTML header if needed. |
| 4687 if (IsMainFrame()) { | 4685 if (success && IsMainFrame()) { |
|
dcheng
2015/12/11 07:36:05
Revert this.
dcheng
2015/12/11 07:36:05
Please revert this =)
Łukasz Anforowicz
2015/12/14 19:39:02
Ooops. Done (here and for the DCHECK below).
| |
| 4688 data = | 4686 data = |
| 4689 WebPageSerializer::generateMHTMLHeader(mhtml_boundary, GetWebFrame()); | 4687 WebPageSerializer::generateMHTMLHeader(mhtml_boundary, GetWebFrame()); |
| 4690 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | 4688 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
| 4691 success = false; | 4689 success = false; |
| 4692 } | 4690 } |
| 4693 } | 4691 } |
| 4692 DCHECK(!mhtml_boundary.isEmpty()); | |
| 4694 | 4693 |
| 4695 // Generate MHTML parts. | 4694 // Generate MHTML parts. |
| 4696 if (success) { | 4695 if (success) { |
| 4697 data = WebPageSerializer::generateMHTMLParts( | 4696 std::vector<WebURL> uris_to_skip; |
| 4698 mhtml_boundary, GetWebFrame(), false, web_frame_to_content_id); | 4697 WebVector<WebURL> all_urls = |
| 4698 WebPageSerializer::enumerateMHTMLResources(GetWebFrame()); | |
|
dcheng
2015/12/11 07:36:05
I think I would prefer to see a new WebPageSeriali
Łukasz Anforowicz
2015/12/14 19:39:02
Let me think a little bit more about this.
Some r
Łukasz Anforowicz
2015/12/18 17:38:48
Some more ideas:
- Stupid idea: Pass a "callback"
| |
| 4699 for (const WebURL url : all_urls) { | |
| 4700 std::string digest = crypto::SHA256HashString(salt + GURL(url).spec()); | |
| 4701 if (0 != params.digests_of_uris_to_skip.count(digest)) | |
| 4702 uris_to_skip.push_back(url); | |
| 4703 else | |
| 4704 uris_of_generated_mhtml_parts.insert(url); | |
| 4705 } | |
| 4706 | |
| 4707 data = WebPageSerializer::generateMHTMLParts(mhtml_boundary, GetWebFrame(), | |
| 4708 false, web_frame_to_content_id, | |
| 4709 uris_to_skip); | |
| 4699 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to | 4710 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to |
| 4700 // the message loop to process other events. | 4711 // the message loop to process other events. |
| 4701 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | 4712 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
| 4702 success = false; | 4713 success = false; |
| 4703 } | 4714 } |
| 4704 } | 4715 } |
| 4705 | 4716 |
| 4706 // Generate MHTML footer if needed. | 4717 // Generate MHTML footer if needed. |
| 4707 if (success && is_last_frame) { | 4718 if (success && params.is_last_frame) { |
| 4708 data = WebPageSerializer::generateMHTMLFooter(mhtml_boundary); | 4719 data = WebPageSerializer::generateMHTMLFooter(mhtml_boundary); |
| 4709 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | 4720 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
| 4710 success = false; | 4721 success = false; |
| 4711 } | 4722 } |
| 4712 } | 4723 } |
| 4713 | 4724 |
| 4714 // Cleanup and notify the browser process about completion. | 4725 // Cleanup and notify the browser process about completion. |
| 4715 file.Close(); // Need to flush file contents before sending IPC response. | 4726 file.Close(); // Need to flush file contents before sending IPC response. |
| 4716 Send(new FrameHostMsg_SerializeAsMHTMLResponse(routing_id_, job_id, success)); | 4727 Send(new FrameHostMsg_SerializeAsMHTMLResponse( |
| 4728 routing_id_, params.job_id, success, uris_of_generated_mhtml_parts)); | |
| 4717 } | 4729 } |
| 4718 | 4730 |
| 4719 void RenderFrameImpl::OpenURL(const GURL& url, | 4731 void RenderFrameImpl::OpenURL(const GURL& url, |
| 4720 const Referrer& referrer, | 4732 const Referrer& referrer, |
| 4721 WebNavigationPolicy policy, | 4733 WebNavigationPolicy policy, |
| 4722 bool should_replace_current_entry, | 4734 bool should_replace_current_entry, |
| 4723 bool is_history_navigation_in_new_child) { | 4735 bool is_history_navigation_in_new_child) { |
| 4724 FrameHostMsg_OpenURL_Params params; | 4736 FrameHostMsg_OpenURL_Params params; |
| 4725 params.url = url; | 4737 params.url = url; |
| 4726 params.referrer = referrer; | 4738 params.referrer = referrer; |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5519 media::ConvertToSwitchOutputDeviceCB(web_callbacks); | 5531 media::ConvertToSwitchOutputDeviceCB(web_callbacks); |
| 5520 scoped_refptr<media::AudioOutputDevice> device = | 5532 scoped_refptr<media::AudioOutputDevice> device = |
| 5521 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), | 5533 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), |
| 5522 security_origin); | 5534 security_origin); |
| 5523 media::OutputDeviceStatus status = device->GetDeviceStatus(); | 5535 media::OutputDeviceStatus status = device->GetDeviceStatus(); |
| 5524 device->Stop(); | 5536 device->Stop(); |
| 5525 callback.Run(status); | 5537 callback.Run(status); |
| 5526 } | 5538 } |
| 5527 | 5539 |
| 5528 } // namespace content | 5540 } // namespace content |
| OLD | NEW |