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 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> | |
540 ResponseCallback; | |
541 | |
542 static void QueryAndUsageQuotaCompletedOnIOThread( | |
pfeldman
2013/09/19 12:35:49
QueryUsageAndQuotaCompletedOnIOThread
pfeldman
2013/09/19 12:35:49
Please move into anonymous namespace.
SeRya
2013/09/19 14:54:24
Done.
SeRya
2013/09/19 14:54:24
Done.
| |
543 base::DictionaryValue* usage, | |
544 base::DictionaryValue* quota, | |
545 ResponseCallback callback) { | |
546 | |
547 scoped_ptr<base::DictionaryValue> response_data(new base::DictionaryValue); | |
548 response_data->Set("usage", usage->DeepCopy()); | |
pfeldman
2013/09/19 12:35:49
Copying usage and quota leaks them, you should set
SeRya
2013/09/19 14:54:24
They don't leak because of using base::Owned (base
| |
549 response_data->Set("quota", quota->DeepCopy()); | |
550 | |
551 BrowserThread::PostTask( | |
552 BrowserThread::UI, FROM_HERE, | |
553 base::Bind( | |
pfeldman
2013/09/19 12:35:49
Does this fit 80 chars?
SeRya
2013/09/19 14:54:24
Done.
| |
554 callback, | |
555 base::Passed(&response_data))); | |
556 } | |
557 | |
558 static 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 namespace { | |
568 | |
569 struct GetHostUsageCommonParams { | |
570 scoped_refptr<quota::QuotaManager> quota_manager; | |
571 std::string host; | |
572 base::DictionaryValue* usage; | |
pfeldman
2013/09/19 12:35:49
why not scoped_ptr?
SeRya
2013/09/19 14:54:24
Because this object is owned by on_complete callba
| |
573 base::Closure barrier; | |
574 }; | |
575 | |
576 } // namespace | |
577 | |
578 static void GetHostUsage( | |
pfeldman
2013/09/19 12:35:49
Please move these into anonymous namespace.
SeRya
2013/09/19 14:54:24
Done.
| |
579 const GetHostUsageCommonParams& params, | |
580 quota::StorageType storage_type, | |
581 quota::QuotaClient::ID client_id, | |
582 const char* item_name) { | |
583 params.quota_manager->GetHostUsage(params.host, storage_type, client_id, | |
584 base::Bind(&DidGetHostUsage, params.usage, item_name, params.barrier)); | |
585 } | |
586 | |
587 static void DidGetQuotaValue( | |
588 base::DictionaryValue* dictionary, | |
589 const char* item_name, | |
590 const base::Closure& barrier, | |
591 quota::QuotaStatusCode status, | |
592 int64 value) { | |
593 if (status == quota::kQuotaStatusOk) | |
594 dictionary->SetDouble(item_name, value); | |
595 barrier.Run(); | |
596 } | |
597 | |
598 static void DidGetUsageAndQuotaForWebApps( | |
599 base::DictionaryValue* quota, | |
600 const char* item_name, | |
601 const base::Closure& barrier, | |
602 quota::QuotaStatusCode status, | |
603 int64 used_bytes, | |
604 int64 quota_in_bytes) { | |
605 if (status == quota::kQuotaStatusOk) | |
606 quota->SetDouble(item_name, quota_in_bytes); | |
607 barrier.Run(); | |
608 } | |
609 | |
610 static void QueryUsageAndQuotaOnIOThread( | |
611 scoped_refptr<quota::QuotaManager> quota_manager, | |
612 const GURL& security_origin, | |
613 const ResponseCallback& callback) { | |
614 base::DictionaryValue* usage = new base::DictionaryValue; | |
615 base::DictionaryValue* quota = new base::DictionaryValue; | |
616 | |
617 base::Closure on_complete = base::Bind( | |
618 &QueryAndUsageQuotaCompletedOnIOThread, | |
619 base::Owned(usage), | |
620 base::Owned(quota), | |
621 callback); | |
622 | |
623 static const int kExpectedResults = 9; | |
624 | |
625 base::Closure barrier = BarrierClosure(kExpectedResults, on_complete); | |
pfeldman
2013/09/19 12:35:49
Just inline on_complete.
SeRya
2013/09/19 14:54:24
Done.
| |
626 std::string host = net::GetHostOrSpecFromURL(security_origin); | |
627 | |
628 quota_manager->GetAvailableSpace( | |
629 base::Bind(&DidGetQuotaValue, quota, "availableSpace", barrier)); | |
630 | |
631 quota_manager->GetUsageAndQuotaForWebApps( | |
632 security_origin, | |
633 quota::kStorageTypeTemporary, | |
634 base::Bind( | |
pfeldman
2013/09/19 12:35:49
No need to put them into columns according to the
SeRya
2013/09/19 14:54:24
Done.
| |
635 &DidGetUsageAndQuotaForWebApps, | |
636 quota, | |
637 "temporaryHostQuota", | |
638 barrier)); | |
639 | |
640 quota_manager->GetPersistentHostQuota( | |
641 host, | |
642 base::Bind( | |
pfeldman
2013/09/19 12:35:49
ditto
SeRya
2013/09/19 14:54:24
Done.
| |
643 &DidGetQuotaValue, | |
644 quota, | |
645 "persistentHostQuota", | |
646 barrier)); | |
647 | |
648 GetHostUsageCommonParams params = { quota_manager, host, usage, barrier }; | |
649 | |
650 GetHostUsage( | |
pfeldman
2013/09/19 12:35:49
Following code does the same and does not require
SeRya
2013/09/19 14:54:24
Done.
| |
651 params, | |
652 quota::kStorageTypeTemporary, | |
653 quota::QuotaClient::kFileSystem, | |
654 "temporaryFileSystemUsage"); | |
655 | |
656 GetHostUsage( | |
657 params, | |
658 quota::kStorageTypePersistent, | |
659 quota::QuotaClient::kFileSystem, | |
660 "persistentFileSystemUsage"); | |
661 | |
662 GetHostUsage( | |
663 params, | |
664 quota::kStorageTypeSyncable, | |
665 quota::QuotaClient::kFileSystem, | |
666 "syncableFileSystemUsage"); | |
667 | |
668 GetHostUsage( | |
669 params, | |
670 quota::kStorageTypeTemporary, | |
671 quota::QuotaClient::kDatabase, | |
672 "databaseUsage"); | |
673 | |
674 GetHostUsage( | |
675 params, | |
676 quota::kStorageTypeTemporary, | |
677 quota::QuotaClient::kAppcache, | |
678 "appcacheUsage"); | |
679 | |
680 GetHostUsage( | |
681 params, | |
682 quota::kStorageTypeTemporary, | |
683 quota::QuotaClient::kIndexedDatabase, | |
684 "indexedDatabaseUsage"); | |
685 } | |
686 | |
687 scoped_refptr<DevToolsProtocol::Response> | |
688 RendererOverridesHandler::PageQueryUsageAndQuota( | |
689 scoped_refptr<DevToolsProtocol::Command> command) { | |
690 base::DictionaryValue* params = command->params(); | |
691 std::string security_origin; | |
692 if (!params || !params->GetString( | |
693 devtools::Page::queryUsageAndQuota::kParamSecurityOrigin, | |
694 &security_origin)) { | |
695 return command->InvalidParamResponse( | |
696 devtools::Page::queryUsageAndQuota::kParamSecurityOrigin); | |
697 } | |
698 | |
699 ResponseCallback callback = base::Bind( | |
700 &RendererOverridesHandler::PageQueryUsageAndQuotaCompleted, | |
701 weak_factory_.GetWeakPtr(), | |
702 command); | |
703 | |
704 scoped_refptr<quota::QuotaManager> quota_manager = | |
705 agent_->GetRenderViewHost()->GetProcess()-> | |
706 GetStoragePartition()->GetQuotaManager(); | |
707 | |
708 // Will be deleted when done. | |
pfeldman
2013/09/19 12:35:49
What will be deleted when done?
SeRya
2013/09/19 14:54:24
Removed.
| |
709 BrowserThread::PostTask( | |
710 BrowserThread::IO, FROM_HERE, | |
711 base::Bind( | |
712 &QueryUsageAndQuotaOnIOThread, | |
713 quota_manager, | |
714 GURL(security_origin), | |
715 callback)); | |
716 | |
717 return command->AsyncResponsePromise(); | |
718 } | |
719 | |
720 void RendererOverridesHandler::PageQueryUsageAndQuotaCompleted( | |
721 scoped_refptr<DevToolsProtocol::Command> command, | |
722 scoped_ptr<base::DictionaryValue> response_data) { | |
723 SendRawMessage( | |
pfeldman
2013/09/19 12:35:49
SendAsyncResponse(command->SuccessResponse(respons
SeRya
2013/09/19 14:54:24
Done.
| |
724 command->SuccessResponse(response_data.release())->Serialize()); | |
725 } | |
528 | 726 |
529 // Input agent handlers ------------------------------------------------------ | 727 // Input agent handlers ------------------------------------------------------ |
530 | 728 |
531 scoped_refptr<DevToolsProtocol::Response> | 729 scoped_refptr<DevToolsProtocol::Response> |
532 RendererOverridesHandler::InputDispatchMouseEvent( | 730 RendererOverridesHandler::InputDispatchMouseEvent( |
533 scoped_refptr<DevToolsProtocol::Command> command) { | 731 scoped_refptr<DevToolsProtocol::Command> command) { |
534 base::DictionaryValue* params = command->params(); | 732 base::DictionaryValue* params = command->params(); |
535 if (!params) | 733 if (!params) |
536 return NULL; | 734 return NULL; |
537 | 735 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
664 return NULL; | 862 return NULL; |
665 } | 863 } |
666 event.data.pinchUpdate.scale = static_cast<float>(scale); | 864 event.data.pinchUpdate.scale = static_cast<float>(scale); |
667 } | 865 } |
668 | 866 |
669 host->ForwardGestureEvent(event); | 867 host->ForwardGestureEvent(event); |
670 return command->SuccessResponse(NULL); | 868 return command->SuccessResponse(NULL); |
671 } | 869 } |
672 | 870 |
673 } // namespace content | 871 } // namespace content |
OLD | NEW |