Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1081)

Side by Side Diff: content/browser/devtools/protocol/page_handler.cc

Issue 2817593004: [DevTools] Move eye dropper functionality from protocol to embedder (Closed)
Patch Set: rebased Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/base64.h" 13 #include "base/base64.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/ref_counted_memory.h" 17 #include "base/memory/ref_counted_memory.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/task_scheduler/post_task.h" 21 #include "base/task_scheduler/post_task.h"
22 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "content/browser/devtools/devtools_session.h" 23 #include "content/browser/devtools/devtools_session.h"
24 #include "content/browser/devtools/page_navigation_throttle.h" 24 #include "content/browser/devtools/page_navigation_throttle.h"
25 #include "content/browser/devtools/protocol/color_picker.h"
26 #include "content/browser/renderer_host/render_widget_host_impl.h" 25 #include "content/browser/renderer_host/render_widget_host_impl.h"
27 #include "content/browser/renderer_host/render_widget_host_view_base.h" 26 #include "content/browser/renderer_host/render_widget_host_view_base.h"
28 #include "content/browser/web_contents/web_contents_impl.h" 27 #include "content/browser/web_contents/web_contents_impl.h"
29 #include "content/browser/web_contents/web_contents_view.h" 28 #include "content/browser/web_contents/web_contents_view.h"
30 #include "content/common/view_messages.h" 29 #include "content/common/view_messages.h"
31 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/javascript_dialog_manager.h" 31 #include "content/public/browser/javascript_dialog_manager.h"
33 #include "content/public/browser/navigation_controller.h" 32 #include "content/public/browser/navigation_controller.h"
34 #include "content/public/browser/navigation_entry.h" 33 #include "content/public/browser/navigation_entry.h"
35 #include "content/public/browser/navigation_handle.h" 34 #include "content/public/browser/navigation_handle.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 screencast_enabled_(false), 93 screencast_enabled_(false),
95 screencast_quality_(kDefaultScreenshotQuality), 94 screencast_quality_(kDefaultScreenshotQuality),
96 screencast_max_width_(-1), 95 screencast_max_width_(-1),
97 screencast_max_height_(-1), 96 screencast_max_height_(-1),
98 capture_every_nth_frame_(1), 97 capture_every_nth_frame_(1),
99 capture_retry_count_(0), 98 capture_retry_count_(0),
100 has_compositor_frame_metadata_(false), 99 has_compositor_frame_metadata_(false),
101 session_id_(0), 100 session_id_(0),
102 frame_counter_(0), 101 frame_counter_(0),
103 frames_in_flight_(0), 102 frames_in_flight_(0),
104 color_picker_(new ColorPicker(
105 base::Bind(&PageHandler::OnColorPicked, base::Unretained(this)))),
106 navigation_throttle_enabled_(false), 103 navigation_throttle_enabled_(false),
107 next_navigation_id_(0), 104 next_navigation_id_(0),
108 host_(nullptr), 105 host_(nullptr),
109 weak_factory_(this) {} 106 weak_factory_(this) {}
110 107
111 PageHandler::~PageHandler() { 108 PageHandler::~PageHandler() {
112 } 109 }
113 110
114 // static 111 // static
115 PageHandler* PageHandler::FromSession(DevToolsSession* session) { 112 PageHandler* PageHandler::FromSession(DevToolsSession* session) {
116 return static_cast<PageHandler*>( 113 return static_cast<PageHandler*>(
117 session->GetHandlerByName(Page::Metainfo::domainName)); 114 session->GetHandlerByName(Page::Metainfo::domainName));
118 } 115 }
119 116
120 void PageHandler::SetRenderFrameHost(RenderFrameHostImpl* host) { 117 void PageHandler::SetRenderFrameHost(RenderFrameHostImpl* host) {
121 if (host_ == host) 118 if (host_ == host)
122 return; 119 return;
123 120
124 RenderWidgetHostImpl* widget_host = 121 RenderWidgetHostImpl* widget_host =
125 host_ ? host_->GetRenderWidgetHost() : nullptr; 122 host_ ? host_->GetRenderWidgetHost() : nullptr;
126 if (widget_host) { 123 if (widget_host) {
127 registrar_.Remove( 124 registrar_.Remove(
128 this, 125 this,
129 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, 126 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
130 content::Source<RenderWidgetHost>(widget_host)); 127 content::Source<RenderWidgetHost>(widget_host));
131 } 128 }
132 129
133 host_ = host; 130 host_ = host;
134 widget_host = host_ ? host_->GetRenderWidgetHost() : nullptr; 131 widget_host = host_ ? host_->GetRenderWidgetHost() : nullptr;
135 color_picker_->SetRenderWidgetHost(widget_host);
136 132
137 if (widget_host) { 133 if (widget_host) {
138 registrar_.Add( 134 registrar_.Add(
139 this, 135 this,
140 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, 136 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
141 content::Source<RenderWidgetHost>(widget_host)); 137 content::Source<RenderWidgetHost>(widget_host));
142 } 138 }
143 } 139 }
144 140
145 void PageHandler::Wire(UberDispatcher* dispatcher) { 141 void PageHandler::Wire(UberDispatcher* dispatcher) {
146 frontend_.reset(new Page::Frontend(dispatcher->channel())); 142 frontend_.reset(new Page::Frontend(dispatcher->channel()));
147 Page::Dispatcher::wire(dispatcher, this); 143 Page::Dispatcher::wire(dispatcher, this);
148 } 144 }
149 145
150 void PageHandler::OnSwapCompositorFrame( 146 void PageHandler::OnSwapCompositorFrame(
151 cc::CompositorFrameMetadata frame_metadata) { 147 cc::CompositorFrameMetadata frame_metadata) {
152 last_compositor_frame_metadata_ = std::move(frame_metadata); 148 last_compositor_frame_metadata_ = std::move(frame_metadata);
153 has_compositor_frame_metadata_ = true; 149 has_compositor_frame_metadata_ = true;
154 150
155 if (screencast_enabled_) 151 if (screencast_enabled_)
156 InnerSwapCompositorFrame(); 152 InnerSwapCompositorFrame();
157 color_picker_->OnSwapCompositorFrame();
158 } 153 }
159 154
160 void PageHandler::OnSynchronousSwapCompositorFrame( 155 void PageHandler::OnSynchronousSwapCompositorFrame(
161 cc::CompositorFrameMetadata frame_metadata) { 156 cc::CompositorFrameMetadata frame_metadata) {
162 if (has_compositor_frame_metadata_) { 157 if (has_compositor_frame_metadata_) {
163 last_compositor_frame_metadata_ = 158 last_compositor_frame_metadata_ =
164 std::move(next_compositor_frame_metadata_); 159 std::move(next_compositor_frame_metadata_);
165 } else { 160 } else {
166 last_compositor_frame_metadata_ = frame_metadata.Clone(); 161 last_compositor_frame_metadata_ = frame_metadata.Clone();
167 } 162 }
168 next_compositor_frame_metadata_ = std::move(frame_metadata); 163 next_compositor_frame_metadata_ = std::move(frame_metadata);
169 164
170 has_compositor_frame_metadata_ = true; 165 has_compositor_frame_metadata_ = true;
171 166
172 if (screencast_enabled_) 167 if (screencast_enabled_)
173 InnerSwapCompositorFrame(); 168 InnerSwapCompositorFrame();
174 color_picker_->OnSwapCompositorFrame();
175 } 169 }
176 170
177 void PageHandler::Observe(int type, 171 void PageHandler::Observe(int type,
178 const NotificationSource& source, 172 const NotificationSource& source,
179 const NotificationDetails& details) { 173 const NotificationDetails& details) {
180 if (!screencast_enabled_) 174 if (!screencast_enabled_)
181 return; 175 return;
182 DCHECK(type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED); 176 DCHECK(type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED);
183 bool visible = *Details<bool>(details).ptr(); 177 bool visible = *Details<bool>(details).ptr();
184 NotifyScreencastVisibility(visible); 178 NotifyScreencastVisibility(visible);
(...skipping 15 matching lines...) Expand all
200 enabled_ = true; 194 enabled_ = true;
201 if (GetWebContents() && GetWebContents()->ShowingInterstitialPage()) 195 if (GetWebContents() && GetWebContents()->ShowingInterstitialPage())
202 frontend_->InterstitialShown(); 196 frontend_->InterstitialShown();
203 return Response::FallThrough(); 197 return Response::FallThrough();
204 } 198 }
205 199
206 Response PageHandler::Disable() { 200 Response PageHandler::Disable() {
207 enabled_ = false; 201 enabled_ = false;
208 screencast_enabled_ = false; 202 screencast_enabled_ = false;
209 SetControlNavigations(false); 203 SetControlNavigations(false);
210 color_picker_->SetEnabled(false);
211 return Response::FallThrough(); 204 return Response::FallThrough();
212 } 205 }
213 206
214 Response PageHandler::Reload(Maybe<bool> bypassCache, 207 Response PageHandler::Reload(Maybe<bool> bypassCache,
215 Maybe<std::string> script_to_evaluate_on_load) { 208 Maybe<std::string> script_to_evaluate_on_load) {
216 WebContentsImpl* web_contents = GetWebContents(); 209 WebContentsImpl* web_contents = GetWebContents();
217 if (!web_contents) 210 if (!web_contents)
218 return Response::InternalError(); 211 return Response::InternalError();
219 212
220 if (web_contents->IsCrashed() || 213 if (web_contents->IsCrashed() ||
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 web_contents->GetDelegate()->GetJavaScriptDialogManager(web_contents); 363 web_contents->GetDelegate()->GetJavaScriptDialogManager(web_contents);
371 if (manager && manager->HandleJavaScriptDialog( 364 if (manager && manager->HandleJavaScriptDialog(
372 web_contents, accept, 365 web_contents, accept,
373 prompt_text.isJust() ? &prompt_override : nullptr)) { 366 prompt_text.isJust() ? &prompt_override : nullptr)) {
374 return Response::OK(); 367 return Response::OK();
375 } 368 }
376 369
377 return Response::Error("Could not handle JavaScript dialog"); 370 return Response::Error("Could not handle JavaScript dialog");
378 } 371 }
379 372
380 Response PageHandler::SetColorPickerEnabled(bool enabled) {
381 if (!host_)
382 return Response::InternalError();
383
384 color_picker_->SetEnabled(enabled);
385 return Response::OK();
386 }
387
388 Response PageHandler::RequestAppBanner() { 373 Response PageHandler::RequestAppBanner() {
389 WebContentsImpl* web_contents = GetWebContents(); 374 WebContentsImpl* web_contents = GetWebContents();
390 if (!web_contents) 375 if (!web_contents)
391 return Response::InternalError(); 376 return Response::InternalError();
392 web_contents->GetDelegate()->RequestAppBannerFromDevTools(web_contents); 377 web_contents->GetDelegate()->RequestAppBannerFromDevTools(web_contents);
393 return Response::OK(); 378 return Response::OK();
394 } 379 }
395 380
396 Response PageHandler::SetControlNavigations(bool enabled) { 381 Response PageHandler::SetControlNavigations(bool enabled) {
397 navigation_throttle_enabled_ = enabled; 382 navigation_throttle_enabled_ = enabled;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 int quality, 565 int quality,
581 const gfx::Image& image) { 566 const gfx::Image& image) {
582 if (image.IsEmpty()) { 567 if (image.IsEmpty()) {
583 callback->sendFailure(Response::Error("Unable to capture screenshot")); 568 callback->sendFailure(Response::Error("Unable to capture screenshot"));
584 return; 569 return;
585 } 570 }
586 571
587 callback->sendSuccess(EncodeImage(image, format, quality)); 572 callback->sendSuccess(EncodeImage(image, format, quality));
588 } 573 }
589 574
590 void PageHandler::OnColorPicked(int r, int g, int b, int a) {
591 frontend_->ColorPicked(
592 DOM::RGBA::Create().SetR(r).SetG(g).SetB(b).SetA(a).Build());
593 }
594
595 Response PageHandler::StopLoading() { 575 Response PageHandler::StopLoading() {
596 WebContentsImpl* web_contents = GetWebContents(); 576 WebContentsImpl* web_contents = GetWebContents();
597 if (!web_contents) 577 if (!web_contents)
598 return Response::InternalError(); 578 return Response::InternalError();
599 web_contents->Stop(); 579 web_contents->Stop();
600 return Response::OK(); 580 return Response::OK();
601 } 581 }
602 582
603 } // namespace protocol 583 } // namespace protocol
604 } // namespace content 584 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/protocol/page_handler.h ('k') | third_party/WebKit/Source/core/inspector/browser_protocol.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698