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

Side by Side Diff: chrome/browser/ui/webui/inspect_ui.cc

Issue 2263843002: DevTools: merge devtools target with devtools host, part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for landing 3 Created 4 years, 3 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 (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 "chrome/browser/ui/webui/inspect_ui.h" 5 #include "chrome/browser/ui/webui/inspect_ui.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "chrome/browser/devtools/devtools_target_impl.h" 9 #include "chrome/browser/devtools/devtools_target_impl.h"
10 #include "chrome/browser/devtools/devtools_targets_ui.h" 10 #include "chrome/browser/devtools/devtools_targets_ui.h"
(...skipping 13 matching lines...) Expand all
24 #include "content/public/browser/user_metrics.h" 24 #include "content/public/browser/user_metrics.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "content/public/browser/web_contents_delegate.h" 26 #include "content/public/browser/web_contents_delegate.h"
27 #include "content/public/browser/web_contents_observer.h" 27 #include "content/public/browser/web_contents_observer.h"
28 #include "content/public/browser/web_ui.h" 28 #include "content/public/browser/web_ui.h"
29 #include "content/public/browser/web_ui_data_source.h" 29 #include "content/public/browser/web_ui_data_source.h"
30 #include "content/public/browser/web_ui_message_handler.h" 30 #include "content/public/browser/web_ui_message_handler.h"
31 #include "content/public/common/frame_navigate_params.h" 31 #include "content/public/common/frame_navigate_params.h"
32 #include "grit/browser_resources.h" 32 #include "grit/browser_resources.h"
33 33
34 using content::DevToolsAgentHost;
34 using content::WebContents; 35 using content::WebContents;
35 using content::WebUIMessageHandler; 36 using content::WebUIMessageHandler;
36 37
37 namespace { 38 namespace {
38 39
39 const char kInitUICommand[] = "init-ui"; 40 const char kInitUICommand[] = "init-ui";
40 const char kInspectCommand[] = "inspect"; 41 const char kInspectCommand[] = "inspect";
41 const char kActivateCommand[] = "activate"; 42 const char kActivateCommand[] = "activate";
42 const char kCloseCommand[] = "close"; 43 const char kCloseCommand[] = "close";
43 const char kReloadCommand[] = "reload"; 44 const char kReloadCommand[] = "reload";
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 void InspectUI::InitUI() { 270 void InspectUI::InitUI() {
270 SetPortForwardingDefaults(); 271 SetPortForwardingDefaults();
271 StartListeningNotifications(); 272 StartListeningNotifications();
272 UpdateDiscoverUsbDevicesEnabled(); 273 UpdateDiscoverUsbDevicesEnabled();
273 UpdatePortForwardingEnabled(); 274 UpdatePortForwardingEnabled();
274 UpdatePortForwardingConfig(); 275 UpdatePortForwardingConfig();
275 } 276 }
276 277
277 void InspectUI::Inspect(const std::string& source_id, 278 void InspectUI::Inspect(const std::string& source_id,
278 const std::string& target_id) { 279 const std::string& target_id) {
279 DevToolsTargetImpl* target = FindTarget(source_id, target_id); 280 scoped_refptr<DevToolsAgentHost> target = FindTarget(source_id, target_id);
280 if (target) { 281 if (target) {
281 const std::string target_type = target->GetType(); 282 const std::string target_type = target->GetType();
282 target->Inspect(Profile::FromWebUI(web_ui())); 283 target->Inspect();
283 ForceUpdateIfNeeded(source_id, target_type); 284 ForceUpdateIfNeeded(source_id, target_type);
284 } 285 }
285 } 286 }
286 287
287 void InspectUI::Activate(const std::string& source_id, 288 void InspectUI::Activate(const std::string& source_id,
288 const std::string& target_id) { 289 const std::string& target_id) {
289 DevToolsTargetImpl* target = FindTarget(source_id, target_id); 290 scoped_refptr<DevToolsAgentHost> target = FindTarget(source_id, target_id);
290 if (target) { 291 if (target) {
291 const std::string target_type = target->GetType(); 292 const std::string target_type = target->GetType();
292 target->Activate(); 293 target->Activate();
293 ForceUpdateIfNeeded(source_id, target_type); 294 ForceUpdateIfNeeded(source_id, target_type);
294 } 295 }
295 } 296 }
296 297
297 void InspectUI::Close(const std::string& source_id, 298 void InspectUI::Close(const std::string& source_id,
298 const std::string& target_id) { 299 const std::string& target_id) {
299 DevToolsTargetImpl* target = FindTarget(source_id, target_id); 300 scoped_refptr<DevToolsAgentHost> target = FindTarget(source_id, target_id);
300 if (target) { 301 if (target) {
301 const std::string target_type = target->GetType(); 302 const std::string target_type = target->GetType();
302 target->Close(); 303 target->Close();
303 ForceUpdateIfNeeded(source_id, target_type); 304 ForceUpdateIfNeeded(source_id, target_type);
304 } 305 }
305 } 306 }
306 307
307 void InspectUI::Reload(const std::string& source_id, 308 void InspectUI::Reload(const std::string& source_id,
308 const std::string& target_id) { 309 const std::string& target_id) {
309 DevToolsTargetImpl* target = FindTarget(source_id, target_id); 310 scoped_refptr<DevToolsAgentHost> target = FindTarget(source_id, target_id);
310 if (target) { 311 if (target) {
311 const std::string target_type = target->GetType(); 312 const std::string target_type = target->GetType();
312 target->Reload(); 313 target->Reload();
313 ForceUpdateIfNeeded(source_id, target_type); 314 ForceUpdateIfNeeded(source_id, target_type);
314 } 315 }
315 } 316 }
316 317
317 void InspectUI::Open(const std::string& source_id, 318 void InspectUI::Open(const std::string& source_id,
318 const std::string& browser_id, 319 const std::string& browser_id,
319 const std::string& url) { 320 const std::string& url) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 492
492 void InspectUI::AddTargetUIHandler( 493 void InspectUI::AddTargetUIHandler(
493 std::unique_ptr<DevToolsTargetsUIHandler> handler) { 494 std::unique_ptr<DevToolsTargetsUIHandler> handler) {
494 DevToolsTargetsUIHandler* handler_ptr = handler.release(); 495 DevToolsTargetsUIHandler* handler_ptr = handler.release();
495 target_handlers_[handler_ptr->source_id()] = handler_ptr; 496 target_handlers_[handler_ptr->source_id()] = handler_ptr;
496 } 497 }
497 498
498 DevToolsTargetsUIHandler* InspectUI::FindTargetHandler( 499 DevToolsTargetsUIHandler* InspectUI::FindTargetHandler(
499 const std::string& source_id) { 500 const std::string& source_id) {
500 TargetHandlerMap::iterator it = target_handlers_.find(source_id); 501 TargetHandlerMap::iterator it = target_handlers_.find(source_id);
501 return it != target_handlers_.end() ? it->second : NULL; 502 return it != target_handlers_.end() ? it->second : nullptr;
502 } 503 }
503 504
504 DevToolsTargetImpl* InspectUI::FindTarget( 505 scoped_refptr<content::DevToolsAgentHost> InspectUI::FindTarget(
505 const std::string& source_id, const std::string& target_id) { 506 const std::string& source_id, const std::string& target_id) {
506 TargetHandlerMap::iterator it = target_handlers_.find(source_id); 507 TargetHandlerMap::iterator it = target_handlers_.find(source_id);
507 return it != target_handlers_.end() ? 508 DevToolsTargetImpl* target = it != target_handlers_.end() ?
508 it->second->GetTarget(target_id) : NULL; 509 it->second->GetTarget(target_id) : nullptr;
510 return target ? target->GetAgentHost() : nullptr;
509 } 511 }
510 512
511 void InspectUI::PopulateTargets(const std::string& source, 513 void InspectUI::PopulateTargets(const std::string& source,
512 const base::ListValue& targets) { 514 const base::ListValue& targets) {
513 web_ui()->CallJavascriptFunctionUnsafe("populateTargets", 515 web_ui()->CallJavascriptFunctionUnsafe("populateTargets",
514 base::StringValue(source), targets); 516 base::StringValue(source), targets);
515 } 517 }
516 518
517 void InspectUI::ForceUpdateIfNeeded(const std::string& source_id, 519 void InspectUI::ForceUpdateIfNeeded(const std::string& source_id,
518 const std::string& target_type) { 520 const std::string& target_type) {
519 // TODO(dgozman): remove this after moving discovery to protocol. 521 // TODO(dgozman): remove this after moving discovery to protocol.
520 // See crbug.com/398049. 522 // See crbug.com/398049.
521 if (target_type != DevToolsTargetImpl::kTargetTypeServiceWorker) 523 if (target_type != content::DevToolsAgentHost::kTypeServiceWorker)
522 return; 524 return;
523 DevToolsTargetsUIHandler* handler = FindTargetHandler(source_id); 525 DevToolsTargetsUIHandler* handler = FindTargetHandler(source_id);
524 if (handler) 526 if (handler)
525 handler->ForceUpdate(); 527 handler->ForceUpdate();
526 } 528 }
527 529
528 void InspectUI::PopulatePortStatus(const base::Value& status) { 530 void InspectUI::PopulatePortStatus(const base::Value& status) {
529 web_ui()->CallJavascriptFunctionUnsafe("populatePortStatus", status); 531 web_ui()->CallJavascriptFunctionUnsafe("populatePortStatus", status);
530 } 532 }
531 533
532 void InspectUI::ShowIncognitoWarning() { 534 void InspectUI::ShowIncognitoWarning() {
533 web_ui()->CallJavascriptFunctionUnsafe("showIncognitoWarning"); 535 web_ui()->CallJavascriptFunctionUnsafe("showIncognitoWarning");
534 } 536 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/inspect_ui.h ('k') | components/devtools_discovery/basic_target_descriptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698