OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/webui/extensions/extension_error_ui_util.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_error_ui_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 } | 150 } |
151 | 151 |
152 content::RenderViewHost* rvh = | 152 content::RenderViewHost* rvh = |
153 content::RenderViewHost::FromID(render_process_id, render_view_id); | 153 content::RenderViewHost::FromID(render_process_id, render_view_id); |
154 | 154 |
155 // It's possible that the render view was closed since we last updated the | 155 // It's possible that the render view was closed since we last updated the |
156 // links. Handle this gracefully. | 156 // links. Handle this gracefully. |
157 if (!rvh) | 157 if (!rvh) |
158 return; | 158 return; |
159 | 159 |
| 160 // Once we open the inspector, we focus on the appropriate tab... |
| 161 content::WebContents* web_contents = |
| 162 content::WebContents::FromRenderViewHost(rvh); |
| 163 if (!web_contents) |
| 164 return; |
| 165 |
160 // If we include a url, we should inspect it specifically (and not just the | 166 // If we include a url, we should inspect it specifically (and not just the |
161 // render view). | 167 // render view). |
162 base::string16 url; | 168 base::string16 url; |
163 if (args->GetString(RuntimeError::kUrlKey, &url)) { | 169 if (args->GetString(RuntimeError::kUrlKey, &url)) { |
164 // Line and column numbers are optional; default to the first line. | 170 // Line and column numbers are optional; default to the first line. |
165 int line_number = 1; | 171 int line_number = 1; |
166 int column_number = 1; | 172 int column_number = 1; |
167 args->GetInteger(RuntimeError::kLineNumberKey, &line_number); | 173 args->GetInteger(RuntimeError::kLineNumberKey, &line_number); |
168 args->GetInteger(RuntimeError::kColumnNumberKey, &column_number); | 174 args->GetInteger(RuntimeError::kColumnNumberKey, &column_number); |
169 | 175 |
170 // Line/column numbers are reported in display-friendly 1-based numbers, | 176 // Line/column numbers are reported in display-friendly 1-based numbers, |
171 // but are inspected in zero-based numbers. | 177 // but are inspected in zero-based numbers. |
172 DevToolsWindow::OpenDevToolsWindow( | 178 DevToolsWindow::OpenDevToolsWindow( |
173 rvh, | 179 web_contents, |
174 DevToolsToggleAction::Reveal(url, line_number - 1, column_number - 1)); | 180 DevToolsToggleAction::Reveal(url, line_number - 1, column_number - 1)); |
175 } else { | 181 } else { |
176 DevToolsWindow::OpenDevToolsWindow(rvh); | 182 DevToolsWindow::OpenDevToolsWindow(web_contents); |
177 } | 183 } |
178 | 184 |
179 // Once we open the inspector, we focus on the appropriate tab... | |
180 content::WebContents* web_contents = | |
181 content::WebContents::FromRenderViewHost(rvh); | |
182 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 185 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
183 | 186 |
184 // ... but some pages (popups and apps) don't have tabs, and some (background | 187 // ... but some pages (popups and apps) don't have tabs, and some (background |
185 // pages) don't have an associated browser. For these, the inspector opens in | 188 // pages) don't have an associated browser. For these, the inspector opens in |
186 // a new window, and our work is done. | 189 // a new window, and our work is done. |
187 if (!browser || !browser->is_type_tabbed()) | 190 if (!browser || !browser->is_type_tabbed()) |
188 return; | 191 return; |
189 | 192 |
190 TabStripModel* tab_strip = browser->tab_strip_model(); | 193 TabStripModel* tab_strip = browser->tab_strip_model(); |
191 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents), | 194 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents), |
192 false); // Not through direct user gesture. | 195 false); // Not through direct user gesture. |
193 } | 196 } |
194 | 197 |
195 } // namespace error_ui_util | 198 } // namespace error_ui_util |
196 } // namespace extensions | 199 } // namespace extensions |
OLD | NEW |