OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/protocol/page_handler.h" | 5 #include "content/browser/devtools/protocol/page_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/threading/worker_pool.h" | 13 #include "base/threading/worker_pool.h" |
14 #include "content/browser/devtools/protocol/color_picker.h" | 14 #include "content/browser/devtools/protocol/color_picker.h" |
15 #include "content/browser/devtools/protocol/frame_recorder.h" | 15 #include "content/browser/devtools/protocol/frame_recorder.h" |
16 #include "content/browser/devtools/protocol/usage_and_quota_query.h" | |
17 #include "content/browser/geolocation/geolocation_service_context.h" | 16 #include "content/browser/geolocation/geolocation_service_context.h" |
18 #include "content/browser/renderer_host/render_view_host_impl.h" | 17 #include "content/browser/renderer_host/render_view_host_impl.h" |
19 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 18 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
20 #include "content/browser/web_contents/web_contents_impl.h" | 19 #include "content/browser/web_contents/web_contents_impl.h" |
21 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
22 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/javascript_dialog_manager.h" | 22 #include "content/public/browser/javascript_dialog_manager.h" |
24 #include "content/public/browser/navigation_controller.h" | 23 #include "content/public/browser/navigation_controller.h" |
25 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
26 #include "content/public/browser/storage_partition.h" | 25 #include "content/public/browser/storage_partition.h" |
27 #include "content/public/browser/web_contents_delegate.h" | 26 #include "content/public/browser/web_contents_delegate.h" |
28 #include "content/public/common/referrer.h" | 27 #include "content/public/common/referrer.h" |
29 #include "content/public/common/url_constants.h" | 28 #include "content/public/common/url_constants.h" |
30 #include "storage/browser/quota/quota_manager.h" | |
31 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 29 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
32 #include "third_party/skia/include/core/SkBitmap.h" | 30 #include "third_party/skia/include/core/SkBitmap.h" |
33 #include "ui/base/page_transition_types.h" | 31 #include "ui/base/page_transition_types.h" |
34 #include "ui/gfx/codec/jpeg_codec.h" | 32 #include "ui/gfx/codec/jpeg_codec.h" |
35 #include "ui/gfx/codec/png_codec.h" | 33 #include "ui/gfx/codec/png_codec.h" |
36 #include "ui/gfx/geometry/size_conversions.h" | 34 #include "ui/gfx/geometry/size_conversions.h" |
37 #include "ui/snapshot/snapshot.h" | 35 #include "ui/snapshot/snapshot.h" |
38 #include "url/gurl.h" | 36 #include "url/gurl.h" |
39 | 37 |
40 namespace content { | 38 namespace content { |
(...skipping 17 matching lines...) Expand all Loading... |
58 set_touch_emulation_enabled::kConfigurationMobile) { | 56 set_touch_emulation_enabled::kConfigurationMobile) { |
59 result = ui::GestureProviderConfigType::GENERIC_MOBILE; | 57 result = ui::GestureProviderConfigType::GENERIC_MOBILE; |
60 } | 58 } |
61 if (protocol_value == | 59 if (protocol_value == |
62 set_touch_emulation_enabled::kConfigurationDesktop) { | 60 set_touch_emulation_enabled::kConfigurationDesktop) { |
63 result = ui::GestureProviderConfigType::GENERIC_DESKTOP; | 61 result = ui::GestureProviderConfigType::GENERIC_DESKTOP; |
64 } | 62 } |
65 return result; | 63 return result; |
66 } | 64 } |
67 | 65 |
68 void QueryUsageAndQuotaCompletedOnIOThread( | |
69 const UsageAndQuotaQuery::Callback& callback, | |
70 scoped_refptr<QueryUsageAndQuotaResponse> response) { | |
71 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
72 base::Bind(callback, response)); | |
73 } | |
74 | |
75 void QueryUsageAndQuotaOnIOThread( | |
76 scoped_refptr<storage::QuotaManager> quota_manager, | |
77 const GURL& security_origin, | |
78 const UsageAndQuotaQuery::Callback& callback) { | |
79 new UsageAndQuotaQuery( | |
80 quota_manager, | |
81 security_origin, | |
82 base::Bind(&QueryUsageAndQuotaCompletedOnIOThread, | |
83 callback)); | |
84 } | |
85 | |
86 std::string EncodeScreencastFrame(const SkBitmap& bitmap, | 66 std::string EncodeScreencastFrame(const SkBitmap& bitmap, |
87 const std::string& format, | 67 const std::string& format, |
88 int quality) { | 68 int quality) { |
89 std::vector<unsigned char> data; | 69 std::vector<unsigned char> data; |
90 SkAutoLockPixels lock_image(bitmap); | 70 SkAutoLockPixels lock_image(bitmap); |
91 bool encoded; | 71 bool encoded; |
92 if (format == kPng) { | 72 if (format == kPng) { |
93 encoded = gfx::PNGCodec::Encode( | 73 encoded = gfx::PNGCodec::Encode( |
94 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | 74 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), |
95 gfx::PNGCodec::FORMAT_SkBitmap, | 75 gfx::PNGCodec::FORMAT_SkBitmap, |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 if (manager && manager->HandleJavaScriptDialog( | 422 if (manager && manager->HandleJavaScriptDialog( |
443 web_contents, accept, prompt_text ? &prompt_override : nullptr)) { | 423 web_contents, accept, prompt_text ? &prompt_override : nullptr)) { |
444 return Response::OK(); | 424 return Response::OK(); |
445 } | 425 } |
446 | 426 |
447 return Response::InternalError("Could not handle JavaScript dialog"); | 427 return Response::InternalError("Could not handle JavaScript dialog"); |
448 } | 428 } |
449 | 429 |
450 Response PageHandler::QueryUsageAndQuota(DevToolsCommandId command_id, | 430 Response PageHandler::QueryUsageAndQuota(DevToolsCommandId command_id, |
451 const std::string& security_origin) { | 431 const std::string& security_origin) { |
452 if (!host_) | |
453 return Response::InternalError("Could not connect to view"); | |
454 | |
455 scoped_refptr<storage::QuotaManager> quota_manager = | |
456 host_->GetProcess()->GetStoragePartition()->GetQuotaManager(); | |
457 | |
458 BrowserThread::PostTask( | |
459 BrowserThread::IO, | |
460 FROM_HERE, | |
461 base::Bind(&QueryUsageAndQuotaOnIOThread, | |
462 quota_manager, | |
463 GURL(security_origin), | |
464 base::Bind(&PageHandler::QueryUsageAndQuotaCompleted, | |
465 weak_factory_.GetWeakPtr(), | |
466 command_id))); | |
467 return Response::OK(); | 432 return Response::OK(); |
468 } | 433 } |
469 | 434 |
470 Response PageHandler::SetColorPickerEnabled(bool enabled) { | 435 Response PageHandler::SetColorPickerEnabled(bool enabled) { |
471 if (!host_) | 436 if (!host_) |
472 return Response::InternalError("Could not connect to view"); | 437 return Response::InternalError("Could not connect to view"); |
473 | 438 |
474 color_picker_->SetEnabled(enabled); | 439 color_picker_->SetEnabled(enabled); |
475 return Response::OK(); | 440 return Response::OK(); |
476 } | 441 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); | 592 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); |
628 client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); | 593 client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); |
629 } | 594 } |
630 | 595 |
631 void PageHandler::OnFramesRecorded( | 596 void PageHandler::OnFramesRecorded( |
632 DevToolsCommandId command_id, | 597 DevToolsCommandId command_id, |
633 scoped_refptr<StopRecordingFramesResponse> response_data) { | 598 scoped_refptr<StopRecordingFramesResponse> response_data) { |
634 client_->SendStopRecordingFramesResponse(command_id, response_data); | 599 client_->SendStopRecordingFramesResponse(command_id, response_data); |
635 } | 600 } |
636 | 601 |
637 void PageHandler::QueryUsageAndQuotaCompleted( | |
638 DevToolsCommandId command_id, | |
639 scoped_refptr<QueryUsageAndQuotaResponse> response_data) { | |
640 client_->SendQueryUsageAndQuotaResponse(command_id, response_data); | |
641 } | |
642 | |
643 } // namespace page | 602 } // namespace page |
644 } // namespace devtools | 603 } // namespace devtools |
645 } // namespace content | 604 } // namespace content |
OLD | NEW |