OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/themes/theme_service_factory.h" | 23 #include "chrome/browser/themes/theme_service_factory.h" |
24 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_list.h" |
26 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
28 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
30 #include "chrome/common/render_messages.h" | 30 #include "chrome/common/render_messages.h" |
31 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
32 #include "content/browser/browsing_instance.h" | 32 #include "content/browser/browsing_instance.h" |
33 #include "content/browser/debugger/devtools_manager.h" | |
34 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 33 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
35 #include "content/browser/load_notification_details.h" | 34 #include "content/browser/load_notification_details.h" |
36 #include "content/browser/renderer_host/render_view_host.h" | 35 #include "content/browser/renderer_host/render_view_host.h" |
37 #include "content/browser/tab_contents/navigation_controller.h" | 36 #include "content/browser/tab_contents/navigation_controller.h" |
38 #include "content/browser/tab_contents/navigation_entry.h" | 37 #include "content/browser/tab_contents/navigation_entry.h" |
39 #include "content/browser/tab_contents/tab_contents.h" | 38 #include "content/browser/tab_contents/tab_contents.h" |
40 #include "content/browser/tab_contents/tab_contents_view.h" | 39 #include "content/browser/tab_contents/tab_contents_view.h" |
41 #include "content/common/devtools_messages.h" | 40 #include "content/common/devtools_messages.h" |
42 #include "content/public/browser/content_browser_client.h" | 41 #include "content/public/browser/content_browser_client.h" |
| 42 #include "content/public/browser/devtools/devtools_agent_host_registry.h" |
| 43 #include "content/public/browser/devtools/devtools_manager.h" |
43 #include "content/public/browser/notification_source.h" | 44 #include "content/public/browser/notification_source.h" |
44 #include "content/public/common/bindings_policy.h" | 45 #include "content/public/common/bindings_policy.h" |
45 #include "grit/generated_resources.h" | 46 #include "grit/generated_resources.h" |
46 | 47 |
| 48 using content::DevToolsAgentHostRegistry; |
| 49 |
47 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; | 50 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; |
48 | 51 |
49 // static | 52 // static |
50 void DevToolsWindow::RegisterUserPrefs(PrefService* prefs) { | 53 void DevToolsWindow::RegisterUserPrefs(PrefService* prefs) { |
51 prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked, | 54 prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked, |
52 true, | 55 true, |
53 PrefService::UNSYNCABLE_PREF); | 56 PrefService::UNSYNCABLE_PREF); |
54 } | 57 } |
55 | 58 |
56 // static | 59 // static |
57 TabContentsWrapper* DevToolsWindow::GetDevToolsContents( | 60 TabContentsWrapper* DevToolsWindow::GetDevToolsContents( |
58 TabContents* inspected_tab) { | 61 TabContents* inspected_tab) { |
59 if (!inspected_tab) | 62 if (!inspected_tab) |
60 return NULL; | 63 return NULL; |
61 | 64 |
62 DevToolsManager* manager = DevToolsManager::GetInstance(); | 65 content::DevToolsManager* manager = |
63 if (!manager) | 66 content::DevToolsManager::GetInstance(); |
64 return NULL; // Happens only in tests. | 67 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::FindDevToolsAgentHost( |
65 | 68 inspected_tab->render_view_host()); |
66 DevToolsClientHost* client_host = manager-> | 69 if (!agent) |
67 GetDevToolsClientHostFor(inspected_tab->render_view_host()); | 70 return NULL; |
| 71 DevToolsClientHost* client_host = manager->GetDevToolsClientHostFor(agent); |
68 DevToolsWindow* window = AsDevToolsWindow(client_host); | 72 DevToolsWindow* window = AsDevToolsWindow(client_host); |
69 if (!window || !window->is_docked()) | 73 if (!window || !window->is_docked()) |
70 return NULL; | 74 return NULL; |
71 return window->tab_contents(); | 75 return window->tab_contents(); |
72 } | 76 } |
73 | 77 |
74 // static | 78 // static |
75 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( | 79 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( |
76 RenderViewHost* window_rvh) { | 80 RenderViewHost* window_rvh) { |
77 DevToolsClientHost* client_host = | 81 DevToolsClientHost* client_host = |
78 DevToolsClientHost::FindOwnerClientHost(window_rvh); | 82 DevToolsClientHost::FindOwnerClientHost(window_rvh); |
79 return client_host != NULL ? DevToolsWindow::AsDevToolsWindow(client_host) | 83 return client_host != NULL ? DevToolsWindow::AsDevToolsWindow(client_host) |
80 : NULL; | 84 : NULL; |
81 } | 85 } |
82 | 86 |
83 // static | 87 // static |
84 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( | 88 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( |
85 Profile* profile, | 89 Profile* profile, |
86 DevToolsAgentHost* worker_agent) { | 90 DevToolsAgentHost* worker_agent) { |
87 DevToolsWindow* window; | 91 DevToolsWindow* window; |
88 DevToolsClientHost* client = | 92 DevToolsClientHost* client = content::DevToolsManager::GetInstance()-> |
89 DevToolsManager::GetInstance()->GetDevToolsClientHostFor(worker_agent); | 93 GetDevToolsClientHostFor(worker_agent); |
90 if (client) { | 94 if (client) { |
91 window = AsDevToolsWindow(client); | 95 window = AsDevToolsWindow(client); |
92 if (!window) | 96 if (!window) |
93 return NULL; | 97 return NULL; |
94 } else { | 98 } else { |
95 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); | 99 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); |
96 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(worker_agent, | 100 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
97 window); | 101 worker_agent, |
| 102 window); |
98 } | 103 } |
99 window->Show(DEVTOOLS_TOGGLE_ACTION_NONE); | 104 window->Show(DEVTOOLS_TOGGLE_ACTION_NONE); |
100 return window; | 105 return window; |
101 } | 106 } |
102 | 107 |
103 // static | 108 // static |
104 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( | 109 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( |
105 Profile* profile) { | 110 Profile* profile) { |
106 return Create(profile, NULL, false, true); | 111 return Create(profile, NULL, false, true); |
107 } | 112 } |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 if (inspected_window) | 612 if (inspected_window) |
608 inspected_window->HandleKeyboardEvent(event); | 613 inspected_window->HandleKeyboardEvent(event); |
609 } | 614 } |
610 } | 615 } |
611 | 616 |
612 // static | 617 // static |
613 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 618 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( |
614 RenderViewHost* inspected_rvh, | 619 RenderViewHost* inspected_rvh, |
615 bool force_open, | 620 bool force_open, |
616 DevToolsToggleAction action) { | 621 DevToolsToggleAction action) { |
617 DevToolsManager* manager = DevToolsManager::GetInstance(); | 622 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
618 | 623 inspected_rvh); |
619 DevToolsClientHost* host = manager->GetDevToolsClientHostFor(inspected_rvh); | 624 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); |
| 625 DevToolsClientHost* host = manager->GetDevToolsClientHostFor(agent); |
620 DevToolsWindow* window = AsDevToolsWindow(host); | 626 DevToolsWindow* window = AsDevToolsWindow(host); |
621 if (host != NULL && window == NULL) { | 627 if (host != NULL && window == NULL) { |
622 // Break remote debugging / extension debugging session. | 628 // Break remote debugging / extension debugging session. |
623 manager->UnregisterDevToolsClientHostFor(inspected_rvh); | 629 manager->UnregisterDevToolsClientHostFor(agent); |
624 } | 630 } |
625 | 631 |
626 bool do_open = force_open; | 632 bool do_open = force_open; |
627 if (!window) { | 633 if (!window) { |
628 Profile* profile = Profile::FromBrowserContext( | 634 Profile* profile = Profile::FromBrowserContext( |
629 inspected_rvh->process()->GetBrowserContext()); | 635 inspected_rvh->process()->GetBrowserContext()); |
630 bool docked = profile->GetPrefs()->GetBoolean(prefs::kDevToolsOpenDocked); | 636 bool docked = profile->GetPrefs()->GetBoolean(prefs::kDevToolsOpenDocked); |
631 window = Create(profile, inspected_rvh, docked, false); | 637 window = Create(profile, inspected_rvh, docked, false); |
632 manager->RegisterDevToolsClientHostFor(inspected_rvh, window); | 638 manager->RegisterDevToolsClientHostFor(agent, window); |
633 do_open = true; | 639 do_open = true; |
634 } | 640 } |
635 | 641 |
636 // If window is docked and visible, we hide it on toggle. If window is | 642 // If window is docked and visible, we hide it on toggle. If window is |
637 // undocked, we show (activate) it. | 643 // undocked, we show (activate) it. |
638 if (!window->is_docked() || do_open) | 644 if (!window->is_docked() || do_open) |
639 window->Show(action); | 645 window->Show(action); |
640 else | 646 else |
641 manager->UnregisterDevToolsClientHostFor(inspected_rvh); | 647 manager->UnregisterDevToolsClientHostFor(agent); |
642 | 648 |
643 return window; | 649 return window; |
644 } | 650 } |
645 | 651 |
646 // static | 652 // static |
647 DevToolsWindow* DevToolsWindow::AsDevToolsWindow( | 653 DevToolsWindow* DevToolsWindow::AsDevToolsWindow( |
648 DevToolsClientHost* client_host) { | 654 DevToolsClientHost* client_host) { |
649 if (!client_host) | 655 if (!client_host) |
650 return NULL; | 656 return NULL; |
651 if (client_host->GetClientRenderViewHost() != NULL) | 657 if (client_host->GetClientRenderViewHost() != NULL) |
(...skipping 30 matching lines...) Expand all Loading... |
682 RequestSetDocked(false); | 688 RequestSetDocked(false); |
683 } | 689 } |
684 | 690 |
685 content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() { | 691 content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() { |
686 if (inspected_tab_ && inspected_tab_->tab_contents()->delegate()) { | 692 if (inspected_tab_ && inspected_tab_->tab_contents()->delegate()) { |
687 return inspected_tab_->tab_contents()->delegate()-> | 693 return inspected_tab_->tab_contents()->delegate()-> |
688 GetJavaScriptDialogCreator(); | 694 GetJavaScriptDialogCreator(); |
689 } | 695 } |
690 return TabContentsDelegate::GetJavaScriptDialogCreator(); | 696 return TabContentsDelegate::GetJavaScriptDialogCreator(); |
691 } | 697 } |
OLD | NEW |