Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/devtools/renderer_overrides_handler.h" | 5 #include "content/browser/devtools/renderer_overrides_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/barrier_closure.h" | |
| 9 #include "base/base64.h" | 10 #include "base/base64.h" |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "content/browser/child_process_security_policy_impl.h" | 16 #include "content/browser/child_process_security_policy_impl.h" |
| 16 #include "content/browser/devtools/devtools_protocol_constants.h" | 17 #include "content/browser/devtools/devtools_protocol_constants.h" |
| 17 #include "content/browser/devtools/devtools_tracing_handler.h" | 18 #include "content/browser/devtools/devtools_tracing_handler.h" |
| 18 #include "content/browser/renderer_host/dip_util.h" | 19 #include "content/browser/renderer_host/dip_util.h" |
| 19 #include "content/browser/renderer_host/render_view_host_delegate.h" | 20 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 20 #include "content/browser/renderer_host/render_view_host_impl.h" | 21 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 21 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
| 22 #include "content/port/browser/render_widget_host_view_port.h" | 23 #include "content/port/browser/render_widget_host_view_port.h" |
| 23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/devtools_agent_host.h" | 25 #include "content/public/browser/devtools_agent_host.h" |
| 25 #include "content/public/browser/javascript_dialog_manager.h" | 26 #include "content/public/browser/javascript_dialog_manager.h" |
| 26 #include "content/public/browser/navigation_controller.h" | 27 #include "content/public/browser/navigation_controller.h" |
| 27 #include "content/public/browser/navigation_entry.h" | 28 #include "content/public/browser/navigation_entry.h" |
| 28 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" |
| 29 #include "content/public/browser/render_view_host.h" | 30 #include "content/public/browser/render_view_host.h" |
| 30 #include "content/public/browser/render_widget_host_view.h" | 31 #include "content/public/browser/render_widget_host_view.h" |
| 32 #include "content/public/browser/storage_partition.h" | |
| 31 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 32 #include "content/public/browser/web_contents_delegate.h" | 34 #include "content/public/browser/web_contents_delegate.h" |
| 33 #include "content/public/common/page_transition_types.h" | 35 #include "content/public/common/page_transition_types.h" |
| 34 #include "content/public/common/referrer.h" | 36 #include "content/public/common/referrer.h" |
| 35 #include "ipc/ipc_sender.h" | 37 #include "ipc/ipc_sender.h" |
| 38 #include "net/base/net_util.h" | |
| 36 #include "third_party/WebKit/public/web/WebInputEvent.h" | 39 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 37 #include "ui/gfx/codec/jpeg_codec.h" | 40 #include "ui/gfx/codec/jpeg_codec.h" |
| 38 #include "ui/gfx/codec/png_codec.h" | 41 #include "ui/gfx/codec/png_codec.h" |
| 39 #include "ui/gfx/size_conversions.h" | 42 #include "ui/gfx/size_conversions.h" |
| 40 #include "ui/snapshot/snapshot.h" | 43 #include "ui/snapshot/snapshot.h" |
| 41 #include "url/gurl.h" | 44 #include "url/gurl.h" |
| 45 #include "webkit/browser/quota/quota_manager.h" | |
| 42 | 46 |
| 43 using WebKit::WebGestureEvent; | 47 using WebKit::WebGestureEvent; |
| 44 using WebKit::WebInputEvent; | 48 using WebKit::WebInputEvent; |
| 45 using WebKit::WebMouseEvent; | 49 using WebKit::WebMouseEvent; |
| 46 | 50 |
| 47 namespace content { | 51 namespace content { |
| 48 | 52 |
| 49 namespace { | 53 namespace { |
| 50 | 54 |
| 51 static const char kPng[] = "png"; | 55 static const char kPng[] = "png"; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 devtools::Page::startScreencast::kName, | 119 devtools::Page::startScreencast::kName, |
| 116 base::Bind( | 120 base::Bind( |
| 117 &RendererOverridesHandler::PageStartScreencast, | 121 &RendererOverridesHandler::PageStartScreencast, |
| 118 base::Unretained(this))); | 122 base::Unretained(this))); |
| 119 RegisterCommandHandler( | 123 RegisterCommandHandler( |
| 120 devtools::Page::stopScreencast::kName, | 124 devtools::Page::stopScreencast::kName, |
| 121 base::Bind( | 125 base::Bind( |
| 122 &RendererOverridesHandler::PageStopScreencast, | 126 &RendererOverridesHandler::PageStopScreencast, |
| 123 base::Unretained(this))); | 127 base::Unretained(this))); |
| 124 RegisterCommandHandler( | 128 RegisterCommandHandler( |
| 129 devtools::Page::queryUsageAndQuota::kName, | |
| 130 base::Bind( | |
| 131 &RendererOverridesHandler::PageQueryUsageAndQuota, | |
| 132 base::Unretained(this))); | |
| 133 RegisterCommandHandler( | |
| 125 devtools::Input::dispatchMouseEvent::kName, | 134 devtools::Input::dispatchMouseEvent::kName, |
| 126 base::Bind( | 135 base::Bind( |
| 127 &RendererOverridesHandler::InputDispatchMouseEvent, | 136 &RendererOverridesHandler::InputDispatchMouseEvent, |
| 128 base::Unretained(this))); | 137 base::Unretained(this))); |
| 129 RegisterCommandHandler( | 138 RegisterCommandHandler( |
| 130 devtools::Input::dispatchGestureEvent::kName, | 139 devtools::Input::dispatchGestureEvent::kName, |
| 131 base::Bind( | 140 base::Bind( |
| 132 &RendererOverridesHandler::InputDispatchGestureEvent, | 141 &RendererOverridesHandler::InputDispatchGestureEvent, |
| 133 base::Unretained(this))); | 142 base::Unretained(this))); |
| 134 } | 143 } |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 response->Set(devtools::Page::kParamViewport, viewport); | 527 response->Set(devtools::Page::kParamViewport, viewport); |
| 519 } | 528 } |
| 520 | 529 |
| 521 if (command) { | 530 if (command) { |
| 522 SendAsyncResponse(command->SuccessResponse(response)); | 531 SendAsyncResponse(command->SuccessResponse(response)); |
| 523 } else { | 532 } else { |
| 524 SendNotification(devtools::Page::screencastFrame::kName, response); | 533 SendNotification(devtools::Page::screencastFrame::kName, response); |
| 525 } | 534 } |
| 526 } | 535 } |
| 527 | 536 |
| 537 // Quota and Usage ------------------------------------------ | |
| 538 | |
| 539 namespace { | |
| 540 | |
| 541 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> | |
| 542 ResponseCallback; | |
| 543 | |
| 544 void QueryUsageAndQuotaCompletedOnIOThread( | |
| 545 base::DictionaryValue* usage, | |
| 546 base::DictionaryValue* quota, | |
| 547 ResponseCallback callback) { | |
| 548 | |
| 549 scoped_ptr<base::DictionaryValue> response_data(new base::DictionaryValue); | |
| 550 response_data->Set("usage", usage->DeepCopy()); | |
| 551 response_data->Set("quota", quota->DeepCopy()); | |
| 552 | |
| 553 BrowserThread::PostTask( | |
| 554 BrowserThread::UI, FROM_HERE, | |
| 555 base::Bind(callback, base::Passed(&response_data))); | |
| 556 } | |
| 557 | |
| 558 void DidGetHostUsage( | |
| 559 base::DictionaryValue* dictionary, | |
| 560 const char* item_name, | |
| 561 const base::Closure& barrier, | |
| 562 int64 value) { | |
| 563 dictionary->SetDouble(item_name, value); | |
| 564 barrier.Run(); | |
| 565 } | |
| 566 | |
| 567 void DidGetQuotaValue( | |
| 568 base::DictionaryValue* dictionary, | |
| 569 const char* item_name, | |
| 570 const base::Closure& barrier, | |
| 571 quota::QuotaStatusCode status, | |
| 572 int64 value) { | |
| 573 if (status == quota::kQuotaStatusOk) | |
| 574 dictionary->SetDouble(item_name, value); | |
| 575 barrier.Run(); | |
| 576 } | |
| 577 | |
| 578 void DidGetUsageAndQuotaForWebApps( | |
| 579 base::DictionaryValue* quota, | |
| 580 const char* item_name, | |
| 581 const base::Closure& barrier, | |
| 582 quota::QuotaStatusCode status, | |
| 583 int64 used_bytes, | |
| 584 int64 quota_in_bytes) { | |
| 585 if (status == quota::kQuotaStatusOk) | |
| 586 quota->SetDouble(item_name, quota_in_bytes); | |
| 587 barrier.Run(); | |
| 588 } | |
| 589 | |
| 590 void QueryUsageAndQuotaOnIOThread( | |
| 591 scoped_refptr<quota::QuotaManager> quota_manager, | |
| 592 const GURL& security_origin, | |
| 593 const ResponseCallback& callback) { | |
| 594 base::DictionaryValue* usage = new base::DictionaryValue; | |
| 595 base::DictionaryValue* quota = new base::DictionaryValue; | |
| 596 | |
| 597 static const int kExpectedResults = 9; | |
| 598 | |
| 599 base::Closure barrier = BarrierClosure( | |
| 600 kExpectedResults, | |
| 601 base::Bind(&QueryUsageAndQuotaCompletedOnIOThread, | |
| 602 base::Owned(usage), | |
|
pfeldman
2013/09/19 15:15:34
Then you could remove base::Owned and get rid of t
SeRya
2013/09/19 17:24:52
Done.
| |
| 603 base::Owned(quota), | |
| 604 callback)); | |
| 605 std::string host = net::GetHostOrSpecFromURL(security_origin); | |
| 606 | |
| 607 quota_manager->GetAvailableSpace( | |
| 608 base::Bind(&DidGetQuotaValue, quota, "availableSpace", barrier)); | |
| 609 | |
| 610 quota_manager->GetUsageAndQuotaForWebApps( | |
| 611 security_origin, | |
| 612 quota::kStorageTypeTemporary, | |
| 613 base::Bind(&DidGetUsageAndQuotaForWebApps, quota, | |
| 614 "temporaryHostQuota", barrier)); | |
| 615 | |
| 616 quota_manager->GetPersistentHostQuota( | |
| 617 host, | |
| 618 base::Bind(&DidGetQuotaValue, quota, "persistentHostQuota", barrier)); | |
| 619 | |
| 620 quota_manager->GetHostUsage(host, quota::kStorageTypeTemporary, | |
| 621 quota::QuotaClient::kFileSystem, | |
| 622 base::Bind(&DidGetHostUsage, usage, | |
| 623 "temporaryFileSystemUsage", | |
|
pfeldman
2013/09/19 15:15:34
Could you share a protocol.json? If it mentions th
SeRya
2013/09/19 17:24:52
https://codereview.chromium.org/23264011/diff/4001
| |
| 624 barrier)); | |
| 625 | |
| 626 quota_manager->GetHostUsage(host, quota::kStorageTypePersistent, | |
| 627 quota::QuotaClient::kFileSystem, | |
| 628 base::Bind(&DidGetHostUsage, usage, | |
| 629 "persistentFileSystemUsage", | |
| 630 barrier)); | |
| 631 | |
| 632 quota_manager->GetHostUsage(host, quota::kStorageTypeSyncable, | |
| 633 quota::QuotaClient::kFileSystem, | |
| 634 base::Bind(&DidGetHostUsage, usage, | |
| 635 "syncableFileSystemUsage", | |
| 636 barrier)); | |
| 637 | |
| 638 quota_manager->GetHostUsage(host, quota::kStorageTypeTemporary, | |
| 639 quota::QuotaClient::kDatabase, | |
| 640 base::Bind(&DidGetHostUsage, usage, | |
| 641 "databaseUsage", | |
| 642 barrier)); | |
| 643 | |
| 644 quota_manager->GetHostUsage(host, quota::kStorageTypeTemporary, | |
| 645 quota::QuotaClient::kAppcache, | |
| 646 base::Bind(&DidGetHostUsage, usage, | |
| 647 "appcacheUsage", | |
| 648 barrier)); | |
| 649 | |
| 650 quota_manager->GetHostUsage(host, quota::kStorageTypeTemporary, | |
| 651 quota::QuotaClient::kIndexedDatabase, | |
| 652 base::Bind(&DidGetHostUsage, usage, | |
| 653 "indexedDatabaseUsage", | |
| 654 barrier)); | |
| 655 } | |
| 656 | |
| 657 } // namespace | |
| 658 | |
| 659 scoped_refptr<DevToolsProtocol::Response> | |
| 660 RendererOverridesHandler::PageQueryUsageAndQuota( | |
| 661 scoped_refptr<DevToolsProtocol::Command> command) { | |
| 662 base::DictionaryValue* params = command->params(); | |
| 663 std::string security_origin; | |
| 664 if (!params || !params->GetString( | |
| 665 devtools::Page::queryUsageAndQuota::kParamSecurityOrigin, | |
| 666 &security_origin)) { | |
| 667 return command->InvalidParamResponse( | |
| 668 devtools::Page::queryUsageAndQuota::kParamSecurityOrigin); | |
| 669 } | |
| 670 | |
| 671 ResponseCallback callback = base::Bind( | |
| 672 &RendererOverridesHandler::PageQueryUsageAndQuotaCompleted, | |
| 673 weak_factory_.GetWeakPtr(), | |
| 674 command); | |
| 675 | |
| 676 scoped_refptr<quota::QuotaManager> quota_manager = | |
| 677 agent_->GetRenderViewHost()->GetProcess()-> | |
| 678 GetStoragePartition()->GetQuotaManager(); | |
| 679 | |
| 680 BrowserThread::PostTask( | |
| 681 BrowserThread::IO, FROM_HERE, | |
| 682 base::Bind( | |
| 683 &QueryUsageAndQuotaOnIOThread, | |
| 684 quota_manager, | |
| 685 GURL(security_origin), | |
| 686 callback)); | |
| 687 | |
| 688 return command->AsyncResponsePromise(); | |
| 689 } | |
| 690 | |
| 691 void RendererOverridesHandler::PageQueryUsageAndQuotaCompleted( | |
| 692 scoped_refptr<DevToolsProtocol::Command> command, | |
| 693 scoped_ptr<base::DictionaryValue> response_data) { | |
| 694 SendAsyncResponse(command->SuccessResponse(response_data.release())); | |
| 695 } | |
| 528 | 696 |
| 529 // Input agent handlers ------------------------------------------------------ | 697 // Input agent handlers ------------------------------------------------------ |
| 530 | 698 |
| 531 scoped_refptr<DevToolsProtocol::Response> | 699 scoped_refptr<DevToolsProtocol::Response> |
| 532 RendererOverridesHandler::InputDispatchMouseEvent( | 700 RendererOverridesHandler::InputDispatchMouseEvent( |
| 533 scoped_refptr<DevToolsProtocol::Command> command) { | 701 scoped_refptr<DevToolsProtocol::Command> command) { |
| 534 base::DictionaryValue* params = command->params(); | 702 base::DictionaryValue* params = command->params(); |
| 535 if (!params) | 703 if (!params) |
| 536 return NULL; | 704 return NULL; |
| 537 | 705 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 return NULL; | 832 return NULL; |
| 665 } | 833 } |
| 666 event.data.pinchUpdate.scale = static_cast<float>(scale); | 834 event.data.pinchUpdate.scale = static_cast<float>(scale); |
| 667 } | 835 } |
| 668 | 836 |
| 669 host->ForwardGestureEvent(event); | 837 host->ForwardGestureEvent(event); |
| 670 return command->SuccessResponse(NULL); | 838 return command->SuccessResponse(NULL); |
| 671 } | 839 } |
| 672 | 840 |
| 673 } // namespace content | 841 } // namespace content |
| OLD | NEW |