| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/browser_window.h" | 12 #include "chrome/browser/browser_window.h" |
| 13 #include "chrome/browser/debugger/devtools_manager.h" | 13 #include "chrome/browser/debugger/devtools_manager.h" |
| 14 #include "chrome/browser/debugger/devtools_window.h" | 14 #include "chrome/browser/debugger/devtools_window.h" |
| 15 #include "chrome/browser/extensions/extensions_service.h" | 15 #include "chrome/browser/extensions/extensions_service.h" |
| 16 #include "chrome/browser/in_process_webkit/session_storage_namespace.h" | 16 #include "chrome/browser/in_process_webkit/session_storage_namespace.h" |
| 17 #include "chrome/browser/load_notification_details.h" | 17 #include "chrome/browser/load_notification_details.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
| 20 #include "chrome/browser/renderer_host/render_view_host.h" | 20 #include "chrome/browser/renderer_host/render_view_host.h" |
| 21 #include "chrome/browser/tab_contents/navigation_controller.h" | 21 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 22 #include "chrome/browser/tab_contents/navigation_entry.h" | 22 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 23 #include "chrome/browser/tab_contents/tab_contents.h" | 23 #include "chrome/browser/tab_contents/tab_contents.h" |
| 24 #include "chrome/browser/tab_contents/tab_contents_view.h" | 24 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 25 #include "chrome/browser/tab_contents_wrapper.h" |
| 25 #include "chrome/browser/tabs/tab_strip_model.h" | 26 #include "chrome/browser/tabs/tab_strip_model.h" |
| 26 #include "chrome/browser/themes/browser_theme_provider.h" | 27 #include "chrome/browser/themes/browser_theme_provider.h" |
| 27 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
| 28 #include "chrome/common/bindings_policy.h" | 29 #include "chrome/common/bindings_policy.h" |
| 29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/render_messages.h" | 32 #include "chrome/common/render_messages.h" |
| 32 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 33 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
| 34 | 35 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 46 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> | 47 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> |
| 47 GetDevToolsClientHostFor(inspected_tab->render_view_host()); | 48 GetDevToolsClientHostFor(inspected_tab->render_view_host()); |
| 48 if (!client_host) { | 49 if (!client_host) { |
| 49 return NULL; | 50 return NULL; |
| 50 } | 51 } |
| 51 | 52 |
| 52 DevToolsWindow* window = client_host->AsDevToolsWindow(); | 53 DevToolsWindow* window = client_host->AsDevToolsWindow(); |
| 53 if (!window || !window->is_docked()) { | 54 if (!window || !window->is_docked()) { |
| 54 return NULL; | 55 return NULL; |
| 55 } | 56 } |
| 56 return window->tab_contents(); | 57 return window->tab_contents()->tab_contents(); |
| 57 } | 58 } |
| 58 | 59 |
| 59 DevToolsWindow::DevToolsWindow(Profile* profile, | 60 DevToolsWindow::DevToolsWindow(Profile* profile, |
| 60 RenderViewHost* inspected_rvh, | 61 RenderViewHost* inspected_rvh, |
| 61 bool docked) | 62 bool docked) |
| 62 : profile_(profile), | 63 : profile_(profile), |
| 63 browser_(NULL), | 64 browser_(NULL), |
| 64 docked_(docked), | 65 docked_(docked), |
| 65 is_loaded_(false), | 66 is_loaded_(false), |
| 66 action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) { | 67 action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) { |
| 67 // Create TabContents with devtools. | 68 // Create TabContents with devtools. |
| 68 tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, NULL); | 69 tab_contents_ = |
| 69 tab_contents_->render_view_host()->AllowBindings(BindingsPolicy::DOM_UI); | 70 Browser::TabContentsFactory(profile, NULL, MSG_ROUTING_NONE, NULL, NULL); |
| 71 tab_contents_->tab_contents()-> |
| 72 render_view_host()->AllowBindings(BindingsPolicy::DOM_UI); |
| 70 tab_contents_->controller().LoadURL( | 73 tab_contents_->controller().LoadURL( |
| 71 GetDevToolsUrl(), GURL(), PageTransition::START_PAGE); | 74 GetDevToolsUrl(), GURL(), PageTransition::START_PAGE); |
| 72 | 75 |
| 73 // Wipe out page icon so that the default application icon is used. | 76 // Wipe out page icon so that the default application icon is used. |
| 74 NavigationEntry* entry = tab_contents_->controller().GetActiveEntry(); | 77 NavigationEntry* entry = tab_contents_->controller().GetActiveEntry(); |
| 75 entry->favicon().set_bitmap(SkBitmap()); | 78 entry->favicon().set_bitmap(SkBitmap()); |
| 76 entry->favicon().set_is_valid(true); | 79 entry->favicon().set_is_valid(true); |
| 77 | 80 |
| 78 // Register on-load actions. | 81 // Register on-load actions. |
| 79 registrar_.Add(this, | 82 registrar_.Add(this, |
| 80 NotificationType::LOAD_STOP, | 83 NotificationType::LOAD_STOP, |
| 81 Source<NavigationController>(&tab_contents_->controller())); | 84 Source<NavigationController>(&tab_contents_->controller())); |
| 82 registrar_.Add(this, | 85 registrar_.Add(this, |
| 83 NotificationType::TAB_CLOSING, | 86 NotificationType::TAB_CLOSING, |
| 84 Source<NavigationController>(&tab_contents_->controller())); | 87 Source<NavigationController>(&tab_contents_->controller())); |
| 85 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 88 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 86 NotificationService::AllSources()); | 89 NotificationService::AllSources()); |
| 87 inspected_tab_ = inspected_rvh->delegate()->GetAsTabContents(); | 90 inspected_tab_ = inspected_rvh->delegate()->GetAsTabContents(); |
| 88 } | 91 } |
| 89 | 92 |
| 90 DevToolsWindow::~DevToolsWindow() { | 93 DevToolsWindow::~DevToolsWindow() { |
| 91 } | 94 } |
| 92 | 95 |
| 93 DevToolsWindow* DevToolsWindow::AsDevToolsWindow() { | 96 DevToolsWindow* DevToolsWindow::AsDevToolsWindow() { |
| 94 return this; | 97 return this; |
| 95 } | 98 } |
| 96 | 99 |
| 97 void DevToolsWindow::SendMessageToClient(const IPC::Message& message) { | 100 void DevToolsWindow::SendMessageToClient(const IPC::Message& message) { |
| 98 RenderViewHost* target_host = tab_contents_->render_view_host(); | 101 RenderViewHost* target_host = |
| 102 tab_contents_->tab_contents()->render_view_host(); |
| 99 IPC::Message* m = new IPC::Message(message); | 103 IPC::Message* m = new IPC::Message(message); |
| 100 m->set_routing_id(target_host->routing_id()); | 104 m->set_routing_id(target_host->routing_id()); |
| 101 target_host->Send(m); | 105 target_host->Send(m); |
| 102 } | 106 } |
| 103 | 107 |
| 104 void DevToolsWindow::InspectedTabClosing() { | 108 void DevToolsWindow::InspectedTabClosing() { |
| 105 if (docked_) { | 109 if (docked_) { |
| 106 // Update dev tools to reflect removed dev tools window. | 110 // Update dev tools to reflect removed dev tools window. |
| 107 | 111 |
| 108 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 112 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 123 } | 127 } |
| 124 | 128 |
| 125 void DevToolsWindow::Show(DevToolsToggleAction action) { | 129 void DevToolsWindow::Show(DevToolsToggleAction action) { |
| 126 if (docked_) { | 130 if (docked_) { |
| 127 Browser* inspected_browser; | 131 Browser* inspected_browser; |
| 128 int inspected_tab_index; | 132 int inspected_tab_index; |
| 129 // Tell inspected browser to update splitter and switch to inspected panel. | 133 // Tell inspected browser to update splitter and switch to inspected panel. |
| 130 if (FindInspectedBrowserAndTabIndex(&inspected_browser, | 134 if (FindInspectedBrowserAndTabIndex(&inspected_browser, |
| 131 &inspected_tab_index)) { | 135 &inspected_tab_index)) { |
| 132 BrowserWindow* inspected_window = inspected_browser->window(); | 136 BrowserWindow* inspected_window = inspected_browser->window(); |
| 133 tab_contents_->set_delegate(this); | 137 tab_contents_->tab_contents()->set_delegate(this); |
| 134 inspected_window->UpdateDevTools(); | 138 inspected_window->UpdateDevTools(); |
| 135 SetAttachedWindow(); | 139 SetAttachedWindow(); |
| 136 tab_contents_->view()->SetInitialFocus(); | 140 tab_contents_->view()->SetInitialFocus(); |
| 137 inspected_window->Show(); | 141 inspected_window->Show(); |
| 138 TabStripModel* tabstrip_model = inspected_browser->tabstrip_model(); | 142 TabStripModel* tabstrip_model = inspected_browser->tabstrip_model(); |
| 139 tabstrip_model->SelectTabContentsAt(inspected_tab_index, true); | 143 tabstrip_model->SelectTabContentsAt(inspected_tab_index, true); |
| 140 ScheduleAction(action); | 144 ScheduleAction(action); |
| 141 return; | 145 return; |
| 142 } else { | 146 } else { |
| 143 // Sometimes we don't know where to dock. Stay undocked. | 147 // Sometimes we don't know where to dock. Stay undocked. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 L"WebInspector.setAttachedWindow(false);"); | 267 L"WebInspector.setAttachedWindow(false);"); |
| 264 } | 268 } |
| 265 | 269 |
| 266 | 270 |
| 267 void DevToolsWindow::AddDevToolsExtensionsToClient() { | 271 void DevToolsWindow::AddDevToolsExtensionsToClient() { |
| 268 if (inspected_tab_) { | 272 if (inspected_tab_) { |
| 269 FundamentalValue tabId(inspected_tab_->controller().session_id().id()); | 273 FundamentalValue tabId(inspected_tab_->controller().session_id().id()); |
| 270 CallClientFunction(L"WebInspector.setInspectedTabId", tabId); | 274 CallClientFunction(L"WebInspector.setInspectedTabId", tabId); |
| 271 } | 275 } |
| 272 ListValue results; | 276 ListValue results; |
| 273 const ExtensionsService* extension_service = tab_contents_->profile()-> | 277 const ExtensionsService* extension_service = |
| 274 GetOriginalProfile()->GetExtensionsService(); | 278 tab_contents_->tab_contents()->profile()-> |
| 279 GetOriginalProfile()->GetExtensionsService(); |
| 275 const ExtensionList* extensions = extension_service->extensions(); | 280 const ExtensionList* extensions = extension_service->extensions(); |
| 276 | 281 |
| 277 for (ExtensionList::const_iterator extension = extensions->begin(); | 282 for (ExtensionList::const_iterator extension = extensions->begin(); |
| 278 extension != extensions->end(); ++extension) { | 283 extension != extensions->end(); ++extension) { |
| 279 if ((*extension)->devtools_url().is_empty()) | 284 if ((*extension)->devtools_url().is_empty()) |
| 280 continue; | 285 continue; |
| 281 DictionaryValue* extension_info = new DictionaryValue(); | 286 DictionaryValue* extension_info = new DictionaryValue(); |
| 282 extension_info->Set("startPage", | 287 extension_info->Set("startPage", |
| 283 new StringValue((*extension)->devtools_url().spec())); | 288 new StringValue((*extension)->devtools_url().spec())); |
| 284 results.Append(extension_info); | 289 results.Append(extension_info); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 return false; | 403 return false; |
| 399 } | 404 } |
| 400 | 405 |
| 401 void DevToolsWindow::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 406 void DevToolsWindow::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 402 if (docked_) { | 407 if (docked_) { |
| 403 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 408 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 404 if (inspected_window) | 409 if (inspected_window) |
| 405 inspected_window->HandleKeyboardEvent(event); | 410 inspected_window->HandleKeyboardEvent(event); |
| 406 } | 411 } |
| 407 } | 412 } |
| OLD | NEW |