| 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 27 matching lines...) Expand all Loading... |
| 38 #include "content/public/browser/navigation_controller.h" | 38 #include "content/public/browser/navigation_controller.h" |
| 39 #include "content/public/browser/navigation_entry.h" | 39 #include "content/public/browser/navigation_entry.h" |
| 40 #include "content/public/browser/render_frame_host.h" | 40 #include "content/public/browser/render_frame_host.h" |
| 41 #include "content/public/browser/render_process_host.h" | 41 #include "content/public/browser/render_process_host.h" |
| 42 #include "content/public/browser/render_view_host.h" | 42 #include "content/public/browser/render_view_host.h" |
| 43 #include "content/public/browser/render_widget_host_view.h" | 43 #include "content/public/browser/render_widget_host_view.h" |
| 44 #include "content/public/browser/user_metrics.h" | 44 #include "content/public/browser/user_metrics.h" |
| 45 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
| 46 #include "content/public/common/content_client.h" | 46 #include "content/public/common/content_client.h" |
| 47 #include "content/public/common/url_constants.h" | 47 #include "content/public/common/url_constants.h" |
| 48 #include "net/base/escape.h" |
| 48 #include "third_party/WebKit/public/web/WebInputEvent.h" | 49 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 49 #include "ui/base/page_transition_types.h" | 50 #include "ui/base/page_transition_types.h" |
| 50 #include "ui/events/keycodes/keyboard_codes.h" | 51 #include "ui/events/keycodes/keyboard_codes.h" |
| 51 | 52 |
| 52 using base::DictionaryValue; | 53 using base::DictionaryValue; |
| 53 using blink::WebInputEvent; | 54 using blink::WebInputEvent; |
| 54 using content::BrowserThread; | 55 using content::BrowserThread; |
| 55 using content::DevToolsAgentHost; | 56 using content::DevToolsAgentHost; |
| 56 using content::WebContents; | 57 using content::WebContents; |
| 57 | 58 |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 window->bindings_->AttachTo(worker_agent); | 412 window->bindings_->AttachTo(worker_agent); |
| 412 } | 413 } |
| 413 window->ScheduleShow(DevToolsToggleAction::Show()); | 414 window->ScheduleShow(DevToolsToggleAction::Show()); |
| 414 return window; | 415 return window; |
| 415 } | 416 } |
| 416 | 417 |
| 417 // static | 418 // static |
| 418 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( | 419 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( |
| 419 Profile* profile) { | 420 Profile* profile) { |
| 420 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); | 421 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); |
| 421 return Create(profile, GURL(), NULL, true, false, false, ""); | 422 return Create(profile, GURL(), NULL, true, std::string(), false, ""); |
| 422 } | 423 } |
| 423 | 424 |
| 424 // static | 425 // static |
| 425 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( | 426 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( |
| 426 content::WebContents* inspected_web_contents) { | 427 content::WebContents* inspected_web_contents) { |
| 427 return ToggleDevToolsWindow( | 428 return ToggleDevToolsWindow( |
| 428 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); | 429 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); |
| 429 } | 430 } |
| 430 | 431 |
| 431 // static | 432 // static |
| (...skipping 20 matching lines...) Expand all Loading... |
| 452 } | 453 } |
| 453 | 454 |
| 454 // static | 455 // static |
| 455 void DevToolsWindow::OpenExternalFrontend( | 456 void DevToolsWindow::OpenExternalFrontend( |
| 456 Profile* profile, | 457 Profile* profile, |
| 457 const std::string& frontend_url, | 458 const std::string& frontend_url, |
| 458 const scoped_refptr<content::DevToolsAgentHost>& agent_host, | 459 const scoped_refptr<content::DevToolsAgentHost>& agent_host, |
| 459 bool isWorker) { | 460 bool isWorker) { |
| 460 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); | 461 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); |
| 461 if (!window) { | 462 if (!window) { |
| 462 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, | 463 window = Create(profile, GURL(), NULL, isWorker, |
| 463 isWorker, true, false, ""); | 464 DevToolsUI::GetProxyURL(frontend_url).spec(), false, ""); |
| 464 window->bindings_->AttachTo(agent_host); | 465 window->bindings_->AttachTo(agent_host); |
| 465 } | 466 } |
| 466 window->ScheduleShow(DevToolsToggleAction::Show()); | 467 window->ScheduleShow(DevToolsToggleAction::Show()); |
| 467 } | 468 } |
| 468 | 469 |
| 469 // static | 470 // static |
| 470 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 471 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( |
| 471 content::WebContents* inspected_web_contents, | 472 content::WebContents* inspected_web_contents, |
| 472 bool force_open, | 473 bool force_open, |
| 473 const DevToolsToggleAction& action, | 474 const DevToolsToggleAction& action, |
| 474 const std::string& settings) { | 475 const std::string& settings) { |
| 475 scoped_refptr<DevToolsAgentHost> agent( | 476 scoped_refptr<DevToolsAgentHost> agent( |
| 476 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); | 477 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); |
| 477 DevToolsWindow* window = FindDevToolsWindow(agent.get()); | 478 DevToolsWindow* window = FindDevToolsWindow(agent.get()); |
| 478 bool do_open = force_open; | 479 bool do_open = force_open; |
| 479 if (!window) { | 480 if (!window) { |
| 480 Profile* profile = Profile::FromBrowserContext( | 481 Profile* profile = Profile::FromBrowserContext( |
| 481 inspected_web_contents->GetBrowserContext()); | 482 inspected_web_contents->GetBrowserContext()); |
| 482 content::RecordAction( | 483 content::RecordAction( |
| 483 base::UserMetricsAction("DevTools_InspectRenderer")); | 484 base::UserMetricsAction("DevTools_InspectRenderer")); |
| 484 window = Create( | 485 window = Create(profile, GURL(), inspected_web_contents, |
| 485 profile, GURL(), inspected_web_contents, false, false, true, settings); | 486 false, std::string(), true, settings); |
| 486 window->bindings_->AttachTo(agent.get()); | 487 window->bindings_->AttachTo(agent.get()); |
| 487 do_open = true; | 488 do_open = true; |
| 488 } | 489 } |
| 489 | 490 |
| 490 // Update toolbar to reflect DevTools changes. | 491 // Update toolbar to reflect DevTools changes. |
| 491 window->UpdateBrowserToolbar(); | 492 window->UpdateBrowserToolbar(); |
| 492 | 493 |
| 493 // If window is docked and visible, we hide it on toggle. If window is | 494 // If window is docked and visible, we hide it on toggle. If window is |
| 494 // undocked, we show (activate) it. | 495 // undocked, we show (activate) it. |
| 495 if (!window->is_docked_ || do_open) | 496 if (!window->is_docked_ || do_open) |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 | 716 |
| 716 event_forwarder_.reset(new DevToolsEventForwarder(this)); | 717 event_forwarder_.reset(new DevToolsEventForwarder(this)); |
| 717 } | 718 } |
| 718 | 719 |
| 719 // static | 720 // static |
| 720 DevToolsWindow* DevToolsWindow::Create( | 721 DevToolsWindow* DevToolsWindow::Create( |
| 721 Profile* profile, | 722 Profile* profile, |
| 722 const GURL& frontend_url, | 723 const GURL& frontend_url, |
| 723 content::WebContents* inspected_web_contents, | 724 content::WebContents* inspected_web_contents, |
| 724 bool shared_worker_frontend, | 725 bool shared_worker_frontend, |
| 725 bool external_frontend, | 726 const std::string& remote_frontend, |
| 726 bool can_dock, | 727 bool can_dock, |
| 727 const std::string& settings) { | 728 const std::string& settings) { |
| 728 if (inspected_web_contents) { | 729 if (inspected_web_contents) { |
| 729 // Check for a place to dock. | 730 // Check for a place to dock. |
| 730 Browser* browser = NULL; | 731 Browser* browser = NULL; |
| 731 int tab; | 732 int tab; |
| 732 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, | 733 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, |
| 733 &browser, &tab) || | 734 &browser, &tab) || |
| 734 browser->is_type_popup()) { | 735 browser->is_type_popup()) { |
| 735 can_dock = false; | 736 can_dock = false; |
| 736 } | 737 } |
| 737 } | 738 } |
| 738 | 739 |
| 739 // Create WebContents with devtools. | 740 // Create WebContents with devtools. |
| 740 GURL url(GetDevToolsURL(profile, frontend_url, | 741 GURL url(GetDevToolsURL(profile, frontend_url, |
| 741 shared_worker_frontend, | 742 shared_worker_frontend, |
| 742 external_frontend, | 743 remote_frontend, |
| 743 can_dock, settings)); | 744 can_dock, settings)); |
| 744 return new DevToolsWindow(profile, url, inspected_web_contents, can_dock); | 745 return new DevToolsWindow(profile, url, inspected_web_contents, can_dock); |
| 745 } | 746 } |
| 746 | 747 |
| 747 // static | 748 // static |
| 748 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, | 749 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, |
| 749 const GURL& base_url, | 750 const GURL& base_url, |
| 750 bool shared_worker_frontend, | 751 bool shared_worker_frontend, |
| 751 bool external_frontend, | 752 const std::string& remote_frontend, |
| 752 bool can_dock, | 753 bool can_dock, |
| 753 const std::string& settings) { | 754 const std::string& settings) { |
| 754 // Compatibility errors are encoded with data urls, pass them | 755 // Compatibility errors are encoded with data urls, pass them |
| 755 // through with no decoration. | 756 // through with no decoration. |
| 756 if (base_url.SchemeIs("data")) | 757 if (base_url.SchemeIs("data")) |
| 757 return base_url; | 758 return base_url; |
| 758 | 759 |
| 759 std::string frontend_url( | 760 std::string frontend_url( |
| 760 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); | 761 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); |
| 761 std::string url_string( | 762 std::string url_string( |
| 762 frontend_url + | 763 frontend_url + |
| 763 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); | 764 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); |
| 764 if (shared_worker_frontend) | 765 if (shared_worker_frontend) |
| 765 url_string += "&isSharedWorker=true"; | 766 url_string += "&isSharedWorker=true"; |
| 766 if (external_frontend) | 767 if (remote_frontend.size()) { |
| 767 url_string += "&remoteFrontend=true"; | 768 url_string += "&remoteFrontend=true"; |
| 769 url_string += "&remoteFrontendUrl=" + net::EscapePath(remote_frontend); |
| 770 } |
| 768 if (can_dock) | 771 if (can_dock) |
| 769 url_string += "&can_dock=true"; | 772 url_string += "&can_dock=true"; |
| 770 if (settings.size()) | 773 if (settings.size()) |
| 771 url_string += "&settings=" + settings; | 774 url_string += "&settings=" + settings; |
| 772 return GURL(url_string); | 775 return GURL(url_string); |
| 773 } | 776 } |
| 774 | 777 |
| 775 // static | 778 // static |
| 776 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( | 779 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( |
| 777 DevToolsAgentHost* agent_host) { | 780 DevToolsAgentHost* agent_host) { |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 closure.Run(); | 1237 closure.Run(); |
| 1235 return; | 1238 return; |
| 1236 } | 1239 } |
| 1237 load_completed_callback_ = closure; | 1240 load_completed_callback_ = closure; |
| 1238 } | 1241 } |
| 1239 | 1242 |
| 1240 bool DevToolsWindow::ForwardKeyboardEvent( | 1243 bool DevToolsWindow::ForwardKeyboardEvent( |
| 1241 const content::NativeWebKeyboardEvent& event) { | 1244 const content::NativeWebKeyboardEvent& event) { |
| 1242 return event_forwarder_->ForwardEvent(event); | 1245 return event_forwarder_->ForwardEvent(event); |
| 1243 } | 1246 } |
| OLD | NEW |