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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 return false; | 387 return false; |
| 388 } | 388 } |
| 389 | 389 |
| 390 // static | 390 // static |
| 391 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( | 391 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( |
| 392 Profile* profile, | 392 Profile* profile, |
| 393 const scoped_refptr<DevToolsAgentHost>& worker_agent) { | 393 const scoped_refptr<DevToolsAgentHost>& worker_agent) { |
| 394 DevToolsWindow* window = FindDevToolsWindow(worker_agent.get()); | 394 DevToolsWindow* window = FindDevToolsWindow(worker_agent.get()); |
| 395 if (!window) { | 395 if (!window) { |
| 396 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); | 396 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); |
| 397 window->bindings_->AttachTo(worker_agent); | 397 if (window) |
| 398 window->bindings_->AttachTo(worker_agent); | |
| 398 } | 399 } |
| 399 window->ScheduleShow(DevToolsToggleAction::Show()); | 400 window->ScheduleShow(DevToolsToggleAction::Show()); |
| 400 return window; | 401 return window; |
| 401 } | 402 } |
| 402 | 403 |
| 403 // static | 404 // static |
| 404 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( | 405 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( |
| 405 Profile* profile) { | 406 Profile* profile) { |
| 406 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); | 407 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); |
| 407 return Create(profile, GURL(), NULL, true, std::string(), false, ""); | 408 return Create(profile, GURL(), NULL, true, std::string(), false, ""); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 438 } | 439 } |
| 439 | 440 |
| 440 // static | 441 // static |
| 441 void DevToolsWindow::OpenExternalFrontend( | 442 void DevToolsWindow::OpenExternalFrontend( |
| 442 Profile* profile, | 443 Profile* profile, |
| 443 const std::string& frontend_url, | 444 const std::string& frontend_url, |
| 444 const scoped_refptr<content::DevToolsAgentHost>& agent_host, | 445 const scoped_refptr<content::DevToolsAgentHost>& agent_host, |
| 445 bool isWorker) { | 446 bool isWorker) { |
| 446 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); | 447 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); |
| 447 if (!window) { | 448 if (!window) { |
| 448 window = Create(profile, GURL(), NULL, isWorker, | 449 window = Create(profile, GURL(), nullptr, isWorker, |
| 449 DevToolsUI::GetProxyURL(frontend_url).spec(), false, ""); | 450 DevToolsUI::GetProxyURL(frontend_url).spec(), false, ""); |
| 450 window->bindings_->AttachTo(agent_host); | 451 if (window) |
|
dgozman
2015/01/29 15:50:35
Let's only |if (window)| in this method, and |DCHE
vkuzkokov
2015/01/30 12:44:15
Done.
| |
| 452 window->bindings_->AttachTo(agent_host); | |
| 451 } | 453 } |
| 452 window->ScheduleShow(DevToolsToggleAction::Show()); | 454 window->ScheduleShow(DevToolsToggleAction::Show()); |
|
dgozman
2015/01/29 15:50:35
This |window| may be nullptr.
vkuzkokov
2015/01/30 12:44:15
Done.
| |
| 453 } | 455 } |
| 454 | 456 |
| 455 // static | 457 // static |
| 456 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 458 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( |
| 457 content::WebContents* inspected_web_contents, | 459 content::WebContents* inspected_web_contents, |
| 458 bool force_open, | 460 bool force_open, |
| 459 const DevToolsToggleAction& action, | 461 const DevToolsToggleAction& action, |
| 460 const std::string& settings) { | 462 const std::string& settings) { |
| 461 scoped_refptr<DevToolsAgentHost> agent( | 463 scoped_refptr<DevToolsAgentHost> agent( |
| 462 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); | 464 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); |
| 463 DevToolsWindow* window = FindDevToolsWindow(agent.get()); | 465 DevToolsWindow* window = FindDevToolsWindow(agent.get()); |
| 464 bool do_open = force_open; | 466 bool do_open = force_open; |
| 465 if (!window) { | 467 if (!window) { |
| 466 Profile* profile = Profile::FromBrowserContext( | 468 Profile* profile = Profile::FromBrowserContext( |
| 467 inspected_web_contents->GetBrowserContext()); | 469 inspected_web_contents->GetBrowserContext()); |
| 468 content::RecordAction( | 470 content::RecordAction( |
| 469 base::UserMetricsAction("DevTools_InspectRenderer")); | 471 base::UserMetricsAction("DevTools_InspectRenderer")); |
| 470 window = Create(profile, GURL(), inspected_web_contents, | 472 window = Create(profile, GURL(), inspected_web_contents, |
| 471 false, std::string(), true, settings); | 473 false, std::string(), true, settings); |
| 474 if (!window) | |
| 475 return nullptr; | |
| 472 window->bindings_->AttachTo(agent.get()); | 476 window->bindings_->AttachTo(agent.get()); |
| 473 do_open = true; | 477 do_open = true; |
| 474 } | 478 } |
| 475 | 479 |
| 476 // Update toolbar to reflect DevTools changes. | 480 // Update toolbar to reflect DevTools changes. |
| 477 window->UpdateBrowserToolbar(); | 481 window->UpdateBrowserToolbar(); |
| 478 | 482 |
| 479 // If window is docked and visible, we hide it on toggle. If window is | 483 // If window is docked and visible, we hide it on toggle. If window is |
| 480 // undocked, we show (activate) it. | 484 // undocked, we show (activate) it. |
| 481 if (!window->is_docked_ || do_open) | 485 if (!window->is_docked_ || do_open) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 492 int x, | 496 int x, |
| 493 int y) { | 497 int y) { |
| 494 scoped_refptr<DevToolsAgentHost> agent( | 498 scoped_refptr<DevToolsAgentHost> agent( |
| 495 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); | 499 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); |
| 496 agent->InspectElement(x, y); | 500 agent->InspectElement(x, y); |
| 497 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; | 501 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; |
| 498 base::TimeTicks start_time = base::TimeTicks::Now(); | 502 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 499 // TODO(loislo): we should initiate DevTools window opening from within | 503 // TODO(loislo): we should initiate DevTools window opening from within |
| 500 // renderer. Otherwise, we still can hit a race condition here. | 504 // renderer. Otherwise, we still can hit a race condition here. |
| 501 DevToolsWindow* window = OpenDevToolsWindow(inspected_web_contents); | 505 DevToolsWindow* window = OpenDevToolsWindow(inspected_web_contents); |
| 502 if (should_measure_time) | 506 if (window && should_measure_time) |
| 503 window->inspect_element_start_time_ = start_time; | 507 window->inspect_element_start_time_ = start_time; |
| 504 } | 508 } |
| 505 | 509 |
| 506 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) { | 510 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) { |
| 507 if (life_stage_ == kLoadCompleted) { | 511 if (life_stage_ == kLoadCompleted) { |
| 508 Show(action); | 512 Show(action); |
| 509 return; | 513 return; |
| 510 } | 514 } |
| 511 | 515 |
| 512 // Action will be done only after load completed. | 516 // Action will be done only after load completed. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 intercepted_page_beforeunload_(false) { | 669 intercepted_page_beforeunload_(false) { |
| 666 // Set up delegate, so we get fully-functional window immediately. | 670 // Set up delegate, so we get fully-functional window immediately. |
| 667 // It will not appear in UI though until |life_stage_ == kLoadCompleted|. | 671 // It will not appear in UI though until |life_stage_ == kLoadCompleted|. |
| 668 main_web_contents_->SetDelegate(this); | 672 main_web_contents_->SetDelegate(this); |
| 669 | 673 |
| 670 main_web_contents_->GetController().LoadURL( | 674 main_web_contents_->GetController().LoadURL( |
| 671 DevToolsUIBindings::ApplyThemeToURL(profile, url), content::Referrer(), | 675 DevToolsUIBindings::ApplyThemeToURL(profile, url), content::Referrer(), |
| 672 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 676 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
| 673 | 677 |
| 674 bindings_ = DevToolsUIBindings::ForWebContents(main_web_contents_); | 678 bindings_ = DevToolsUIBindings::ForWebContents(main_web_contents_); |
| 675 DCHECK(bindings_); | 679 if (!bindings_) |
| 680 return; | |
| 676 | 681 |
| 677 // Bindings take ownership over devtools as its delegate. | 682 // Bindings take ownership over devtools as its delegate. |
| 678 bindings_->SetDelegate(this); | 683 bindings_->SetDelegate(this); |
| 679 // DevTools uses PageZoom::Zoom(), so main_web_contents_ requires a | 684 // DevTools uses PageZoom::Zoom(), so main_web_contents_ requires a |
| 680 // ZoomController. | 685 // ZoomController. |
| 681 ui_zoom::ZoomController::CreateForWebContents(main_web_contents_); | 686 ui_zoom::ZoomController::CreateForWebContents(main_web_contents_); |
| 682 ui_zoom::ZoomController::FromWebContents(main_web_contents_) | 687 ui_zoom::ZoomController::FromWebContents(main_web_contents_) |
| 683 ->SetShowsNotificationBubble(false); | 688 ->SetShowsNotificationBubble(false); |
| 684 | 689 |
| 685 g_instances.Get().push_back(this); | 690 g_instances.Get().push_back(this); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 browser->is_type_popup()) { | 725 browser->is_type_popup()) { |
| 721 can_dock = false; | 726 can_dock = false; |
| 722 } | 727 } |
| 723 } | 728 } |
| 724 | 729 |
| 725 // Create WebContents with devtools. | 730 // Create WebContents with devtools. |
| 726 GURL url(GetDevToolsURL(profile, frontend_url, | 731 GURL url(GetDevToolsURL(profile, frontend_url, |
| 727 shared_worker_frontend, | 732 shared_worker_frontend, |
| 728 remote_frontend, | 733 remote_frontend, |
| 729 can_dock, settings)); | 734 can_dock, settings)); |
| 730 return new DevToolsWindow(profile, url, inspected_web_contents, can_dock); | 735 DevToolsWindow* window = |
| 736 new DevToolsWindow(profile, url, inspected_web_contents, can_dock); | |
| 737 if (!window->bindings_) { | |
|
pfeldman
2015/01/29 16:09:59
Why is this happening? It makes code so much more
vkuzkokov
2015/01/30 12:44:14
DevToolsUI might be not created for some reason. B
| |
| 738 delete window; | |
| 739 window = nullptr; | |
| 740 } | |
| 741 return window; | |
| 731 } | 742 } |
| 732 | 743 |
| 733 // static | 744 // static |
| 734 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, | 745 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, |
| 735 const GURL& base_url, | 746 const GURL& base_url, |
| 736 bool shared_worker_frontend, | 747 bool shared_worker_frontend, |
| 737 const std::string& remote_frontend, | 748 const std::string& remote_frontend, |
| 738 bool can_dock, | 749 bool can_dock, |
| 739 const std::string& settings) { | 750 const std::string& settings) { |
| 740 // Compatibility errors are encoded with data urls, pass them | 751 // Compatibility errors are encoded with data urls, pass them |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1194 closure.Run(); | 1205 closure.Run(); |
| 1195 return; | 1206 return; |
| 1196 } | 1207 } |
| 1197 load_completed_callback_ = closure; | 1208 load_completed_callback_ = closure; |
| 1198 } | 1209 } |
| 1199 | 1210 |
| 1200 bool DevToolsWindow::ForwardKeyboardEvent( | 1211 bool DevToolsWindow::ForwardKeyboardEvent( |
| 1201 const content::NativeWebKeyboardEvent& event) { | 1212 const content::NativeWebKeyboardEvent& event) { |
| 1202 return event_forwarder_->ForwardEvent(event); | 1213 return event_forwarder_->ForwardEvent(event); |
| 1203 } | 1214 } |
| OLD | NEW |