Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: chrome/browser/debugger/devtools_window.cc

Issue 8549022: Define DevTools content API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DevToolsManager -> DevToolsManagerImpl, moved client to public Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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::DevToolsAgentHost;
49 using content::DevToolsAgentHostRegistry;
50
47 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; 51 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp";
48 52
49 // static 53 // static
50 void DevToolsWindow::RegisterUserPrefs(PrefService* prefs) { 54 void DevToolsWindow::RegisterUserPrefs(PrefService* prefs) {
51 prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked, 55 prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked,
52 true, 56 true,
53 PrefService::UNSYNCABLE_PREF); 57 PrefService::UNSYNCABLE_PREF);
54 } 58 }
55 59
56 // static 60 // static
57 TabContentsWrapper* DevToolsWindow::GetDevToolsContents( 61 TabContentsWrapper* DevToolsWindow::GetDevToolsContents(
58 TabContents* inspected_tab) { 62 TabContents* inspected_tab) {
59 if (!inspected_tab) 63 if (!inspected_tab)
60 return NULL; 64 return NULL;
61 65
62 DevToolsManager* manager = DevToolsManager::GetInstance(); 66 content::DevToolsManager* manager =
63 if (!manager) 67 content::DevToolsManager::GetInstance();
64 return NULL; // Happens only in tests. 68 if (!DevToolsAgentHostRegistry::HasDevToolsAgentHost(
65 69 inspected_tab->render_view_host()))
66 DevToolsClientHost* client_host = manager-> 70 return NULL;
67 GetDevToolsClientHostFor(inspected_tab->render_view_host()); 71 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost(
72 inspected_tab->render_view_host());
73 DevToolsClientHost* client_host = manager->GetDevToolsClientHostFor(agent);
68 DevToolsWindow* window = AsDevToolsWindow(client_host); 74 DevToolsWindow* window = AsDevToolsWindow(client_host);
69 if (!window || !window->is_docked()) 75 if (!window || !window->is_docked())
70 return NULL; 76 return NULL;
71 return window->tab_contents(); 77 return window->tab_contents();
72 } 78 }
73 79
74 // static 80 // static
75 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( 81 DevToolsWindow* DevToolsWindow::FindDevToolsWindow(
76 RenderViewHost* window_rvh) { 82 RenderViewHost* window_rvh) {
77 DevToolsClientHost* client_host = 83 DevToolsClientHost* client_host =
78 DevToolsClientHost::FindOwnerClientHost(window_rvh); 84 DevToolsClientHost::FindOwnerClientHost(window_rvh);
79 return client_host != NULL ? DevToolsWindow::AsDevToolsWindow(client_host) 85 return client_host != NULL ? DevToolsWindow::AsDevToolsWindow(client_host)
80 : NULL; 86 : NULL;
81 } 87 }
82 88
83 // static 89 // static
84 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( 90 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker(
85 Profile* profile, 91 Profile* profile,
86 DevToolsAgentHost* worker_agent) { 92 DevToolsAgentHost* worker_agent) {
87 DevToolsWindow* window; 93 DevToolsWindow* window;
88 DevToolsClientHost* client = 94 DevToolsClientHost* client = content::DevToolsManager::GetInstance()->
89 DevToolsManager::GetInstance()->GetDevToolsClientHostFor(worker_agent); 95 GetDevToolsClientHostFor(worker_agent);
90 if (client) { 96 if (client) {
91 window = AsDevToolsWindow(client); 97 window = AsDevToolsWindow(client);
92 if (!window) 98 if (!window)
93 return NULL; 99 return NULL;
94 } else { 100 } else {
95 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); 101 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile);
96 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(worker_agent, 102 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
97 window); 103 worker_agent,
104 window);
98 } 105 }
99 window->Show(DEVTOOLS_TOGGLE_ACTION_NONE); 106 window->Show(DEVTOOLS_TOGGLE_ACTION_NONE);
100 return window; 107 return window;
101 } 108 }
102 109
103 // static 110 // static
104 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( 111 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker(
105 Profile* profile) { 112 Profile* profile) {
106 return Create(profile, NULL, false, true); 113 return Create(profile, NULL, false, true);
107 } 114 }
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 if (inspected_window) 614 if (inspected_window)
608 inspected_window->HandleKeyboardEvent(event); 615 inspected_window->HandleKeyboardEvent(event);
609 } 616 }
610 } 617 }
611 618
612 // static 619 // static
613 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( 620 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
614 RenderViewHost* inspected_rvh, 621 RenderViewHost* inspected_rvh,
615 bool force_open, 622 bool force_open,
616 DevToolsToggleAction action) { 623 DevToolsToggleAction action) {
617 DevToolsManager* manager = DevToolsManager::GetInstance(); 624 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost(
618 625 inspected_rvh);
619 DevToolsClientHost* host = manager->GetDevToolsClientHostFor(inspected_rvh); 626 content::DevToolsManager* manager = content::DevToolsManager::GetInstance();
627 DevToolsClientHost* host = manager->GetDevToolsClientHostFor(agent);
620 DevToolsWindow* window = AsDevToolsWindow(host); 628 DevToolsWindow* window = AsDevToolsWindow(host);
621 if (host != NULL && window == NULL) { 629 if (host != NULL && window == NULL) {
622 // Break remote debugging / extension debugging session. 630 // Break remote debugging / extension debugging session.
623 manager->UnregisterDevToolsClientHostFor(inspected_rvh); 631 manager->UnregisterDevToolsClientHostFor(agent);
624 } 632 }
625 633
626 bool do_open = force_open; 634 bool do_open = force_open;
627 if (!window) { 635 if (!window) {
628 Profile* profile = Profile::FromBrowserContext( 636 Profile* profile = Profile::FromBrowserContext(
629 inspected_rvh->process()->GetBrowserContext()); 637 inspected_rvh->process()->GetBrowserContext());
630 bool docked = profile->GetPrefs()->GetBoolean(prefs::kDevToolsOpenDocked); 638 bool docked = profile->GetPrefs()->GetBoolean(prefs::kDevToolsOpenDocked);
631 window = Create(profile, inspected_rvh, docked, false); 639 window = Create(profile, inspected_rvh, docked, false);
632 manager->RegisterDevToolsClientHostFor(inspected_rvh, window); 640 manager->RegisterDevToolsClientHostFor(agent, window);
633 do_open = true; 641 do_open = true;
634 } 642 }
635 643
636 // If window is docked and visible, we hide it on toggle. If window is 644 // If window is docked and visible, we hide it on toggle. If window is
637 // undocked, we show (activate) it. 645 // undocked, we show (activate) it.
638 if (!window->is_docked() || do_open) 646 if (!window->is_docked() || do_open)
639 window->Show(action); 647 window->Show(action);
640 else 648 else
641 manager->UnregisterDevToolsClientHostFor(inspected_rvh); 649 manager->UnregisterDevToolsClientHostFor(agent);
642 650
643 return window; 651 return window;
644 } 652 }
645 653
646 // static 654 // static
647 DevToolsWindow* DevToolsWindow::AsDevToolsWindow( 655 DevToolsWindow* DevToolsWindow::AsDevToolsWindow(
648 DevToolsClientHost* client_host) { 656 DevToolsClientHost* client_host) {
649 if (!client_host) 657 if (!client_host)
650 return NULL; 658 return NULL;
651 if (client_host->GetClientRenderViewHost() != NULL) 659 if (client_host->GetClientRenderViewHost() != NULL)
(...skipping 30 matching lines...) Expand all
682 RequestSetDocked(false); 690 RequestSetDocked(false);
683 } 691 }
684 692
685 content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() { 693 content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() {
686 if (inspected_tab_ && inspected_tab_->tab_contents()->delegate()) { 694 if (inspected_tab_ && inspected_tab_->tab_contents()->delegate()) {
687 return inspected_tab_->tab_contents()->delegate()-> 695 return inspected_tab_->tab_contents()->delegate()->
688 GetJavaScriptDialogCreator(); 696 GetJavaScriptDialogCreator();
689 } 697 }
690 return TabContentsDelegate::GetJavaScriptDialogCreator(); 698 return TabContentsDelegate::GetJavaScriptDialogCreator();
691 } 699 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698