Chromium Code Reviews| 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/devtools/devtools_window.h" | 5 #include "chrome/browser/devtools/devtools_window.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 WebContents* inspected_contents = | 164 WebContents* inspected_contents = |
| 165 inspected_contents_observer_->web_contents(); | 165 inspected_contents_observer_->web_contents(); |
| 166 if (!inspected_contents) | 166 if (!inspected_contents) |
| 167 return NULL; | 167 return NULL; |
| 168 Browser* browser = NULL; | 168 Browser* browser = NULL; |
| 169 int tab = 0; | 169 int tab = 0; |
| 170 if (FindInspectedBrowserAndTabIndex(inspected_contents, &browser, &tab)) | 170 if (FindInspectedBrowserAndTabIndex(inspected_contents, &browser, &tab)) |
| 171 return browser->window(); | 171 return browser->window(); |
| 172 return NULL; | 172 return NULL; |
| 173 } | 173 } |
| 174 | |
| 175 } // namespace | 174 } // namespace |
| 176 | 175 |
| 177 // DevToolsEventForwarder ----------------------------------------------------- | 176 // DevToolsEventForwarder ----------------------------------------------------- |
| 178 | 177 |
| 179 class DevToolsEventForwarder { | 178 class DevToolsEventForwarder { |
| 180 public: | 179 public: |
| 181 explicit DevToolsEventForwarder(DevToolsWindow* window) | 180 explicit DevToolsEventForwarder(DevToolsWindow* window) |
| 182 : devtools_window_(window) {} | 181 : devtools_window_(window) {} |
| 183 | 182 |
| 184 // Registers whitelisted shortcuts with the forwarder. | 183 // Registers whitelisted shortcuts with the forwarder. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); | 380 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); |
| 382 ++it) { | 381 ++it) { |
| 383 if ((*it)->main_web_contents_ == web_contents || | 382 if ((*it)->main_web_contents_ == web_contents || |
| 384 (*it)->toolbox_web_contents_ == web_contents) | 383 (*it)->toolbox_web_contents_ == web_contents) |
| 385 return true; | 384 return true; |
| 386 } | 385 } |
| 387 return false; | 386 return false; |
| 388 } | 387 } |
| 389 | 388 |
| 390 // static | 389 // static |
| 391 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( | 390 void DevToolsWindow::OpenDevToolsWindowForWorker( |
| 392 Profile* profile, | 391 Profile* profile, |
| 393 const scoped_refptr<DevToolsAgentHost>& worker_agent) { | 392 const scoped_refptr<DevToolsAgentHost>& worker_agent) { |
| 394 DevToolsWindow* window = FindDevToolsWindow(worker_agent.get()); | 393 DevToolsWindow* window = FindDevToolsWindow(worker_agent.get()); |
| 395 if (!window) { | 394 if (!window) { |
| 396 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); | 395 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); |
| 397 DCHECK(window); | 396 if (!window) |
| 397 return; | |
| 398 window->bindings_->AttachTo(worker_agent); | 398 window->bindings_->AttachTo(worker_agent); |
| 399 } | 399 } |
| 400 window->ScheduleShow(DevToolsToggleAction::Show()); | 400 window->ScheduleShow(DevToolsToggleAction::Show()); |
| 401 return window; | |
| 402 } | 401 } |
| 403 | 402 |
| 404 // static | 403 // static |
| 405 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( | 404 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( |
| 406 Profile* profile) { | 405 Profile* profile) { |
| 407 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); | 406 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); |
| 408 return Create(profile, GURL(), NULL, true, std::string(), false, ""); | 407 return Create(profile, GURL(), NULL, true, std::string(), false, ""); |
| 409 } | 408 } |
| 410 | 409 |
| 411 // static | 410 // static |
| 412 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( | 411 void DevToolsWindow::OpenDevToolsWindow( |
| 413 content::WebContents* inspected_web_contents) { | 412 content::WebContents* inspected_web_contents) { |
| 414 return ToggleDevToolsWindow( | 413 ToggleDevToolsWindow( |
| 415 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); | 414 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); |
| 416 } | 415 } |
| 417 | 416 |
| 418 // static | 417 // static |
| 419 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( | 418 void DevToolsWindow::OpenDevToolsWindow( |
| 420 content::WebContents* inspected_web_contents, | 419 content::WebContents* inspected_web_contents, |
| 421 const DevToolsToggleAction& action) { | 420 const DevToolsToggleAction& action) { |
| 422 return ToggleDevToolsWindow(inspected_web_contents, true, action, ""); | 421 ToggleDevToolsWindow(inspected_web_contents, true, action, ""); |
| 423 } | 422 } |
| 424 | 423 |
| 425 // static | 424 // static |
| 426 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( | 425 void DevToolsWindow::OpenDevToolsWindow( |
| 427 Profile* profile, | 426 Profile* profile, |
| 428 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { | 427 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { |
| 429 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); | 428 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); |
| 430 if (!window) { | 429 if (!window) { |
| 431 window = DevToolsWindow::Create( | 430 window = DevToolsWindow::Create( |
| 432 profile, GURL(), nullptr, false, std::string(), false, std::string()); | 431 profile, GURL(), nullptr, false, std::string(), false, std::string()); |
| 433 DCHECK(window); | 432 if (!window) |
| 433 return; | |
| 434 window->bindings_->AttachTo(agent_host); | 434 window->bindings_->AttachTo(agent_host); |
| 435 } | 435 } |
| 436 window->ScheduleShow(DevToolsToggleAction::Show()); | 436 window->ScheduleShow(DevToolsToggleAction::Show()); |
| 437 return window; | |
| 438 } | 437 } |
| 439 | 438 |
| 440 // static | 439 // static |
| 441 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 440 void DevToolsWindow::ToggleDevToolsWindow( |
| 442 Browser* browser, | 441 Browser* browser, |
| 443 const DevToolsToggleAction& action) { | 442 const DevToolsToggleAction& action) { |
| 444 if (action.type() == DevToolsToggleAction::kToggle && | 443 if (action.type() == DevToolsToggleAction::kToggle && |
| 445 browser->is_devtools()) { | 444 browser->is_devtools()) { |
| 446 browser->tab_strip_model()->CloseAllTabs(); | 445 browser->tab_strip_model()->CloseAllTabs(); |
| 447 return NULL; | 446 return; |
| 448 } | 447 } |
| 449 | 448 |
| 450 return ToggleDevToolsWindow( | 449 ToggleDevToolsWindow( |
| 451 browser->tab_strip_model()->GetActiveWebContents(), | 450 browser->tab_strip_model()->GetActiveWebContents(), |
| 452 action.type() == DevToolsToggleAction::kInspect, | 451 action.type() == DevToolsToggleAction::kInspect, |
| 453 action, ""); | 452 action, ""); |
| 454 } | 453 } |
| 455 | 454 |
| 456 // static | 455 // static |
| 457 void DevToolsWindow::OpenExternalFrontend( | 456 void DevToolsWindow::OpenExternalFrontend( |
| 458 Profile* profile, | 457 Profile* profile, |
| 459 const std::string& frontend_url, | 458 const std::string& frontend_url, |
| 460 const scoped_refptr<content::DevToolsAgentHost>& agent_host, | 459 const scoped_refptr<content::DevToolsAgentHost>& agent_host, |
| 461 bool isWorker) { | 460 bool isWorker) { |
| 462 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); | 461 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); |
| 463 if (!window) { | 462 if (!window) { |
| 464 window = Create(profile, GURL(), nullptr, isWorker, | 463 window = Create(profile, GURL(), nullptr, isWorker, |
| 465 DevToolsUI::GetProxyURL(frontend_url).spec(), false, std::string()); | 464 DevToolsUI::GetProxyURL(frontend_url).spec(), false, std::string()); |
| 466 if (window) | 465 if (!window) |
| 467 window->bindings_->AttachTo(agent_host); | 466 return; |
| 467 window->bindings_->AttachTo(agent_host); | |
| 468 } | 468 } |
| 469 if (window) | 469 |
| 470 window->ScheduleShow(DevToolsToggleAction::Show()); | 470 window->ScheduleShow(DevToolsToggleAction::Show()); |
| 471 } | 471 } |
| 472 | 472 |
| 473 // static | 473 // static |
| 474 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 474 void DevToolsWindow::ToggleDevToolsWindow( |
| 475 content::WebContents* inspected_web_contents, | 475 content::WebContents* inspected_web_contents, |
| 476 bool force_open, | 476 bool force_open, |
| 477 const DevToolsToggleAction& action, | 477 const DevToolsToggleAction& action, |
| 478 const std::string& settings) { | 478 const std::string& settings) { |
| 479 scoped_refptr<DevToolsAgentHost> agent( | 479 scoped_refptr<DevToolsAgentHost> agent( |
| 480 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); | 480 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); |
| 481 DevToolsWindow* window = FindDevToolsWindow(agent.get()); | 481 DevToolsWindow* window = FindDevToolsWindow(agent.get()); |
| 482 bool do_open = force_open; | 482 bool do_open = force_open; |
| 483 if (!window) { | 483 if (!window) { |
| 484 Profile* profile = Profile::FromBrowserContext( | 484 Profile* profile = Profile::FromBrowserContext( |
| 485 inspected_web_contents->GetBrowserContext()); | 485 inspected_web_contents->GetBrowserContext()); |
| 486 content::RecordAction( | 486 content::RecordAction( |
| 487 base::UserMetricsAction("DevTools_InspectRenderer")); | 487 base::UserMetricsAction("DevTools_InspectRenderer")); |
| 488 window = Create(profile, GURL(), inspected_web_contents, | 488 window = Create(profile, GURL(), inspected_web_contents, |
| 489 false, std::string(), true, settings); | 489 false, std::string(), true, settings); |
| 490 DCHECK(window); | 490 if (!window) |
| 491 return; | |
| 491 window->bindings_->AttachTo(agent.get()); | 492 window->bindings_->AttachTo(agent.get()); |
| 492 do_open = true; | 493 do_open = true; |
| 493 } | 494 } |
| 494 | 495 |
| 495 // Update toolbar to reflect DevTools changes. | 496 // Update toolbar to reflect DevTools changes. |
| 496 window->UpdateBrowserToolbar(); | 497 window->UpdateBrowserToolbar(); |
| 497 | 498 |
| 498 // If window is docked and visible, we hide it on toggle. If window is | 499 // If window is docked and visible, we hide it on toggle. If window is |
| 499 // undocked, we show (activate) it. | 500 // undocked, we show (activate) it. |
| 500 if (!window->is_docked_ || do_open) | 501 if (!window->is_docked_ || do_open) |
| 501 window->ScheduleShow(action); | 502 window->ScheduleShow(action); |
| 502 else | 503 else |
| 503 window->CloseWindow(); | 504 window->CloseWindow(); |
| 504 | |
| 505 return window; | |
| 506 } | 505 } |
| 507 | 506 |
| 508 // static | 507 // static |
| 509 void DevToolsWindow::InspectElement( | 508 void DevToolsWindow::InspectElement( |
| 510 content::WebContents* inspected_web_contents, | 509 content::WebContents* inspected_web_contents, |
| 511 int x, | 510 int x, |
| 512 int y) { | 511 int y) { |
| 513 scoped_refptr<DevToolsAgentHost> agent( | 512 scoped_refptr<DevToolsAgentHost> agent( |
| 514 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); | 513 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); |
| 515 agent->InspectElement(x, y); | 514 agent->InspectElement(x, y); |
| 516 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; | 515 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; |
| 517 base::TimeTicks start_time = base::TimeTicks::Now(); | 516 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 518 // TODO(loislo): we should initiate DevTools window opening from within | 517 // TODO(loislo): we should initiate DevTools window opening from within |
| 519 // renderer. Otherwise, we still can hit a race condition here. | 518 // renderer. Otherwise, we still can hit a race condition here. |
| 520 DevToolsWindow* window = OpenDevToolsWindow(inspected_web_contents); | 519 OpenDevToolsWindow(inspected_web_contents); |
| 521 if (should_measure_time) | 520 |
| 521 DevToolsWindow* window = FindDevToolsWindow(agent.get()); | |
| 522 if (should_measure_time && window) | |
| 522 window->inspect_element_start_time_ = start_time; | 523 window->inspect_element_start_time_ = start_time; |
| 523 } | 524 } |
| 524 | 525 |
| 525 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) { | 526 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) { |
| 526 if (life_stage_ == kLoadCompleted) { | 527 if (life_stage_ == kLoadCompleted) { |
| 527 Show(action); | 528 Show(action); |
| 528 return; | 529 return; |
| 529 } | 530 } |
| 530 | 531 |
| 531 // Action will be done only after load completed. | 532 // Action will be done only after load completed. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 | 716 |
| 716 // static | 717 // static |
| 717 DevToolsWindow* DevToolsWindow::Create( | 718 DevToolsWindow* DevToolsWindow::Create( |
| 718 Profile* profile, | 719 Profile* profile, |
| 719 const GURL& frontend_url, | 720 const GURL& frontend_url, |
| 720 content::WebContents* inspected_web_contents, | 721 content::WebContents* inspected_web_contents, |
| 721 bool shared_worker_frontend, | 722 bool shared_worker_frontend, |
| 722 const std::string& remote_frontend, | 723 const std::string& remote_frontend, |
| 723 bool can_dock, | 724 bool can_dock, |
| 724 const std::string& settings) { | 725 const std::string& settings) { |
| 726 // If development tools disabled by policy don't open the window. | |
|
dgozman
2015/03/11 10:32:31
nit: "development" -> "developer"
| |
| 727 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) | |
| 728 return nullptr; | |
| 729 | |
| 725 if (inspected_web_contents) { | 730 if (inspected_web_contents) { |
| 726 // Check for a place to dock. | 731 // Check for a place to dock. |
| 727 Browser* browser = NULL; | 732 Browser* browser = NULL; |
| 728 int tab; | 733 int tab; |
| 729 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, | 734 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, |
| 730 &browser, &tab) || | 735 &browser, &tab) || |
| 731 browser->is_type_popup()) { | 736 browser->is_type_popup()) { |
| 732 can_dock = false; | 737 can_dock = false; |
| 733 } | 738 } |
| 734 } | 739 } |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1220 closure.Run(); | 1225 closure.Run(); |
| 1221 return; | 1226 return; |
| 1222 } | 1227 } |
| 1223 load_completed_callback_ = closure; | 1228 load_completed_callback_ = closure; |
| 1224 } | 1229 } |
| 1225 | 1230 |
| 1226 bool DevToolsWindow::ForwardKeyboardEvent( | 1231 bool DevToolsWindow::ForwardKeyboardEvent( |
| 1227 const content::NativeWebKeyboardEvent& event) { | 1232 const content::NativeWebKeyboardEvent& event) { |
| 1228 return event_forwarder_->ForwardEvent(event); | 1233 return event_forwarder_->ForwardEvent(event); |
| 1229 } | 1234 } |
| OLD | NEW |