| 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/browser/renderer_host/render_view_host_impl.h" | 5 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 #include "content/public/common/content_constants.h" | 74 #include "content/public/common/content_constants.h" |
| 75 #include "content/public/common/content_features.h" | 75 #include "content/public/common/content_features.h" |
| 76 #include "content/public/common/content_switches.h" | 76 #include "content/public/common/content_switches.h" |
| 77 #include "content/public/common/context_menu_params.h" | 77 #include "content/public/common/context_menu_params.h" |
| 78 #include "content/public/common/drop_data.h" | 78 #include "content/public/common/drop_data.h" |
| 79 #include "content/public/common/file_chooser_file_info.h" | 79 #include "content/public/common/file_chooser_file_info.h" |
| 80 #include "content/public/common/file_chooser_params.h" | 80 #include "content/public/common/file_chooser_params.h" |
| 81 #include "content/public/common/result_codes.h" | 81 #include "content/public/common/result_codes.h" |
| 82 #include "content/public/common/url_constants.h" | 82 #include "content/public/common/url_constants.h" |
| 83 #include "content/public/common/url_utils.h" | 83 #include "content/public/common/url_utils.h" |
| 84 #include "net/base/filename_util.h" | |
| 85 #include "net/base/url_util.h" | 84 #include "net/base/url_util.h" |
| 86 #include "net/url_request/url_request_context_getter.h" | 85 #include "net/url_request/url_request_context_getter.h" |
| 87 #include "storage/browser/fileapi/isolated_context.h" | |
| 88 #include "third_party/skia/include/core/SkBitmap.h" | 86 #include "third_party/skia/include/core/SkBitmap.h" |
| 89 #include "ui/base/clipboard/clipboard.h" | 87 #include "ui/base/clipboard/clipboard.h" |
| 90 #include "ui/base/touch/touch_device.h" | 88 #include "ui/base/touch/touch_device.h" |
| 91 #include "ui/base/touch/touch_enabled.h" | 89 #include "ui/base/touch/touch_enabled.h" |
| 92 #include "ui/base/ui_base_switches.h" | 90 #include "ui/base/ui_base_switches.h" |
| 93 #include "ui/gfx/animation/animation.h" | 91 #include "ui/gfx/animation/animation.h" |
| 94 #include "ui/gfx/color_space.h" | 92 #include "ui/gfx/color_space.h" |
| 95 #include "ui/gfx/image/image_skia.h" | 93 #include "ui/gfx/image/image_skia.h" |
| 96 #include "ui/gfx/native_widget_types.h" | 94 #include "ui/gfx/native_widget_types.h" |
| 97 #include "ui/native_theme/native_theme_switches.h" | 95 #include "ui/native_theme/native_theme_switches.h" |
| 98 #include "url/url_constants.h" | 96 #include "url/url_constants.h" |
| 99 | 97 |
| 100 #if defined(OS_WIN) | 98 #if defined(OS_WIN) |
| 101 #include "ui/display/win/screen_win.h" | 99 #include "ui/display/win/screen_win.h" |
| 102 #include "ui/gfx/geometry/dip_util.h" | 100 #include "ui/gfx/geometry/dip_util.h" |
| 103 #include "ui/gfx/platform_font_win.h" | 101 #include "ui/gfx/platform_font_win.h" |
| 104 #endif | 102 #endif |
| 105 | 103 |
| 106 using base::TimeDelta; | 104 using base::TimeDelta; |
| 107 using blink::WebConsoleMessage; | 105 using blink::WebConsoleMessage; |
| 108 using blink::WebDragOperation; | 106 using blink::WebDragOperation; |
| 109 using blink::WebDragOperationNone; | |
| 110 using blink::WebDragOperationsMask; | |
| 111 using blink::WebInputEvent; | 107 using blink::WebInputEvent; |
| 112 using blink::WebMediaPlayerAction; | 108 using blink::WebMediaPlayerAction; |
| 113 using blink::WebPluginAction; | 109 using blink::WebPluginAction; |
| 114 | 110 |
| 115 namespace content { | 111 namespace content { |
| 116 namespace { | 112 namespace { |
| 117 | 113 |
| 118 void GetPlatformSpecificPrefs(RendererPreferences* prefs) { | 114 void GetPlatformSpecificPrefs(RendererPreferences* prefs) { |
| 119 #if defined(OS_WIN) | 115 #if defined(OS_WIN) |
| 120 NONCLIENTMETRICS_XP metrics = {0}; | 116 NONCLIENTMETRICS_XP metrics = {0}; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 146 display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYHSCROLL); | 142 display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYHSCROLL); |
| 147 prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips = | 143 prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips = |
| 148 display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYVSCROLL); | 144 display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYVSCROLL); |
| 149 prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips = | 145 prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips = |
| 150 display::win::ScreenWin::GetSystemMetricsInDIP(SM_CXHSCROLL); | 146 display::win::ScreenWin::GetSystemMetricsInDIP(SM_CXHSCROLL); |
| 151 #elif defined(OS_LINUX) | 147 #elif defined(OS_LINUX) |
| 152 prefs->system_font_family_name = gfx::Font().GetFontName(); | 148 prefs->system_font_family_name = gfx::Font().GetFontName(); |
| 153 #endif | 149 #endif |
| 154 } | 150 } |
| 155 | 151 |
| 156 std::vector<DropData::Metadata> DropDataToMetaData(const DropData& drop_data) { | |
| 157 std::vector<DropData::Metadata> metadata; | |
| 158 if (!drop_data.text.is_null()) { | |
| 159 metadata.push_back(DropData::Metadata::CreateForMimeType( | |
| 160 DropData::Kind::STRING, | |
| 161 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeText))); | |
| 162 } | |
| 163 | |
| 164 if (drop_data.url.is_valid()) { | |
| 165 metadata.push_back(DropData::Metadata::CreateForMimeType( | |
| 166 DropData::Kind::STRING, | |
| 167 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeURIList))); | |
| 168 } | |
| 169 | |
| 170 if (!drop_data.html.is_null()) { | |
| 171 metadata.push_back(DropData::Metadata::CreateForMimeType( | |
| 172 DropData::Kind::STRING, | |
| 173 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeHTML))); | |
| 174 } | |
| 175 | |
| 176 // On Aura, filenames are available before drop. | |
| 177 for (const auto& file_info : drop_data.filenames) { | |
| 178 if (!file_info.path.empty()) { | |
| 179 metadata.push_back(DropData::Metadata::CreateForFilePath(file_info.path)); | |
| 180 } | |
| 181 } | |
| 182 | |
| 183 // On Android, only files' mime types are available before drop. | |
| 184 for (const auto& mime_type : drop_data.file_mime_types) { | |
| 185 if (!mime_type.empty()) { | |
| 186 metadata.push_back(DropData::Metadata::CreateForMimeType( | |
| 187 DropData::Kind::FILENAME, mime_type)); | |
| 188 } | |
| 189 } | |
| 190 | |
| 191 for (const auto& file_system_file : drop_data.file_system_files) { | |
| 192 if (!file_system_file.url.is_empty()) { | |
| 193 metadata.push_back( | |
| 194 DropData::Metadata::CreateForFileSystemUrl(file_system_file.url)); | |
| 195 } | |
| 196 } | |
| 197 | |
| 198 for (const auto& custom_data_item : drop_data.custom_data) { | |
| 199 metadata.push_back(DropData::Metadata::CreateForMimeType( | |
| 200 DropData::Kind::STRING, custom_data_item.first)); | |
| 201 } | |
| 202 | |
| 203 return metadata; | |
| 204 } | |
| 205 | |
| 206 } // namespace | 152 } // namespace |
| 207 | 153 |
| 208 // static | 154 // static |
| 209 const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000; | 155 const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000; |
| 210 | 156 |
| 211 /////////////////////////////////////////////////////////////////////////////// | 157 /////////////////////////////////////////////////////////////////////////////// |
| 212 // RenderViewHost, public: | 158 // RenderViewHost, public: |
| 213 | 159 |
| 214 // static | 160 // static |
| 215 RenderViewHost* RenderViewHost::FromID(int render_process_id, | 161 RenderViewHost* RenderViewHost::FromID(int render_process_id, |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 void RenderViewHostImpl::RenderProcessExited(RenderProcessHost* host, | 599 void RenderViewHostImpl::RenderProcessExited(RenderProcessHost* host, |
| 654 base::TerminationStatus status, | 600 base::TerminationStatus status, |
| 655 int exit_code) { | 601 int exit_code) { |
| 656 if (!GetWidget()->renderer_initialized()) | 602 if (!GetWidget()->renderer_initialized()) |
| 657 return; | 603 return; |
| 658 | 604 |
| 659 GetWidget()->RendererExited(status, exit_code); | 605 GetWidget()->RendererExited(status, exit_code); |
| 660 delegate_->RenderViewTerminated(this, status, exit_code); | 606 delegate_->RenderViewTerminated(this, status, exit_code); |
| 661 } | 607 } |
| 662 | 608 |
| 663 void RenderViewHostImpl::DragTargetDragEnter( | |
| 664 const DropData& drop_data, | |
| 665 const gfx::Point& client_pt, | |
| 666 const gfx::Point& screen_pt, | |
| 667 WebDragOperationsMask operations_allowed, | |
| 668 int key_modifiers) { | |
| 669 DragTargetDragEnterWithMetaData(DropDataToMetaData(drop_data), client_pt, | |
| 670 screen_pt, operations_allowed, key_modifiers); | |
| 671 } | |
| 672 | |
| 673 void RenderViewHostImpl::DragTargetDragEnterWithMetaData( | |
| 674 const std::vector<DropData::Metadata>& metadata, | |
| 675 const gfx::Point& client_pt, | |
| 676 const gfx::Point& screen_pt, | |
| 677 WebDragOperationsMask operations_allowed, | |
| 678 int key_modifiers) { | |
| 679 Send(new DragMsg_TargetDragEnter(GetRoutingID(), metadata, client_pt, | |
| 680 screen_pt, operations_allowed, | |
| 681 key_modifiers)); | |
| 682 } | |
| 683 | |
| 684 void RenderViewHostImpl::DragTargetDragOver( | |
| 685 const gfx::Point& client_pt, | |
| 686 const gfx::Point& screen_pt, | |
| 687 WebDragOperationsMask operations_allowed, | |
| 688 int key_modifiers) { | |
| 689 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt, | |
| 690 operations_allowed, key_modifiers)); | |
| 691 } | |
| 692 | |
| 693 void RenderViewHostImpl::DragTargetDragLeave() { | |
| 694 Send(new DragMsg_TargetDragLeave(GetRoutingID())); | |
| 695 } | |
| 696 | |
| 697 void RenderViewHostImpl::DragTargetDrop(const DropData& drop_data, | |
| 698 const gfx::Point& client_pt, | |
| 699 const gfx::Point& screen_pt, | |
| 700 int key_modifiers) { | |
| 701 DropData drop_data_with_permissions(drop_data); | |
| 702 GrantFileAccessFromDropData(&drop_data_with_permissions); | |
| 703 Send(new DragMsg_TargetDrop(GetRoutingID(), drop_data_with_permissions, | |
| 704 client_pt, screen_pt, key_modifiers)); | |
| 705 } | |
| 706 | |
| 707 void RenderViewHostImpl::FilterDropData(DropData* drop_data) { | |
| 708 #if DCHECK_IS_ON() | |
| 709 drop_data->view_id = GetRoutingID(); | |
| 710 #endif // DCHECK_IS_ON() | |
| 711 | |
| 712 GetProcess()->FilterURL(true, &drop_data->url); | |
| 713 if (drop_data->did_originate_from_renderer) { | |
| 714 drop_data->filenames.clear(); | |
| 715 } | |
| 716 } | |
| 717 | |
| 718 void RenderViewHostImpl::DragSourceEndedAt( | 609 void RenderViewHostImpl::DragSourceEndedAt( |
| 719 int client_x, int client_y, int screen_x, int screen_y, | 610 int client_x, int client_y, int screen_x, int screen_y, |
| 720 WebDragOperation operation) { | 611 WebDragOperation operation) { |
| 721 Send(new DragMsg_SourceEnded(GetRoutingID(), | 612 Send(new DragMsg_SourceEnded(GetRoutingID(), |
| 722 gfx::Point(client_x, client_y), | 613 gfx::Point(client_x, client_y), |
| 723 gfx::Point(screen_x, screen_y), | 614 gfx::Point(screen_x, screen_y), |
| 724 operation)); | 615 operation)); |
| 725 } | 616 } |
| 726 | 617 |
| 727 void RenderViewHostImpl::DragSourceSystemDragEnded() { | 618 void RenderViewHostImpl::DragSourceSystemDragEnded() { |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 weak_factory_.GetWeakPtr())); | 1096 weak_factory_.GetWeakPtr())); |
| 1206 } else { | 1097 } else { |
| 1207 render_view_ready_on_process_launch_ = true; | 1098 render_view_ready_on_process_launch_ = true; |
| 1208 } | 1099 } |
| 1209 } | 1100 } |
| 1210 | 1101 |
| 1211 void RenderViewHostImpl::RenderViewReady() { | 1102 void RenderViewHostImpl::RenderViewReady() { |
| 1212 delegate_->RenderViewReady(this); | 1103 delegate_->RenderViewReady(this); |
| 1213 } | 1104 } |
| 1214 | 1105 |
| 1215 void RenderViewHostImpl::GrantFileAccessFromDropData(DropData* drop_data) { | |
| 1216 DCHECK_EQ(GetRoutingID(), drop_data->view_id); | |
| 1217 const int renderer_id = GetProcess()->GetID(); | |
| 1218 ChildProcessSecurityPolicyImpl* policy = | |
| 1219 ChildProcessSecurityPolicyImpl::GetInstance(); | |
| 1220 | |
| 1221 #if defined(OS_CHROMEOS) | |
| 1222 // The externalfile:// scheme is used in Chrome OS to open external files in a | |
| 1223 // browser tab. | |
| 1224 if (drop_data->url.SchemeIs(content::kExternalFileScheme)) | |
| 1225 policy->GrantRequestURL(renderer_id, drop_data->url); | |
| 1226 #endif | |
| 1227 | |
| 1228 // The filenames vector represents a capability to access the given files. | |
| 1229 storage::IsolatedContext::FileInfoSet files; | |
| 1230 for (auto& filename : drop_data->filenames) { | |
| 1231 // Make sure we have the same display_name as the one we register. | |
| 1232 if (filename.display_name.empty()) { | |
| 1233 std::string name; | |
| 1234 files.AddPath(filename.path, &name); | |
| 1235 filename.display_name = base::FilePath::FromUTF8Unsafe(name); | |
| 1236 } else { | |
| 1237 files.AddPathWithName(filename.path, | |
| 1238 filename.display_name.AsUTF8Unsafe()); | |
| 1239 } | |
| 1240 // A dragged file may wind up as the value of an input element, or it | |
| 1241 // may be used as the target of a navigation instead. We don't know | |
| 1242 // which will happen at this point, so generously grant both access | |
| 1243 // and request permissions to the specific file to cover both cases. | |
| 1244 // We do not give it the permission to request all file:// URLs. | |
| 1245 policy->GrantRequestSpecificFileURL(renderer_id, | |
| 1246 net::FilePathToFileURL(filename.path)); | |
| 1247 | |
| 1248 // If the renderer already has permission to read these paths, we don't need | |
| 1249 // to re-grant them. This prevents problems with DnD for files in the CrOS | |
| 1250 // file manager--the file manager already had read/write access to those | |
| 1251 // directories, but dragging a file would cause the read/write access to be | |
| 1252 // overwritten with read-only access, making them impossible to delete or | |
| 1253 // rename until the renderer was killed. | |
| 1254 if (!policy->CanReadFile(renderer_id, filename.path)) | |
| 1255 policy->GrantReadFile(renderer_id, filename.path); | |
| 1256 } | |
| 1257 | |
| 1258 storage::IsolatedContext* isolated_context = | |
| 1259 storage::IsolatedContext::GetInstance(); | |
| 1260 DCHECK(isolated_context); | |
| 1261 | |
| 1262 if (!files.fileset().empty()) { | |
| 1263 std::string filesystem_id = | |
| 1264 isolated_context->RegisterDraggedFileSystem(files); | |
| 1265 if (!filesystem_id.empty()) { | |
| 1266 // Grant the permission iff the ID is valid. | |
| 1267 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 1268 } | |
| 1269 drop_data->filesystem_id = base::UTF8ToUTF16(filesystem_id); | |
| 1270 } | |
| 1271 | |
| 1272 storage::FileSystemContext* file_system_context = | |
| 1273 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(), | |
| 1274 GetSiteInstance()) | |
| 1275 ->GetFileSystemContext(); | |
| 1276 for (auto& file_system_file : drop_data->file_system_files) { | |
| 1277 storage::FileSystemURL file_system_url = | |
| 1278 file_system_context->CrackURL(file_system_file.url); | |
| 1279 | |
| 1280 std::string register_name; | |
| 1281 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( | |
| 1282 file_system_url.type(), file_system_url.filesystem_id(), | |
| 1283 file_system_url.path(), ®ister_name); | |
| 1284 | |
| 1285 if (!filesystem_id.empty()) { | |
| 1286 // Grant the permission iff the ID is valid. | |
| 1287 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 1288 } | |
| 1289 | |
| 1290 // Note: We are using the origin URL provided by the sender here. It may be | |
| 1291 // different from the receiver's. | |
| 1292 file_system_file.url = | |
| 1293 GURL(storage::GetIsolatedFileSystemRootURIString( | |
| 1294 file_system_url.origin(), filesystem_id, std::string()) | |
| 1295 .append(register_name)); | |
| 1296 } | |
| 1297 } | |
| 1298 | |
| 1299 } // namespace content | 1106 } // namespace content |
| OLD | NEW |