| 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 "chrome/browser/devtools/devtools_window.h" | 5 #include "chrome/browser/devtools/devtools_window.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 } | 402 } |
| 403 | 403 |
| 404 // static | 404 // static |
| 405 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( | 405 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( |
| 406 Profile* profile) { | 406 Profile* profile) { |
| 407 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); | 407 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); |
| 408 return Create(profile, GURL(), NULL, true, std::string(), false, ""); | 408 return Create(profile, GURL(), NULL, true, std::string(), false, ""); |
| 409 } | 409 } |
| 410 | 410 |
| 411 // static | 411 // static |
| 412 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( | 412 void DevToolsWindow::OpenDevToolsWindow( |
| 413 content::WebContents* inspected_web_contents) { | 413 content::WebContents* inspected_web_contents) { |
| 414 return ToggleDevToolsWindow( | 414 DevToolsWindow::OpenDevToolsWindow(inspected_web_contents, |
| 415 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); | 415 DevToolsToggleAction::Show()); |
| 416 } | 416 } |
| 417 | 417 |
| 418 // static | 418 // static |
| 419 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( | 419 void DevToolsWindow::OpenDevToolsWindow( |
| 420 content::WebContents* inspected_web_contents, | 420 content::WebContents* inspected_web_contents, |
| 421 const DevToolsToggleAction& action) { | 421 const DevToolsToggleAction& action) { |
| 422 return ToggleDevToolsWindow(inspected_web_contents, true, action, ""); | 422 Profile* profile = |
| 423 Profile::FromBrowserContext(inspected_web_contents->GetBrowserContext()); |
| 424 // If development tools disabled by policy don't open the window. |
| 425 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) { |
| 426 return; |
| 427 } |
| 428 ToggleDevToolsWindow(inspected_web_contents, true, action, ""); |
| 423 } | 429 } |
| 424 | 430 |
| 425 // static | 431 // static |
| 426 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 432 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( |
| 427 Browser* browser, | 433 Browser* browser, |
| 428 const DevToolsToggleAction& action) { | 434 const DevToolsToggleAction& action) { |
| 429 if (action.type() == DevToolsToggleAction::kToggle && | 435 if (action.type() == DevToolsToggleAction::kToggle && |
| 430 browser->is_devtools()) { | 436 browser->is_devtools()) { |
| 431 browser->tab_strip_model()->CloseAllTabs(); | 437 browser->tab_strip_model()->CloseAllTabs(); |
| 432 return NULL; | 438 return NULL; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 content::WebContents* inspected_web_contents, | 501 content::WebContents* inspected_web_contents, |
| 496 int x, | 502 int x, |
| 497 int y) { | 503 int y) { |
| 498 scoped_refptr<DevToolsAgentHost> agent( | 504 scoped_refptr<DevToolsAgentHost> agent( |
| 499 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); | 505 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); |
| 500 agent->InspectElement(x, y); | 506 agent->InspectElement(x, y); |
| 501 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; | 507 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; |
| 502 base::TimeTicks start_time = base::TimeTicks::Now(); | 508 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 503 // TODO(loislo): we should initiate DevTools window opening from within | 509 // TODO(loislo): we should initiate DevTools window opening from within |
| 504 // renderer. Otherwise, we still can hit a race condition here. | 510 // renderer. Otherwise, we still can hit a race condition here. |
| 505 DevToolsWindow* window = OpenDevToolsWindow(inspected_web_contents); | 511 OpenDevToolsWindow(inspected_web_contents); |
| 506 if (should_measure_time) | 512 |
| 513 DevToolsWindow* window = FindDevToolsWindow(agent.get()); |
| 514 if (should_measure_time && window) |
| 507 window->inspect_element_start_time_ = start_time; | 515 window->inspect_element_start_time_ = start_time; |
| 508 } | 516 } |
| 509 | 517 |
| 510 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) { | 518 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) { |
| 511 if (life_stage_ == kLoadCompleted) { | 519 if (life_stage_ == kLoadCompleted) { |
| 512 Show(action); | 520 Show(action); |
| 513 return; | 521 return; |
| 514 } | 522 } |
| 515 | 523 |
| 516 // Action will be done only after load completed. | 524 // Action will be done only after load completed. |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 closure.Run(); | 1211 closure.Run(); |
| 1204 return; | 1212 return; |
| 1205 } | 1213 } |
| 1206 load_completed_callback_ = closure; | 1214 load_completed_callback_ = closure; |
| 1207 } | 1215 } |
| 1208 | 1216 |
| 1209 bool DevToolsWindow::ForwardKeyboardEvent( | 1217 bool DevToolsWindow::ForwardKeyboardEvent( |
| 1210 const content::NativeWebKeyboardEvent& event) { | 1218 const content::NativeWebKeyboardEvent& event) { |
| 1211 return event_forwarder_->ForwardEvent(event); | 1219 return event_forwarder_->ForwardEvent(event); |
| 1212 } | 1220 } |
| OLD | NEW |