| 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 5173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5184 | 5184 |
| 5185 // Serialize the frame (without recursing into subframes). | 5185 // Serialize the frame (without recursing into subframes). |
| 5186 WebFrameSerializer::serialize(GetWebFrame(), | 5186 WebFrameSerializer::serialize(GetWebFrame(), |
| 5187 this, // WebFrameSerializerClient. | 5187 this, // WebFrameSerializerClient. |
| 5188 &delegate); | 5188 &delegate); |
| 5189 } | 5189 } |
| 5190 | 5190 |
| 5191 void RenderFrameImpl::OnSerializeAsMHTML( | 5191 void RenderFrameImpl::OnSerializeAsMHTML( |
| 5192 const FrameMsg_SerializeAsMHTML_Params& params) { | 5192 const FrameMsg_SerializeAsMHTML_Params& params) { |
| 5193 TRACE_EVENT0("page-serialization", "RenderFrameImpl::OnSerializeAsMHTML"); | 5193 TRACE_EVENT0("page-serialization", "RenderFrameImpl::OnSerializeAsMHTML"); |
| 5194 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 5194 // Unpack IPC payload. | 5195 // Unpack IPC payload. |
| 5195 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); | 5196 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); |
| 5196 const WebString mhtml_boundary = | 5197 const WebString mhtml_boundary = |
| 5197 WebString::fromUTF8(params.mhtml_boundary_marker); | 5198 WebString::fromUTF8(params.mhtml_boundary_marker); |
| 5198 DCHECK(!mhtml_boundary.isEmpty()); | 5199 DCHECK(!mhtml_boundary.isEmpty()); |
| 5199 | 5200 |
| 5200 WebData data; | 5201 // Three WebData instances for header, parts and footer. |
| 5202 WebData mhtml_contents[3]; |
| 5201 std::set<std::string> digests_of_uris_of_serialized_resources; | 5203 std::set<std::string> digests_of_uris_of_serialized_resources; |
| 5202 MHTMLPartsGenerationDelegate delegate( | 5204 MHTMLPartsGenerationDelegate delegate( |
| 5203 params, &digests_of_uris_of_serialized_resources); | 5205 params, &digests_of_uris_of_serialized_resources); |
| 5204 | 5206 |
| 5205 bool success = true; | 5207 bool success = true; |
| 5206 | 5208 |
| 5207 // Generate MHTML header if needed. | 5209 // Generate MHTML header if needed. |
| 5208 if (IsMainFrame()) { | 5210 if (IsMainFrame()) { |
| 5209 TRACE_EVENT0("page-serialization", | 5211 TRACE_EVENT0("page-serialization", |
| 5210 "RenderFrameImpl::OnSerializeAsMHTML header"); | 5212 "RenderFrameImpl::OnSerializeAsMHTML header"); |
| 5211 // |data| can be empty if the main frame should be skipped. If the main | 5213 // |data| can be empty if the main frame should be skipped. If the main |
| 5212 // frame is skipped, then the whole archive is bad, so bail to the error | 5214 // frame is skipped, then the whole archive is bad, so bail to the error |
| 5213 // condition. | 5215 // condition. |
| 5214 WebData data = WebFrameSerializer::generateMHTMLHeader( | 5216 mhtml_contents[0] = WebFrameSerializer::generateMHTMLHeader( |
| 5215 mhtml_boundary, GetWebFrame(), &delegate); | 5217 mhtml_boundary, GetWebFrame(), &delegate); |
| 5216 if (data.isEmpty() || | 5218 success = !mhtml_contents[0].isEmpty(); |
| 5217 file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | |
| 5218 success = false; | |
| 5219 } | |
| 5220 } | 5219 } |
| 5221 | 5220 |
| 5222 // Generate MHTML parts. Note that if this is not the main frame, then even | 5221 // Generate MHTML parts. Note that if this is not the main frame, then even |
| 5223 // skipping the whole parts generation step is not an error - it simply | 5222 // skipping the whole parts generation step is not an error - it simply |
| 5224 // results in an omitted resource in the final file. | 5223 // results in an omitted resource in the final file. |
| 5225 if (success) { | 5224 if (success) { |
| 5226 TRACE_EVENT0("page-serialization", | 5225 TRACE_EVENT0("page-serialization", |
| 5227 "RenderFrameImpl::OnSerializeAsMHTML parts serialization"); | 5226 "RenderFrameImpl::OnSerializeAsMHTML parts serialization"); |
| 5228 // |data| can be empty if the frame should be skipped, but this is OK. | 5227 // |data| can be empty if the frame should be skipped, but this is OK. |
| 5229 data = WebFrameSerializer::generateMHTMLParts(mhtml_boundary, GetWebFrame(), | 5228 mhtml_contents[1] = WebFrameSerializer::generateMHTMLParts( |
| 5230 &delegate); | 5229 mhtml_boundary, GetWebFrame(), &delegate); |
| 5231 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to | |
| 5232 // the message loop to process other events. | |
| 5233 TRACE_EVENT0("page-serialization", | |
| 5234 "RenderFrameImpl::OnSerializeAsMHTML parts file writing"); | |
| 5235 if (!data.isEmpty() && | |
| 5236 file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | |
| 5237 success = false; | |
| 5238 } | |
| 5239 } | 5230 } |
| 5240 | 5231 |
| 5241 // Generate MHTML footer if needed. | 5232 // Generate MHTML footer if needed. |
| 5242 if (success && params.is_last_frame) { | 5233 if (success && params.is_last_frame) { |
| 5243 TRACE_EVENT0("page-serialization", | 5234 TRACE_EVENT0("page-serialization", |
| 5244 "RenderFrameImpl::OnSerializeAsMHTML footer"); | 5235 "RenderFrameImpl::OnSerializeAsMHTML footer"); |
| 5245 data = WebFrameSerializer::generateMHTMLFooter(mhtml_boundary); | 5236 mhtml_contents[2] = WebFrameSerializer::generateMHTMLFooter(mhtml_boundary); |
| 5246 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | 5237 } |
| 5247 success = false; | 5238 |
| 5239 // Writes all serialized data to file. |
| 5240 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to |
| 5241 // the message loop to process other events. |
| 5242 if (success) { |
| 5243 TRACE_EVENT0("page-serialization", |
| 5244 "RenderFrameImpl::OnSerializeAsMHTML writing to file"); |
| 5245 SCOPED_UMA_HISTOGRAM_TIMER( |
| 5246 "PageSerialization.MhtmlGeneration.WriteToDiskTime.SingleFrame"); |
| 5247 for (const WebData& data : mhtml_contents) { |
| 5248 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
| 5249 success = false; |
| 5250 break; |
| 5251 } |
| 5248 } | 5252 } |
| 5249 } | 5253 } |
| 5250 | 5254 |
| 5251 // Cleanup and notify the browser process about completion. | 5255 // Cleanup and notify the browser process about completion. |
| 5252 file.Close(); // Need to flush file contents before sending IPC response. | 5256 file.Close(); // Need to flush file contents before sending IPC response. |
| 5257 base::TimeDelta main_thread_use_time = base::TimeTicks::Now() - start_time; |
| 5253 Send(new FrameHostMsg_SerializeAsMHTMLResponse( | 5258 Send(new FrameHostMsg_SerializeAsMHTMLResponse( |
| 5254 routing_id_, params.job_id, success, | 5259 routing_id_, params.job_id, success, |
| 5255 digests_of_uris_of_serialized_resources)); | 5260 digests_of_uris_of_serialized_resources, main_thread_use_time)); |
| 5261 UMA_HISTOGRAM_TIMES( |
| 5262 "PageSerialization.MhtmlGeneration.RendererMainThreadTime.SingleFrame", |
| 5263 main_thread_use_time); |
| 5256 } | 5264 } |
| 5257 | 5265 |
| 5258 void RenderFrameImpl::OnFind(int request_id, | 5266 void RenderFrameImpl::OnFind(int request_id, |
| 5259 const base::string16& search_text, | 5267 const base::string16& search_text, |
| 5260 const WebFindOptions& options) { | 5268 const WebFindOptions& options) { |
| 5261 DCHECK(!search_text.empty()); | 5269 DCHECK(!search_text.empty()); |
| 5262 | 5270 |
| 5263 blink::WebPlugin* plugin = GetWebPluginForFind(); | 5271 blink::WebPlugin* plugin = GetWebPluginForFind(); |
| 5264 // Check if the plugin still exists in the document. | 5272 // Check if the plugin still exists in the document. |
| 5265 if (plugin) { | 5273 if (plugin) { |
| (...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6431 // event target. Potentially a Pepper plugin will receive the event. | 6439 // event target. Potentially a Pepper plugin will receive the event. |
| 6432 // In order to tell whether a plugin gets the last mouse event and which it | 6440 // In order to tell whether a plugin gets the last mouse event and which it |
| 6433 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets | 6441 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets |
| 6434 // the event, it will notify us via DidReceiveMouseEvent() and set itself as | 6442 // the event, it will notify us via DidReceiveMouseEvent() and set itself as |
| 6435 // |pepper_last_mouse_event_target_|. | 6443 // |pepper_last_mouse_event_target_|. |
| 6436 pepper_last_mouse_event_target_ = nullptr; | 6444 pepper_last_mouse_event_target_ = nullptr; |
| 6437 #endif | 6445 #endif |
| 6438 } | 6446 } |
| 6439 | 6447 |
| 6440 } // namespace content | 6448 } // namespace content |
| OLD | NEW |