Chromium Code Reviews| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 gfx::win::GetSystemMetricsInDIP(SM_CXVSCROLL); | 158 gfx::win::GetSystemMetricsInDIP(SM_CXVSCROLL); |
| 158 prefs->horizontal_scroll_bar_height_in_dips = | 159 prefs->horizontal_scroll_bar_height_in_dips = |
| 159 gfx::win::GetSystemMetricsInDIP(SM_CYHSCROLL); | 160 gfx::win::GetSystemMetricsInDIP(SM_CYHSCROLL); |
| 160 prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips = | 161 prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips = |
| 161 gfx::win::GetSystemMetricsInDIP(SM_CYVSCROLL); | 162 gfx::win::GetSystemMetricsInDIP(SM_CYVSCROLL); |
| 162 prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips = | 163 prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips = |
| 163 gfx::win::GetSystemMetricsInDIP(SM_CXHSCROLL); | 164 gfx::win::GetSystemMetricsInDIP(SM_CXHSCROLL); |
| 164 } | 165 } |
| 165 #endif | 166 #endif |
| 166 | 167 |
| 168 void DropDataToMetaData(const DropData& drop_data, | |
| 169 std::vector<MimeTypeKindPair>& meta_data) { | |
| 170 base::string16 string_kind = base::ASCIIToUTF16("string"); | |
| 171 base::string16 filename_kind = base::ASCIIToUTF16("filename"); | |
| 172 base::string16 filesystemfile_kind = base::ASCIIToUTF16("filesystemfile"); | |
| 173 if (!drop_data.text.is_null()) { | |
| 174 MimeTypeKindPair pair = std::make_pair( | |
| 175 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeText), string_kind); | |
| 176 meta_data.push_back(pair); | |
| 177 } | |
| 178 | |
| 179 if (!drop_data.url.is_empty()) { | |
| 180 MimeTypeKindPair pair = std::make_pair( | |
| 181 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeURIList), string_kind); | |
| 182 meta_data.push_back(pair); | |
| 183 } | |
| 184 | |
| 185 if (!drop_data.html.is_null()) { | |
| 186 MimeTypeKindPair pair = std::make_pair( | |
| 187 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeHTML), string_kind); | |
| 188 meta_data.push_back(pair); | |
| 189 } | |
| 190 | |
| 191 for (std::vector<ui::FileInfo>::const_iterator it = | |
| 192 drop_data.filenames.begin(); | |
| 193 it != drop_data.filenames.end(); ++it) { | |
| 194 if (!it->path.empty()) { | |
| 195 MimeTypeKindPair pair = std::make_pair(base::string16(), filename_kind); | |
| 196 meta_data.push_back(pair); | |
| 197 } | |
| 198 } | |
| 199 | |
| 200 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it = | |
| 201 drop_data.file_system_files.begin(); | |
| 202 it != drop_data.file_system_files.end(); ++it) { | |
| 203 if (!it->url.is_empty()) { | |
| 204 MimeTypeKindPair pair = | |
| 205 std::make_pair(base::string16(), filesystemfile_kind); | |
| 206 meta_data.push_back(pair); | |
| 207 } | |
| 208 } | |
| 209 | |
| 210 for (std::map<base::string16, base::string16>::const_iterator it = | |
| 211 drop_data.custom_data.begin(); | |
| 212 it != drop_data.custom_data.end(); ++it) { | |
| 213 MimeTypeKindPair pair = std::make_pair(it->first, string_kind); | |
| 214 meta_data.push_back(pair); | |
| 215 } | |
|
Avi (use Gerrit)
2016/04/08 21:24:08
For these three loops, you easily could do |for (c
hush (inactive)
2016/04/12 00:07:49
Done. This is definitely better with the new synta
| |
| 216 } | |
| 217 | |
| 167 } // namespace | 218 } // namespace |
| 168 | 219 |
| 169 // static | 220 // static |
| 170 const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000; | 221 const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000; |
| 171 | 222 |
| 172 /////////////////////////////////////////////////////////////////////////////// | 223 /////////////////////////////////////////////////////////////////////////////// |
| 173 // RenderViewHost, public: | 224 // RenderViewHost, public: |
| 174 | 225 |
| 175 // static | 226 // static |
| 176 RenderViewHost* RenderViewHost::FromID(int render_process_id, | 227 RenderViewHost* RenderViewHost::FromID(int render_process_id, |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 GetWidget()->RendererExited(status, exit_code); | 637 GetWidget()->RendererExited(status, exit_code); |
| 587 delegate_->RenderViewTerminated(this, status, exit_code); | 638 delegate_->RenderViewTerminated(this, status, exit_code); |
| 588 } | 639 } |
| 589 | 640 |
| 590 void RenderViewHostImpl::DragTargetDragEnter( | 641 void RenderViewHostImpl::DragTargetDragEnter( |
| 591 const DropData& drop_data, | 642 const DropData& drop_data, |
| 592 const gfx::Point& client_pt, | 643 const gfx::Point& client_pt, |
| 593 const gfx::Point& screen_pt, | 644 const gfx::Point& screen_pt, |
| 594 WebDragOperationsMask operations_allowed, | 645 WebDragOperationsMask operations_allowed, |
| 595 int key_modifiers) { | 646 int key_modifiers) { |
| 647 #if defined(OS_CHROMEOS) | |
| 596 const int renderer_id = GetProcess()->GetID(); | 648 const int renderer_id = GetProcess()->GetID(); |
| 597 ChildProcessSecurityPolicyImpl* policy = | 649 ChildProcessSecurityPolicyImpl* policy = |
| 598 ChildProcessSecurityPolicyImpl::GetInstance(); | 650 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 599 | 651 |
| 600 #if defined(OS_CHROMEOS) | |
| 601 // The externalfile:// scheme is used in Chrome OS to open external files in a | 652 // The externalfile:// scheme is used in Chrome OS to open external files in a |
| 602 // browser tab. | 653 // browser tab. |
| 603 if (drop_data.url.SchemeIs(content::kExternalFileScheme)) | 654 if (drop_data.url.SchemeIs(content::kExternalFileScheme)) |
| 604 policy->GrantRequestURL(renderer_id, drop_data.url); | 655 policy->GrantRequestURL(renderer_id, drop_data.url); |
| 605 #endif | 656 #endif |
| 606 | 657 |
| 607 // The URL could have been cobbled together from any highlighted text string, | 658 // The URL could have been cobbled together from any highlighted text string, |
| 608 // and can't be interpreted as a capability. | 659 // and can't be interpreted as a capability. |
| 609 DropData filtered_data(drop_data); | 660 DropData filtered_data(drop_data); |
| 610 GetProcess()->FilterURL(true, &filtered_data.url); | 661 FilterDropData(filtered_data); |
| 611 if (drop_data.did_originate_from_renderer) { | |
| 612 filtered_data.filenames.clear(); | |
| 613 } | |
| 614 | 662 |
| 615 // The filenames vector, on the other hand, does represent a capability to | 663 std::vector<MimeTypeKindPair> meta_data; |
| 616 // access the given files. | 664 DropDataToMetaData(filtered_data, meta_data); |
| 617 storage::IsolatedContext::FileInfoSet files; | 665 Send(new DragMsg_TargetDragEnter(GetRoutingID(), meta_data, client_pt, |
| 618 for (std::vector<ui::FileInfo>::iterator iter( | |
| 619 filtered_data.filenames.begin()); | |
| 620 iter != filtered_data.filenames.end(); | |
| 621 ++iter) { | |
| 622 // A dragged file may wind up as the value of an input element, or it | |
| 623 // may be used as the target of a navigation instead. We don't know | |
| 624 // which will happen at this point, so generously grant both access | |
| 625 // and request permissions to the specific file to cover both cases. | |
| 626 // We do not give it the permission to request all file:// URLs. | |
| 627 | |
| 628 // Make sure we have the same display_name as the one we register. | |
| 629 if (iter->display_name.empty()) { | |
| 630 std::string name; | |
| 631 files.AddPath(iter->path, &name); | |
| 632 iter->display_name = base::FilePath::FromUTF8Unsafe(name); | |
| 633 } else { | |
| 634 files.AddPathWithName(iter->path, iter->display_name.AsUTF8Unsafe()); | |
| 635 } | |
| 636 | |
| 637 policy->GrantRequestSpecificFileURL(renderer_id, | |
| 638 net::FilePathToFileURL(iter->path)); | |
| 639 | |
| 640 // If the renderer already has permission to read these paths, we don't need | |
| 641 // to re-grant them. This prevents problems with DnD for files in the CrOS | |
| 642 // file manager--the file manager already had read/write access to those | |
| 643 // directories, but dragging a file would cause the read/write access to be | |
| 644 // overwritten with read-only access, making them impossible to delete or | |
| 645 // rename until the renderer was killed. | |
| 646 if (!policy->CanReadFile(renderer_id, iter->path)) | |
| 647 policy->GrantReadFile(renderer_id, iter->path); | |
| 648 } | |
| 649 | |
| 650 storage::IsolatedContext* isolated_context = | |
| 651 storage::IsolatedContext::GetInstance(); | |
| 652 DCHECK(isolated_context); | |
| 653 std::string filesystem_id = isolated_context->RegisterDraggedFileSystem( | |
| 654 files); | |
| 655 if (!filesystem_id.empty()) { | |
| 656 // Grant the permission iff the ID is valid. | |
| 657 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 658 } | |
| 659 filtered_data.filesystem_id = base::UTF8ToUTF16(filesystem_id); | |
| 660 | |
| 661 storage::FileSystemContext* file_system_context = | |
| 662 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(), | |
| 663 GetSiteInstance()) | |
| 664 ->GetFileSystemContext(); | |
| 665 for (size_t i = 0; i < filtered_data.file_system_files.size(); ++i) { | |
| 666 storage::FileSystemURL file_system_url = | |
| 667 file_system_context->CrackURL(filtered_data.file_system_files[i].url); | |
| 668 | |
| 669 std::string register_name; | |
| 670 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( | |
| 671 file_system_url.type(), file_system_url.filesystem_id(), | |
| 672 file_system_url.path(), ®ister_name); | |
| 673 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 674 | |
| 675 // Note: We are using the origin URL provided by the sender here. It may be | |
| 676 // different from the receiver's. | |
| 677 filtered_data.file_system_files[i].url = | |
| 678 GURL(storage::GetIsolatedFileSystemRootURIString( | |
| 679 file_system_url.origin(), filesystem_id, std::string()) | |
| 680 .append(register_name)); | |
| 681 } | |
| 682 | |
| 683 Send(new DragMsg_TargetDragEnter(GetRoutingID(), filtered_data, client_pt, | |
| 684 screen_pt, operations_allowed, | 666 screen_pt, operations_allowed, |
| 685 key_modifiers)); | 667 key_modifiers)); |
| 686 } | 668 } |
| 687 | 669 |
| 688 void RenderViewHostImpl::DragTargetDragOver( | 670 void RenderViewHostImpl::DragTargetDragOver( |
| 689 const gfx::Point& client_pt, | 671 const gfx::Point& client_pt, |
| 690 const gfx::Point& screen_pt, | 672 const gfx::Point& screen_pt, |
| 691 WebDragOperationsMask operations_allowed, | 673 WebDragOperationsMask operations_allowed, |
| 692 int key_modifiers) { | 674 int key_modifiers) { |
| 693 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt, | 675 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt, |
| 694 operations_allowed, key_modifiers)); | 676 operations_allowed, key_modifiers)); |
| 695 } | 677 } |
| 696 | 678 |
| 697 void RenderViewHostImpl::DragTargetDragLeave() { | 679 void RenderViewHostImpl::DragTargetDragLeave() { |
| 698 Send(new DragMsg_TargetDragLeave(GetRoutingID())); | 680 Send(new DragMsg_TargetDragLeave(GetRoutingID())); |
| 699 } | 681 } |
| 700 | 682 |
| 701 void RenderViewHostImpl::DragTargetDrop( | 683 void RenderViewHostImpl::DragTargetDrop(const DropData& drop_data, |
| 702 const gfx::Point& client_pt, | 684 const gfx::Point& client_pt, |
| 703 const gfx::Point& screen_pt, | 685 const gfx::Point& screen_pt, |
| 704 int key_modifiers) { | 686 int key_modifiers) { |
| 705 Send(new DragMsg_TargetDrop(GetRoutingID(), client_pt, screen_pt, | 687 DropData filtered_data(drop_data); |
| 706 key_modifiers)); | 688 FilterDropData(filtered_data); |
| 689 Send(new DragMsg_TargetDrop(GetRoutingID(), filtered_data, client_pt, | |
| 690 screen_pt, key_modifiers)); | |
| 707 } | 691 } |
| 708 | 692 |
| 709 void RenderViewHostImpl::DragSourceEndedAt( | 693 void RenderViewHostImpl::DragSourceEndedAt( |
| 710 int client_x, int client_y, int screen_x, int screen_y, | 694 int client_x, int client_y, int screen_x, int screen_y, |
| 711 WebDragOperation operation) { | 695 WebDragOperation operation) { |
| 712 Send(new DragMsg_SourceEnded(GetRoutingID(), | 696 Send(new DragMsg_SourceEnded(GetRoutingID(), |
| 713 gfx::Point(client_x, client_y), | 697 gfx::Point(client_x, client_y), |
| 714 gfx::Point(screen_x, screen_y), | 698 gfx::Point(screen_x, screen_y), |
| 715 operation)); | 699 operation)); |
| 716 } | 700 } |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1350 weak_factory_.GetWeakPtr())); | 1334 weak_factory_.GetWeakPtr())); |
| 1351 } else { | 1335 } else { |
| 1352 render_view_ready_on_process_launch_ = true; | 1336 render_view_ready_on_process_launch_ = true; |
| 1353 } | 1337 } |
| 1354 } | 1338 } |
| 1355 | 1339 |
| 1356 void RenderViewHostImpl::RenderViewReady() { | 1340 void RenderViewHostImpl::RenderViewReady() { |
| 1357 delegate_->RenderViewReady(this); | 1341 delegate_->RenderViewReady(this); |
| 1358 } | 1342 } |
| 1359 | 1343 |
| 1344 void RenderViewHostImpl::FilterDropData(DropData& filtered_data) { | |
| 1345 const int renderer_id = GetProcess()->GetID(); | |
| 1346 ChildProcessSecurityPolicyImpl* policy = | |
| 1347 ChildProcessSecurityPolicyImpl::GetInstance(); | |
| 1348 | |
| 1349 GetProcess()->FilterURL(true, &filtered_data.url); | |
| 1350 if (filtered_data.did_originate_from_renderer) { | |
| 1351 filtered_data.filenames.clear(); | |
| 1352 } | |
| 1353 | |
| 1354 // The filenames vector, on the other hand, does represent a capability to | |
| 1355 // access the given files. | |
| 1356 storage::IsolatedContext::FileInfoSet files; | |
| 1357 for (std::vector<ui::FileInfo>::iterator iter( | |
| 1358 filtered_data.filenames.begin()); | |
| 1359 iter != filtered_data.filenames.end(); ++iter) { | |
|
Avi (use Gerrit)
2016/04/08 21:24:08
Prefer |for (:)| syntax; it's cleaner and easier t
hush (inactive)
2016/04/12 00:07:49
done
| |
| 1360 // A dragged file may wind up as the value of an input element, or it | |
| 1361 // may be used as the target of a navigation instead. We don't know | |
| 1362 // which will happen at this point, so generously grant both access | |
| 1363 // and request permissions to the specific file to cover both cases. | |
| 1364 // We do not give it the permission to request all file:// URLs. | |
| 1365 | |
| 1366 // Make sure we have the same display_name as the one we register. | |
| 1367 if (iter->display_name.empty()) { | |
| 1368 std::string name; | |
| 1369 files.AddPath(iter->path, &name); | |
| 1370 iter->display_name = base::FilePath::FromUTF8Unsafe(name); | |
| 1371 } else { | |
| 1372 files.AddPathWithName(iter->path, iter->display_name.AsUTF8Unsafe()); | |
| 1373 } | |
| 1374 | |
| 1375 policy->GrantRequestSpecificFileURL(renderer_id, | |
| 1376 net::FilePathToFileURL(iter->path)); | |
| 1377 | |
| 1378 // If the renderer already has permission to read these paths, we don't need | |
| 1379 // to re-grant them. This prevents problems with DnD for files in the CrOS | |
| 1380 // file manager--the file manager already had read/write access to those | |
| 1381 // directories, but dragging a file would cause the read/write access to be | |
| 1382 // overwritten with read-only access, making them impossible to delete or | |
| 1383 // rename until the renderer was killed. | |
| 1384 if (!policy->CanReadFile(renderer_id, iter->path)) | |
| 1385 policy->GrantReadFile(renderer_id, iter->path); | |
| 1386 } | |
| 1387 | |
| 1388 storage::IsolatedContext* isolated_context = | |
| 1389 storage::IsolatedContext::GetInstance(); | |
| 1390 DCHECK(isolated_context); | |
| 1391 std::string filesystem_id = | |
| 1392 isolated_context->RegisterDraggedFileSystem(files); | |
| 1393 if (!filesystem_id.empty()) { | |
| 1394 // Grant the permission iff the ID is valid. | |
| 1395 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 1396 } | |
| 1397 filtered_data.filesystem_id = base::UTF8ToUTF16(filesystem_id); | |
| 1398 | |
| 1399 storage::FileSystemContext* file_system_context = | |
| 1400 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(), | |
| 1401 GetSiteInstance()) | |
| 1402 ->GetFileSystemContext(); | |
| 1403 for (size_t i = 0; i < filtered_data.file_system_files.size(); ++i) { | |
| 1404 storage::FileSystemURL file_system_url = | |
| 1405 file_system_context->CrackURL(filtered_data.file_system_files[i].url); | |
| 1406 | |
| 1407 std::string register_name; | |
| 1408 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( | |
| 1409 file_system_url.type(), file_system_url.filesystem_id(), | |
| 1410 file_system_url.path(), ®ister_name); | |
| 1411 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 1412 | |
| 1413 // Note: We are using the origin URL provided by the sender here. It may be | |
| 1414 // different from the receiver's. | |
| 1415 filtered_data.file_system_files[i].url = | |
| 1416 GURL(storage::GetIsolatedFileSystemRootURIString( | |
| 1417 file_system_url.origin(), filesystem_id, std::string()) | |
| 1418 .append(register_name)); | |
| 1419 } | |
| 1420 } | |
| 1421 | |
| 1360 } // namespace content | 1422 } // namespace content |
| OLD | NEW |