| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 #include "content/public/common/file_chooser_file_info.h" | 73 #include "content/public/common/file_chooser_file_info.h" |
| 74 #include "content/public/common/file_chooser_params.h" | 74 #include "content/public/common/file_chooser_params.h" |
| 75 #include "content/public/common/result_codes.h" | 75 #include "content/public/common/result_codes.h" |
| 76 #include "content/public/common/url_constants.h" | 76 #include "content/public/common/url_constants.h" |
| 77 #include "content/public/common/url_utils.h" | 77 #include "content/public/common/url_utils.h" |
| 78 #include "net/base/filename_util.h" | 78 #include "net/base/filename_util.h" |
| 79 #include "net/base/url_util.h" | 79 #include "net/base/url_util.h" |
| 80 #include "net/url_request/url_request_context_getter.h" | 80 #include "net/url_request/url_request_context_getter.h" |
| 81 #include "storage/browser/fileapi/isolated_context.h" | 81 #include "storage/browser/fileapi/isolated_context.h" |
| 82 #include "third_party/skia/include/core/SkBitmap.h" | 82 #include "third_party/skia/include/core/SkBitmap.h" |
| 83 #include "ui/base/clipboard/clipboard.h" |
| 83 #include "ui/base/touch/touch_device.h" | 84 #include "ui/base/touch/touch_device.h" |
| 84 #include "ui/base/touch/touch_enabled.h" | 85 #include "ui/base/touch/touch_enabled.h" |
| 85 #include "ui/base/ui_base_switches.h" | 86 #include "ui/base/ui_base_switches.h" |
| 86 #include "ui/gfx/animation/animation.h" | 87 #include "ui/gfx/animation/animation.h" |
| 87 #include "ui/gfx/image/image_skia.h" | 88 #include "ui/gfx/image/image_skia.h" |
| 88 #include "ui/gfx/native_widget_types.h" | 89 #include "ui/gfx/native_widget_types.h" |
| 89 #include "ui/native_theme/native_theme_switches.h" | 90 #include "ui/native_theme/native_theme_switches.h" |
| 90 #include "url/url_constants.h" | 91 #include "url/url_constants.h" |
| 91 | 92 |
| 92 #if defined(OS_WIN) | 93 #if defined(OS_WIN) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 prefs->vertical_scroll_bar_width_in_dips = | 136 prefs->vertical_scroll_bar_width_in_dips = |
| 136 display::win::GetSystemMetricsInDIP(SM_CXVSCROLL); | 137 display::win::GetSystemMetricsInDIP(SM_CXVSCROLL); |
| 137 prefs->horizontal_scroll_bar_height_in_dips = | 138 prefs->horizontal_scroll_bar_height_in_dips = |
| 138 display::win::GetSystemMetricsInDIP(SM_CYHSCROLL); | 139 display::win::GetSystemMetricsInDIP(SM_CYHSCROLL); |
| 139 prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips = | 140 prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips = |
| 140 display::win::GetSystemMetricsInDIP(SM_CYVSCROLL); | 141 display::win::GetSystemMetricsInDIP(SM_CYVSCROLL); |
| 141 prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips = | 142 prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips = |
| 142 display::win::GetSystemMetricsInDIP(SM_CXHSCROLL); | 143 display::win::GetSystemMetricsInDIP(SM_CXHSCROLL); |
| 143 } | 144 } |
| 144 #endif | 145 #endif |
| 146 |
| 147 std::vector<DropData::Metadata> DropDataToMetaData(const DropData& drop_data) { |
| 148 std::vector<DropData::Metadata> metadata; |
| 149 if (!drop_data.text.is_null()) { |
| 150 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 151 DropData::Kind::STRING, |
| 152 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeText))); |
| 153 } |
| 154 |
| 155 if (drop_data.url.is_valid()) { |
| 156 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 157 DropData::Kind::STRING, |
| 158 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeURIList))); |
| 159 } |
| 160 |
| 161 if (!drop_data.html.is_null()) { |
| 162 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 163 DropData::Kind::STRING, |
| 164 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeHTML))); |
| 165 } |
| 166 |
| 167 // On Aura, filenames are available before drop. |
| 168 for (const auto& file_info : drop_data.filenames) { |
| 169 if (!file_info.path.empty()) { |
| 170 metadata.push_back(DropData::Metadata::CreateForFilePath(file_info.path)); |
| 171 } |
| 172 } |
| 173 |
| 174 // On Android, only files' mime types are available before drop. |
| 175 for (const auto& mime_type : drop_data.file_mime_types) { |
| 176 if (!mime_type.empty()) { |
| 177 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 178 DropData::Kind::FILENAME, mime_type)); |
| 179 } |
| 180 } |
| 181 |
| 182 for (const auto& file_system_file : drop_data.file_system_files) { |
| 183 if (!file_system_file.url.is_empty()) { |
| 184 metadata.push_back( |
| 185 DropData::Metadata::CreateForFileSystemUrl(file_system_file.url)); |
| 186 } |
| 187 } |
| 188 |
| 189 for (const auto& custom_data_item : drop_data.custom_data) { |
| 190 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 191 DropData::Kind::STRING, custom_data_item.first)); |
| 192 } |
| 193 |
| 194 return metadata; |
| 195 } |
| 196 |
| 145 } // namespace | 197 } // namespace |
| 146 | 198 |
| 147 // static | 199 // static |
| 148 const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000; | 200 const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000; |
| 149 | 201 |
| 150 /////////////////////////////////////////////////////////////////////////////// | 202 /////////////////////////////////////////////////////////////////////////////// |
| 151 // RenderViewHost, public: | 203 // RenderViewHost, public: |
| 152 | 204 |
| 153 // static | 205 // static |
| 154 RenderViewHost* RenderViewHost::FromID(int render_process_id, | 206 RenderViewHost* RenderViewHost::FromID(int render_process_id, |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 GetWidget()->RendererExited(status, exit_code); | 615 GetWidget()->RendererExited(status, exit_code); |
| 564 delegate_->RenderViewTerminated(this, status, exit_code); | 616 delegate_->RenderViewTerminated(this, status, exit_code); |
| 565 } | 617 } |
| 566 | 618 |
| 567 void RenderViewHostImpl::DragTargetDragEnter( | 619 void RenderViewHostImpl::DragTargetDragEnter( |
| 568 const DropData& drop_data, | 620 const DropData& drop_data, |
| 569 const gfx::Point& client_pt, | 621 const gfx::Point& client_pt, |
| 570 const gfx::Point& screen_pt, | 622 const gfx::Point& screen_pt, |
| 571 WebDragOperationsMask operations_allowed, | 623 WebDragOperationsMask operations_allowed, |
| 572 int key_modifiers) { | 624 int key_modifiers) { |
| 573 const int renderer_id = GetProcess()->GetID(); | 625 Send(new DragMsg_TargetDragEnter( |
| 574 ChildProcessSecurityPolicyImpl* policy = | 626 GetRoutingID(), DropDataToMetaData(drop_data), client_pt, screen_pt, |
| 575 ChildProcessSecurityPolicyImpl::GetInstance(); | 627 operations_allowed, key_modifiers)); |
| 576 | |
| 577 #if defined(OS_CHROMEOS) | |
| 578 // The externalfile:// scheme is used in Chrome OS to open external files in a | |
| 579 // browser tab. | |
| 580 if (drop_data.url.SchemeIs(content::kExternalFileScheme)) | |
| 581 policy->GrantRequestURL(renderer_id, drop_data.url); | |
| 582 #endif | |
| 583 | |
| 584 // The URL could have been cobbled together from any highlighted text string, | |
| 585 // and can't be interpreted as a capability. | |
| 586 DropData filtered_data(drop_data); | |
| 587 GetProcess()->FilterURL(true, &filtered_data.url); | |
| 588 if (drop_data.did_originate_from_renderer) { | |
| 589 filtered_data.filenames.clear(); | |
| 590 } | |
| 591 | |
| 592 // The filenames vector, on the other hand, does represent a capability to | |
| 593 // access the given files. | |
| 594 storage::IsolatedContext::FileInfoSet files; | |
| 595 for (std::vector<ui::FileInfo>::iterator iter( | |
| 596 filtered_data.filenames.begin()); | |
| 597 iter != filtered_data.filenames.end(); | |
| 598 ++iter) { | |
| 599 // A dragged file may wind up as the value of an input element, or it | |
| 600 // may be used as the target of a navigation instead. We don't know | |
| 601 // which will happen at this point, so generously grant both access | |
| 602 // and request permissions to the specific file to cover both cases. | |
| 603 // We do not give it the permission to request all file:// URLs. | |
| 604 | |
| 605 // Make sure we have the same display_name as the one we register. | |
| 606 if (iter->display_name.empty()) { | |
| 607 std::string name; | |
| 608 files.AddPath(iter->path, &name); | |
| 609 iter->display_name = base::FilePath::FromUTF8Unsafe(name); | |
| 610 } else { | |
| 611 files.AddPathWithName(iter->path, iter->display_name.AsUTF8Unsafe()); | |
| 612 } | |
| 613 | |
| 614 policy->GrantRequestSpecificFileURL(renderer_id, | |
| 615 net::FilePathToFileURL(iter->path)); | |
| 616 | |
| 617 // If the renderer already has permission to read these paths, we don't need | |
| 618 // to re-grant them. This prevents problems with DnD for files in the CrOS | |
| 619 // file manager--the file manager already had read/write access to those | |
| 620 // directories, but dragging a file would cause the read/write access to be | |
| 621 // overwritten with read-only access, making them impossible to delete or | |
| 622 // rename until the renderer was killed. | |
| 623 if (!policy->CanReadFile(renderer_id, iter->path)) | |
| 624 policy->GrantReadFile(renderer_id, iter->path); | |
| 625 } | |
| 626 | |
| 627 storage::IsolatedContext* isolated_context = | |
| 628 storage::IsolatedContext::GetInstance(); | |
| 629 DCHECK(isolated_context); | |
| 630 std::string filesystem_id = isolated_context->RegisterDraggedFileSystem( | |
| 631 files); | |
| 632 if (!filesystem_id.empty()) { | |
| 633 // Grant the permission iff the ID is valid. | |
| 634 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 635 } | |
| 636 filtered_data.filesystem_id = base::UTF8ToUTF16(filesystem_id); | |
| 637 | |
| 638 storage::FileSystemContext* file_system_context = | |
| 639 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(), | |
| 640 GetSiteInstance()) | |
| 641 ->GetFileSystemContext(); | |
| 642 for (size_t i = 0; i < filtered_data.file_system_files.size(); ++i) { | |
| 643 storage::FileSystemURL file_system_url = | |
| 644 file_system_context->CrackURL(filtered_data.file_system_files[i].url); | |
| 645 | |
| 646 std::string register_name; | |
| 647 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( | |
| 648 file_system_url.type(), file_system_url.filesystem_id(), | |
| 649 file_system_url.path(), ®ister_name); | |
| 650 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 651 | |
| 652 // Note: We are using the origin URL provided by the sender here. It may be | |
| 653 // different from the receiver's. | |
| 654 filtered_data.file_system_files[i].url = | |
| 655 GURL(storage::GetIsolatedFileSystemRootURIString( | |
| 656 file_system_url.origin(), filesystem_id, std::string()) | |
| 657 .append(register_name)); | |
| 658 } | |
| 659 | |
| 660 Send(new DragMsg_TargetDragEnter(GetRoutingID(), filtered_data, client_pt, | |
| 661 screen_pt, operations_allowed, | |
| 662 key_modifiers)); | |
| 663 } | 628 } |
| 664 | 629 |
| 665 void RenderViewHostImpl::DragTargetDragOver( | 630 void RenderViewHostImpl::DragTargetDragOver( |
| 666 const gfx::Point& client_pt, | 631 const gfx::Point& client_pt, |
| 667 const gfx::Point& screen_pt, | 632 const gfx::Point& screen_pt, |
| 668 WebDragOperationsMask operations_allowed, | 633 WebDragOperationsMask operations_allowed, |
| 669 int key_modifiers) { | 634 int key_modifiers) { |
| 670 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt, | 635 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt, |
| 671 operations_allowed, key_modifiers)); | 636 operations_allowed, key_modifiers)); |
| 672 } | 637 } |
| 673 | 638 |
| 674 void RenderViewHostImpl::DragTargetDragLeave() { | 639 void RenderViewHostImpl::DragTargetDragLeave() { |
| 675 Send(new DragMsg_TargetDragLeave(GetRoutingID())); | 640 Send(new DragMsg_TargetDragLeave(GetRoutingID())); |
| 676 } | 641 } |
| 677 | 642 |
| 678 void RenderViewHostImpl::DragTargetDrop( | 643 void RenderViewHostImpl::DragTargetDrop(const DropData& drop_data, |
| 679 const gfx::Point& client_pt, | 644 const gfx::Point& client_pt, |
| 680 const gfx::Point& screen_pt, | 645 const gfx::Point& screen_pt, |
| 681 int key_modifiers) { | 646 int key_modifiers) { |
| 682 Send(new DragMsg_TargetDrop(GetRoutingID(), client_pt, screen_pt, | 647 DropData drop_data_with_permissions(drop_data); |
| 683 key_modifiers)); | 648 GrantFileAccessFromDropData(&drop_data_with_permissions); |
| 649 Send(new DragMsg_TargetDrop(GetRoutingID(), drop_data_with_permissions, |
| 650 client_pt, screen_pt, key_modifiers)); |
| 651 } |
| 652 |
| 653 void RenderViewHostImpl::FilterDropData(DropData* drop_data) { |
| 654 #if DCHECK_IS_ON() |
| 655 drop_data->view_id = GetRoutingID(); |
| 656 #endif // DCHECK_IS_ON() |
| 657 |
| 658 GetProcess()->FilterURL(true, &drop_data->url); |
| 659 if (drop_data->did_originate_from_renderer) { |
| 660 drop_data->filenames.clear(); |
| 661 } |
| 684 } | 662 } |
| 685 | 663 |
| 686 void RenderViewHostImpl::DragSourceEndedAt( | 664 void RenderViewHostImpl::DragSourceEndedAt( |
| 687 int client_x, int client_y, int screen_x, int screen_y, | 665 int client_x, int client_y, int screen_x, int screen_y, |
| 688 WebDragOperation operation) { | 666 WebDragOperation operation) { |
| 689 Send(new DragMsg_SourceEnded(GetRoutingID(), | 667 Send(new DragMsg_SourceEnded(GetRoutingID(), |
| 690 gfx::Point(client_x, client_y), | 668 gfx::Point(client_x, client_y), |
| 691 gfx::Point(screen_x, screen_y), | 669 gfx::Point(screen_x, screen_y), |
| 692 operation)); | 670 operation)); |
| 693 } | 671 } |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 weak_factory_.GetWeakPtr())); | 1259 weak_factory_.GetWeakPtr())); |
| 1282 } else { | 1260 } else { |
| 1283 render_view_ready_on_process_launch_ = true; | 1261 render_view_ready_on_process_launch_ = true; |
| 1284 } | 1262 } |
| 1285 } | 1263 } |
| 1286 | 1264 |
| 1287 void RenderViewHostImpl::RenderViewReady() { | 1265 void RenderViewHostImpl::RenderViewReady() { |
| 1288 delegate_->RenderViewReady(this); | 1266 delegate_->RenderViewReady(this); |
| 1289 } | 1267 } |
| 1290 | 1268 |
| 1269 void RenderViewHostImpl::GrantFileAccessFromDropData(DropData* drop_data) { |
| 1270 DCHECK_EQ(GetRoutingID(), drop_data->view_id); |
| 1271 const int renderer_id = GetProcess()->GetID(); |
| 1272 ChildProcessSecurityPolicyImpl* policy = |
| 1273 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 1274 |
| 1275 #if defined(OS_CHROMEOS) |
| 1276 // The externalfile:// scheme is used in Chrome OS to open external files in a |
| 1277 // browser tab. |
| 1278 if (drop_data->url.SchemeIs(content::kExternalFileScheme)) |
| 1279 policy->GrantRequestURL(renderer_id, drop_data->url); |
| 1280 #endif |
| 1281 |
| 1282 // The filenames vector represents a capability to access the given files. |
| 1283 storage::IsolatedContext::FileInfoSet files; |
| 1284 for (auto& filename : drop_data->filenames) { |
| 1285 // Make sure we have the same display_name as the one we register. |
| 1286 if (filename.display_name.empty()) { |
| 1287 std::string name; |
| 1288 files.AddPath(filename.path, &name); |
| 1289 filename.display_name = base::FilePath::FromUTF8Unsafe(name); |
| 1290 } else { |
| 1291 files.AddPathWithName(filename.path, |
| 1292 filename.display_name.AsUTF8Unsafe()); |
| 1293 } |
| 1294 // A dragged file may wind up as the value of an input element, or it |
| 1295 // may be used as the target of a navigation instead. We don't know |
| 1296 // which will happen at this point, so generously grant both access |
| 1297 // and request permissions to the specific file to cover both cases. |
| 1298 // We do not give it the permission to request all file:// URLs. |
| 1299 policy->GrantRequestSpecificFileURL(renderer_id, |
| 1300 net::FilePathToFileURL(filename.path)); |
| 1301 |
| 1302 // If the renderer already has permission to read these paths, we don't need |
| 1303 // to re-grant them. This prevents problems with DnD for files in the CrOS |
| 1304 // file manager--the file manager already had read/write access to those |
| 1305 // directories, but dragging a file would cause the read/write access to be |
| 1306 // overwritten with read-only access, making them impossible to delete or |
| 1307 // rename until the renderer was killed. |
| 1308 if (!policy->CanReadFile(renderer_id, filename.path)) |
| 1309 policy->GrantReadFile(renderer_id, filename.path); |
| 1310 } |
| 1311 |
| 1312 storage::IsolatedContext* isolated_context = |
| 1313 storage::IsolatedContext::GetInstance(); |
| 1314 DCHECK(isolated_context); |
| 1315 |
| 1316 if (!files.fileset().empty()) { |
| 1317 std::string filesystem_id = |
| 1318 isolated_context->RegisterDraggedFileSystem(files); |
| 1319 if (!filesystem_id.empty()) { |
| 1320 // Grant the permission iff the ID is valid. |
| 1321 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| 1322 } |
| 1323 drop_data->filesystem_id = base::UTF8ToUTF16(filesystem_id); |
| 1324 } |
| 1325 |
| 1326 storage::FileSystemContext* file_system_context = |
| 1327 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(), |
| 1328 GetSiteInstance()) |
| 1329 ->GetFileSystemContext(); |
| 1330 for (auto& file_system_file : drop_data->file_system_files) { |
| 1331 storage::FileSystemURL file_system_url = |
| 1332 file_system_context->CrackURL(file_system_file.url); |
| 1333 |
| 1334 std::string register_name; |
| 1335 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( |
| 1336 file_system_url.type(), file_system_url.filesystem_id(), |
| 1337 file_system_url.path(), ®ister_name); |
| 1338 |
| 1339 if (!filesystem_id.empty()) { |
| 1340 // Grant the permission iff the ID is valid. |
| 1341 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| 1342 } |
| 1343 |
| 1344 // Note: We are using the origin URL provided by the sender here. It may be |
| 1345 // different from the receiver's. |
| 1346 file_system_file.url = |
| 1347 GURL(storage::GetIsolatedFileSystemRootURIString( |
| 1348 file_system_url.origin(), filesystem_id, std::string()) |
| 1349 .append(register_name)); |
| 1350 } |
| 1351 } |
| 1352 |
| 1291 } // namespace content | 1353 } // namespace content |
| OLD | NEW |