OLD | NEW |
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 Loading... |
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; | |
35 using content::WebContents; | 34 using content::WebContents; |
36 using content::WebUIMessageHandler; | 35 using content::WebUIMessageHandler; |
37 | 36 |
38 namespace { | 37 namespace { |
39 | 38 |
40 const char kInitUICommand[] = "init-ui"; | 39 const char kInitUICommand[] = "init-ui"; |
41 const char kInspectCommand[] = "inspect"; | 40 const char kInspectCommand[] = "inspect"; |
42 const char kActivateCommand[] = "activate"; | 41 const char kActivateCommand[] = "activate"; |
43 const char kCloseCommand[] = "close"; | 42 const char kCloseCommand[] = "close"; |
44 const char kReloadCommand[] = "reload"; | 43 const char kReloadCommand[] = "reload"; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 void InspectUI::InitUI() { | 269 void InspectUI::InitUI() { |
271 SetPortForwardingDefaults(); | 270 SetPortForwardingDefaults(); |
272 StartListeningNotifications(); | 271 StartListeningNotifications(); |
273 UpdateDiscoverUsbDevicesEnabled(); | 272 UpdateDiscoverUsbDevicesEnabled(); |
274 UpdatePortForwardingEnabled(); | 273 UpdatePortForwardingEnabled(); |
275 UpdatePortForwardingConfig(); | 274 UpdatePortForwardingConfig(); |
276 } | 275 } |
277 | 276 |
278 void InspectUI::Inspect(const std::string& source_id, | 277 void InspectUI::Inspect(const std::string& source_id, |
279 const std::string& target_id) { | 278 const std::string& target_id) { |
280 scoped_refptr<DevToolsAgentHost> target = FindTarget(source_id, target_id); | 279 DevToolsTargetImpl* target = FindTarget(source_id, target_id); |
281 if (target) { | 280 if (target) { |
282 const std::string target_type = target->GetType(); | 281 const std::string target_type = target->GetType(); |
283 target->Inspect(); | 282 target->Inspect(Profile::FromWebUI(web_ui())); |
284 ForceUpdateIfNeeded(source_id, target_type); | 283 ForceUpdateIfNeeded(source_id, target_type); |
285 } | 284 } |
286 } | 285 } |
287 | 286 |
288 void InspectUI::Activate(const std::string& source_id, | 287 void InspectUI::Activate(const std::string& source_id, |
289 const std::string& target_id) { | 288 const std::string& target_id) { |
290 scoped_refptr<DevToolsAgentHost> target = FindTarget(source_id, target_id); | 289 DevToolsTargetImpl* target = FindTarget(source_id, target_id); |
291 if (target) { | 290 if (target) { |
292 const std::string target_type = target->GetType(); | 291 const std::string target_type = target->GetType(); |
293 target->Activate(); | 292 target->Activate(); |
294 ForceUpdateIfNeeded(source_id, target_type); | 293 ForceUpdateIfNeeded(source_id, target_type); |
295 } | 294 } |
296 } | 295 } |
297 | 296 |
298 void InspectUI::Close(const std::string& source_id, | 297 void InspectUI::Close(const std::string& source_id, |
299 const std::string& target_id) { | 298 const std::string& target_id) { |
300 scoped_refptr<DevToolsAgentHost> target = FindTarget(source_id, target_id); | 299 DevToolsTargetImpl* target = FindTarget(source_id, target_id); |
301 if (target) { | 300 if (target) { |
302 const std::string target_type = target->GetType(); | 301 const std::string target_type = target->GetType(); |
303 target->Close(); | 302 target->Close(); |
304 ForceUpdateIfNeeded(source_id, target_type); | 303 ForceUpdateIfNeeded(source_id, target_type); |
305 } | 304 } |
306 } | 305 } |
307 | 306 |
308 void InspectUI::Reload(const std::string& source_id, | 307 void InspectUI::Reload(const std::string& source_id, |
309 const std::string& target_id) { | 308 const std::string& target_id) { |
310 scoped_refptr<DevToolsAgentHost> target = FindTarget(source_id, target_id); | 309 DevToolsTargetImpl* target = FindTarget(source_id, target_id); |
311 if (target) { | 310 if (target) { |
312 const std::string target_type = target->GetType(); | 311 const std::string target_type = target->GetType(); |
313 target->Reload(); | 312 target->Reload(); |
314 ForceUpdateIfNeeded(source_id, target_type); | 313 ForceUpdateIfNeeded(source_id, target_type); |
315 } | 314 } |
316 } | 315 } |
317 | 316 |
318 void InspectUI::Open(const std::string& source_id, | 317 void InspectUI::Open(const std::string& source_id, |
319 const std::string& browser_id, | 318 const std::string& browser_id, |
320 const std::string& url) { | 319 const std::string& url) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 491 |
493 void InspectUI::AddTargetUIHandler( | 492 void InspectUI::AddTargetUIHandler( |
494 std::unique_ptr<DevToolsTargetsUIHandler> handler) { | 493 std::unique_ptr<DevToolsTargetsUIHandler> handler) { |
495 DevToolsTargetsUIHandler* handler_ptr = handler.release(); | 494 DevToolsTargetsUIHandler* handler_ptr = handler.release(); |
496 target_handlers_[handler_ptr->source_id()] = handler_ptr; | 495 target_handlers_[handler_ptr->source_id()] = handler_ptr; |
497 } | 496 } |
498 | 497 |
499 DevToolsTargetsUIHandler* InspectUI::FindTargetHandler( | 498 DevToolsTargetsUIHandler* InspectUI::FindTargetHandler( |
500 const std::string& source_id) { | 499 const std::string& source_id) { |
501 TargetHandlerMap::iterator it = target_handlers_.find(source_id); | 500 TargetHandlerMap::iterator it = target_handlers_.find(source_id); |
502 return it != target_handlers_.end() ? it->second : nullptr; | 501 return it != target_handlers_.end() ? it->second : NULL; |
503 } | 502 } |
504 | 503 |
505 scoped_refptr<content::DevToolsAgentHost> InspectUI::FindTarget( | 504 DevToolsTargetImpl* InspectUI::FindTarget( |
506 const std::string& source_id, const std::string& target_id) { | 505 const std::string& source_id, const std::string& target_id) { |
507 TargetHandlerMap::iterator it = target_handlers_.find(source_id); | 506 TargetHandlerMap::iterator it = target_handlers_.find(source_id); |
508 DevToolsTargetImpl* target = it != target_handlers_.end() ? | 507 return it != target_handlers_.end() ? |
509 it->second->GetTarget(target_id) : nullptr; | 508 it->second->GetTarget(target_id) : NULL; |
510 return target ? target->GetAgentHost() : nullptr; | |
511 } | 509 } |
512 | 510 |
513 void InspectUI::PopulateTargets(const std::string& source, | 511 void InspectUI::PopulateTargets(const std::string& source, |
514 const base::ListValue& targets) { | 512 const base::ListValue& targets) { |
515 web_ui()->CallJavascriptFunctionUnsafe("populateTargets", | 513 web_ui()->CallJavascriptFunctionUnsafe("populateTargets", |
516 base::StringValue(source), targets); | 514 base::StringValue(source), targets); |
517 } | 515 } |
518 | 516 |
519 void InspectUI::ForceUpdateIfNeeded(const std::string& source_id, | 517 void InspectUI::ForceUpdateIfNeeded(const std::string& source_id, |
520 const std::string& target_type) { | 518 const std::string& target_type) { |
521 // TODO(dgozman): remove this after moving discovery to protocol. | 519 // TODO(dgozman): remove this after moving discovery to protocol. |
522 // See crbug.com/398049. | 520 // See crbug.com/398049. |
523 if (target_type != content::DevToolsAgentHost::kTypeServiceWorker) | 521 if (target_type != DevToolsTargetImpl::kTargetTypeServiceWorker) |
524 return; | 522 return; |
525 DevToolsTargetsUIHandler* handler = FindTargetHandler(source_id); | 523 DevToolsTargetsUIHandler* handler = FindTargetHandler(source_id); |
526 if (handler) | 524 if (handler) |
527 handler->ForceUpdate(); | 525 handler->ForceUpdate(); |
528 } | 526 } |
529 | 527 |
530 void InspectUI::PopulatePortStatus(const base::Value& status) { | 528 void InspectUI::PopulatePortStatus(const base::Value& status) { |
531 web_ui()->CallJavascriptFunctionUnsafe("populatePortStatus", status); | 529 web_ui()->CallJavascriptFunctionUnsafe("populatePortStatus", status); |
532 } | 530 } |
533 | 531 |
534 void InspectUI::ShowIncognitoWarning() { | 532 void InspectUI::ShowIncognitoWarning() { |
535 web_ui()->CallJavascriptFunctionUnsafe("showIncognitoWarning"); | 533 web_ui()->CallJavascriptFunctionUnsafe("showIncognitoWarning"); |
536 } | 534 } |
OLD | NEW |