| 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 12 matching lines...) Expand all Loading... |
| 23 #include "base/memory/shared_memory.h" | 23 #include "base/memory/shared_memory.h" |
| 24 #include "base/memory/weak_ptr.h" | 24 #include "base/memory/weak_ptr.h" |
| 25 #include "base/metrics/field_trial.h" | 25 #include "base/metrics/field_trial.h" |
| 26 #include "base/metrics/histogram_macros.h" | 26 #include "base/metrics/histogram_macros.h" |
| 27 #include "base/process/process.h" | 27 #include "base/process/process.h" |
| 28 #include "base/stl_util.h" | 28 #include "base/stl_util.h" |
| 29 #include "base/strings/string16.h" | 29 #include "base/strings/string16.h" |
| 30 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
| 31 #include "base/threading/thread_task_runner_handle.h" | 31 #include "base/threading/thread_task_runner_handle.h" |
| 32 #include "base/time/time.h" | 32 #include "base/time/time.h" |
| 33 #include "base/trace_event/trace_event_argument.h" | 33 #include "base/trace_event/trace_event.h" |
| 34 #include "build/build_config.h" | 34 #include "build/build_config.h" |
| 35 #include "cc/base/switches.h" | 35 #include "cc/base/switches.h" |
| 36 #include "content/child/appcache/appcache_dispatcher.h" | 36 #include "content/child/appcache/appcache_dispatcher.h" |
| 37 #include "content/child/quota_dispatcher.h" | 37 #include "content/child/quota_dispatcher.h" |
| 38 #include "content/child/request_extra_data.h" | 38 #include "content/child/request_extra_data.h" |
| 39 #include "content/child/service_worker/service_worker_handle_reference.h" | 39 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 40 #include "content/child/service_worker/service_worker_network_provider.h" | 40 #include "content/child/service_worker/service_worker_network_provider.h" |
| 41 #include "content/child/service_worker/service_worker_provider_context.h" | 41 #include "content/child/service_worker/service_worker_provider_context.h" |
| 42 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 42 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
| 43 #include "content/child/v8_value_converter_impl.h" | 43 #include "content/child/v8_value_converter_impl.h" |
| (...skipping 5116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5160 frame_routing_id_to_local_path); | 5160 frame_routing_id_to_local_path); |
| 5161 | 5161 |
| 5162 // Serialize the frame (without recursing into subframes). | 5162 // Serialize the frame (without recursing into subframes). |
| 5163 WebFrameSerializer::serialize(GetWebFrame(), | 5163 WebFrameSerializer::serialize(GetWebFrame(), |
| 5164 this, // WebFrameSerializerClient. | 5164 this, // WebFrameSerializerClient. |
| 5165 &delegate); | 5165 &delegate); |
| 5166 } | 5166 } |
| 5167 | 5167 |
| 5168 void RenderFrameImpl::OnSerializeAsMHTML( | 5168 void RenderFrameImpl::OnSerializeAsMHTML( |
| 5169 const FrameMsg_SerializeAsMHTML_Params& params) { | 5169 const FrameMsg_SerializeAsMHTML_Params& params) { |
| 5170 TRACE_EVENT0("page-serialization", "RenderFrameImpl::OnSerializeAsMHTML"); |
| 5170 // Unpack IPC payload. | 5171 // Unpack IPC payload. |
| 5171 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); | 5172 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); |
| 5172 const WebString mhtml_boundary = | 5173 const WebString mhtml_boundary = |
| 5173 WebString::fromUTF8(params.mhtml_boundary_marker); | 5174 WebString::fromUTF8(params.mhtml_boundary_marker); |
| 5174 DCHECK(!mhtml_boundary.isEmpty()); | 5175 DCHECK(!mhtml_boundary.isEmpty()); |
| 5175 | 5176 |
| 5176 WebData data; | 5177 WebData data; |
| 5177 std::set<std::string> digests_of_uris_of_serialized_resources; | 5178 std::set<std::string> digests_of_uris_of_serialized_resources; |
| 5178 MHTMLPartsGenerationDelegate delegate( | 5179 MHTMLPartsGenerationDelegate delegate( |
| 5179 params, &digests_of_uris_of_serialized_resources); | 5180 params, &digests_of_uris_of_serialized_resources); |
| 5180 | 5181 |
| 5181 bool success = true; | 5182 bool success = true; |
| 5182 | 5183 |
| 5183 // Generate MHTML header if needed. | 5184 // Generate MHTML header if needed. |
| 5184 if (IsMainFrame()) { | 5185 if (IsMainFrame()) { |
| 5186 TRACE_EVENT0("page-serialization", |
| 5187 "RenderFrameImpl::OnSerializeAsMHTML header"); |
| 5185 // |data| can be empty if the main frame should be skipped. If the main | 5188 // |data| can be empty if the main frame should be skipped. If the main |
| 5186 // frame is | 5189 // frame is skipped, then the whole archive is bad, so bail to the error |
| 5187 // skipped, then the whole archive is bad, so bail to the error condition. | 5190 // condition. |
| 5188 WebData data = WebFrameSerializer::generateMHTMLHeader( | 5191 WebData data = WebFrameSerializer::generateMHTMLHeader( |
| 5189 mhtml_boundary, GetWebFrame(), &delegate); | 5192 mhtml_boundary, GetWebFrame(), &delegate); |
| 5190 if (data.isEmpty() || | 5193 if (data.isEmpty() || |
| 5191 file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | 5194 file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
| 5192 success = false; | 5195 success = false; |
| 5193 } | 5196 } |
| 5194 } | 5197 } |
| 5195 | 5198 |
| 5196 // Generate MHTML parts. Note that if this is not the main frame, then even | 5199 // Generate MHTML parts. Note that if this is not the main frame, then even |
| 5197 // skipping the whole parts generation step is not an error - it simply | 5200 // skipping the whole parts generation step is not an error - it simply |
| 5198 // results in an omitted resource in the final file. | 5201 // results in an omitted resource in the final file. |
| 5199 if (success) { | 5202 if (success) { |
| 5203 TRACE_EVENT0("page-serialization", |
| 5204 "RenderFrameImpl::OnSerializeAsMHTML parts serialization"); |
| 5200 // |data| can be empty if the frame should be skipped, but this is OK. | 5205 // |data| can be empty if the frame should be skipped, but this is OK. |
| 5201 data = WebFrameSerializer::generateMHTMLParts(mhtml_boundary, GetWebFrame(), | 5206 data = WebFrameSerializer::generateMHTMLParts(mhtml_boundary, GetWebFrame(), |
| 5202 &delegate); | 5207 &delegate); |
| 5203 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to | 5208 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to |
| 5204 // the message loop to process other events. | 5209 // the message loop to process other events. |
| 5210 TRACE_EVENT0("page-serialization", |
| 5211 "RenderFrameImpl::OnSerializeAsMHTML parts file writing"); |
| 5205 if (!data.isEmpty() && | 5212 if (!data.isEmpty() && |
| 5206 file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | 5213 file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
| 5207 success = false; | 5214 success = false; |
| 5208 } | 5215 } |
| 5209 } | 5216 } |
| 5210 | 5217 |
| 5211 // Generate MHTML footer if needed. | 5218 // Generate MHTML footer if needed. |
| 5212 if (success && params.is_last_frame) { | 5219 if (success && params.is_last_frame) { |
| 5220 TRACE_EVENT0("page-serialization", |
| 5221 "RenderFrameImpl::OnSerializeAsMHTML footer"); |
| 5213 data = WebFrameSerializer::generateMHTMLFooter(mhtml_boundary); | 5222 data = WebFrameSerializer::generateMHTMLFooter(mhtml_boundary); |
| 5214 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | 5223 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
| 5215 success = false; | 5224 success = false; |
| 5216 } | 5225 } |
| 5217 } | 5226 } |
| 5218 | 5227 |
| 5219 // Cleanup and notify the browser process about completion. | 5228 // Cleanup and notify the browser process about completion. |
| 5220 file.Close(); // Need to flush file contents before sending IPC response. | 5229 file.Close(); // Need to flush file contents before sending IPC response. |
| 5221 Send(new FrameHostMsg_SerializeAsMHTMLResponse( | 5230 Send(new FrameHostMsg_SerializeAsMHTMLResponse( |
| 5222 routing_id_, params.job_id, success, | 5231 routing_id_, params.job_id, success, |
| (...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6389 // event target. Potentially a Pepper plugin will receive the event. | 6398 // event target. Potentially a Pepper plugin will receive the event. |
| 6390 // In order to tell whether a plugin gets the last mouse event and which it | 6399 // In order to tell whether a plugin gets the last mouse event and which it |
| 6391 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets | 6400 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets |
| 6392 // the event, it will notify us via DidReceiveMouseEvent() and set itself as | 6401 // the event, it will notify us via DidReceiveMouseEvent() and set itself as |
| 6393 // |pepper_last_mouse_event_target_|. | 6402 // |pepper_last_mouse_event_target_|. |
| 6394 pepper_last_mouse_event_target_ = nullptr; | 6403 pepper_last_mouse_event_target_ = nullptr; |
| 6395 #endif | 6404 #endif |
| 6396 } | 6405 } |
| 6397 | 6406 |
| 6398 } // namespace content | 6407 } // namespace content |
| OLD | NEW |