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 <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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 DevToolsManager* manager = DevToolsManager::GetInstance(); | 96 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 97 DevToolsClientHost* client_host = manager->GetDevToolsClientHostFor(agent); | 97 DevToolsClientHost* client_host = manager->GetDevToolsClientHostFor(agent); |
| 98 DevToolsWindow* window = AsDevToolsWindow(client_host); | 98 DevToolsWindow* window = AsDevToolsWindow(client_host); |
| 99 if (!window || !window->is_docked()) | 99 if (!window || !window->is_docked()) |
| 100 return NULL; | 100 return NULL; |
| 101 return window->tab_contents(); | 101 return window->tab_contents(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // static | 104 // static |
| 105 bool DevToolsWindow::IsDevToolsWindow(RenderViewHost* window_rvh) { | 105 bool DevToolsWindow::IsDevToolsWindow(RenderViewHost* window_rvh) { |
| 106 if (g_instances == NULL) | 106 return AsDevToolsWindow(window_rvh) != NULL; |
|
pfeldman
2012/08/24 10:16:14
drop the != NULL
apavlov
2012/08/24 11:02:13
Done.
| |
| 107 return false; | |
| 108 DevToolsWindowList& instances = g_instances.Get(); | |
| 109 for (DevToolsWindowList::iterator it = instances.begin(); | |
| 110 it != instances.end(); ++it) { | |
| 111 if ((*it)->tab_contents_->web_contents()->GetRenderViewHost() == window_rvh) | |
| 112 return true; | |
| 113 } | |
| 114 return false; | |
| 115 } | 107 } |
| 116 | 108 |
| 117 // static | 109 // static |
| 118 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( | 110 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( |
| 119 Profile* profile, | 111 Profile* profile, |
| 120 DevToolsAgentHost* worker_agent) { | 112 DevToolsAgentHost* worker_agent) { |
| 121 DevToolsWindow* window; | 113 DevToolsWindow* window; |
| 122 DevToolsClientHost* client = content::DevToolsManager::GetInstance()-> | 114 DevToolsClientHost* client = content::DevToolsManager::GetInstance()-> |
| 123 GetDevToolsClientHostFor(worker_agent); | 115 GetDevToolsClientHostFor(worker_agent); |
| 124 if (client) { | 116 if (client) { |
| 125 window = AsDevToolsWindow(client); | 117 window = AsDevToolsWindow(client); |
| 126 if (!window) | 118 if (!window) |
| 127 return NULL; | 119 return NULL; |
| 128 } else { | 120 } else { |
| 129 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); | 121 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); |
| 130 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 122 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
| 131 worker_agent, | 123 worker_agent, |
| 132 window->frontend_host_); | 124 window->frontend_host_); |
| 133 } | 125 } |
| 134 window->Show(DEVTOOLS_TOGGLE_ACTION_NONE); | 126 window->Show(DEVTOOLS_TOGGLE_ACTION_SHOW); |
| 135 return window; | 127 return window; |
| 136 } | 128 } |
| 137 | 129 |
| 138 // static | 130 // static |
| 139 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( | 131 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( |
| 140 Profile* profile) { | 132 Profile* profile) { |
| 141 return Create(profile, NULL, false, true); | 133 return Create(profile, NULL, false, true); |
| 142 } | 134 } |
| 143 | 135 |
| 144 // static | 136 // static |
| 145 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( | 137 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( |
| 146 RenderViewHost* inspected_rvh) { | 138 RenderViewHost* inspected_rvh) { |
| 147 return ToggleDevToolsWindow(inspected_rvh, true, | 139 return ToggleDevToolsWindow(inspected_rvh, true, |
| 148 DEVTOOLS_TOGGLE_ACTION_NONE); | 140 DEVTOOLS_TOGGLE_ACTION_SHOW); |
| 149 } | 141 } |
| 150 | 142 |
| 151 // static | 143 // static |
| 152 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 144 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( |
| 153 RenderViewHost* inspected_rvh, | 145 Browser* browser, |
| 154 DevToolsToggleAction action) { | 146 DevToolsToggleAction action) { |
| 147 RenderViewHost* inspected_rvh = | |
| 148 chrome::GetActiveWebContents(browser)->GetRenderViewHost(); | |
| 149 if (action == DEVTOOLS_TOGGLE_ACTION_TOGGLE && browser->is_devtools()) { | |
| 150 chrome::CloseAllTabs(browser); | |
| 151 return AsDevToolsWindow(inspected_rvh); | |
|
pfeldman
2012/08/24 10:16:14
This is always NULL.
apavlov
2012/08/24 11:02:13
This is NULL for ordinary RVH's but not for the De
pfeldman
2012/08/24 11:23:19
- So browser _is_ the devtools window
- Then there
| |
| 152 } | |
| 153 | |
| 155 return ToggleDevToolsWindow(inspected_rvh, | 154 return ToggleDevToolsWindow(inspected_rvh, |
| 156 action == DEVTOOLS_TOGGLE_ACTION_INSPECT, | 155 action == DEVTOOLS_TOGGLE_ACTION_INSPECT, |
| 157 action); | 156 action); |
| 158 } | 157 } |
| 159 | 158 |
| 160 void DevToolsWindow::InspectElement(RenderViewHost* inspected_rvh, | 159 void DevToolsWindow::InspectElement(RenderViewHost* inspected_rvh, |
| 161 int x, | 160 int x, |
| 162 int y) { | 161 int y) { |
| 163 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 162 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 164 inspected_rvh); | 163 inspected_rvh); |
| 165 DevToolsManager::GetInstance()->InspectElement(agent, x, y); | 164 DevToolsManager::GetInstance()->InspectElement(agent, x, y); |
| 166 // TODO(loislo): we should initiate DevTools window opening from within | 165 // TODO(loislo): we should initiate DevTools window opening from within |
| 167 // renderer. Otherwise, we still can hit a race condition here. | 166 // renderer. Otherwise, we still can hit a race condition here. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 190 DevToolsWindow::DevToolsWindow(TabContents* tab_contents, | 189 DevToolsWindow::DevToolsWindow(TabContents* tab_contents, |
| 191 Profile* profile, | 190 Profile* profile, |
| 192 RenderViewHost* inspected_rvh, | 191 RenderViewHost* inspected_rvh, |
| 193 bool docked) | 192 bool docked) |
| 194 : profile_(profile), | 193 : profile_(profile), |
| 195 inspected_tab_(NULL), | 194 inspected_tab_(NULL), |
| 196 tab_contents_(tab_contents), | 195 tab_contents_(tab_contents), |
| 197 browser_(NULL), | 196 browser_(NULL), |
| 198 docked_(docked), | 197 docked_(docked), |
| 199 is_loaded_(false), | 198 is_loaded_(false), |
| 200 action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) { | 199 action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW) { |
| 201 frontend_host_ = DevToolsClientHost::CreateDevToolsFrontendHost( | 200 frontend_host_ = DevToolsClientHost::CreateDevToolsFrontendHost( |
| 202 tab_contents->web_contents(), | 201 tab_contents->web_contents(), |
| 203 this); | 202 this); |
| 204 file_helper_.reset(new DevToolsFileHelper(profile, this)); | 203 file_helper_.reset(new DevToolsFileHelper(profile, this)); |
| 205 | 204 |
| 206 g_instances.Get().push_back(this); | 205 g_instances.Get().push_back(this); |
| 207 // Wipe out page icon so that the default application icon is used. | 206 // Wipe out page icon so that the default application icon is used. |
| 208 NavigationEntry* entry = | 207 NavigationEntry* entry = |
| 209 tab_contents_->web_contents()->GetController().GetActiveEntry(); | 208 tab_contents_->web_contents()->GetController().GetActiveEntry(); |
| 210 entry->GetFavicon().image = gfx::Image(); | 209 entry->GetFavicon().image = gfx::Image(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 tab_strip_model->GetIndexOfTabContents(tab_contents_)); | 341 tab_strip_model->GetIndexOfTabContents(tab_contents_)); |
| 343 browser_ = NULL; | 342 browser_ = NULL; |
| 344 } else { | 343 } else { |
| 345 // Update inspected window to hide split and reset it. | 344 // Update inspected window to hide split and reset it. |
| 346 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 345 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 347 if (inspected_window) { | 346 if (inspected_window) { |
| 348 inspected_window->UpdateDevTools(); | 347 inspected_window->UpdateDevTools(); |
| 349 inspected_window = NULL; | 348 inspected_window = NULL; |
| 350 } | 349 } |
| 351 } | 350 } |
| 352 Show(DEVTOOLS_TOGGLE_ACTION_NONE); | 351 Show(DEVTOOLS_TOGGLE_ACTION_SHOW); |
| 353 } | 352 } |
| 354 | 353 |
| 355 RenderViewHost* DevToolsWindow::GetRenderViewHost() { | 354 RenderViewHost* DevToolsWindow::GetRenderViewHost() { |
| 356 return tab_contents_->web_contents()->GetRenderViewHost(); | 355 return tab_contents_->web_contents()->GetRenderViewHost(); |
| 357 } | 356 } |
| 358 | 357 |
| 359 void DevToolsWindow::CreateDevToolsBrowser() { | 358 void DevToolsWindow::CreateDevToolsBrowser() { |
| 360 // TODO(pfeldman): Make browser's getter for this key static. | 359 // TODO(pfeldman): Make browser's getter for this key static. |
| 361 std::string wp_key; | 360 std::string wp_key; |
| 362 wp_key.append(prefs::kBrowserWindowPlacement); | 361 wp_key.append(prefs::kBrowserWindowPlacement); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 | 506 |
| 508 void DevToolsWindow::DoAction() { | 507 void DevToolsWindow::DoAction() { |
| 509 UpdateFrontendAttachedState(); | 508 UpdateFrontendAttachedState(); |
| 510 // TODO: these messages should be pushed through the WebKit API instead. | 509 // TODO: these messages should be pushed through the WebKit API instead. |
| 511 switch (action_on_load_) { | 510 switch (action_on_load_) { |
| 512 case DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE: | 511 case DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE: |
| 513 CallClientFunction("InspectorFrontendAPI.showConsole", NULL); | 512 CallClientFunction("InspectorFrontendAPI.showConsole", NULL); |
| 514 break; | 513 break; |
| 515 case DEVTOOLS_TOGGLE_ACTION_INSPECT: | 514 case DEVTOOLS_TOGGLE_ACTION_INSPECT: |
| 516 CallClientFunction("InspectorFrontendAPI.enterInspectElementMode", NULL); | 515 CallClientFunction("InspectorFrontendAPI.enterInspectElementMode", NULL); |
| 517 case DEVTOOLS_TOGGLE_ACTION_NONE: | 516 case DEVTOOLS_TOGGLE_ACTION_SHOW: |
| 517 case DEVTOOLS_TOGGLE_ACTION_TOGGLE: | |
| 518 // Do nothing. | 518 // Do nothing. |
| 519 break; | 519 break; |
| 520 default: | 520 default: |
| 521 NOTREACHED(); | 521 NOTREACHED(); |
| 522 } | 522 } |
| 523 action_on_load_ = DEVTOOLS_TOGGLE_ACTION_NONE; | 523 action_on_load_ = DEVTOOLS_TOGGLE_ACTION_SHOW; |
| 524 } | 524 } |
| 525 | 525 |
| 526 std::string SkColorToRGBAString(SkColor color) { | 526 std::string SkColorToRGBAString(SkColor color) { |
| 527 // We convert the alpha using DoubleToString because StringPrintf will use | 527 // We convert the alpha using DoubleToString because StringPrintf will use |
| 528 // locale specific formatters (e.g., use , instead of . in German). | 528 // locale specific formatters (e.g., use , instead of . in German). |
| 529 return StringPrintf("rgba(%d,%d,%d,%s)", SkColorGetR(color), | 529 return StringPrintf("rgba(%d,%d,%d,%s)", SkColorGetR(color), |
| 530 SkColorGetG(color), SkColorGetB(color), | 530 SkColorGetG(color), SkColorGetB(color), |
| 531 base::DoubleToString(SkColorGetA(color) / 255.0).c_str()); | 531 base::DoubleToString(SkColorGetA(color) / 255.0).c_str()); |
| 532 } | 532 } |
| 533 | 533 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 return NULL; | 658 return NULL; |
| 659 DevToolsWindowList& instances = g_instances.Get(); | 659 DevToolsWindowList& instances = g_instances.Get(); |
| 660 for (DevToolsWindowList::iterator it = instances.begin(); | 660 for (DevToolsWindowList::iterator it = instances.begin(); |
| 661 it != instances.end(); ++it) { | 661 it != instances.end(); ++it) { |
| 662 if ((*it)->frontend_host_ == client_host) | 662 if ((*it)->frontend_host_ == client_host) |
| 663 return *it; | 663 return *it; |
| 664 } | 664 } |
| 665 return NULL; | 665 return NULL; |
| 666 } | 666 } |
| 667 | 667 |
| 668 // static | |
| 669 DevToolsWindow* DevToolsWindow::AsDevToolsWindow(RenderViewHost* rvh) { | |
| 670 if (g_instances == NULL) | |
| 671 return NULL; | |
| 672 DevToolsWindowList& instances = g_instances.Get(); | |
| 673 for (DevToolsWindowList::iterator it = instances.begin(); | |
| 674 it != instances.end(); ++it) { | |
| 675 if ((*it)->tab_contents_->web_contents()->GetRenderViewHost() == rvh) | |
| 676 return *it; | |
| 677 } | |
| 678 return NULL; | |
| 679 } | |
| 680 | |
| 668 void DevToolsWindow::ActivateWindow() { | 681 void DevToolsWindow::ActivateWindow() { |
| 669 if (!docked_) { | 682 if (!docked_) { |
| 670 if (!browser_->window()->IsActive()) { | 683 if (!browser_->window()->IsActive()) { |
| 671 browser_->window()->Activate(); | 684 browser_->window()->Activate(); |
| 672 } | 685 } |
| 673 } else { | 686 } else { |
| 674 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 687 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 675 if (inspected_window) | 688 if (inspected_window) |
| 676 tab_contents_->web_contents()->GetView()->Focus(); | 689 tab_contents_->web_contents()->GetView()->Focus(); |
| 677 } | 690 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 } | 779 } |
| 767 | 780 |
| 768 void DevToolsWindow::UpdateBrowserToolbar() { | 781 void DevToolsWindow::UpdateBrowserToolbar() { |
| 769 if (!inspected_tab_) | 782 if (!inspected_tab_) |
| 770 return; | 783 return; |
| 771 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 784 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 772 if (inspected_window) | 785 if (inspected_window) |
| 773 inspected_window->UpdateToolbar(inspected_tab_, false); | 786 inspected_window->UpdateToolbar(inspected_tab_, false); |
| 774 } | 787 } |
| 775 | 788 |
| OLD | NEW |