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

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

Issue 1386873003: OOPIFs: Transitioning MHTML generation from view-oriented to frame-oriented. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mhtml-generation-mgr-cleanup
Patch Set: Rebasing... Created 5 years 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 10
10 #include "base/auto_reset.h" 11 #include "base/auto_reset.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/debug/alias.h" 13 #include "base/debug/alias.h"
13 #include "base/debug/asan_invalid_access.h" 14 #include "base/debug/asan_invalid_access.h"
14 #include "base/debug/dump_without_crashing.h" 15 #include "base/debug/dump_without_crashing.h"
16 #include "base/files/file.h"
15 #include "base/i18n/char_iterator.h" 17 #include "base/i18n/char_iterator.h"
18 #include "base/logging.h"
16 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
17 #include "base/metrics/histogram.h" 20 #include "base/metrics/histogram.h"
18 #include "base/process/process.h" 21 #include "base/process/process.h"
19 #include "base/strings/string16.h" 22 #include "base/strings/string16.h"
20 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
21 #include "base/thread_task_runner_handle.h" 24 #include "base/thread_task_runner_handle.h"
22 #include "base/time/time.h" 25 #include "base/time/time.h"
23 #include "cc/base/switches.h" 26 #include "cc/base/switches.h"
24 #include "components/scheduler/renderer/renderer_scheduler.h" 27 #include "components/scheduler/renderer/renderer_scheduler.h"
25 #include "content/child/appcache/appcache_dispatcher.h" 28 #include "content/child/appcache/appcache_dispatcher.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 #include "media/base/media_log.h" 131 #include "media/base/media_log.h"
129 #include "media/base/media_switches.h" 132 #include "media/base/media_switches.h"
130 #include "media/blink/webencryptedmediaclient_impl.h" 133 #include "media/blink/webencryptedmediaclient_impl.h"
131 #include "media/blink/webmediaplayer_impl.h" 134 #include "media/blink/webmediaplayer_impl.h"
132 #include "media/renderers/gpu_video_accelerator_factories.h" 135 #include "media/renderers/gpu_video_accelerator_factories.h"
133 #include "mojo/common/url_type_converters.h" 136 #include "mojo/common/url_type_converters.h"
134 #include "net/base/data_url.h" 137 #include "net/base/data_url.h"
135 #include "net/base/net_errors.h" 138 #include "net/base/net_errors.h"
136 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 139 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
137 #include "net/http/http_util.h" 140 #include "net/http/http_util.h"
141 #include "third_party/WebKit/public/platform/WebData.h"
138 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" 142 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
139 #include "third_party/WebKit/public/platform/WebString.h" 143 #include "third_party/WebKit/public/platform/WebString.h"
140 #include "third_party/WebKit/public/platform/WebURL.h" 144 #include "third_party/WebKit/public/platform/WebURL.h"
141 #include "third_party/WebKit/public/platform/WebURLError.h" 145 #include "third_party/WebKit/public/platform/WebURLError.h"
142 #include "third_party/WebKit/public/platform/WebURLResponse.h" 146 #include "third_party/WebKit/public/platform/WebURLResponse.h"
143 #include "third_party/WebKit/public/platform/WebVector.h" 147 #include "third_party/WebKit/public/platform/WebVector.h"
144 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBClient.h" 148 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBClient.h"
145 #include "third_party/WebKit/public/web/WebColorSuggestion.h" 149 #include "third_party/WebKit/public/web/WebColorSuggestion.h"
146 #include "third_party/WebKit/public/web/WebDocument.h" 150 #include "third_party/WebKit/public/web/WebDocument.h"
147 #include "third_party/WebKit/public/web/WebFrameWidget.h" 151 #include "third_party/WebKit/public/web/WebFrameWidget.h"
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 OnSetFrameOwnerProperties) 1223 OnSetFrameOwnerProperties)
1220 IPC_MESSAGE_HANDLER(FrameMsg_AdvanceFocus, OnAdvanceFocus) 1224 IPC_MESSAGE_HANDLER(FrameMsg_AdvanceFocus, OnAdvanceFocus)
1221 IPC_MESSAGE_HANDLER(FrameMsg_SetTextTrackSettings, 1225 IPC_MESSAGE_HANDLER(FrameMsg_SetTextTrackSettings,
1222 OnTextTrackSettingsChanged) 1226 OnTextTrackSettingsChanged)
1223 IPC_MESSAGE_HANDLER(FrameMsg_PostMessageEvent, OnPostMessageEvent) 1227 IPC_MESSAGE_HANDLER(FrameMsg_PostMessageEvent, OnPostMessageEvent)
1224 IPC_MESSAGE_HANDLER(FrameMsg_FailedNavigation, OnFailedNavigation) 1228 IPC_MESSAGE_HANDLER(FrameMsg_FailedNavigation, OnFailedNavigation)
1225 IPC_MESSAGE_HANDLER(FrameMsg_GetSavableResourceLinks, 1229 IPC_MESSAGE_HANDLER(FrameMsg_GetSavableResourceLinks,
1226 OnGetSavableResourceLinks) 1230 OnGetSavableResourceLinks)
1227 IPC_MESSAGE_HANDLER(FrameMsg_GetSerializedHtmlWithLocalLinks, 1231 IPC_MESSAGE_HANDLER(FrameMsg_GetSerializedHtmlWithLocalLinks,
1228 OnGetSerializedHtmlWithLocalLinks) 1232 OnGetSerializedHtmlWithLocalLinks)
1233 IPC_MESSAGE_HANDLER(FrameMsg_SerializeAsMHTML, OnSerializeAsMHTML)
1229 #if defined(OS_ANDROID) 1234 #if defined(OS_ANDROID)
1230 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) 1235 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
1231 #elif defined(OS_MACOSX) 1236 #elif defined(OS_MACOSX)
1232 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) 1237 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1233 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) 1238 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard)
1234 #endif 1239 #endif
1235 IPC_END_MESSAGE_MAP() 1240 IPC_END_MESSAGE_MAP()
1236 1241
1237 return handled; 1242 return handled;
1238 } 1243 }
(...skipping 3408 matching lines...) Expand 10 before | Expand all | Expand 10 after
4647 weburl_to_local_path.push_back(std::make_pair( 4652 weburl_to_local_path.push_back(std::make_pair(
4648 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path))); 4653 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path)));
4649 } 4654 }
4650 4655
4651 // Serialize the frame (without recursing into subframes). 4656 // Serialize the frame (without recursing into subframes).
4652 WebPageSerializer::serialize(GetWebFrame(), 4657 WebPageSerializer::serialize(GetWebFrame(),
4653 this, // WebPageSerializerClient. 4658 this, // WebPageSerializerClient.
4654 weburl_to_local_path); 4659 weburl_to_local_path);
4655 } 4660 }
4656 4661
4662 void RenderFrameImpl::OnSerializeAsMHTML(
4663 int job_id,
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.
4669 base::File file = IPC::PlatformFileForTransitToFile(file_for_transit);
4670 const WebString mhtml_boundary = WebString::fromUTF8(std_mhtml_boundary);
4671 DCHECK(!mhtml_boundary.isEmpty());
4672 std::vector<std::pair<WebFrame*, WebString>> web_frame_to_content_id;
4673 for (const auto& it : frame_routing_id_to_content_id) {
4674 const std::string& content_id = it.second;
4675 WebFrame* web_frame = GetWebFrameFromRoutingIdForFrameOrProxy(it.first);
4676 if (!web_frame)
4677 continue;
4678
4679 web_frame_to_content_id.push_back(
4680 std::make_pair(web_frame, WebString::fromUTF8(content_id)));
4681 }
4682
4683 WebData data;
4684 bool success = true;
4685
4686 // Generate MHTML header if needed.
4687 if (IsMainFrame()) {
4688 data =
4689 WebPageSerializer::generateMHTMLHeader(mhtml_boundary, GetWebFrame());
4690 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) {
4691 success = false;
4692 }
4693 }
4694
4695 // Generate MHTML parts.
4696 if (success) {
4697 data = WebPageSerializer::generateMHTMLParts(
4698 mhtml_boundary, GetWebFrame(), false, web_frame_to_content_id);
4699 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to
4700 // the message loop to process other events.
4701 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) {
4702 success = false;
4703 }
4704 }
4705
4706 // Generate MHTML footer if needed.
4707 if (success && is_last_frame) {
4708 data = WebPageSerializer::generateMHTMLFooter(mhtml_boundary);
4709 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) {
4710 success = false;
4711 }
4712 }
4713
4714 // Cleanup and notify the browser process about completion.
4715 file.Close(); // Need to flush file contents before sending IPC response.
4716 Send(new FrameHostMsg_SerializeAsMHTMLResponse(routing_id_, job_id, success));
4717 }
4718
4657 void RenderFrameImpl::OpenURL(const GURL& url, 4719 void RenderFrameImpl::OpenURL(const GURL& url,
4658 const Referrer& referrer, 4720 const Referrer& referrer,
4659 WebNavigationPolicy policy, 4721 WebNavigationPolicy policy,
4660 bool should_replace_current_entry, 4722 bool should_replace_current_entry,
4661 bool is_history_navigation_in_new_child) { 4723 bool is_history_navigation_in_new_child) {
4662 FrameHostMsg_OpenURL_Params params; 4724 FrameHostMsg_OpenURL_Params params;
4663 params.url = url; 4725 params.url = url;
4664 params.referrer = referrer; 4726 params.referrer = referrer;
4665 params.disposition = RenderViewImpl::NavigationPolicyToDisposition(policy); 4727 params.disposition = RenderViewImpl::NavigationPolicyToDisposition(policy);
4666 4728
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
5457 media::ConvertToSwitchOutputDeviceCB(web_callbacks); 5519 media::ConvertToSwitchOutputDeviceCB(web_callbacks);
5458 scoped_refptr<media::AudioOutputDevice> device = 5520 scoped_refptr<media::AudioOutputDevice> device =
5459 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), 5521 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(),
5460 security_origin); 5522 security_origin);
5461 media::OutputDeviceStatus status = device->GetDeviceStatus(); 5523 media::OutputDeviceStatus status = device->GetDeviceStatus();
5462 device->Stop(); 5524 device->Stop();
5463 callback.Run(status); 5525 callback.Run(status);
5464 } 5526 }
5465 5527
5466 } // namespace content 5528 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698