| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 #include "media/base/media_log.h" | 132 #include "media/base/media_log.h" |
| 130 #include "media/base/media_switches.h" | 133 #include "media/base/media_switches.h" |
| 131 #include "media/blink/webencryptedmediaclient_impl.h" | 134 #include "media/blink/webencryptedmediaclient_impl.h" |
| 132 #include "media/blink/webmediaplayer_impl.h" | 135 #include "media/blink/webmediaplayer_impl.h" |
| 133 #include "media/renderers/gpu_video_accelerator_factories.h" | 136 #include "media/renderers/gpu_video_accelerator_factories.h" |
| 134 #include "mojo/common/url_type_converters.h" | 137 #include "mojo/common/url_type_converters.h" |
| 135 #include "net/base/data_url.h" | 138 #include "net/base/data_url.h" |
| 136 #include "net/base/net_errors.h" | 139 #include "net/base/net_errors.h" |
| 137 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 140 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 138 #include "net/http/http_util.h" | 141 #include "net/http/http_util.h" |
| 142 #include "third_party/WebKit/public/platform/WebData.h" |
| 139 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" | 143 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" |
| 140 #include "third_party/WebKit/public/platform/WebString.h" | 144 #include "third_party/WebKit/public/platform/WebString.h" |
| 141 #include "third_party/WebKit/public/platform/WebURL.h" | 145 #include "third_party/WebKit/public/platform/WebURL.h" |
| 142 #include "third_party/WebKit/public/platform/WebURLError.h" | 146 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 143 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 147 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 144 #include "third_party/WebKit/public/platform/WebVector.h" | 148 #include "third_party/WebKit/public/platform/WebVector.h" |
| 145 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBClient.h" | 149 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBClient.h" |
| 146 #include "third_party/WebKit/public/web/WebColorSuggestion.h" | 150 #include "third_party/WebKit/public/web/WebColorSuggestion.h" |
| 147 #include "third_party/WebKit/public/web/WebDocument.h" | 151 #include "third_party/WebKit/public/web/WebDocument.h" |
| 148 #include "third_party/WebKit/public/web/WebFrameWidget.h" | 152 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
| (...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 OnSetFrameOwnerProperties) | 1256 OnSetFrameOwnerProperties) |
| 1253 IPC_MESSAGE_HANDLER(FrameMsg_AdvanceFocus, OnAdvanceFocus) | 1257 IPC_MESSAGE_HANDLER(FrameMsg_AdvanceFocus, OnAdvanceFocus) |
| 1254 IPC_MESSAGE_HANDLER(FrameMsg_SetTextTrackSettings, | 1258 IPC_MESSAGE_HANDLER(FrameMsg_SetTextTrackSettings, |
| 1255 OnTextTrackSettingsChanged) | 1259 OnTextTrackSettingsChanged) |
| 1256 IPC_MESSAGE_HANDLER(FrameMsg_PostMessageEvent, OnPostMessageEvent) | 1260 IPC_MESSAGE_HANDLER(FrameMsg_PostMessageEvent, OnPostMessageEvent) |
| 1257 IPC_MESSAGE_HANDLER(FrameMsg_FailedNavigation, OnFailedNavigation) | 1261 IPC_MESSAGE_HANDLER(FrameMsg_FailedNavigation, OnFailedNavigation) |
| 1258 IPC_MESSAGE_HANDLER(FrameMsg_GetSavableResourceLinks, | 1262 IPC_MESSAGE_HANDLER(FrameMsg_GetSavableResourceLinks, |
| 1259 OnGetSavableResourceLinks) | 1263 OnGetSavableResourceLinks) |
| 1260 IPC_MESSAGE_HANDLER(FrameMsg_GetSerializedHtmlWithLocalLinks, | 1264 IPC_MESSAGE_HANDLER(FrameMsg_GetSerializedHtmlWithLocalLinks, |
| 1261 OnGetSerializedHtmlWithLocalLinks) | 1265 OnGetSerializedHtmlWithLocalLinks) |
| 1266 IPC_MESSAGE_HANDLER(FrameMsg_SerializeAsMHTML, OnSerializeAsMHTML) |
| 1262 #if defined(OS_ANDROID) | 1267 #if defined(OS_ANDROID) |
| 1263 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) | 1268 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
| 1264 #elif defined(OS_MACOSX) | 1269 #elif defined(OS_MACOSX) |
| 1265 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) | 1270 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| 1266 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) | 1271 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) |
| 1267 #endif | 1272 #endif |
| 1268 IPC_END_MESSAGE_MAP() | 1273 IPC_END_MESSAGE_MAP() |
| 1269 | 1274 |
| 1270 return handled; | 1275 return handled; |
| 1271 } | 1276 } |
| (...skipping 3434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4706 weburl_to_local_path.push_back(std::make_pair( | 4711 weburl_to_local_path.push_back(std::make_pair( |
| 4707 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path))); | 4712 WebURL(url), ConvertRelativePathToHtmlAttribute(local_path))); |
| 4708 } | 4713 } |
| 4709 | 4714 |
| 4710 // Serialize the frame (without recursing into subframes). | 4715 // Serialize the frame (without recursing into subframes). |
| 4711 WebPageSerializer::serialize(GetWebFrame(), | 4716 WebPageSerializer::serialize(GetWebFrame(), |
| 4712 this, // WebPageSerializerClient. | 4717 this, // WebPageSerializerClient. |
| 4713 weburl_to_local_path); | 4718 weburl_to_local_path); |
| 4714 } | 4719 } |
| 4715 | 4720 |
| 4721 void RenderFrameImpl::OnSerializeAsMHTML( |
| 4722 int job_id, |
| 4723 IPC::PlatformFileForTransit file_for_transit, |
| 4724 const std::string& std_mhtml_boundary, |
| 4725 const std::map<int, std::string>& frame_routing_id_to_content_id, |
| 4726 bool is_last_frame) { |
| 4727 // Unpack IPC payload. |
| 4728 base::File file = IPC::PlatformFileForTransitToFile(file_for_transit); |
| 4729 const WebString mhtml_boundary = WebString::fromUTF8(std_mhtml_boundary); |
| 4730 DCHECK(!mhtml_boundary.isEmpty()); |
| 4731 std::vector<std::pair<WebFrame*, WebString>> web_frame_to_content_id; |
| 4732 for (const auto& it : frame_routing_id_to_content_id) { |
| 4733 const std::string& content_id = it.second; |
| 4734 WebFrame* web_frame = GetWebFrameFromRoutingIdForFrameOrProxy(it.first); |
| 4735 if (!web_frame) |
| 4736 continue; |
| 4737 |
| 4738 web_frame_to_content_id.push_back( |
| 4739 std::make_pair(web_frame, WebString::fromUTF8(content_id))); |
| 4740 } |
| 4741 |
| 4742 WebData data; |
| 4743 bool success = true; |
| 4744 |
| 4745 // Generate MHTML header if needed. |
| 4746 if (IsMainFrame()) { |
| 4747 data = |
| 4748 WebPageSerializer::generateMHTMLHeader(mhtml_boundary, GetWebFrame()); |
| 4749 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
| 4750 success = false; |
| 4751 } |
| 4752 } |
| 4753 |
| 4754 // Generate MHTML parts. |
| 4755 if (success) { |
| 4756 data = WebPageSerializer::generateMHTMLParts( |
| 4757 mhtml_boundary, GetWebFrame(), false, web_frame_to_content_id); |
| 4758 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to |
| 4759 // the message loop to process other events. |
| 4760 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
| 4761 success = false; |
| 4762 } |
| 4763 } |
| 4764 |
| 4765 // Generate MHTML footer if needed. |
| 4766 if (success && is_last_frame) { |
| 4767 data = WebPageSerializer::generateMHTMLFooter(mhtml_boundary); |
| 4768 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
| 4769 success = false; |
| 4770 } |
| 4771 } |
| 4772 |
| 4773 // Cleanup and notify the browser process about completion. |
| 4774 file.Close(); // Need to flush file contents before sending IPC response. |
| 4775 Send(new FrameHostMsg_SerializeAsMHTMLResponse(routing_id_, job_id, success)); |
| 4776 } |
| 4777 |
| 4716 void RenderFrameImpl::OpenURL(const GURL& url, | 4778 void RenderFrameImpl::OpenURL(const GURL& url, |
| 4717 const Referrer& referrer, | 4779 const Referrer& referrer, |
| 4718 WebNavigationPolicy policy, | 4780 WebNavigationPolicy policy, |
| 4719 bool should_replace_current_entry, | 4781 bool should_replace_current_entry, |
| 4720 bool is_history_navigation_in_new_child) { | 4782 bool is_history_navigation_in_new_child) { |
| 4721 FrameHostMsg_OpenURL_Params params; | 4783 FrameHostMsg_OpenURL_Params params; |
| 4722 params.url = url; | 4784 params.url = url; |
| 4723 params.referrer = referrer; | 4785 params.referrer = referrer; |
| 4724 params.disposition = RenderViewImpl::NavigationPolicyToDisposition(policy); | 4786 params.disposition = RenderViewImpl::NavigationPolicyToDisposition(policy); |
| 4725 | 4787 |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5516 media::ConvertToSwitchOutputDeviceCB(web_callbacks); | 5578 media::ConvertToSwitchOutputDeviceCB(web_callbacks); |
| 5517 scoped_refptr<media::AudioOutputDevice> device = | 5579 scoped_refptr<media::AudioOutputDevice> device = |
| 5518 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), | 5580 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), |
| 5519 security_origin); | 5581 security_origin); |
| 5520 media::OutputDeviceStatus status = device->GetDeviceStatus(); | 5582 media::OutputDeviceStatus status = device->GetDeviceStatus(); |
| 5521 device->Stop(); | 5583 device->Stop(); |
| 5522 callback.Run(status); | 5584 callback.Run(status); |
| 5523 } | 5585 } |
| 5524 | 5586 |
| 5525 } // namespace content | 5587 } // namespace content |
| OLD | NEW |