OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_view_impl.h" | 5 #include "content/renderer/render_view_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #include "content/common/page_messages.h" | 54 #include "content/common/page_messages.h" |
55 #include "content/common/site_isolation_policy.h" | 55 #include "content/common/site_isolation_policy.h" |
56 #include "content/common/ssl_status_serialization.h" | 56 #include "content/common/ssl_status_serialization.h" |
57 #include "content/common/view_messages.h" | 57 #include "content/common/view_messages.h" |
58 #include "content/public/common/bindings_policy.h" | 58 #include "content/public/common/bindings_policy.h" |
59 #include "content/public/common/content_client.h" | 59 #include "content/public/common/content_client.h" |
60 #include "content/public/common/content_constants.h" | 60 #include "content/public/common/content_constants.h" |
61 #include "content/public/common/content_switches.h" | 61 #include "content/public/common/content_switches.h" |
62 #include "content/public/common/drop_data.h" | 62 #include "content/public/common/drop_data.h" |
63 #include "content/public/common/favicon_url.h" | 63 #include "content/public/common/favicon_url.h" |
64 #include "content/public/common/file_chooser_file_info.h" | |
65 #include "content/public/common/file_chooser_params.h" | |
66 #include "content/public/common/page_importance_signals.h" | 64 #include "content/public/common/page_importance_signals.h" |
67 #include "content/public/common/page_state.h" | 65 #include "content/public/common/page_state.h" |
68 #include "content/public/common/page_zoom.h" | 66 #include "content/public/common/page_zoom.h" |
69 #include "content/public/common/ssl_status.h" | 67 #include "content/public/common/ssl_status.h" |
70 #include "content/public/common/three_d_api_types.h" | 68 #include "content/public/common/three_d_api_types.h" |
71 #include "content/public/common/url_constants.h" | 69 #include "content/public/common/url_constants.h" |
72 #include "content/public/common/web_preferences.h" | 70 #include "content/public/common/web_preferences.h" |
73 #include "content/public/renderer/content_renderer_client.h" | 71 #include "content/public/renderer/content_renderer_client.h" |
74 #include "content/public/renderer/document_state.h" | 72 #include "content/public/renderer/document_state.h" |
75 #include "content/public/renderer/navigation_state.h" | 73 #include "content/public/renderer/navigation_state.h" |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 const blink::WebVector<blink::WebSize>& web_sizes, | 383 const blink::WebVector<blink::WebSize>& web_sizes, |
386 std::vector<gfx::Size>* sizes) { | 384 std::vector<gfx::Size>* sizes) { |
387 DCHECK(sizes->empty()); | 385 DCHECK(sizes->empty()); |
388 sizes->reserve(web_sizes.size()); | 386 sizes->reserve(web_sizes.size()); |
389 for (size_t i = 0; i < web_sizes.size(); ++i) | 387 for (size_t i = 0; i < web_sizes.size(); ++i) |
390 sizes->push_back(gfx::Size(web_sizes[i])); | 388 sizes->push_back(gfx::Size(web_sizes[i])); |
391 } | 389 } |
392 | 390 |
393 /////////////////////////////////////////////////////////////////////////////// | 391 /////////////////////////////////////////////////////////////////////////////// |
394 | 392 |
395 struct RenderViewImpl::PendingFileChooser { | |
396 PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c) | |
397 : params(p), | |
398 completion(c) { | |
399 } | |
400 FileChooserParams params; | |
401 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. | |
402 }; | |
403 | |
404 namespace { | 393 namespace { |
405 | 394 |
406 WebDragData DropDataToWebDragData(const DropData& drop_data) { | 395 WebDragData DropDataToWebDragData(const DropData& drop_data) { |
407 std::vector<WebDragData::Item> item_list; | 396 std::vector<WebDragData::Item> item_list; |
408 | 397 |
409 // These fields are currently unused when dragging into WebKit. | 398 // These fields are currently unused when dragging into WebKit. |
410 DCHECK(drop_data.download_metadata.empty()); | 399 DCHECK(drop_data.download_metadata.empty()); |
411 DCHECK(drop_data.file_contents.empty()); | 400 DCHECK(drop_data.file_contents.empty()); |
412 DCHECK(drop_data.file_description_filename.empty()); | 401 DCHECK(drop_data.file_description_filename.empty()); |
413 | 402 |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 } | 791 } |
803 | 792 |
804 RenderViewImpl::~RenderViewImpl() { | 793 RenderViewImpl::~RenderViewImpl() { |
805 DCHECK(!frame_widget_); | 794 DCHECK(!frame_widget_); |
806 | 795 |
807 for (BitmapMap::iterator it = disambiguation_bitmaps_.begin(); | 796 for (BitmapMap::iterator it = disambiguation_bitmaps_.begin(); |
808 it != disambiguation_bitmaps_.end(); | 797 it != disambiguation_bitmaps_.end(); |
809 ++it) | 798 ++it) |
810 delete it->second; | 799 delete it->second; |
811 | 800 |
812 // If file chooser is still waiting for answer, dispatch empty answer. | |
813 while (!file_chooser_completions_.empty()) { | |
814 if (file_chooser_completions_.front()->completion) { | |
815 file_chooser_completions_.front()->completion->didChooseFile( | |
816 WebVector<WebString>()); | |
817 } | |
818 file_chooser_completions_.pop_front(); | |
819 } | |
820 | |
821 #if defined(OS_ANDROID) | 801 #if defined(OS_ANDROID) |
822 // The date/time picker client is both a std::unique_ptr member of this class | 802 // The date/time picker client is both a std::unique_ptr member of this class |
823 // and a RenderViewObserver. Reset it to prevent double deletion. | 803 // and a RenderViewObserver. Reset it to prevent double deletion. |
824 date_time_picker_client_.reset(); | 804 date_time_picker_client_.reset(); |
825 #endif | 805 #endif |
826 | 806 |
827 #ifndef NDEBUG | 807 #ifndef NDEBUG |
828 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap. | 808 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap. |
829 ViewMap* views = g_view_map.Pointer(); | 809 ViewMap* views = g_view_map.Pointer(); |
830 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) | 810 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) | 1249 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
1270 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded) | 1250 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded) |
1271 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, | 1251 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
1272 OnDragSourceSystemDragEnded) | 1252 OnDragSourceSystemDragEnded) |
1273 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) | 1253 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
1274 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) | 1254 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
1275 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) | 1255 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
1276 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) | 1256 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
1277 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, | 1257 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
1278 OnEnumerateDirectoryResponse) | 1258 OnEnumerateDirectoryResponse) |
1279 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) | |
1280 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) | 1259 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
1281 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) | 1260 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
1282 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) | 1261 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
1283 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedElement, OnClearFocusedElement) | 1262 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedElement, OnClearFocusedElement) |
1284 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque) | 1263 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque) |
1285 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, | 1264 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
1286 OnEnablePreferredSizeChangedMode) | 1265 OnEnablePreferredSizeChangedMode) |
1287 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) | 1266 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) |
1288 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) | 1267 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) |
1289 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, | 1268 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1660 // seems safest to not execute the rest. | 1639 // seems safest to not execute the rest. |
1661 if (!frame->executeCommand(WebString::fromUTF8(it->name), | 1640 if (!frame->executeCommand(WebString::fromUTF8(it->name), |
1662 WebString::fromUTF8(it->value))) | 1641 WebString::fromUTF8(it->value))) |
1663 break; | 1642 break; |
1664 did_execute_command = true; | 1643 did_execute_command = true; |
1665 } | 1644 } |
1666 | 1645 |
1667 return did_execute_command; | 1646 return did_execute_command; |
1668 } | 1647 } |
1669 | 1648 |
1670 bool RenderViewImpl::runFileChooser( | |
1671 const blink::WebFileChooserParams& params, | |
1672 WebFileChooserCompletion* chooser_completion) { | |
1673 // Do not open the file dialog in a hidden RenderView. | |
1674 if (is_hidden()) | |
1675 return false; | |
1676 FileChooserParams ipc_params; | |
1677 if (params.directory) | |
1678 ipc_params.mode = FileChooserParams::UploadFolder; | |
1679 else if (params.multiSelect) | |
1680 ipc_params.mode = FileChooserParams::OpenMultiple; | |
1681 else if (params.saveAs) | |
1682 ipc_params.mode = FileChooserParams::Save; | |
1683 else | |
1684 ipc_params.mode = FileChooserParams::Open; | |
1685 ipc_params.title = params.title; | |
1686 ipc_params.default_file_name = | |
1687 blink::WebStringToFilePath(params.initialValue).BaseName(); | |
1688 ipc_params.accept_types.reserve(params.acceptTypes.size()); | |
1689 for (size_t i = 0; i < params.acceptTypes.size(); ++i) | |
1690 ipc_params.accept_types.push_back(params.acceptTypes[i]); | |
1691 ipc_params.need_local_path = params.needLocalPath; | |
1692 #if defined(OS_ANDROID) | |
1693 ipc_params.capture = params.useMediaCapture; | |
1694 #endif | |
1695 ipc_params.requestor = params.requestor; | |
1696 | |
1697 return ScheduleFileChooser(ipc_params, chooser_completion); | |
1698 } | |
1699 | |
1700 void RenderViewImpl::SetValidationMessageDirection( | 1649 void RenderViewImpl::SetValidationMessageDirection( |
1701 base::string16* wrapped_main_text, | 1650 base::string16* wrapped_main_text, |
1702 blink::WebTextDirection main_text_hint, | 1651 blink::WebTextDirection main_text_hint, |
1703 base::string16* wrapped_sub_text, | 1652 base::string16* wrapped_sub_text, |
1704 blink::WebTextDirection sub_text_hint) { | 1653 blink::WebTextDirection sub_text_hint) { |
1705 if (main_text_hint == blink::WebTextDirectionLeftToRight) { | 1654 if (main_text_hint == blink::WebTextDirectionLeftToRight) { |
1706 *wrapped_main_text = | 1655 *wrapped_main_text = |
1707 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text); | 1656 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text); |
1708 } else if (main_text_hint == blink::WebTextDirectionRightToLeft && | 1657 } else if (main_text_hint == blink::WebTextDirectionRightToLeft && |
1709 !base::i18n::IsRTL()) { | 1658 !base::i18n::IsRTL()) { |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2436 return; | 2385 return; |
2437 | 2386 |
2438 WebVector<WebString> ws_file_names(paths.size()); | 2387 WebVector<WebString> ws_file_names(paths.size()); |
2439 for (size_t i = 0; i < paths.size(); ++i) | 2388 for (size_t i = 0; i < paths.size(); ++i) |
2440 ws_file_names[i] = paths[i].AsUTF16Unsafe(); | 2389 ws_file_names[i] = paths[i].AsUTF16Unsafe(); |
2441 | 2390 |
2442 enumeration_completions_[id]->didChooseFile(ws_file_names); | 2391 enumeration_completions_[id]->didChooseFile(ws_file_names); |
2443 enumeration_completions_.erase(id); | 2392 enumeration_completions_.erase(id); |
2444 } | 2393 } |
2445 | 2394 |
2446 void RenderViewImpl::OnFileChooserResponse( | |
2447 const std::vector<content::FileChooserFileInfo>& files) { | |
2448 // This could happen if we navigated to a different page before the user | |
2449 // closed the chooser. | |
2450 if (file_chooser_completions_.empty()) | |
2451 return; | |
2452 | |
2453 // Convert Chrome's SelectedFileInfo list to WebKit's. | |
2454 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files( | |
2455 files.size()); | |
2456 for (size_t i = 0; i < files.size(); ++i) { | |
2457 WebFileChooserCompletion::SelectedFileInfo selected_file; | |
2458 selected_file.path = files[i].file_path.AsUTF16Unsafe(); | |
2459 selected_file.displayName = | |
2460 base::FilePath(files[i].display_name).AsUTF16Unsafe(); | |
2461 if (files[i].file_system_url.is_valid()) { | |
2462 selected_file.fileSystemURL = files[i].file_system_url; | |
2463 selected_file.length = files[i].length; | |
2464 selected_file.modificationTime = files[i].modification_time.ToDoubleT(); | |
2465 selected_file.isDirectory = files[i].is_directory; | |
2466 } | |
2467 selected_files[i] = selected_file; | |
2468 } | |
2469 | |
2470 if (file_chooser_completions_.front()->completion) | |
2471 file_chooser_completions_.front()->completion->didChooseFile( | |
2472 selected_files); | |
2473 file_chooser_completions_.pop_front(); | |
2474 | |
2475 // If there are more pending file chooser requests, schedule one now. | |
2476 if (!file_chooser_completions_.empty()) { | |
2477 Send(new ViewHostMsg_RunFileChooser( | |
2478 GetRoutingID(), file_chooser_completions_.front()->params)); | |
2479 } | |
2480 } | |
2481 | |
2482 void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size, | 2395 void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size, |
2483 const gfx::Size& max_size) { | 2396 const gfx::Size& max_size) { |
2484 DCHECK(disable_scrollbars_size_limit_.IsEmpty()); | 2397 DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
2485 if (!webview()) | 2398 if (!webview()) |
2486 return; | 2399 return; |
2487 | 2400 |
2488 auto_resize_mode_ = true; | 2401 auto_resize_mode_ = true; |
2489 if (IsUseZoomForDSFEnabled()) { | 2402 if (IsUseZoomForDSFEnabled()) { |
2490 webview()->enableAutoResizeMode( | 2403 webview()->enableAutoResizeMode( |
2491 gfx::ScaleToCeiledSize(min_size, device_scale_factor_), | 2404 gfx::ScaleToCeiledSize(min_size, device_scale_factor_), |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2950 bool enabled, | 2863 bool enabled, |
2951 const blink::WebDeviceEmulationParams& params) { | 2864 const blink::WebDeviceEmulationParams& params) { |
2952 if (webview() && compositor()) { | 2865 if (webview() && compositor()) { |
2953 if (enabled) | 2866 if (enabled) |
2954 webview()->enableDeviceEmulation(params); | 2867 webview()->enableDeviceEmulation(params); |
2955 else | 2868 else |
2956 webview()->disableDeviceEmulation(); | 2869 webview()->disableDeviceEmulation(); |
2957 } | 2870 } |
2958 } | 2871 } |
2959 | 2872 |
2960 bool RenderViewImpl::ScheduleFileChooser( | |
2961 const FileChooserParams& params, | |
2962 WebFileChooserCompletion* completion) { | |
2963 static const size_t kMaximumPendingFileChooseRequests = 4; | |
2964 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { | |
2965 // This sanity check prevents too many file choose requests from getting | |
2966 // queued which could DoS the user. Getting these is most likely a | |
2967 // programming error (there are many ways to DoS the user so it's not | |
2968 // considered a "real" security check), either in JS requesting many file | |
2969 // choosers to pop up, or in a plugin. | |
2970 // | |
2971 // TODO(brettw) we might possibly want to require a user gesture to open | |
2972 // a file picker, which will address this issue in a better way. | |
2973 return false; | |
2974 } | |
2975 | |
2976 file_chooser_completions_.push_back( | |
2977 base::WrapUnique(new PendingFileChooser(params, completion))); | |
2978 if (file_chooser_completions_.size() == 1) { | |
2979 // Actually show the browse dialog when this is the first request. | |
2980 Send(new ViewHostMsg_RunFileChooser(GetRoutingID(), params)); | |
2981 } | |
2982 return true; | |
2983 } | |
2984 | |
2985 blink::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() { | 2873 blink::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() { |
2986 if (!speech_recognition_dispatcher_) | 2874 if (!speech_recognition_dispatcher_) |
2987 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this); | 2875 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this); |
2988 return speech_recognition_dispatcher_; | 2876 return speech_recognition_dispatcher_; |
2989 } | 2877 } |
2990 | 2878 |
2991 void RenderViewImpl::zoomLimitsChanged(double minimum_level, | 2879 void RenderViewImpl::zoomLimitsChanged(double minimum_level, |
2992 double maximum_level) { | 2880 double maximum_level) { |
2993 // Round the double to avoid returning incorrect minimum/maximum zoom | 2881 // Round the double to avoid returning incorrect minimum/maximum zoom |
2994 // percentages. | 2882 // percentages. |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3340 return render_frame->focused_pepper_plugin(); | 3228 return render_frame->focused_pepper_plugin(); |
3341 } | 3229 } |
3342 frame = frame->traverseNext(false); | 3230 frame = frame->traverseNext(false); |
3343 } | 3231 } |
3344 | 3232 |
3345 return nullptr; | 3233 return nullptr; |
3346 } | 3234 } |
3347 #endif | 3235 #endif |
3348 | 3236 |
3349 } // namespace content | 3237 } // namespace content |
OLD | NEW |