| 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.has_url) { |
| 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 GetWidget()->RendererExited(status, exit_code); | 613 GetWidget()->RendererExited(status, exit_code); |
| 562 delegate_->RenderViewTerminated(this, status, exit_code); | 614 delegate_->RenderViewTerminated(this, status, exit_code); |
| 563 } | 615 } |
| 564 | 616 |
| 565 void RenderViewHostImpl::DragTargetDragEnter( | 617 void RenderViewHostImpl::DragTargetDragEnter( |
| 566 const DropData& drop_data, | 618 const DropData& drop_data, |
| 567 const gfx::Point& client_pt, | 619 const gfx::Point& client_pt, |
| 568 const gfx::Point& screen_pt, | 620 const gfx::Point& screen_pt, |
| 569 WebDragOperationsMask operations_allowed, | 621 WebDragOperationsMask operations_allowed, |
| 570 int key_modifiers) { | 622 int key_modifiers) { |
| 571 const int renderer_id = GetProcess()->GetID(); | 623 Send(new DragMsg_TargetDragEnter( |
| 572 ChildProcessSecurityPolicyImpl* policy = | 624 GetRoutingID(), DropDataToMetaData(drop_data), client_pt, screen_pt, |
| 573 ChildProcessSecurityPolicyImpl::GetInstance(); | 625 operations_allowed, key_modifiers)); |
| 574 | |
| 575 #if defined(OS_CHROMEOS) | |
| 576 // The externalfile:// scheme is used in Chrome OS to open external files in a | |
| 577 // browser tab. | |
| 578 if (drop_data.url.SchemeIs(content::kExternalFileScheme)) | |
| 579 policy->GrantRequestURL(renderer_id, drop_data.url); | |
| 580 #endif | |
| 581 | |
| 582 // The URL could have been cobbled together from any highlighted text string, | |
| 583 // and can't be interpreted as a capability. | |
| 584 DropData filtered_data(drop_data); | |
| 585 GetProcess()->FilterURL(true, &filtered_data.url); | |
| 586 if (drop_data.did_originate_from_renderer) { | |
| 587 filtered_data.filenames.clear(); | |
| 588 } | |
| 589 | |
| 590 // The filenames vector, on the other hand, does represent a capability to | |
| 591 // access the given files. | |
| 592 storage::IsolatedContext::FileInfoSet files; | |
| 593 for (std::vector<ui::FileInfo>::iterator iter( | |
| 594 filtered_data.filenames.begin()); | |
| 595 iter != filtered_data.filenames.end(); | |
| 596 ++iter) { | |
| 597 // A dragged file may wind up as the value of an input element, or it | |
| 598 // may be used as the target of a navigation instead. We don't know | |
| 599 // which will happen at this point, so generously grant both access | |
| 600 // and request permissions to the specific file to cover both cases. | |
| 601 // We do not give it the permission to request all file:// URLs. | |
| 602 | |
| 603 // Make sure we have the same display_name as the one we register. | |
| 604 if (iter->display_name.empty()) { | |
| 605 std::string name; | |
| 606 files.AddPath(iter->path, &name); | |
| 607 iter->display_name = base::FilePath::FromUTF8Unsafe(name); | |
| 608 } else { | |
| 609 files.AddPathWithName(iter->path, iter->display_name.AsUTF8Unsafe()); | |
| 610 } | |
| 611 | |
| 612 policy->GrantRequestSpecificFileURL(renderer_id, | |
| 613 net::FilePathToFileURL(iter->path)); | |
| 614 | |
| 615 // If the renderer already has permission to read these paths, we don't need | |
| 616 // to re-grant them. This prevents problems with DnD for files in the CrOS | |
| 617 // file manager--the file manager already had read/write access to those | |
| 618 // directories, but dragging a file would cause the read/write access to be | |
| 619 // overwritten with read-only access, making them impossible to delete or | |
| 620 // rename until the renderer was killed. | |
| 621 if (!policy->CanReadFile(renderer_id, iter->path)) | |
| 622 policy->GrantReadFile(renderer_id, iter->path); | |
| 623 } | |
| 624 | |
| 625 storage::IsolatedContext* isolated_context = | |
| 626 storage::IsolatedContext::GetInstance(); | |
| 627 DCHECK(isolated_context); | |
| 628 std::string filesystem_id = isolated_context->RegisterDraggedFileSystem( | |
| 629 files); | |
| 630 if (!filesystem_id.empty()) { | |
| 631 // Grant the permission iff the ID is valid. | |
| 632 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 633 } | |
| 634 filtered_data.filesystem_id = base::UTF8ToUTF16(filesystem_id); | |
| 635 | |
| 636 storage::FileSystemContext* file_system_context = | |
| 637 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(), | |
| 638 GetSiteInstance()) | |
| 639 ->GetFileSystemContext(); | |
| 640 for (size_t i = 0; i < filtered_data.file_system_files.size(); ++i) { | |
| 641 storage::FileSystemURL file_system_url = | |
| 642 file_system_context->CrackURL(filtered_data.file_system_files[i].url); | |
| 643 | |
| 644 std::string register_name; | |
| 645 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( | |
| 646 file_system_url.type(), file_system_url.filesystem_id(), | |
| 647 file_system_url.path(), ®ister_name); | |
| 648 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 649 | |
| 650 // Note: We are using the origin URL provided by the sender here. It may be | |
| 651 // different from the receiver's. | |
| 652 filtered_data.file_system_files[i].url = | |
| 653 GURL(storage::GetIsolatedFileSystemRootURIString( | |
| 654 file_system_url.origin(), filesystem_id, std::string()) | |
| 655 .append(register_name)); | |
| 656 } | |
| 657 | |
| 658 Send(new DragMsg_TargetDragEnter(GetRoutingID(), filtered_data, client_pt, | |
| 659 screen_pt, operations_allowed, | |
| 660 key_modifiers)); | |
| 661 } | 626 } |
| 662 | 627 |
| 663 void RenderViewHostImpl::DragTargetDragOver( | 628 void RenderViewHostImpl::DragTargetDragOver( |
| 664 const gfx::Point& client_pt, | 629 const gfx::Point& client_pt, |
| 665 const gfx::Point& screen_pt, | 630 const gfx::Point& screen_pt, |
| 666 WebDragOperationsMask operations_allowed, | 631 WebDragOperationsMask operations_allowed, |
| 667 int key_modifiers) { | 632 int key_modifiers) { |
| 668 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt, | 633 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt, |
| 669 operations_allowed, key_modifiers)); | 634 operations_allowed, key_modifiers)); |
| 670 } | 635 } |
| 671 | 636 |
| 672 void RenderViewHostImpl::DragTargetDragLeave() { | 637 void RenderViewHostImpl::DragTargetDragLeave() { |
| 673 Send(new DragMsg_TargetDragLeave(GetRoutingID())); | 638 Send(new DragMsg_TargetDragLeave(GetRoutingID())); |
| 674 } | 639 } |
| 675 | 640 |
| 676 void RenderViewHostImpl::DragTargetDrop( | 641 void RenderViewHostImpl::DragTargetDrop(const DropData& drop_data, |
| 677 const gfx::Point& client_pt, | 642 const gfx::Point& client_pt, |
| 678 const gfx::Point& screen_pt, | 643 const gfx::Point& screen_pt, |
| 679 int key_modifiers) { | 644 int key_modifiers) { |
| 680 Send(new DragMsg_TargetDrop(GetRoutingID(), client_pt, screen_pt, | 645 DropData drop_data_with_permissions(drop_data); |
| 681 key_modifiers)); | 646 GrantFileAccessFromDropData(&drop_data_with_permissions); |
| 647 Send(new DragMsg_TargetDrop(GetRoutingID(), drop_data_with_permissions, |
| 648 client_pt, screen_pt, key_modifiers)); |
| 649 } |
| 650 |
| 651 void RenderViewHostImpl::FilterDropData(DropData* drop_data) { |
| 652 #if DCHECK_IS_ON() |
| 653 drop_data->view_id = GetRoutingID(); |
| 654 #endif // DCHECK_IS_ON() |
| 655 |
| 656 GetProcess()->FilterURL(true, &drop_data->url); |
| 657 if (drop_data->did_originate_from_renderer) { |
| 658 drop_data->filenames.clear(); |
| 659 } |
| 682 } | 660 } |
| 683 | 661 |
| 684 void RenderViewHostImpl::DragSourceEndedAt( | 662 void RenderViewHostImpl::DragSourceEndedAt( |
| 685 int client_x, int client_y, int screen_x, int screen_y, | 663 int client_x, int client_y, int screen_x, int screen_y, |
| 686 WebDragOperation operation) { | 664 WebDragOperation operation) { |
| 687 Send(new DragMsg_SourceEnded(GetRoutingID(), | 665 Send(new DragMsg_SourceEnded(GetRoutingID(), |
| 688 gfx::Point(client_x, client_y), | 666 gfx::Point(client_x, client_y), |
| 689 gfx::Point(screen_x, screen_y), | 667 gfx::Point(screen_x, screen_y), |
| 690 operation)); | 668 operation)); |
| 691 } | 669 } |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 weak_factory_.GetWeakPtr())); | 1298 weak_factory_.GetWeakPtr())); |
| 1321 } else { | 1299 } else { |
| 1322 render_view_ready_on_process_launch_ = true; | 1300 render_view_ready_on_process_launch_ = true; |
| 1323 } | 1301 } |
| 1324 } | 1302 } |
| 1325 | 1303 |
| 1326 void RenderViewHostImpl::RenderViewReady() { | 1304 void RenderViewHostImpl::RenderViewReady() { |
| 1327 delegate_->RenderViewReady(this); | 1305 delegate_->RenderViewReady(this); |
| 1328 } | 1306 } |
| 1329 | 1307 |
| 1308 void RenderViewHostImpl::GrantFileAccessFromDropData(DropData* drop_data) { |
| 1309 DCHECK_EQ(GetRoutingID(), drop_data->view_id); |
| 1310 const int renderer_id = GetProcess()->GetID(); |
| 1311 ChildProcessSecurityPolicyImpl* policy = |
| 1312 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 1313 |
| 1314 #if defined(OS_CHROMEOS) |
| 1315 // The externalfile:// scheme is used in Chrome OS to open external files in a |
| 1316 // browser tab. |
| 1317 if (drop_data->url.SchemeIs(content::kExternalFileScheme)) |
| 1318 policy->GrantRequestURL(renderer_id, drop_data->url); |
| 1319 #endif |
| 1320 |
| 1321 // The filenames vector represents a capability to access the given files. |
| 1322 storage::IsolatedContext::FileInfoSet files; |
| 1323 for (auto& filename : drop_data->filenames) { |
| 1324 // Make sure we have the same display_name as the one we register. |
| 1325 if (filename.display_name.empty()) { |
| 1326 std::string name; |
| 1327 files.AddPath(filename.path, &name); |
| 1328 filename.display_name = base::FilePath::FromUTF8Unsafe(name); |
| 1329 } else { |
| 1330 files.AddPathWithName(filename.path, |
| 1331 filename.display_name.AsUTF8Unsafe()); |
| 1332 } |
| 1333 // A dragged file may wind up as the value of an input element, or it |
| 1334 // may be used as the target of a navigation instead. We don't know |
| 1335 // which will happen at this point, so generously grant both access |
| 1336 // and request permissions to the specific file to cover both cases. |
| 1337 // We do not give it the permission to request all file:// URLs. |
| 1338 policy->GrantRequestSpecificFileURL(renderer_id, |
| 1339 net::FilePathToFileURL(filename.path)); |
| 1340 |
| 1341 // If the renderer already has permission to read these paths, we don't need |
| 1342 // to re-grant them. This prevents problems with DnD for files in the CrOS |
| 1343 // file manager--the file manager already had read/write access to those |
| 1344 // directories, but dragging a file would cause the read/write access to be |
| 1345 // overwritten with read-only access, making them impossible to delete or |
| 1346 // rename until the renderer was killed. |
| 1347 if (!policy->CanReadFile(renderer_id, filename.path)) |
| 1348 policy->GrantReadFile(renderer_id, filename.path); |
| 1349 } |
| 1350 |
| 1351 storage::IsolatedContext* isolated_context = |
| 1352 storage::IsolatedContext::GetInstance(); |
| 1353 DCHECK(isolated_context); |
| 1354 |
| 1355 if (!files.fileset().empty()) { |
| 1356 std::string filesystem_id = |
| 1357 isolated_context->RegisterDraggedFileSystem(files); |
| 1358 if (!filesystem_id.empty()) { |
| 1359 // Grant the permission iff the ID is valid. |
| 1360 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| 1361 } |
| 1362 drop_data->filesystem_id = base::UTF8ToUTF16(filesystem_id); |
| 1363 } |
| 1364 |
| 1365 storage::FileSystemContext* file_system_context = |
| 1366 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(), |
| 1367 GetSiteInstance()) |
| 1368 ->GetFileSystemContext(); |
| 1369 for (auto& file_system_file : drop_data->file_system_files) { |
| 1370 storage::FileSystemURL file_system_url = |
| 1371 file_system_context->CrackURL(file_system_file.url); |
| 1372 |
| 1373 std::string register_name; |
| 1374 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( |
| 1375 file_system_url.type(), file_system_url.filesystem_id(), |
| 1376 file_system_url.path(), ®ister_name); |
| 1377 |
| 1378 if (!filesystem_id.empty()) { |
| 1379 // Grant the permission iff the ID is valid. |
| 1380 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| 1381 } |
| 1382 |
| 1383 // Note: We are using the origin URL provided by the sender here. It may be |
| 1384 // different from the receiver's. |
| 1385 file_system_file.url = |
| 1386 GURL(storage::GetIsolatedFileSystemRootURIString( |
| 1387 file_system_url.origin(), filesystem_id, std::string()) |
| 1388 .append(register_name)); |
| 1389 } |
| 1390 } |
| 1391 |
| 1330 } // namespace content | 1392 } // namespace content |
| OLD | NEW |