Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1127)

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 1417323006: OOPIFs: Deduplicating MHTML parts across frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mhtml-serialization-per-frame
Patch Set: Passing MHTMLPartsGenerationDelegate by pointer. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/auto_reset.h" 11 #include "base/auto_reset.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/debug/alias.h" 13 #include "base/debug/alias.h"
14 #include "base/debug/asan_invalid_access.h" 14 #include "base/debug/asan_invalid_access.h"
15 #include "base/debug/dump_without_crashing.h" 15 #include "base/debug/dump_without_crashing.h"
16 #include "base/files/file.h" 16 #include "base/files/file.h"
17 #include "base/i18n/char_iterator.h" 17 #include "base/i18n/char_iterator.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/macros.h"
19 #include "base/memory/shared_memory.h" 20 #include "base/memory/shared_memory.h"
20 #include "base/memory/weak_ptr.h" 21 #include "base/memory/weak_ptr.h"
21 #include "base/metrics/histogram.h" 22 #include "base/metrics/histogram.h"
22 #include "base/process/process.h" 23 #include "base/process/process.h"
24 #include "base/stl_util.h"
23 #include "base/strings/string16.h" 25 #include "base/strings/string16.h"
24 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
25 #include "base/thread_task_runner_handle.h" 27 #include "base/thread_task_runner_handle.h"
26 #include "base/time/time.h" 28 #include "base/time/time.h"
27 #include "cc/base/switches.h" 29 #include "cc/base/switches.h"
28 #include "components/scheduler/renderer/renderer_scheduler.h" 30 #include "components/scheduler/renderer/renderer_scheduler.h"
29 #include "content/child/appcache/appcache_dispatcher.h" 31 #include "content/child/appcache/appcache_dispatcher.h"
30 #include "content/child/permissions/permission_dispatcher.h" 32 #include "content/child/permissions/permission_dispatcher.h"
31 #include "content/child/plugin_messages.h" 33 #include "content/child/plugin_messages.h"
32 #include "content/child/quota_dispatcher.h" 34 #include "content/child/quota_dispatcher.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 #include "content/renderer/savable_resources.h" 120 #include "content/renderer/savable_resources.h"
119 #include "content/renderer/screen_orientation/screen_orientation_dispatcher.h" 121 #include "content/renderer/screen_orientation/screen_orientation_dispatcher.h"
120 #include "content/renderer/shared_worker_repository.h" 122 #include "content/renderer/shared_worker_repository.h"
121 #include "content/renderer/skia_benchmarking_extension.h" 123 #include "content/renderer/skia_benchmarking_extension.h"
122 #include "content/renderer/stats_collection_controller.h" 124 #include "content/renderer/stats_collection_controller.h"
123 #include "content/renderer/usb/web_usb_client_impl.h" 125 #include "content/renderer/usb/web_usb_client_impl.h"
124 #include "content/renderer/wake_lock/wake_lock_dispatcher.h" 126 #include "content/renderer/wake_lock/wake_lock_dispatcher.h"
125 #include "content/renderer/web_frame_utils.h" 127 #include "content/renderer/web_frame_utils.h"
126 #include "content/renderer/web_ui_extension.h" 128 #include "content/renderer/web_ui_extension.h"
127 #include "content/renderer/websharedworker_proxy.h" 129 #include "content/renderer/websharedworker_proxy.h"
130 #include "crypto/sha2.h"
128 #include "gin/modules/module_registry.h" 131 #include "gin/modules/module_registry.h"
129 #include "media/audio/audio_output_device.h" 132 #include "media/audio/audio_output_device.h"
130 #include "media/base/audio_renderer_mixer_input.h" 133 #include "media/base/audio_renderer_mixer_input.h"
131 #include "media/base/media_log.h" 134 #include "media/base/media_log.h"
132 #include "media/base/media_switches.h" 135 #include "media/base/media_switches.h"
133 #include "media/blink/url_index.h" 136 #include "media/blink/url_index.h"
134 #include "media/blink/webencryptedmediaclient_impl.h" 137 #include "media/blink/webencryptedmediaclient_impl.h"
135 #include "media/blink/webmediaplayer_impl.h" 138 #include "media/blink/webmediaplayer_impl.h"
136 #include "media/renderers/gpu_video_accelerator_factories.h" 139 #include "media/renderers/gpu_video_accelerator_factories.h"
137 #include "mojo/common/url_type_converters.h" 140 #include "mojo/common/url_type_converters.h"
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 574
572 void OnGotContentHandlerID(uint32_t content_handler_id) {} 575 void OnGotContentHandlerID(uint32_t content_handler_id) {}
573 576
574 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { 577 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) {
575 DCHECK(!path.IsAbsolute()); 578 DCHECK(!path.IsAbsolute());
576 return WebString::fromUTF8( 579 return WebString::fromUTF8(
577 std::string("./") + 580 std::string("./") +
578 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); 581 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe());
579 } 582 }
580 583
584 // Implementation of WebPageSerializer::MHTMLPartsGenerationDelegate that
585 // 1. Bases shouldSkipResource and getContentID responses on contents of
586 // FrameMsg_SerializeAsMHTML_Params.
587 // 2. Stores digests of urls of serialized resources (i.e. urls reported via
588 // shouldSkipResource) into |digests_of_uris_of_serialized_resources| passed
589 // to the constructor.
590 class MHTMLPartsGenerationDelegate
591 : public WebPageSerializer::MHTMLPartsGenerationDelegate {
592 public:
593 MHTMLPartsGenerationDelegate(
594 const FrameMsg_SerializeAsMHTML_Params& params,
595 std::set<std::string>* digests_of_uris_of_serialized_resources)
596 : params_(params),
597 digests_of_uris_of_serialized_resources_(
598 digests_of_uris_of_serialized_resources) {
599 DCHECK(digests_of_uris_of_serialized_resources_);
600 }
601
602 bool shouldSkipResource(const WebURL& url) override {
603 std::string digest =
604 crypto::SHA256HashString(params_.salt + GURL(url).spec());
605
606 if (ContainsKey(params_.digests_of_uris_to_skip, digest))
607 return true;
608
609 digests_of_uris_of_serialized_resources_->insert(digest);
Randy Smith (Not in Mondays) 2015/12/30 00:45:49 No claim to understand the WebKit code, so this is
Łukasz Anforowicz 2015/12/30 19:09:09 Blink should take care of deduping within a single
610 return false;
611 }
612
613 WebString getContentID(const WebFrame& frame) override {
614 int routing_id = GetRoutingIdForFrameOrProxy(const_cast<WebFrame*>(&frame));
615 auto it = params_.frame_routing_id_to_content_id.find(routing_id);
616 DCHECK(it != params_.frame_routing_id_to_content_id.end());
617 const std::string& content_id = it->second;
618 return WebString::fromUTF8(content_id);
619 }
620
621 private:
622 const FrameMsg_SerializeAsMHTML_Params& params_;
623 std::set<std::string>* digests_of_uris_of_serialized_resources_;
624
625 DISALLOW_COPY_AND_ASSIGN(MHTMLPartsGenerationDelegate);
626 };
627
581 bool IsContentWithCertificateErrorsRelevantToUI( 628 bool IsContentWithCertificateErrorsRelevantToUI(
582 const blink::WebURL& url, 629 const blink::WebURL& url,
583 const blink::WebCString& security_info, 630 const blink::WebCString& security_info,
584 const blink::WebURL& main_resource_url, 631 const blink::WebURL& main_resource_url,
585 const blink::WebCString& main_resource_security_info) { 632 const blink::WebCString& main_resource_security_info) {
586 content::SSLStatus ssl_status; 633 content::SSLStatus ssl_status;
587 content::SSLStatus main_resource_ssl_status; 634 content::SSLStatus main_resource_ssl_status;
588 CHECK(DeserializeSecurityInfo(security_info, &ssl_status)); 635 CHECK(DeserializeSecurityInfo(security_info, &ssl_status));
589 CHECK(DeserializeSecurityInfo(main_resource_security_info, 636 CHECK(DeserializeSecurityInfo(main_resource_security_info,
590 &main_resource_ssl_status)); 637 &main_resource_ssl_status));
(...skipping 4171 matching lines...) Expand 10 before | Expand all | Expand 10 after
4762 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path))); 4809 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path)));
4763 } 4810 }
4764 4811
4765 // Serialize the frame (without recursing into subframes). 4812 // Serialize the frame (without recursing into subframes).
4766 WebPageSerializer::serialize(GetWebFrame(), 4813 WebPageSerializer::serialize(GetWebFrame(),
4767 this, // WebPageSerializerClient. 4814 this, // WebPageSerializerClient.
4768 weburl_to_local_path); 4815 weburl_to_local_path);
4769 } 4816 }
4770 4817
4771 void RenderFrameImpl::OnSerializeAsMHTML( 4818 void RenderFrameImpl::OnSerializeAsMHTML(
4772 int job_id, 4819 const FrameMsg_SerializeAsMHTML_Params& params) {
4773 IPC::PlatformFileForTransit file_for_transit,
4774 const std::string& std_mhtml_boundary,
4775 const std::map<int, std::string>& frame_routing_id_to_content_id,
4776 bool is_last_frame) {
4777 // Unpack IPC payload. 4820 // Unpack IPC payload.
4778 base::File file = IPC::PlatformFileForTransitToFile(file_for_transit); 4821 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file);
4779 const WebString mhtml_boundary = WebString::fromUTF8(std_mhtml_boundary); 4822 const WebString mhtml_boundary =
4823 WebString::fromUTF8(params.mhtml_boundary_marker);
4780 DCHECK(!mhtml_boundary.isEmpty()); 4824 DCHECK(!mhtml_boundary.isEmpty());
4781 std::vector<std::pair<WebFrame*, WebString>> web_frame_to_content_id;
4782 for (const auto& it : frame_routing_id_to_content_id) {
4783 const std::string& content_id = it.second;
4784 WebFrame* web_frame = GetWebFrameFromRoutingIdForFrameOrProxy(it.first);
4785 if (!web_frame)
4786 continue;
4787
4788 web_frame_to_content_id.push_back(
4789 std::make_pair(web_frame, WebString::fromUTF8(content_id)));
4790 }
4791 4825
4792 WebData data; 4826 WebData data;
4793 bool success = true; 4827 bool success = true;
4828 std::set<std::string> digests_of_uris_of_serialized_resources;
4829 MHTMLPartsGenerationDelegate delegate(
4830 params, &digests_of_uris_of_serialized_resources);
4794 4831
4795 // Generate MHTML header if needed. 4832 // Generate MHTML header if needed.
4796 if (IsMainFrame()) { 4833 if (IsMainFrame()) {
4797 data = 4834 data =
4798 WebPageSerializer::generateMHTMLHeader(mhtml_boundary, GetWebFrame()); 4835 WebPageSerializer::generateMHTMLHeader(mhtml_boundary, GetWebFrame());
4799 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { 4836 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) {
4800 success = false; 4837 success = false;
4801 } 4838 }
4802 } 4839 }
4803 4840
4804 // Generate MHTML parts. 4841 // Generate MHTML parts.
4805 if (success) { 4842 if (success) {
4806 data = WebPageSerializer::generateMHTMLParts( 4843 data = WebPageSerializer::generateMHTMLParts(mhtml_boundary, GetWebFrame(),
4807 mhtml_boundary, GetWebFrame(), false, web_frame_to_content_id); 4844 false, &delegate);
4808 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to 4845 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to
4809 // the message loop to process other events. 4846 // the message loop to process other events.
4810 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { 4847 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) {
4811 success = false; 4848 success = false;
4812 } 4849 }
4813 } 4850 }
4814 4851
4815 // Generate MHTML footer if needed. 4852 // Generate MHTML footer if needed.
4816 if (success && is_last_frame) { 4853 if (success && params.is_last_frame) {
4817 data = WebPageSerializer::generateMHTMLFooter(mhtml_boundary); 4854 data = WebPageSerializer::generateMHTMLFooter(mhtml_boundary);
4818 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { 4855 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) {
4819 success = false; 4856 success = false;
4820 } 4857 }
4821 } 4858 }
4822 4859
4823 // Cleanup and notify the browser process about completion. 4860 // Cleanup and notify the browser process about completion.
4824 file.Close(); // Need to flush file contents before sending IPC response. 4861 file.Close(); // Need to flush file contents before sending IPC response.
4825 Send(new FrameHostMsg_SerializeAsMHTMLResponse(routing_id_, job_id, success)); 4862 Send(new FrameHostMsg_SerializeAsMHTMLResponse(
4863 routing_id_, params.job_id, success,
4864 digests_of_uris_of_serialized_resources));
4826 } 4865 }
4827 4866
4828 void RenderFrameImpl::OpenURL(const GURL& url, 4867 void RenderFrameImpl::OpenURL(const GURL& url,
4829 const Referrer& referrer, 4868 const Referrer& referrer,
4830 WebNavigationPolicy policy, 4869 WebNavigationPolicy policy,
4831 bool should_replace_current_entry, 4870 bool should_replace_current_entry,
4832 bool is_history_navigation_in_new_child) { 4871 bool is_history_navigation_in_new_child) {
4833 FrameHostMsg_OpenURL_Params params; 4872 FrameHostMsg_OpenURL_Params params;
4834 params.url = url; 4873 params.url = url;
4835 params.referrer = referrer; 4874 params.referrer = referrer;
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
5642 media::ConvertToSwitchOutputDeviceCB(web_callbacks); 5681 media::ConvertToSwitchOutputDeviceCB(web_callbacks);
5643 scoped_refptr<media::AudioOutputDevice> device = 5682 scoped_refptr<media::AudioOutputDevice> device =
5644 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), 5683 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(),
5645 security_origin); 5684 security_origin);
5646 media::OutputDeviceStatus status = device->GetDeviceStatus(); 5685 media::OutputDeviceStatus status = device->GetDeviceStatus();
5647 device->Stop(); 5686 device->Stop();
5648 callback.Run(status); 5687 callback.Run(status);
5649 } 5688 }
5650 5689
5651 } // namespace content 5690 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698