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 | 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 #include "media/base/media_log.h" | 130 #include "media/base/media_log.h" |
128 #include "media/base/media_switches.h" | 131 #include "media/base/media_switches.h" |
129 #include "media/blink/webencryptedmediaclient_impl.h" | 132 #include "media/blink/webencryptedmediaclient_impl.h" |
130 #include "media/blink/webmediaplayer_impl.h" | 133 #include "media/blink/webmediaplayer_impl.h" |
131 #include "media/renderers/gpu_video_accelerator_factories.h" | 134 #include "media/renderers/gpu_video_accelerator_factories.h" |
132 #include "mojo/common/url_type_converters.h" | 135 #include "mojo/common/url_type_converters.h" |
133 #include "net/base/data_url.h" | 136 #include "net/base/data_url.h" |
134 #include "net/base/net_errors.h" | 137 #include "net/base/net_errors.h" |
135 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 138 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
136 #include "net/http/http_util.h" | 139 #include "net/http/http_util.h" |
140 #include "third_party/WebKit/public/platform/WebData.h" | |
137 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" | 141 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" |
138 #include "third_party/WebKit/public/platform/WebString.h" | 142 #include "third_party/WebKit/public/platform/WebString.h" |
139 #include "third_party/WebKit/public/platform/WebURL.h" | 143 #include "third_party/WebKit/public/platform/WebURL.h" |
140 #include "third_party/WebKit/public/platform/WebURLError.h" | 144 #include "third_party/WebKit/public/platform/WebURLError.h" |
141 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 145 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
142 #include "third_party/WebKit/public/platform/WebVector.h" | 146 #include "third_party/WebKit/public/platform/WebVector.h" |
143 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBClient.h" | 147 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBClient.h" |
144 #include "third_party/WebKit/public/web/WebColorSuggestion.h" | 148 #include "third_party/WebKit/public/web/WebColorSuggestion.h" |
145 #include "third_party/WebKit/public/web/WebDocument.h" | 149 #include "third_party/WebKit/public/web/WebDocument.h" |
146 #include "third_party/WebKit/public/web/WebFrameWidget.h" | 150 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1243 IPC_MESSAGE_HANDLER(FrameMsg_SetFrameOwnerProperties, | 1247 IPC_MESSAGE_HANDLER(FrameMsg_SetFrameOwnerProperties, |
1244 OnSetFrameOwnerProperties) | 1248 OnSetFrameOwnerProperties) |
1245 IPC_MESSAGE_HANDLER(FrameMsg_SetTextTrackSettings, | 1249 IPC_MESSAGE_HANDLER(FrameMsg_SetTextTrackSettings, |
1246 OnTextTrackSettingsChanged) | 1250 OnTextTrackSettingsChanged) |
1247 IPC_MESSAGE_HANDLER(FrameMsg_PostMessageEvent, OnPostMessageEvent) | 1251 IPC_MESSAGE_HANDLER(FrameMsg_PostMessageEvent, OnPostMessageEvent) |
1248 IPC_MESSAGE_HANDLER(FrameMsg_FailedNavigation, OnFailedNavigation) | 1252 IPC_MESSAGE_HANDLER(FrameMsg_FailedNavigation, OnFailedNavigation) |
1249 IPC_MESSAGE_HANDLER(FrameMsg_GetSavableResourceLinks, | 1253 IPC_MESSAGE_HANDLER(FrameMsg_GetSavableResourceLinks, |
1250 OnGetSavableResourceLinks) | 1254 OnGetSavableResourceLinks) |
1251 IPC_MESSAGE_HANDLER(FrameMsg_GetSerializedHtmlWithLocalLinks, | 1255 IPC_MESSAGE_HANDLER(FrameMsg_GetSerializedHtmlWithLocalLinks, |
1252 OnGetSerializedHtmlWithLocalLinks) | 1256 OnGetSerializedHtmlWithLocalLinks) |
1257 IPC_MESSAGE_HANDLER(FrameMsg_SerializeAsMHTML, OnSerializeAsMHTML) | |
1253 #if defined(OS_ANDROID) | 1258 #if defined(OS_ANDROID) |
1254 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) | 1259 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
1255 #elif defined(OS_MACOSX) | 1260 #elif defined(OS_MACOSX) |
1256 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) | 1261 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
1257 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) | 1262 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) |
1258 #endif | 1263 #endif |
1259 IPC_END_MESSAGE_MAP() | 1264 IPC_END_MESSAGE_MAP() |
1260 | 1265 |
1261 return handled; | 1266 return handled; |
1262 } | 1267 } |
(...skipping 3432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4695 for (size_t i = 0; i < equivalent_local_paths.size(); i++) | 4700 for (size_t i = 0; i < equivalent_local_paths.size(); i++) |
4696 webstring_paths[i] = equivalent_local_paths[i].AsUTF16Unsafe(); | 4701 webstring_paths[i] = equivalent_local_paths[i].AsUTF16Unsafe(); |
4697 | 4702 |
4698 // Serialize the frame (without recursing into subframes). | 4703 // Serialize the frame (without recursing into subframes). |
4699 WebPageSerializer::serialize(GetWebFrame(), | 4704 WebPageSerializer::serialize(GetWebFrame(), |
4700 this, // WebPageSerializerClient. | 4705 this, // WebPageSerializerClient. |
4701 weburl_links, webstring_paths, | 4706 weburl_links, webstring_paths, |
4702 local_directory_path.AsUTF16Unsafe()); | 4707 local_directory_path.AsUTF16Unsafe()); |
4703 } | 4708 } |
4704 | 4709 |
4710 void RenderFrameImpl::OnSerializeAsMHTML( | |
4711 int job_id, | |
4712 IPC::PlatformFileForTransit file_for_transit, | |
4713 const std::string& std_mhtml_boundary, | |
4714 const std::map<int, std::string>& frame_routing_id_to_content_id, | |
4715 bool is_last_frame) { | |
4716 // Unpack IPC payload. | |
4717 base::File file = IPC::PlatformFileForTransitToFile(file_for_transit); | |
4718 WebString mhtml_boundary = WebString::fromUTF8(std_mhtml_boundary); | |
4719 std::vector<std::pair<WebFrame*, WebString>> web_frame_to_content_id; | |
4720 for (const auto& it : frame_routing_id_to_content_id) { | |
4721 const std::string& content_id = it.second; | |
4722 WebFrame* web_frame = GetWebFrameFromRoutingIdForFrameOrProxy(it.first); | |
4723 if (!web_frame) | |
4724 continue; | |
4725 | |
4726 web_frame_to_content_id.push_back( | |
4727 std::make_pair(web_frame, WebString::fromUTF8(content_id))); | |
4728 } | |
4729 | |
4730 WebData data; | |
4731 bool success = true; | |
4732 | |
4733 // Generate MHTML header if needed. | |
4734 if (success && IsMainFrame()) { | |
dcheng
2015/12/08 06:22:27
Isn't success always true here?
Łukasz Anforowicz
2015/12/08 21:26:43
Yes - it is always true. I've written this way fo
| |
4735 data = | |
4736 WebPageSerializer::generateMHTMLHeader(mhtml_boundary, GetWebFrame()); | |
4737 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | |
4738 success = false; | |
4739 } | |
4740 } | |
4741 DCHECK(!mhtml_boundary.isEmpty()); | |
dcheng
2015/12/08 06:22:27
Seems like this should probably go with where it's
Łukasz Anforowicz
2015/12/08 21:26:43
Good point. Done.
| |
4742 | |
4743 // Generate MHTML parts. | |
4744 if (success) { | |
4745 data = WebPageSerializer::generateMHTMLParts( | |
4746 mhtml_boundary, GetWebFrame(), false, web_frame_to_content_id); | |
4747 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to | |
4748 // the message loop to process other events. | |
4749 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | |
4750 success = false; | |
4751 } | |
4752 } | |
4753 | |
4754 // Generate MHTML footer if needed. | |
4755 if (success && is_last_frame) { | |
4756 data = WebPageSerializer::generateMHTMLFooter(mhtml_boundary); | |
4757 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { | |
4758 success = false; | |
4759 } | |
4760 } | |
4761 | |
4762 // Cleanup and notify the browser process about completion. | |
4763 file.Close(); // Need to flush file contents before sending IPC response. | |
4764 Send(new FrameHostMsg_SerializeAsMHTMLResponse(routing_id_, job_id, success)); | |
4765 } | |
4766 | |
4705 void RenderFrameImpl::OpenURL(const GURL& url, | 4767 void RenderFrameImpl::OpenURL(const GURL& url, |
4706 const Referrer& referrer, | 4768 const Referrer& referrer, |
4707 WebNavigationPolicy policy, | 4769 WebNavigationPolicy policy, |
4708 bool should_replace_current_entry, | 4770 bool should_replace_current_entry, |
4709 bool is_history_navigation_in_new_child) { | 4771 bool is_history_navigation_in_new_child) { |
4710 FrameHostMsg_OpenURL_Params params; | 4772 FrameHostMsg_OpenURL_Params params; |
4711 params.url = url; | 4773 params.url = url; |
4712 params.referrer = referrer; | 4774 params.referrer = referrer; |
4713 params.disposition = RenderViewImpl::NavigationPolicyToDisposition(policy); | 4775 params.disposition = RenderViewImpl::NavigationPolicyToDisposition(policy); |
4714 | 4776 |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5492 media::ConvertToSwitchOutputDeviceCB(web_callbacks); | 5554 media::ConvertToSwitchOutputDeviceCB(web_callbacks); |
5493 scoped_refptr<media::AudioOutputDevice> device = | 5555 scoped_refptr<media::AudioOutputDevice> device = |
5494 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), | 5556 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), |
5495 security_origin); | 5557 security_origin); |
5496 media::OutputDeviceStatus status = device->GetDeviceStatus(); | 5558 media::OutputDeviceStatus status = device->GetDeviceStatus(); |
5497 device->Stop(); | 5559 device->Stop(); |
5498 callback.Run(status); | 5560 callback.Run(status); |
5499 } | 5561 } |
5500 | 5562 |
5501 } // namespace content | 5563 } // namespace content |
OLD | NEW |