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

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

Issue 2050623005: Move file chooser from RenderView(Host) to RenderFrame(Host). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some cleanup. Created 4 years, 6 months 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 <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 #include "content/common/site_isolation_policy.h" 62 #include "content/common/site_isolation_policy.h"
63 #include "content/common/ssl_status_serialization.h" 63 #include "content/common/ssl_status_serialization.h"
64 #include "content/common/swapped_out_messages.h" 64 #include "content/common/swapped_out_messages.h"
65 #include "content/common/view_messages.h" 65 #include "content/common/view_messages.h"
66 #include "content/public/common/bindings_policy.h" 66 #include "content/public/common/bindings_policy.h"
67 #include "content/public/common/browser_side_navigation_policy.h" 67 #include "content/public/common/browser_side_navigation_policy.h"
68 #include "content/public/common/content_constants.h" 68 #include "content/public/common/content_constants.h"
69 #include "content/public/common/content_features.h" 69 #include "content/public/common/content_features.h"
70 #include "content/public/common/content_switches.h" 70 #include "content/public/common/content_switches.h"
71 #include "content/public/common/context_menu_params.h" 71 #include "content/public/common/context_menu_params.h"
72 #include "content/public/common/file_chooser_file_info.h"
73 #include "content/public/common/file_chooser_params.h"
72 #include "content/public/common/isolated_world_ids.h" 74 #include "content/public/common/isolated_world_ids.h"
73 #include "content/public/common/page_state.h" 75 #include "content/public/common/page_state.h"
74 #include "content/public/common/resource_response.h" 76 #include "content/public/common/resource_response.h"
75 #include "content/public/common/url_constants.h" 77 #include "content/public/common/url_constants.h"
76 #include "content/public/common/url_utils.h" 78 #include "content/public/common/url_utils.h"
77 #include "content/public/renderer/browser_plugin_delegate.h" 79 #include "content/public/renderer/browser_plugin_delegate.h"
78 #include "content/public/renderer/content_renderer_client.h" 80 #include "content/public/renderer/content_renderer_client.h"
79 #include "content/public/renderer/context_menu_client.h" 81 #include "content/public/renderer/context_menu_client.h"
80 #include "content/public/renderer/document_state.h" 82 #include "content/public/renderer/document_state.h"
81 #include "content/public/renderer/navigation_state.h" 83 #include "content/public/renderer/navigation_state.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 #include "media/blink/webmediaplayer_impl.h" 146 #include "media/blink/webmediaplayer_impl.h"
145 #include "media/renderers/gpu_video_accelerator_factories.h" 147 #include "media/renderers/gpu_video_accelerator_factories.h"
146 #include "mojo/common/url_type_converters.h" 148 #include "mojo/common/url_type_converters.h"
147 #include "mojo/edk/js/core.h" 149 #include "mojo/edk/js/core.h"
148 #include "mojo/edk/js/support.h" 150 #include "mojo/edk/js/support.h"
149 #include "net/base/data_url.h" 151 #include "net/base/data_url.h"
150 #include "net/base/net_errors.h" 152 #include "net/base/net_errors.h"
151 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 153 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
152 #include "net/http/http_util.h" 154 #include "net/http/http_util.h"
153 #include "storage/common/data_element.h" 155 #include "storage/common/data_element.h"
156 #include "third_party/WebKit/public/platform/FilePathConversion.h"
154 #include "third_party/WebKit/public/platform/URLConversion.h" 157 #include "third_party/WebKit/public/platform/URLConversion.h"
155 #include "third_party/WebKit/public/platform/WebCachePolicy.h" 158 #include "third_party/WebKit/public/platform/WebCachePolicy.h"
156 #include "third_party/WebKit/public/platform/WebData.h" 159 #include "third_party/WebKit/public/platform/WebData.h"
157 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" 160 #include "third_party/WebKit/public/platform/WebMediaPlayer.h"
158 #include "third_party/WebKit/public/platform/WebMediaPlayerSource.h" 161 #include "third_party/WebKit/public/platform/WebMediaPlayerSource.h"
159 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 162 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
160 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" 163 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
161 #include "third_party/WebKit/public/platform/WebString.h" 164 #include "third_party/WebKit/public/platform/WebString.h"
162 #include "third_party/WebKit/public/platform/WebURL.h" 165 #include "third_party/WebKit/public/platform/WebURL.h"
163 #include "third_party/WebKit/public/platform/WebURLError.h" 166 #include "third_party/WebKit/public/platform/WebURLError.h"
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 #if defined(OS_ANDROID) 847 #if defined(OS_ANDROID)
845 return media::IsUnifiedMediaPipelineEnabled(); 848 return media::IsUnifiedMediaPipelineEnabled();
846 #else 849 #else
847 return true; 850 return true;
848 #endif 851 #endif
849 } 852 }
850 #endif // defined(ENABLE_MOJO_CDM) 853 #endif // defined(ENABLE_MOJO_CDM)
851 854
852 } // namespace 855 } // namespace
853 856
857 struct RenderFrameImpl::PendingFileChooser {
858 PendingFileChooser(const FileChooserParams& p,
859 blink::WebFileChooserCompletion* c)
860 : params(p), completion(c) {}
861 FileChooserParams params;
862 blink::WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
863 };
864
854 // static 865 // static
855 RenderFrameImpl* RenderFrameImpl::Create(RenderViewImpl* render_view, 866 RenderFrameImpl* RenderFrameImpl::Create(RenderViewImpl* render_view,
856 int32_t routing_id) { 867 int32_t routing_id) {
857 DCHECK(routing_id != MSG_ROUTING_NONE); 868 DCHECK(routing_id != MSG_ROUTING_NONE);
858 CreateParams params(render_view, routing_id); 869 CreateParams params(render_view, routing_id);
859 870
860 if (g_create_render_frame_impl) 871 if (g_create_render_frame_impl)
861 return g_create_render_frame_impl(params); 872 return g_create_render_frame_impl(params);
862 else 873 else
863 return new RenderFrameImpl(params); 874 return new RenderFrameImpl(params);
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 1118
1108 #if defined(ENABLE_PLUGINS) 1119 #if defined(ENABLE_PLUGINS)
1109 // Manages its own lifetime. 1120 // Manages its own lifetime.
1110 plugin_power_saver_helper_ = new PluginPowerSaverHelper(this); 1121 plugin_power_saver_helper_ = new PluginPowerSaverHelper(this);
1111 #endif 1122 #endif
1112 1123
1113 manifest_manager_ = new ManifestManager(this); 1124 manifest_manager_ = new ManifestManager(this);
1114 } 1125 }
1115 1126
1116 RenderFrameImpl::~RenderFrameImpl() { 1127 RenderFrameImpl::~RenderFrameImpl() {
1128 // If file chooser is still waiting for answer, dispatch empty answer.
1129 while (!file_chooser_completions_.empty()) {
1130 if (file_chooser_completions_.front()->completion) {
1131 file_chooser_completions_.front()->completion->didChooseFile(
1132 WebVector<WebString>());
1133 }
1134 file_chooser_completions_.pop_front();
1135 }
1136
1117 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, RenderFrameGone()); 1137 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, RenderFrameGone());
1118 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, OnDestruct()); 1138 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, OnDestruct());
1119 1139
1120 base::trace_event::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_); 1140 base::trace_event::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_);
1121 1141
1122 #if defined(VIDEO_HOLE) 1142 #if defined(VIDEO_HOLE)
1123 if (contains_media_player_) 1143 if (contains_media_player_)
1124 render_view_->UnregisterVideoHoleFrame(this); 1144 render_view_->UnregisterVideoHoleFrame(this);
1125 #endif 1145 #endif
1126 1146
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 OnGetSavableResourceLinks) 1518 OnGetSavableResourceLinks)
1499 IPC_MESSAGE_HANDLER(FrameMsg_GetSerializedHtmlWithLocalLinks, 1519 IPC_MESSAGE_HANDLER(FrameMsg_GetSerializedHtmlWithLocalLinks,
1500 OnGetSerializedHtmlWithLocalLinks) 1520 OnGetSerializedHtmlWithLocalLinks)
1501 IPC_MESSAGE_HANDLER(FrameMsg_SerializeAsMHTML, OnSerializeAsMHTML) 1521 IPC_MESSAGE_HANDLER(FrameMsg_SerializeAsMHTML, OnSerializeAsMHTML)
1502 IPC_MESSAGE_HANDLER(FrameMsg_Find, OnFind) 1522 IPC_MESSAGE_HANDLER(FrameMsg_Find, OnFind)
1503 IPC_MESSAGE_HANDLER(FrameMsg_ClearActiveFindMatch, OnClearActiveFindMatch) 1523 IPC_MESSAGE_HANDLER(FrameMsg_ClearActiveFindMatch, OnClearActiveFindMatch)
1504 IPC_MESSAGE_HANDLER(FrameMsg_StopFinding, OnStopFinding) 1524 IPC_MESSAGE_HANDLER(FrameMsg_StopFinding, OnStopFinding)
1505 IPC_MESSAGE_HANDLER(FrameMsg_EnableViewSourceMode, OnEnableViewSourceMode) 1525 IPC_MESSAGE_HANDLER(FrameMsg_EnableViewSourceMode, OnEnableViewSourceMode)
1506 IPC_MESSAGE_HANDLER(FrameMsg_SuppressFurtherDialogs, 1526 IPC_MESSAGE_HANDLER(FrameMsg_SuppressFurtherDialogs,
1507 OnSuppressFurtherDialogs) 1527 OnSuppressFurtherDialogs)
1528 IPC_MESSAGE_HANDLER(FrameMsg_RunFileChooserResponse, OnFileChooserResponse)
1508 #if defined(OS_ANDROID) 1529 #if defined(OS_ANDROID)
1509 IPC_MESSAGE_HANDLER(FrameMsg_ActivateNearestFindResult, 1530 IPC_MESSAGE_HANDLER(FrameMsg_ActivateNearestFindResult,
1510 OnActivateNearestFindResult) 1531 OnActivateNearestFindResult)
1511 IPC_MESSAGE_HANDLER(FrameMsg_GetNearestFindResult, 1532 IPC_MESSAGE_HANDLER(FrameMsg_GetNearestFindResult,
1512 OnGetNearestFindResult) 1533 OnGetNearestFindResult)
1513 IPC_MESSAGE_HANDLER(FrameMsg_FindMatchRects, OnFindMatchRects) 1534 IPC_MESSAGE_HANDLER(FrameMsg_FindMatchRects, OnFindMatchRects)
1514 #endif 1535 #endif
1515 1536
1516 #if defined(USE_EXTERNAL_POPUP_MENU) 1537 #if defined(USE_EXTERNAL_POPUP_MENU)
1517 #if defined(OS_MACOSX) 1538 #if defined(OS_MACOSX)
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
2211 bool success = false; 2232 bool success = false;
2212 base::string16 result_temp; 2233 base::string16 result_temp;
2213 if (!result) 2234 if (!result)
2214 result = &result_temp; 2235 result = &result_temp;
2215 2236
2216 Send(new FrameHostMsg_RunJavaScriptMessage( 2237 Send(new FrameHostMsg_RunJavaScriptMessage(
2217 routing_id_, message, default_value, frame_url, type, &success, result)); 2238 routing_id_, message, default_value, frame_url, type, &success, result));
2218 return success; 2239 return success;
2219 } 2240 }
2220 2241
2242 bool RenderFrameImpl::ScheduleFileChooser(
2243 const FileChooserParams& params,
2244 blink::WebFileChooserCompletion* completion) {
2245 static const size_t kMaximumPendingFileChooseRequests = 4;
2246 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
2247 // This sanity check prevents too many file choose requests from getting
2248 // queued which could DoS the user. Getting these is most likely a
2249 // programming error (there are many ways to DoS the user so it's not
2250 // considered a "real" security check), either in JS requesting many file
2251 // choosers to pop up, or in a plugin.
2252 //
2253 // TODO(brettw) we might possibly want to require a user gesture to open
Avi (use Gerrit) 2016/06/10 21:52:54 TODO(brettw): We ...
nasko 2016/06/10 22:07:50 Done.
2254 // a file picker, which will address this issue in a better way.
2255 return false;
2256 }
2257
2258 file_chooser_completions_.push_back(
2259 base::WrapUnique(new PendingFileChooser(params, completion)));
2260 if (file_chooser_completions_.size() == 1) {
2261 // Actually show the browse dialog when this is the first request.
2262 Send(new FrameHostMsg_RunFileChooser(routing_id_, params));
2263 }
2264 return true;
2265 }
2266
2221 void RenderFrameImpl::LoadNavigationErrorPage( 2267 void RenderFrameImpl::LoadNavigationErrorPage(
2222 const WebURLRequest& failed_request, 2268 const WebURLRequest& failed_request,
2223 const WebURLError& error, 2269 const WebURLError& error,
2224 bool replace) { 2270 bool replace) {
2225 std::string error_html; 2271 std::string error_html;
2226 GetContentClient()->renderer()->GetNavigationErrorStrings( 2272 GetContentClient()->renderer()->GetNavigationErrorStrings(
2227 this, failed_request, error, &error_html, nullptr); 2273 this, failed_request, error, &error_html, nullptr);
2228 2274
2229 frame_->loadHTMLString(error_html, 2275 frame_->loadHTMLString(error_html,
2230 GURL(kUnreachableWebDataURL), 2276 GURL(kUnreachableWebDataURL),
(...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after
3737 bool success = false; 3783 bool success = false;
3738 // This is an ignored return value, but is included so we can accept the same 3784 // This is an ignored return value, but is included so we can accept the same
3739 // response as RunJavaScriptMessage. 3785 // response as RunJavaScriptMessage.
3740 base::string16 ignored_result; 3786 base::string16 ignored_result;
3741 Send(new FrameHostMsg_RunBeforeUnloadConfirm( 3787 Send(new FrameHostMsg_RunBeforeUnloadConfirm(
3742 routing_id_, frame_->document().url(), is_reload, &success, 3788 routing_id_, frame_->document().url(), is_reload, &success,
3743 &ignored_result)); 3789 &ignored_result));
3744 return success; 3790 return success;
3745 } 3791 }
3746 3792
3793 bool RenderFrameImpl::runFileChooser(
3794 const blink::WebFileChooserParams& params,
3795 blink::WebFileChooserCompletion* chooser_completion) {
3796 // Do not open the file dialog in a hidden RenderView.
3797 if (render_view_->is_hidden())
3798 return false;
3799
3800 FileChooserParams ipc_params;
3801 if (params.directory)
3802 ipc_params.mode = FileChooserParams::UploadFolder;
3803 else if (params.multiSelect)
3804 ipc_params.mode = FileChooserParams::OpenMultiple;
3805 else if (params.saveAs)
3806 ipc_params.mode = FileChooserParams::Save;
3807 else
3808 ipc_params.mode = FileChooserParams::Open;
3809 ipc_params.title = params.title;
3810 ipc_params.default_file_name =
3811 blink::WebStringToFilePath(params.initialValue).BaseName();
3812 ipc_params.accept_types.reserve(params.acceptTypes.size());
3813 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
Avi (use Gerrit) 2016/06/10 21:52:54 for ( : )
nasko 2016/06/10 22:07:50 Done.
3814 ipc_params.accept_types.push_back(params.acceptTypes[i]);
3815 ipc_params.need_local_path = params.needLocalPath;
3816 #if defined(OS_ANDROID)
3817 ipc_params.capture = params.useMediaCapture;
3818 #endif
3819 ipc_params.requestor = params.requestor;
3820
3821 return ScheduleFileChooser(ipc_params, chooser_completion);
3822 }
3823
3747 void RenderFrameImpl::showContextMenu(const blink::WebContextMenuData& data) { 3824 void RenderFrameImpl::showContextMenu(const blink::WebContextMenuData& data) {
3748 ContextMenuParams params = ContextMenuParamsBuilder::Build(data); 3825 ContextMenuParams params = ContextMenuParamsBuilder::Build(data);
3749 blink::WebRect position_in_window(params.x, params.y, 0, 0); 3826 blink::WebRect position_in_window(params.x, params.y, 0, 0);
3750 GetRenderWidget()->convertViewportToWindow(&position_in_window); 3827 GetRenderWidget()->convertViewportToWindow(&position_in_window);
3751 params.x = position_in_window.x; 3828 params.x = position_in_window.x;
3752 params.y = position_in_window.y; 3829 params.y = position_in_window.y;
3753 params.source_type = 3830 params.source_type =
3754 GetRenderWidget()->input_handler().context_menu_source_type(); 3831 GetRenderWidget()->input_handler().context_menu_source_type();
3755 GetRenderWidget()->OnShowHostContextMenu(&params); 3832 GetRenderWidget()->OnShowHostContextMenu(&params);
3756 if (GetRenderWidget()->has_host_context_menu_location()) { 3833 if (GetRenderWidget()->has_host_context_menu_location()) {
(...skipping 1365 matching lines...) Expand 10 before | Expand all | Expand 10 after
5122 void RenderFrameImpl::OnEnableViewSourceMode() { 5199 void RenderFrameImpl::OnEnableViewSourceMode() {
5123 DCHECK(frame_); 5200 DCHECK(frame_);
5124 DCHECK(!frame_->parent()); 5201 DCHECK(!frame_->parent());
5125 frame_->enableViewSourceMode(true); 5202 frame_->enableViewSourceMode(true);
5126 } 5203 }
5127 5204
5128 void RenderFrameImpl::OnSuppressFurtherDialogs() { 5205 void RenderFrameImpl::OnSuppressFurtherDialogs() {
5129 suppress_further_dialogs_ = true; 5206 suppress_further_dialogs_ = true;
5130 } 5207 }
5131 5208
5209 void RenderFrameImpl::OnFileChooserResponse(
5210 const std::vector<content::FileChooserFileInfo>& files) {
5211 // This could happen if we navigated to a different page before the user
5212 // closed the chooser.
5213 if (file_chooser_completions_.empty())
5214 return;
5215
5216 // Convert Chrome's SelectedFileInfo list to WebKit's.
5217 WebVector<blink::WebFileChooserCompletion::SelectedFileInfo> selected_files(
5218 files.size());
5219 for (size_t i = 0; i < files.size(); ++i) {
Avi (use Gerrit) 2016/06/10 21:52:54 for ( : )
nasko 2016/06/10 22:07:49 This one uses i for the WebVector access, so I kep
5220 blink::WebFileChooserCompletion::SelectedFileInfo selected_file;
5221 selected_file.path = files[i].file_path.AsUTF16Unsafe();
5222 selected_file.displayName =
5223 base::FilePath(files[i].display_name).AsUTF16Unsafe();
5224 if (files[i].file_system_url.is_valid()) {
5225 selected_file.fileSystemURL = files[i].file_system_url;
5226 selected_file.length = files[i].length;
5227 selected_file.modificationTime = files[i].modification_time.ToDoubleT();
5228 selected_file.isDirectory = files[i].is_directory;
5229 }
5230 selected_files[i] = selected_file;
5231 }
5232
5233 if (file_chooser_completions_.front()->completion) {
5234 file_chooser_completions_.front()->completion->didChooseFile(
5235 selected_files);
5236 }
5237 file_chooser_completions_.pop_front();
5238
5239 // If there are more pending file chooser requests, schedule one now.
5240 if (!file_chooser_completions_.empty()) {
5241 Send(new FrameHostMsg_RunFileChooser(
5242 routing_id_, file_chooser_completions_.front()->params));
5243 }
5244 }
5245
5132 #if defined(OS_ANDROID) 5246 #if defined(OS_ANDROID)
5133 void RenderFrameImpl::OnActivateNearestFindResult(int request_id, 5247 void RenderFrameImpl::OnActivateNearestFindResult(int request_id,
5134 float x, 5248 float x,
5135 float y) { 5249 float y) {
5136 WebRect selection_rect; 5250 WebRect selection_rect;
5137 int ordinal = 5251 int ordinal =
5138 frame_->selectNearestFindMatch(WebFloatPoint(x, y), &selection_rect); 5252 frame_->selectNearestFindMatch(WebFloatPoint(x, y), &selection_rect);
5139 if (ordinal == -1) { 5253 if (ordinal == -1) {
5140 // Something went wrong, so send a no-op reply (force the frame to report 5254 // Something went wrong, so send a no-op reply (force the frame to report
5141 // the current match count) in case the host is waiting for a response due 5255 // the current match count) in case the host is waiting for a response due
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
6104 // event target. Potentially a Pepper plugin will receive the event. 6218 // event target. Potentially a Pepper plugin will receive the event.
6105 // In order to tell whether a plugin gets the last mouse event and which it 6219 // In order to tell whether a plugin gets the last mouse event and which it
6106 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6220 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6107 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6221 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6108 // |pepper_last_mouse_event_target_|. 6222 // |pepper_last_mouse_event_target_|.
6109 pepper_last_mouse_event_target_ = nullptr; 6223 pepper_last_mouse_event_target_ = nullptr;
6110 #endif 6224 #endif
6111 } 6225 }
6112 6226
6113 } // namespace content 6227 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698