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/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/sessions/session_tab_helper.h" | 23 #include "chrome/browser/sessions/session_tab_helper.h" |
24 #include "chrome/browser/themes/theme_properties.h" | 24 #include "chrome/browser/themes/theme_properties.h" |
25 #include "chrome/browser/themes/theme_service.h" | 25 #include "chrome/browser/themes/theme_service.h" |
26 #include "chrome/browser/themes/theme_service_factory.h" | 26 #include "chrome/browser/themes/theme_service_factory.h" |
27 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/browser_iterator.h" | 28 #include "chrome/browser/ui/browser_iterator.h" |
29 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
30 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
31 #include "chrome/browser/ui/host_desktop.h" | 31 #include "chrome/browser/ui/host_desktop.h" |
| 32 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" |
32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
33 #include "chrome/browser/ui/webui/devtools_ui.h" | 34 #include "chrome/browser/ui/webui/devtools_ui.h" |
34 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
35 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
36 #include "chrome/common/extensions/manifest_url_handler.h" | 37 #include "chrome/common/extensions/manifest_url_handler.h" |
37 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
38 #include "chrome/common/render_messages.h" | 39 #include "chrome/common/render_messages.h" |
39 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
40 #include "components/user_prefs/pref_registry_syncable.h" | 41 #include "components/user_prefs/pref_registry_syncable.h" |
41 #include "content/public/browser/child_process_security_policy.h" | 42 #include "content/public/browser/child_process_security_policy.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 return NULL; | 191 return NULL; |
191 } | 192 } |
192 RenderViewHost* inspected_rvh = | 193 RenderViewHost* inspected_rvh = |
193 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); | 194 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); |
194 | 195 |
195 return ToggleDevToolsWindow(inspected_rvh, | 196 return ToggleDevToolsWindow(inspected_rvh, |
196 action == DEVTOOLS_TOGGLE_ACTION_INSPECT, | 197 action == DEVTOOLS_TOGGLE_ACTION_INSPECT, |
197 action); | 198 action); |
198 } | 199 } |
199 | 200 |
| 201 // static |
200 void DevToolsWindow::InspectElement(RenderViewHost* inspected_rvh, | 202 void DevToolsWindow::InspectElement(RenderViewHost* inspected_rvh, |
201 int x, | 203 int x, |
202 int y) { | 204 int y) { |
203 scoped_refptr<DevToolsAgentHost> agent( | 205 scoped_refptr<DevToolsAgentHost> agent( |
204 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); | 206 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); |
205 agent->InspectElement(x, y); | 207 agent->InspectElement(x, y); |
206 // TODO(loislo): we should initiate DevTools window opening from within | 208 // TODO(loislo): we should initiate DevTools window opening from within |
207 // renderer. Otherwise, we still can hit a race condition here. | 209 // renderer. Otherwise, we still can hit a race condition here. |
208 OpenDevToolsWindow(inspected_rvh); | 210 OpenDevToolsWindow(inspected_rvh); |
209 } | 211 } |
210 | 212 |
211 // static | 213 // static |
212 void DevToolsWindow::OpenExternalFrontend( | 214 void DevToolsWindow::OpenExternalFrontend( |
213 Profile* profile, | 215 Profile* profile, |
214 const std::string& frontend_url, | 216 const std::string& frontend_url, |
215 content::DevToolsAgentHost* agent_host) { | 217 content::DevToolsAgentHost* agent_host) { |
216 DevToolsWindow* window = FindDevToolsWindow(agent_host); | 218 DevToolsWindow* window = FindDevToolsWindow(agent_host); |
217 if (!window) { | 219 if (!window) { |
218 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, | 220 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, |
219 DEVTOOLS_DOCK_SIDE_UNDOCKED, false); | 221 DEVTOOLS_DOCK_SIDE_UNDOCKED, false); |
220 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 222 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
221 agent_host, window->frontend_host_.get()); | 223 agent_host, window->frontend_host_.get()); |
222 } | 224 } |
223 window->Show(DEVTOOLS_TOGGLE_ACTION_SHOW); | 225 window->Show(DEVTOOLS_TOGGLE_ACTION_SHOW); |
224 } | 226 } |
225 | 227 |
| 228 // static |
226 DevToolsWindow* DevToolsWindow::Create( | 229 DevToolsWindow* DevToolsWindow::Create( |
227 Profile* profile, | 230 Profile* profile, |
228 const GURL& frontend_url, | 231 const GURL& frontend_url, |
229 RenderViewHost* inspected_rvh, | 232 RenderViewHost* inspected_rvh, |
230 DevToolsDockSide dock_side, | 233 DevToolsDockSide dock_side, |
231 bool shared_worker_frontend) { | 234 bool shared_worker_frontend) { |
232 // Create WebContents with devtools. | 235 // Create WebContents with devtools. |
233 WebContents* web_contents = | 236 WebContents* web_contents = |
234 WebContents::Create(WebContents::CreateParams(profile)); | 237 WebContents::Create(WebContents::CreateParams(profile)); |
235 GURL url = GetDevToolsURL(profile, frontend_url, dock_side, | 238 GURL url = GetDevToolsURL(profile, frontend_url, dock_side, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 if (!IsInspectedBrowserPopupOrPanel() && | 346 if (!IsInspectedBrowserPopupOrPanel() && |
344 FindInspectedBrowserAndTabIndex(&inspected_browser, | 347 FindInspectedBrowserAndTabIndex(&inspected_browser, |
345 &inspected_tab_index)) { | 348 &inspected_tab_index)) { |
346 BrowserWindow* inspected_window = inspected_browser->window(); | 349 BrowserWindow* inspected_window = inspected_browser->window(); |
347 web_contents_->SetDelegate(this); | 350 web_contents_->SetDelegate(this); |
348 inspected_window->UpdateDevTools(); | 351 inspected_window->UpdateDevTools(); |
349 web_contents_->GetView()->SetInitialFocus(); | 352 web_contents_->GetView()->SetInitialFocus(); |
350 inspected_window->Show(); | 353 inspected_window->Show(); |
351 TabStripModel* tab_strip_model = inspected_browser->tab_strip_model(); | 354 TabStripModel* tab_strip_model = inspected_browser->tab_strip_model(); |
352 tab_strip_model->ActivateTabAt(inspected_tab_index, true); | 355 tab_strip_model->ActivateTabAt(inspected_tab_index, true); |
| 356 PrefsTabHelper::CreateForWebContents(web_contents_); |
| 357 GetRenderViewHost()->SyncRendererPrefs(); |
353 ScheduleAction(action); | 358 ScheduleAction(action); |
354 return; | 359 return; |
355 } else { | 360 } else { |
356 // Sometimes we don't know where to dock. Stay undocked. | 361 // Sometimes we don't know where to dock. Stay undocked. |
357 dock_side_ = DEVTOOLS_DOCK_SIDE_UNDOCKED; | 362 dock_side_ = DEVTOOLS_DOCK_SIDE_UNDOCKED; |
358 } | 363 } |
359 } | 364 } |
360 | 365 |
361 // Avoid consecutive window switching if the devtools window has been opened | 366 // Avoid consecutive window switching if the devtools window has been opened |
362 // and the Inspect Element shortcut is pressed in the inspected tab. | 367 // and the Inspect Element shortcut is pressed in the inspected tab. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 | 463 |
459 chrome::HostDesktopType host_desktop_type = | 464 chrome::HostDesktopType host_desktop_type = |
460 chrome::GetHostDesktopTypeForNativeView( | 465 chrome::GetHostDesktopTypeForNativeView( |
461 web_contents_->GetView()->GetNativeView()); | 466 web_contents_->GetView()->GetNativeView()); |
462 | 467 |
463 browser_ = new Browser(Browser::CreateParams::CreateForDevTools( | 468 browser_ = new Browser(Browser::CreateParams::CreateForDevTools( |
464 profile_, host_desktop_type)); | 469 profile_, host_desktop_type)); |
465 browser_->tab_strip_model()->AddWebContents( | 470 browser_->tab_strip_model()->AddWebContents( |
466 web_contents_, -1, content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 471 web_contents_, -1, content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
467 TabStripModel::ADD_ACTIVE); | 472 TabStripModel::ADD_ACTIVE); |
| 473 GetRenderViewHost()->SyncRendererPrefs(); |
468 } | 474 } |
469 | 475 |
470 bool DevToolsWindow::FindInspectedBrowserAndTabIndex(Browser** browser, | 476 bool DevToolsWindow::FindInspectedBrowserAndTabIndex(Browser** browser, |
471 int* tab) { | 477 int* tab) { |
472 content::WebContents* inspected_web_contents = GetInspectedWebContents(); | 478 content::WebContents* inspected_web_contents = GetInspectedWebContents(); |
473 if (!inspected_web_contents) | 479 if (!inspected_web_contents) |
474 return false; | 480 return false; |
475 | 481 |
476 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 482 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
477 int tab_index = it->tab_strip_model()->GetIndexOfWebContents( | 483 int tab_index = it->tab_strip_model()->GetIndexOfWebContents( |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 DevToolsDockSide DevToolsWindow::SideFromString( | 1089 DevToolsDockSide DevToolsWindow::SideFromString( |
1084 const std::string& dock_side) { | 1090 const std::string& dock_side) { |
1085 if (dock_side == kDockSideRight) | 1091 if (dock_side == kDockSideRight) |
1086 return DEVTOOLS_DOCK_SIDE_RIGHT; | 1092 return DEVTOOLS_DOCK_SIDE_RIGHT; |
1087 if (dock_side == kDockSideBottom) | 1093 if (dock_side == kDockSideBottom) |
1088 return DEVTOOLS_DOCK_SIDE_BOTTOM; | 1094 return DEVTOOLS_DOCK_SIDE_BOTTOM; |
1089 if (dock_side == kDockSideMinimized) | 1095 if (dock_side == kDockSideMinimized) |
1090 return DEVTOOLS_DOCK_SIDE_MINIMIZED; | 1096 return DEVTOOLS_DOCK_SIDE_MINIMIZED; |
1091 return DEVTOOLS_DOCK_SIDE_UNDOCKED; | 1097 return DEVTOOLS_DOCK_SIDE_UNDOCKED; |
1092 } | 1098 } |
OLD | NEW |