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 "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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 } | 221 } |
| 222 | 222 |
| 223 // DevToolsWindow ------------------------------------------------------------- | 223 // DevToolsWindow ------------------------------------------------------------- |
| 224 | 224 |
| 225 namespace { | 225 namespace { |
| 226 | 226 |
| 227 typedef std::vector<DevToolsWindow*> DevToolsWindows; | 227 typedef std::vector<DevToolsWindow*> DevToolsWindows; |
| 228 base::LazyInstance<DevToolsWindows>::Leaky g_instances = | 228 base::LazyInstance<DevToolsWindows>::Leaky g_instances = |
| 229 LAZY_INSTANCE_INITIALIZER; | 229 LAZY_INSTANCE_INITIALIZER; |
| 230 | 230 |
| 231 const char kPrefBottom[] = "dock_bottom"; | |
| 232 const char kPrefRight[] = "dock_right"; | |
| 233 const char kPrefUndocked[] = "undocked"; | |
| 234 | |
| 235 const char kDockSideBottom[] = "bottom"; | 231 const char kDockSideBottom[] = "bottom"; |
| 236 const char kDockSideRight[] = "right"; | 232 const char kDockSideRight[] = "right"; |
| 237 const char kDockSideUndocked[] = "undocked"; | 233 const char kDockSideUndocked[] = "undocked"; |
| 238 const char kDockSideMinimized[] = "minimized"; | 234 const char kDockSideMinimized[] = "minimized"; |
| 239 | 235 |
| 240 static const char kFrontendHostId[] = "id"; | 236 static const char kFrontendHostId[] = "id"; |
| 241 static const char kFrontendHostMethod[] = "method"; | 237 static const char kFrontendHostMethod[] = "method"; |
| 242 static const char kFrontendHostParams[] = "params"; | 238 static const char kFrontendHostParams[] = "params"; |
| 243 | 239 |
| 244 std::string SkColorToRGBAString(SkColor color) { | 240 std::string SkColorToRGBAString(SkColor color) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 | 279 |
| 284 // static | 280 // static |
| 285 std::string DevToolsWindow::GetDevToolsWindowPlacementPrefKey() { | 281 std::string DevToolsWindow::GetDevToolsWindowPlacementPrefKey() { |
| 286 return std::string(prefs::kBrowserWindowPlacement) + "_" + | 282 return std::string(prefs::kBrowserWindowPlacement) + "_" + |
| 287 std::string(kDevToolsApp); | 283 std::string(kDevToolsApp); |
| 288 } | 284 } |
| 289 | 285 |
| 290 // static | 286 // static |
| 291 void DevToolsWindow::RegisterProfilePrefs( | 287 void DevToolsWindow::RegisterProfilePrefs( |
| 292 user_prefs::PrefRegistrySyncable* registry) { | 288 user_prefs::PrefRegistrySyncable* registry) { |
| 293 registry->RegisterBooleanPref( | |
| 294 prefs::kDevToolsOpenDocked, true, | |
| 295 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 296 registry->RegisterStringPref( | |
| 297 prefs::kDevToolsDockSide, kDockSideBottom, | |
| 298 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 299 registry->RegisterDictionaryPref( | 289 registry->RegisterDictionaryPref( |
| 300 prefs::kDevToolsEditedFiles, | 290 prefs::kDevToolsEditedFiles, |
| 301 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 291 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 302 registry->RegisterDictionaryPref( | 292 registry->RegisterDictionaryPref( |
| 303 prefs::kDevToolsFileSystemPaths, | 293 prefs::kDevToolsFileSystemPaths, |
| 304 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 294 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 305 registry->RegisterStringPref( | 295 registry->RegisterStringPref( |
| 306 prefs::kDevToolsAdbKey, std::string(), | 296 prefs::kDevToolsAdbKey, std::string(), |
| 307 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 297 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 308 | 298 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 325 registry->RegisterDictionaryPref( | 315 registry->RegisterDictionaryPref( |
| 326 prefs::kDevToolsPortForwardingConfig, | 316 prefs::kDevToolsPortForwardingConfig, |
| 327 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 317 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 328 } | 318 } |
| 329 | 319 |
| 330 // static | 320 // static |
| 331 DevToolsWindow* DevToolsWindow::GetDockedInstanceForInspectedTab( | 321 DevToolsWindow* DevToolsWindow::GetDockedInstanceForInspectedTab( |
| 332 content::WebContents* inspected_web_contents) { | 322 content::WebContents* inspected_web_contents) { |
| 333 DevToolsWindow* window = GetInstanceForInspectedRenderViewHost( | 323 DevToolsWindow* window = GetInstanceForInspectedRenderViewHost( |
| 334 inspected_web_contents->GetRenderViewHost()); | 324 inspected_web_contents->GetRenderViewHost()); |
| 335 return (window && window->IsDocked()) ? window : NULL; | 325 return (window && window->is_docked_) ? window : NULL; |
| 336 } | 326 } |
| 337 | 327 |
| 338 // static | 328 // static |
| 339 DevToolsWindow* DevToolsWindow::GetInstanceForInspectedRenderViewHost( | 329 DevToolsWindow* DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| 340 content::RenderViewHost* inspected_rvh) { | 330 content::RenderViewHost* inspected_rvh) { |
| 341 if (!inspected_rvh || !DevToolsAgentHost::HasFor(inspected_rvh)) | 331 if (!inspected_rvh || !DevToolsAgentHost::HasFor(inspected_rvh)) |
| 342 return NULL; | 332 return NULL; |
| 343 | 333 |
| 344 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor( | 334 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor( |
| 345 inspected_rvh)); | 335 inspected_rvh)); |
| 346 return FindDevToolsWindow(agent.get()); | 336 return FindDevToolsWindow(agent.get()); |
| 347 } | 337 } |
| 348 | 338 |
| 349 // static | 339 // static |
| 350 bool DevToolsWindow::IsDevToolsWindow(content::RenderViewHost* window_rvh) { | 340 bool DevToolsWindow::IsDevToolsWindow(content::RenderViewHost* window_rvh) { |
| 351 return AsDevToolsWindow(window_rvh) != NULL; | 341 return AsDevToolsWindow(window_rvh) != NULL; |
| 352 } | 342 } |
| 353 | 343 |
| 354 // static | 344 // static |
| 355 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( | 345 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( |
| 356 Profile* profile, | 346 Profile* profile, |
| 357 DevToolsAgentHost* worker_agent) { | 347 DevToolsAgentHost* worker_agent) { |
| 358 DevToolsWindow* window = FindDevToolsWindow(worker_agent); | 348 DevToolsWindow* window = FindDevToolsWindow(worker_agent); |
| 359 if (!window) { | 349 if (!window) { |
| 360 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); | 350 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); |
| 361 // Will disconnect the current client host if there is one. | 351 // Will disconnect the current client host if there is one. |
| 362 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 352 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
| 363 worker_agent, window->frontend_host_.get()); | 353 worker_agent, window->frontend_host_.get()); |
| 364 } | 354 } |
| 365 window->Show(DevToolsToggleAction::Show()); | 355 window->ScheduleShow(DevToolsToggleAction::Show()); |
| 366 return window; | 356 return window; |
| 367 } | 357 } |
| 368 | 358 |
| 369 // static | 359 // static |
| 370 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( | 360 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( |
| 371 Profile* profile) { | 361 Profile* profile) { |
| 372 content::RecordAction(content::UserMetricsAction("DevTools_InspectWorker")); | 362 content::RecordAction(content::UserMetricsAction("DevTools_InspectWorker")); |
| 373 return Create(profile, GURL(), NULL, DEVTOOLS_DOCK_SIDE_UNDOCKED, true, | 363 return Create(profile, GURL(), NULL, true, false, false); |
| 374 false, false); | |
| 375 } | 364 } |
| 376 | 365 |
| 377 // static | 366 // static |
| 378 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( | 367 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( |
| 379 content::RenderViewHost* inspected_rvh) { | 368 content::RenderViewHost* inspected_rvh) { |
| 380 return ToggleDevToolsWindow( | 369 return ToggleDevToolsWindow( |
| 381 inspected_rvh, true, DevToolsToggleAction::Show()); | 370 inspected_rvh, true, DevToolsToggleAction::Show()); |
| 382 } | 371 } |
| 383 | 372 |
| 384 // static | 373 // static |
| 374 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( | |
| 375 content::RenderViewHost* inspected_rvh, | |
| 376 const DevToolsToggleAction& action) { | |
| 377 return ToggleDevToolsWindow( | |
| 378 inspected_rvh, true, action); | |
| 379 } | |
| 380 | |
| 381 // static | |
| 385 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 382 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( |
| 386 Browser* browser, | 383 Browser* browser, |
| 387 const DevToolsToggleAction& action) { | 384 const DevToolsToggleAction& action) { |
| 388 if (action.type() == DevToolsToggleAction::kToggle && | 385 if (action.type() == DevToolsToggleAction::kToggle && |
| 389 browser->is_devtools()) { | 386 browser->is_devtools()) { |
| 390 browser->tab_strip_model()->CloseAllTabs(); | 387 browser->tab_strip_model()->CloseAllTabs(); |
| 391 return NULL; | 388 return NULL; |
| 392 } | 389 } |
| 393 | 390 |
| 394 return ToggleDevToolsWindow( | 391 return ToggleDevToolsWindow( |
| 395 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | 392 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), |
| 396 action.type() == DevToolsToggleAction::kInspect, action); | 393 action.type() == DevToolsToggleAction::kInspect, action); |
| 397 } | 394 } |
| 398 | 395 |
| 399 // static | 396 // static |
| 400 void DevToolsWindow::OpenExternalFrontend( | 397 void DevToolsWindow::OpenExternalFrontend( |
| 401 Profile* profile, | 398 Profile* profile, |
| 402 const std::string& frontend_url, | 399 const std::string& frontend_url, |
| 403 content::DevToolsAgentHost* agent_host) { | 400 content::DevToolsAgentHost* agent_host) { |
| 404 DevToolsWindow* window = FindDevToolsWindow(agent_host); | 401 DevToolsWindow* window = FindDevToolsWindow(agent_host); |
| 405 if (!window) { | 402 if (!window) { |
| 406 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, | 403 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, |
| 407 DEVTOOLS_DOCK_SIDE_UNDOCKED, false, true, false); | 404 false, true, false); |
| 408 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 405 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
| 409 agent_host, window->frontend_host_.get()); | 406 agent_host, window->frontend_host_.get()); |
| 410 } | 407 } |
| 411 window->Show(DevToolsToggleAction::Show()); | 408 window->ScheduleShow(DevToolsToggleAction::Show()); |
| 412 } | 409 } |
| 413 | 410 |
| 414 // static | 411 // static |
| 415 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 412 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( |
| 416 content::RenderViewHost* inspected_rvh, | 413 content::RenderViewHost* inspected_rvh, |
| 417 bool force_open, | 414 bool force_open, |
| 418 const DevToolsToggleAction& action) { | 415 const DevToolsToggleAction& action) { |
| 419 scoped_refptr<DevToolsAgentHost> agent( | 416 scoped_refptr<DevToolsAgentHost> agent( |
| 420 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); | 417 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); |
| 421 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); | 418 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); |
| 422 DevToolsWindow* window = FindDevToolsWindow(agent.get()); | 419 DevToolsWindow* window = FindDevToolsWindow(agent.get()); |
| 423 bool do_open = force_open; | 420 bool do_open = force_open; |
| 424 if (!window) { | 421 if (!window) { |
| 425 Profile* profile = Profile::FromBrowserContext( | 422 Profile* profile = Profile::FromBrowserContext( |
| 426 inspected_rvh->GetProcess()->GetBrowserContext()); | 423 inspected_rvh->GetProcess()->GetBrowserContext()); |
| 427 DevToolsDockSide dock_side = GetDockSideFromPrefs(profile); | |
| 428 content::RecordAction( | 424 content::RecordAction( |
| 429 content::UserMetricsAction("DevTools_InspectRenderer")); | 425 content::UserMetricsAction("DevTools_InspectRenderer")); |
| 430 window = Create(profile, GURL(), inspected_rvh, dock_side, false, false, | 426 window = Create(profile, GURL(), inspected_rvh, false, false, |
| 431 true); | 427 true); |
| 432 manager->RegisterDevToolsClientHostFor(agent.get(), | 428 manager->RegisterDevToolsClientHostFor(agent.get(), |
| 433 window->frontend_host_.get()); | 429 window->frontend_host_.get()); |
| 434 do_open = true; | 430 do_open = true; |
| 435 } | 431 } |
| 436 | 432 |
| 437 // Update toolbar to reflect DevTools changes. | 433 // Update toolbar to reflect DevTools changes. |
| 438 window->UpdateBrowserToolbar(); | 434 window->UpdateBrowserToolbar(); |
| 439 | 435 |
| 440 // If window is docked and visible, we hide it on toggle. If window is | 436 // If window is docked and visible, we hide it on toggle. If window is |
| 441 // undocked, we show (activate) it. If window is minimized, we maximize it. | 437 // undocked, we show (activate) it. |
| 442 if (window->dock_side_ == DEVTOOLS_DOCK_SIDE_MINIMIZED) | 438 if (!window->is_docked_ || do_open) |
| 443 window->Restore(); | 439 window->ScheduleShow(action); |
| 444 else if (!window->IsDocked() || do_open) | |
| 445 window->Show(action); | |
| 446 else | 440 else |
| 447 window->CloseWindow(); | 441 window->CloseWindow(); |
| 448 | 442 |
| 449 return window; | 443 return window; |
| 450 } | 444 } |
| 451 | 445 |
| 452 // static | 446 // static |
| 453 void DevToolsWindow::InspectElement(content::RenderViewHost* inspected_rvh, | 447 void DevToolsWindow::InspectElement(content::RenderViewHost* inspected_rvh, |
| 454 int x, | 448 int x, |
| 455 int y) { | 449 int y) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 469 | 463 |
| 470 void DevToolsWindow::InspectedContentsClosing() { | 464 void DevToolsWindow::InspectedContentsClosing() { |
| 471 intercepted_page_beforeunload_ = false; | 465 intercepted_page_beforeunload_ = false; |
| 472 web_contents_->GetRenderViewHost()->ClosePage(); | 466 web_contents_->GetRenderViewHost()->ClosePage(); |
| 473 } | 467 } |
| 474 | 468 |
| 475 content::RenderViewHost* DevToolsWindow::GetRenderViewHost() { | 469 content::RenderViewHost* DevToolsWindow::GetRenderViewHost() { |
| 476 return web_contents_->GetRenderViewHost(); | 470 return web_contents_->GetRenderViewHost(); |
| 477 } | 471 } |
| 478 | 472 |
| 479 content::DevToolsClientHost* DevToolsWindow::GetDevToolsClientHostForTest() { | |
| 480 return frontend_host_.get(); | |
| 481 } | |
| 482 | |
| 483 gfx::Insets DevToolsWindow::GetContentsInsets() const { | 473 gfx::Insets DevToolsWindow::GetContentsInsets() const { |
| 484 return contents_insets_; | 474 return contents_insets_; |
| 485 } | 475 } |
| 486 | 476 |
| 487 gfx::Size DevToolsWindow::GetMinimumSize() const { | 477 gfx::Size DevToolsWindow::GetMinimumSize() const { |
| 488 const gfx::Size kMinDevToolsSize = gfx::Size(200, 100); | 478 const gfx::Size kMinDevToolsSize = gfx::Size(200, 100); |
| 489 return kMinDevToolsSize; | 479 return kMinDevToolsSize; |
| 490 } | 480 } |
| 491 | 481 |
| 482 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) { | |
| 483 if (load_state_mask_ == kLoadCompleted) | |
| 484 Show(action); | |
| 485 else | |
| 486 action_on_load_ = action; | |
| 487 } | |
| 488 | |
| 492 void DevToolsWindow::Show(const DevToolsToggleAction& action) { | 489 void DevToolsWindow::Show(const DevToolsToggleAction& action) { |
| 493 if (IsDocked()) { | 490 if (action.type() == DevToolsToggleAction::kNothing) |
| 491 return; | |
| 492 | |
| 493 if (is_docked_) { | |
| 494 DCHECK(can_dock_); | |
| 494 Browser* inspected_browser = NULL; | 495 Browser* inspected_browser = NULL; |
| 495 int inspected_tab_index = -1; | 496 int inspected_tab_index = -1; |
| 497 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), | |
| 498 &inspected_browser, | |
| 499 &inspected_tab_index); | |
| 500 DCHECK(inspected_browser); | |
| 501 DCHECK(inspected_tab_index); | |
| 502 | |
| 496 // Tell inspected browser to update splitter and switch to inspected panel. | 503 // Tell inspected browser to update splitter and switch to inspected panel. |
| 497 if (!IsInspectedBrowserPopup() && | 504 BrowserWindow* inspected_window = inspected_browser->window(); |
| 498 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), | 505 web_contents_->SetDelegate(this); |
| 499 &inspected_browser, | 506 inspected_window->UpdateDevTools(); |
| 500 &inspected_tab_index)) { | 507 web_contents_->GetView()->SetInitialFocus(); |
| 501 BrowserWindow* inspected_window = inspected_browser->window(); | 508 inspected_window->Show(); |
| 502 web_contents_->SetDelegate(this); | |
| 503 inspected_window->UpdateDevTools(); | |
| 504 web_contents_->GetView()->SetInitialFocus(); | |
| 505 inspected_window->Show(); | |
| 506 TabStripModel* tab_strip_model = inspected_browser->tab_strip_model(); | |
| 507 tab_strip_model->ActivateTabAt(inspected_tab_index, true); | |
| 508 PrefsTabHelper::CreateForWebContents(web_contents_); | |
| 509 GetRenderViewHost()->SyncRendererPrefs(); | |
| 510 ScheduleAction(action); | |
| 511 return; | |
| 512 } | |
| 513 | 509 |
| 514 // Sometimes we don't know where to dock. Stay undocked. | 510 TabStripModel* tab_strip_model = inspected_browser->tab_strip_model(); |
| 515 dock_side_ = DEVTOOLS_DOCK_SIDE_UNDOCKED; | 511 tab_strip_model->ActivateTabAt(inspected_tab_index, true); |
| 512 PrefsTabHelper::CreateForWebContents(web_contents_); | |
| 513 GetRenderViewHost()->SyncRendererPrefs(); | |
| 514 | |
| 515 DoAction(action); | |
| 516 return; | |
| 516 } | 517 } |
| 517 | 518 |
| 518 // Avoid consecutive window switching if the devtools window has been opened | 519 // Avoid consecutive window switching if the devtools window has been opened |
| 519 // and the Inspect Element shortcut is pressed in the inspected tab. | 520 // and the Inspect Element shortcut is pressed in the inspected tab. |
| 520 bool should_show_window = | 521 bool should_show_window = |
| 521 !browser_ || (action.type() != DevToolsToggleAction::kInspect); | 522 !browser_ || (action.type() != DevToolsToggleAction::kInspect); |
| 522 | 523 |
| 523 if (!browser_) | 524 if (!browser_) |
| 524 CreateDevToolsBrowser(); | 525 CreateDevToolsBrowser(); |
| 525 | 526 |
| 526 if (should_show_window) { | 527 if (should_show_window) { |
| 527 browser_->window()->Show(); | 528 browser_->window()->Show(); |
| 528 web_contents_->GetView()->SetInitialFocus(); | 529 web_contents_->GetView()->SetInitialFocus(); |
| 529 } | 530 } |
| 530 | 531 |
| 531 ScheduleAction(action); | 532 DoAction(action); |
| 532 } | 533 } |
| 533 | 534 |
| 534 // static | 535 // static |
| 535 bool DevToolsWindow::HandleBeforeUnload(content::WebContents* frontend_contents, | 536 bool DevToolsWindow::HandleBeforeUnload(content::WebContents* frontend_contents, |
| 536 bool proceed, bool* proceed_to_fire_unload) { | 537 bool proceed, bool* proceed_to_fire_unload) { |
| 537 DevToolsWindow* window = AsDevToolsWindow( | 538 DevToolsWindow* window = AsDevToolsWindow( |
| 538 frontend_contents->GetRenderViewHost()); | 539 frontend_contents->GetRenderViewHost()); |
| 539 if (!window) | 540 if (!window) |
| 540 return false; | 541 return false; |
| 541 if (!window->intercepted_page_beforeunload_) | 542 if (!window->intercepted_page_beforeunload_) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 DevToolsWindow *window = | 594 DevToolsWindow *window = |
| 594 DevToolsWindow::GetInstanceForInspectedRenderViewHost( | 595 DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| 595 contents->GetRenderViewHost()); | 596 contents->GetRenderViewHost()); |
| 596 if (!window) | 597 if (!window) |
| 597 return; | 598 return; |
| 598 window->intercepted_page_beforeunload_ = false; | 599 window->intercepted_page_beforeunload_ = false; |
| 599 // Propagate to devtools opened on devtools if any. | 600 // Propagate to devtools opened on devtools if any. |
| 600 DevToolsWindow::OnPageCloseCanceled(window->web_contents()); | 601 DevToolsWindow::OnPageCloseCanceled(window->web_contents()); |
| 601 } | 602 } |
| 602 | 603 |
| 603 void DevToolsWindow::SetDockSideForTest(DevToolsDockSide dock_side) { | |
| 604 SetDockSide(SideToString(dock_side)); | |
| 605 } | |
| 606 | |
| 607 DevToolsWindow::DevToolsWindow(Profile* profile, | 604 DevToolsWindow::DevToolsWindow(Profile* profile, |
| 608 const GURL& url, | 605 const GURL& url, |
| 609 content::RenderViewHost* inspected_rvh, | 606 content::RenderViewHost* inspected_rvh, |
| 610 DevToolsDockSide dock_side) | 607 bool can_dock) |
| 611 : profile_(profile), | 608 : profile_(profile), |
| 612 browser_(NULL), | 609 browser_(NULL), |
| 613 dock_side_(dock_side), | 610 is_docked_(false), |
| 614 is_loaded_(false), | 611 can_dock_(can_dock), |
| 615 action_on_load_(DevToolsToggleAction::Show()), | 612 load_state_mask_(can_dock ? kNotLoaded : kIsDockedSet), |
|
dgozman
2013/12/30 13:06:17
This initialization allows old frontends to work a
| |
| 616 dock_side_before_minimized_(dock_side), | 613 action_on_load_(DevToolsToggleAction::Nothing()), |
| 614 set_is_docked_for_test_on_load_(false), | |
| 617 intercepted_page_beforeunload_(false), | 615 intercepted_page_beforeunload_(false), |
| 618 weak_factory_(this) { | 616 weak_factory_(this) { |
| 619 web_contents_ = | 617 web_contents_ = |
| 620 content::WebContents::Create(content::WebContents::CreateParams(profile)); | 618 content::WebContents::Create(content::WebContents::CreateParams(profile)); |
| 621 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 619 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
| 622 | 620 |
| 623 web_contents_->GetController().LoadURL(url, content::Referrer(), | 621 web_contents_->GetController().LoadURL(url, content::Referrer(), |
| 624 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 622 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
| 625 | 623 |
| 626 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( | 624 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 650 | 648 |
| 651 embedder_message_dispatcher_.reset( | 649 embedder_message_dispatcher_.reset( |
| 652 new DevToolsEmbedderMessageDispatcher(this)); | 650 new DevToolsEmbedderMessageDispatcher(this)); |
| 653 } | 651 } |
| 654 | 652 |
| 655 // static | 653 // static |
| 656 DevToolsWindow* DevToolsWindow::Create( | 654 DevToolsWindow* DevToolsWindow::Create( |
| 657 Profile* profile, | 655 Profile* profile, |
| 658 const GURL& frontend_url, | 656 const GURL& frontend_url, |
| 659 content::RenderViewHost* inspected_rvh, | 657 content::RenderViewHost* inspected_rvh, |
| 660 DevToolsDockSide dock_side, | |
| 661 bool shared_worker_frontend, | 658 bool shared_worker_frontend, |
| 662 bool external_frontend, | 659 bool external_frontend, |
| 663 bool can_dock) { | 660 bool can_dock) { |
| 664 if (inspected_rvh) { | 661 if (inspected_rvh) { |
| 665 // Check for a place to dock. | 662 // Check for a place to dock. |
| 666 Browser* browser = NULL; | 663 Browser* browser = NULL; |
| 667 int tab; | 664 int tab; |
| 668 content::WebContents* inspected_web_contents = | 665 content::WebContents* inspected_web_contents = |
| 669 content::WebContents::FromRenderViewHost(inspected_rvh); | 666 content::WebContents::FromRenderViewHost(inspected_rvh); |
| 670 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, | 667 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, |
| 671 &browser, &tab) || | 668 &browser, &tab) || |
| 672 browser->is_type_popup()) { | 669 browser->is_type_popup()) { |
| 673 can_dock = false; | 670 can_dock = false; |
| 674 } | 671 } |
| 675 } | 672 } |
| 676 | 673 |
| 677 // Create WebContents with devtools. | 674 // Create WebContents with devtools. |
| 678 GURL url(GetDevToolsURL(profile, frontend_url, dock_side, | 675 GURL url(GetDevToolsURL(profile, frontend_url, |
| 679 shared_worker_frontend, | 676 shared_worker_frontend, |
| 680 external_frontend, | 677 external_frontend, |
| 681 can_dock)); | 678 can_dock)); |
| 682 return new DevToolsWindow(profile, url, inspected_rvh, dock_side); | 679 return new DevToolsWindow(profile, url, inspected_rvh, can_dock); |
| 683 } | 680 } |
| 684 | 681 |
| 685 // static | 682 // static |
| 686 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, | 683 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, |
| 687 const GURL& base_url, | 684 const GURL& base_url, |
| 688 DevToolsDockSide dock_side, | |
| 689 bool shared_worker_frontend, | 685 bool shared_worker_frontend, |
| 690 bool external_frontend, | 686 bool external_frontend, |
| 691 bool can_dock) { | 687 bool can_dock) { |
| 692 if (base_url.SchemeIs("data")) | 688 if (base_url.SchemeIs("data")) |
| 693 return base_url; | 689 return base_url; |
| 694 | 690 |
| 695 std::string frontend_url( | 691 std::string frontend_url( |
| 696 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); | 692 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); |
| 697 ThemeService* tp = ThemeServiceFactory::GetForProfile(profile); | 693 ThemeService* tp = ThemeServiceFactory::GetForProfile(profile); |
| 698 DCHECK(tp); | 694 DCHECK(tp); |
| 699 std::string url_string( | 695 std::string url_string( |
| 700 frontend_url + | 696 frontend_url + |
| 701 ((frontend_url.find("?") == std::string::npos) ? "?" : "&") + | 697 ((frontend_url.find("?") == std::string::npos) ? "?" : "&") + |
| 702 "dockSide=" + SideToString(dock_side) + | 698 "dockSide=undocked" + // TODO(dgozman): remove this support in M38. |
| 703 "&toolbarColor=" + | 699 "&toolbarColor=" + |
| 704 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_TOOLBAR)) + | 700 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_TOOLBAR)) + |
| 705 "&textColor=" + | 701 "&textColor=" + |
| 706 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT))); | 702 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT))); |
| 707 if (shared_worker_frontend) | 703 if (shared_worker_frontend) |
| 708 url_string += "&isSharedWorker=true"; | 704 url_string += "&isSharedWorker=true"; |
| 709 if (external_frontend) | 705 if (external_frontend) |
| 710 url_string += "&remoteFrontend=true"; | 706 url_string += "&remoteFrontend=true"; |
| 711 if (can_dock) | 707 if (can_dock) |
| 712 url_string += "&can_dock=true"; | 708 url_string += "&can_dock=true"; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 740 DevToolsWindows* instances = &g_instances.Get(); | 736 DevToolsWindows* instances = &g_instances.Get(); |
| 741 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); | 737 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); |
| 742 ++it) { | 738 ++it) { |
| 743 if ((*it)->web_contents_->GetRenderViewHost() == window_rvh) | 739 if ((*it)->web_contents_->GetRenderViewHost() == window_rvh) |
| 744 return *it; | 740 return *it; |
| 745 } | 741 } |
| 746 return NULL; | 742 return NULL; |
| 747 } | 743 } |
| 748 | 744 |
| 749 // static | 745 // static |
| 750 DevToolsDockSide DevToolsWindow::GetDockSideFromPrefs(Profile* profile) { | 746 bool DevToolsWindow::IsDockedFromString(const std::string& dock_side) { |
| 751 std::string dock_side = | 747 return dock_side != kDockSideUndocked; |
| 752 profile->GetPrefs()->GetString(prefs::kDevToolsDockSide); | |
| 753 | |
| 754 // Migrate prefs. | |
| 755 const char kOldPrefBottom[] = "bottom"; | |
| 756 const char kOldPrefRight[] = "right"; | |
| 757 if ((dock_side == kOldPrefBottom) || (dock_side == kOldPrefRight)) { | |
| 758 if (!profile->GetPrefs()->GetBoolean(prefs::kDevToolsOpenDocked)) | |
| 759 return DEVTOOLS_DOCK_SIDE_UNDOCKED; | |
| 760 return (dock_side == kOldPrefBottom) ? | |
| 761 DEVTOOLS_DOCK_SIDE_BOTTOM : DEVTOOLS_DOCK_SIDE_RIGHT; | |
| 762 } | |
| 763 | |
| 764 if (dock_side == kPrefUndocked) | |
| 765 return DEVTOOLS_DOCK_SIDE_UNDOCKED; | |
| 766 if (dock_side == kPrefRight) | |
| 767 return DEVTOOLS_DOCK_SIDE_RIGHT; | |
| 768 // Default to docked to bottom. | |
| 769 return DEVTOOLS_DOCK_SIDE_BOTTOM; | |
| 770 } | |
| 771 | |
| 772 // static | |
| 773 std::string DevToolsWindow::SideToString(DevToolsDockSide dock_side) { | |
| 774 switch (dock_side) { | |
| 775 case DEVTOOLS_DOCK_SIDE_UNDOCKED: return kDockSideUndocked; | |
| 776 case DEVTOOLS_DOCK_SIDE_RIGHT: return kDockSideRight; | |
| 777 case DEVTOOLS_DOCK_SIDE_BOTTOM: return kDockSideBottom; | |
| 778 case DEVTOOLS_DOCK_SIDE_MINIMIZED: return kDockSideMinimized; | |
| 779 default: return kDockSideUndocked; | |
| 780 } | |
| 781 } | |
| 782 | |
| 783 // static | |
| 784 DevToolsDockSide DevToolsWindow::SideFromString( | |
| 785 const std::string& dock_side) { | |
| 786 if (dock_side == kDockSideRight) | |
| 787 return DEVTOOLS_DOCK_SIDE_RIGHT; | |
| 788 if (dock_side == kDockSideBottom) | |
| 789 return DEVTOOLS_DOCK_SIDE_BOTTOM; | |
| 790 return (dock_side == kDockSideMinimized) ? | |
| 791 DEVTOOLS_DOCK_SIDE_MINIMIZED : DEVTOOLS_DOCK_SIDE_UNDOCKED; | |
| 792 } | 748 } |
| 793 | 749 |
| 794 void DevToolsWindow::Observe(int type, | 750 void DevToolsWindow::Observe(int type, |
| 795 const content::NotificationSource& source, | 751 const content::NotificationSource& source, |
| 796 const content::NotificationDetails& details) { | 752 const content::NotificationDetails& details) { |
| 797 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); | 753 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); |
| 798 UpdateTheme(); | 754 UpdateTheme(); |
| 799 } | 755 } |
| 800 | 756 |
| 801 content::WebContents* DevToolsWindow::OpenURLFromTab( | 757 content::WebContents* DevToolsWindow::OpenURLFromTab( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 834 bool* was_blocked) { | 790 bool* was_blocked) { |
| 835 content::WebContents* inspected_web_contents = GetInspectedWebContents(); | 791 content::WebContents* inspected_web_contents = GetInspectedWebContents(); |
| 836 if (inspected_web_contents) { | 792 if (inspected_web_contents) { |
| 837 inspected_web_contents->GetDelegate()->AddNewContents( | 793 inspected_web_contents->GetDelegate()->AddNewContents( |
| 838 source, new_contents, disposition, initial_pos, user_gesture, | 794 source, new_contents, disposition, initial_pos, user_gesture, |
| 839 was_blocked); | 795 was_blocked); |
| 840 } | 796 } |
| 841 } | 797 } |
| 842 | 798 |
| 843 void DevToolsWindow::CloseContents(content::WebContents* source) { | 799 void DevToolsWindow::CloseContents(content::WebContents* source) { |
| 844 CHECK(IsDocked()); | 800 CHECK(is_docked_); |
| 845 // Update dev tools to reflect removed dev tools window. | 801 // Update dev tools to reflect removed dev tools window. |
| 846 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 802 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 847 if (inspected_window) | 803 if (inspected_window) |
| 848 inspected_window->UpdateDevTools(); | 804 inspected_window->UpdateDevTools(); |
| 849 // In case of docked web_contents_, we own it so delete here. | 805 // In case of docked web_contents_, we own it so delete here. |
| 850 // Embedding DevTools window will be deleted as a result of | 806 // Embedding DevTools window will be deleted as a result of |
| 851 // WebContentsDestroyed callback. | 807 // WebContentsDestroyed callback. |
| 852 delete web_contents_; | 808 delete web_contents_; |
| 853 } | 809 } |
| 854 | 810 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 874 DCHECK(!should_proceed); | 830 DCHECK(!should_proceed); |
| 875 } | 831 } |
| 876 *proceed_to_fire_unload = false; | 832 *proceed_to_fire_unload = false; |
| 877 } | 833 } |
| 878 } | 834 } |
| 879 | 835 |
| 880 bool DevToolsWindow::PreHandleKeyboardEvent( | 836 bool DevToolsWindow::PreHandleKeyboardEvent( |
| 881 content::WebContents* source, | 837 content::WebContents* source, |
| 882 const content::NativeWebKeyboardEvent& event, | 838 const content::NativeWebKeyboardEvent& event, |
| 883 bool* is_keyboard_shortcut) { | 839 bool* is_keyboard_shortcut) { |
| 884 if (IsDocked()) { | 840 if (is_docked_) { |
| 885 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 841 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 886 if (inspected_window) { | 842 if (inspected_window) { |
| 887 return inspected_window->PreHandleKeyboardEvent(event, | 843 return inspected_window->PreHandleKeyboardEvent(event, |
| 888 is_keyboard_shortcut); | 844 is_keyboard_shortcut); |
| 889 } | 845 } |
| 890 } | 846 } |
| 891 return false; | 847 return false; |
| 892 } | 848 } |
| 893 | 849 |
| 894 void DevToolsWindow::HandleKeyboardEvent( | 850 void DevToolsWindow::HandleKeyboardEvent( |
| 895 content::WebContents* source, | 851 content::WebContents* source, |
| 896 const content::NativeWebKeyboardEvent& event) { | 852 const content::NativeWebKeyboardEvent& event) { |
| 897 if (IsDocked()) { | 853 if (is_docked_) { |
| 898 if (event.windowsKeyCode == 0x08) { | 854 if (event.windowsKeyCode == 0x08) { |
| 899 // Do not navigate back in history on Windows (http://crbug.com/74156). | 855 // Do not navigate back in history on Windows (http://crbug.com/74156). |
| 900 return; | 856 return; |
| 901 } | 857 } |
| 902 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 858 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 903 if (inspected_window) | 859 if (inspected_window) |
| 904 inspected_window->HandleKeyboardEvent(event); | 860 inspected_window->HandleKeyboardEvent(event); |
| 905 } | 861 } |
| 906 } | 862 } |
| 907 | 863 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 920 } | 876 } |
| 921 | 877 |
| 922 void DevToolsWindow::RunFileChooser(content::WebContents* web_contents, | 878 void DevToolsWindow::RunFileChooser(content::WebContents* web_contents, |
| 923 const content::FileChooserParams& params) { | 879 const content::FileChooserParams& params) { |
| 924 FileSelectHelper::RunFileChooser(web_contents, params); | 880 FileSelectHelper::RunFileChooser(web_contents, params); |
| 925 } | 881 } |
| 926 | 882 |
| 927 void DevToolsWindow::WebContentsFocused(content::WebContents* contents) { | 883 void DevToolsWindow::WebContentsFocused(content::WebContents* contents) { |
| 928 Browser* inspected_browser = NULL; | 884 Browser* inspected_browser = NULL; |
| 929 int inspected_tab_index = -1; | 885 int inspected_tab_index = -1; |
| 930 if (IsDocked() && FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), | 886 if (is_docked_ && FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), |
| 931 &inspected_browser, | 887 &inspected_browser, |
| 932 &inspected_tab_index)) | 888 &inspected_tab_index)) |
| 933 inspected_browser->window()->WebContentsFocused(contents); | 889 inspected_browser->window()->WebContentsFocused(contents); |
| 934 } | 890 } |
| 935 | 891 |
| 936 void DevToolsWindow::DispatchOnEmbedder(const std::string& message) { | 892 void DevToolsWindow::DispatchOnEmbedder(const std::string& message) { |
| 937 std::string method; | 893 std::string method; |
| 938 base::ListValue empty_params; | 894 base::ListValue empty_params; |
| 939 base::ListValue* params = &empty_params; | 895 base::ListValue* params = &empty_params; |
| 940 | 896 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 955 std::string error = embedder_message_dispatcher_->Dispatch(method, params); | 911 std::string error = embedder_message_dispatcher_->Dispatch(method, params); |
| 956 if (id) { | 912 if (id) { |
| 957 scoped_ptr<base::Value> id_value(base::Value::CreateIntegerValue(id)); | 913 scoped_ptr<base::Value> id_value(base::Value::CreateIntegerValue(id)); |
| 958 scoped_ptr<base::Value> error_value(base::Value::CreateStringValue(error)); | 914 scoped_ptr<base::Value> error_value(base::Value::CreateStringValue(error)); |
| 959 CallClientFunction("InspectorFrontendAPI.embedderMessageAck", | 915 CallClientFunction("InspectorFrontendAPI.embedderMessageAck", |
| 960 id_value.get(), error_value.get(), NULL); | 916 id_value.get(), error_value.get(), NULL); |
| 961 } | 917 } |
| 962 } | 918 } |
| 963 | 919 |
| 964 void DevToolsWindow::ActivateWindow() { | 920 void DevToolsWindow::ActivateWindow() { |
| 965 if (IsDocked() && GetInspectedBrowserWindow()) | 921 if (is_docked_ && GetInspectedBrowserWindow()) |
| 966 web_contents_->GetView()->Focus(); | 922 web_contents_->GetView()->Focus(); |
| 967 else if (!IsDocked() && !browser_->window()->IsActive()) | 923 else if (!is_docked_ && !browser_->window()->IsActive()) |
| 968 browser_->window()->Activate(); | 924 browser_->window()->Activate(); |
| 969 } | 925 } |
| 970 | 926 |
| 971 void DevToolsWindow::ActivateContents(content::WebContents* contents) { | 927 void DevToolsWindow::ActivateContents(content::WebContents* contents) { |
| 972 if (IsDocked()) { | 928 if (is_docked_) { |
| 973 content::WebContents* inspected_tab = this->GetInspectedWebContents(); | 929 content::WebContents* inspected_tab = this->GetInspectedWebContents(); |
| 974 inspected_tab->GetDelegate()->ActivateContents(inspected_tab); | 930 inspected_tab->GetDelegate()->ActivateContents(inspected_tab); |
| 975 } else { | 931 } else { |
| 976 browser_->window()->Activate(); | 932 browser_->window()->Activate(); |
| 977 } | 933 } |
| 978 } | 934 } |
| 979 | 935 |
| 980 void DevToolsWindow::CloseWindow() { | 936 void DevToolsWindow::CloseWindow() { |
| 981 DCHECK(IsDocked()); | 937 DCHECK(is_docked_); |
| 982 web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); | 938 web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); |
| 983 } | 939 } |
| 984 | 940 |
| 985 void DevToolsWindow::SetContentsInsets( | 941 void DevToolsWindow::SetContentsInsets( |
| 986 int top, int left, int bottom, int right) { | 942 int top, int left, int bottom, int right) { |
| 987 if (contents_insets_.top() == top && | 943 if (contents_insets_.top() == top && |
| 988 contents_insets_.left() == left && | 944 contents_insets_.left() == left && |
| 989 contents_insets_.bottom() == bottom && | 945 contents_insets_.bottom() == bottom && |
| 990 contents_insets_.right() == right) { | 946 contents_insets_.right() == right) { |
| 991 return; | 947 return; |
| 992 } | 948 } |
| 993 | 949 |
| 994 contents_insets_ = gfx::Insets(top, left, bottom, right); | 950 contents_insets_ = gfx::Insets(top, left, bottom, right); |
| 995 if (IsDocked()) { | 951 if (is_docked_) { |
| 996 // Update inspected window. | 952 // Update inspected window. |
| 997 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 953 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 998 if (inspected_window) | 954 if (inspected_window) |
| 999 inspected_window->UpdateDevTools(); | 955 inspected_window->UpdateDevTools(); |
| 1000 } | 956 } |
| 1001 } | 957 } |
| 1002 | 958 |
| 1003 void DevToolsWindow::MoveWindow(int x, int y) { | 959 void DevToolsWindow::MoveWindow(int x, int y) { |
| 1004 if (!IsDocked()) { | 960 if (!is_docked_) { |
| 1005 gfx::Rect bounds = browser_->window()->GetBounds(); | 961 gfx::Rect bounds = browser_->window()->GetBounds(); |
| 1006 bounds.Offset(x, y); | 962 bounds.Offset(x, y); |
| 1007 browser_->window()->SetBounds(bounds); | 963 browser_->window()->SetBounds(bounds); |
| 1008 } | 964 } |
| 1009 } | 965 } |
| 1010 | 966 |
| 967 void DevToolsWindow::SetIsDockedForTest(bool is_docked) { | |
| 968 SetIsDocked(is_docked); | |
| 969 if (load_state_mask_ == kLoadCompleted) { | |
| 970 base::FundamentalValue docked(is_docked_); | |
| 971 CallClientFunction("InspectorFrontendAPI.setIsDocked", &docked, NULL, NULL); | |
| 972 } else { | |
| 973 set_is_docked_for_test_on_load_ = true; | |
| 974 } | |
| 975 } | |
| 976 | |
| 977 void DevToolsWindow::SetIsDockedAndShowImmediatelyForTest(bool is_docked) { | |
| 978 is_docked_ = is_docked; | |
| 979 LoadCompleted(); | |
| 980 } | |
| 981 | |
| 1011 void DevToolsWindow::SetDockSide(const std::string& side) { | 982 void DevToolsWindow::SetDockSide(const std::string& side) { |
| 1012 DevToolsDockSide requested_side = SideFromString(side); | 983 // TODO(dgozman): remove this method after frontend switches to SetIsDocked. |
| 1013 bool dock_requested = requested_side != DEVTOOLS_DOCK_SIDE_UNDOCKED; | 984 SetIsDocked(IsDockedFromString(side)); |
| 1014 bool is_docked = IsDocked(); | 985 } |
| 1015 | 986 |
| 1016 if (dock_requested && | 987 void DevToolsWindow::SetIsDocked(bool dock_requested) { |
| 1017 (!GetInspectedWebContents() || !GetInspectedBrowserWindow() || | 988 if (dock_requested && !can_dock_) |
| 1018 IsInspectedBrowserPopup())) { | 989 return; |
| 1019 // Cannot dock, avoid window flashing due to close-reopen cycle. | 990 |
| 991 bool was_docked = is_docked_; | |
| 992 is_docked_ = dock_requested; | |
| 993 | |
| 994 if (load_state_mask_ != kLoadCompleted) { | |
| 995 load_state_mask_ |= kIsDockedSet; | |
| 996 if (load_state_mask_ == kLoadCompleted) | |
| 997 LoadCompleted(); | |
| 1020 return; | 998 return; |
| 1021 } | 999 } |
| 1022 | 1000 |
| 1023 if ((dock_side_ != DEVTOOLS_DOCK_SIDE_MINIMIZED) && | 1001 if (dock_requested == was_docked) |
| 1024 (requested_side == DEVTOOLS_DOCK_SIDE_MINIMIZED)) | 1002 return; |
| 1025 dock_side_before_minimized_ = dock_side_; | |
| 1026 | 1003 |
| 1027 dock_side_ = requested_side; | 1004 if (dock_requested && !was_docked) { |
| 1028 if (dock_requested && !is_docked) { | |
| 1029 // Detach window from the external devtools browser. It will lead to | 1005 // Detach window from the external devtools browser. It will lead to |
| 1030 // the browser object's close and delete. Remove observer first. | 1006 // the browser object's close and delete. Remove observer first. |
| 1031 TabStripModel* tab_strip_model = browser_->tab_strip_model(); | 1007 TabStripModel* tab_strip_model = browser_->tab_strip_model(); |
| 1032 tab_strip_model->DetachWebContentsAt( | 1008 tab_strip_model->DetachWebContentsAt( |
| 1033 tab_strip_model->GetIndexOfWebContents(web_contents_)); | 1009 tab_strip_model->GetIndexOfWebContents(web_contents_)); |
| 1034 browser_ = NULL; | 1010 browser_ = NULL; |
| 1035 } else if (!dock_requested && is_docked) { | 1011 } else if (!dock_requested && was_docked) { |
| 1036 // Update inspected window to hide split and reset it. | 1012 // Update inspected window to hide split and reset it. |
| 1037 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 1013 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 1038 if (inspected_window) | 1014 if (inspected_window) |
| 1039 inspected_window->UpdateDevTools(); | 1015 inspected_window->UpdateDevTools(); |
| 1040 } | 1016 } |
| 1041 | 1017 |
| 1042 if (dock_side_ != DEVTOOLS_DOCK_SIDE_MINIMIZED) { | |
| 1043 std::string pref_value = kPrefBottom; | |
| 1044 switch (dock_side_) { | |
| 1045 case DEVTOOLS_DOCK_SIDE_UNDOCKED: | |
| 1046 pref_value = kPrefUndocked; | |
| 1047 break; | |
| 1048 case DEVTOOLS_DOCK_SIDE_RIGHT: | |
| 1049 pref_value = kPrefRight; | |
| 1050 break; | |
| 1051 case DEVTOOLS_DOCK_SIDE_BOTTOM: | |
| 1052 pref_value = kPrefBottom; | |
| 1053 break; | |
| 1054 case DEVTOOLS_DOCK_SIDE_MINIMIZED: | |
| 1055 // We don't persist minimized state. | |
| 1056 break; | |
| 1057 } | |
| 1058 profile_->GetPrefs()->SetString(prefs::kDevToolsDockSide, pref_value); | |
| 1059 } | |
| 1060 | |
| 1061 Show(DevToolsToggleAction::Show()); | 1018 Show(DevToolsToggleAction::Show()); |
| 1062 } | 1019 } |
| 1063 | 1020 |
| 1064 void DevToolsWindow::OpenInNewTab(const std::string& url) { | 1021 void DevToolsWindow::OpenInNewTab(const std::string& url) { |
| 1065 content::OpenURLParams params( | 1022 content::OpenURLParams params( |
| 1066 GURL(url), content::Referrer(), NEW_FOREGROUND_TAB, | 1023 GURL(url), content::Referrer(), NEW_FOREGROUND_TAB, |
| 1067 content::PAGE_TRANSITION_LINK, false); | 1024 content::PAGE_TRANSITION_LINK, false); |
| 1068 content::WebContents* inspected_web_contents = GetInspectedWebContents(); | 1025 content::WebContents* inspected_web_contents = GetInspectedWebContents(); |
| 1069 if (inspected_web_contents) { | 1026 if (inspected_web_contents) { |
| 1070 inspected_web_contents->OpenURL(params); | 1027 inspected_web_contents->OpenURL(params); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1276 base::FundamentalValue request_id_value(request_id); | 1233 base::FundamentalValue request_id_value(request_id); |
| 1277 base::StringValue file_system_path_value(file_system_path); | 1234 base::StringValue file_system_path_value(file_system_path); |
| 1278 CallClientFunction("InspectorFrontendAPI.searchCompleted", &request_id_value, | 1235 CallClientFunction("InspectorFrontendAPI.searchCompleted", &request_id_value, |
| 1279 &file_system_path_value, &file_paths_value); | 1236 &file_system_path_value, &file_paths_value); |
| 1280 } | 1237 } |
| 1281 | 1238 |
| 1282 void DevToolsWindow::ShowDevToolsConfirmInfoBar( | 1239 void DevToolsWindow::ShowDevToolsConfirmInfoBar( |
| 1283 const base::string16& message, | 1240 const base::string16& message, |
| 1284 const InfoBarCallback& callback) { | 1241 const InfoBarCallback& callback) { |
| 1285 DevToolsConfirmInfoBarDelegate::Create( | 1242 DevToolsConfirmInfoBarDelegate::Create( |
| 1286 IsDocked() ? | 1243 is_docked_ ? |
| 1287 InfoBarService::FromWebContents(GetInspectedWebContents()) : | 1244 InfoBarService::FromWebContents(GetInspectedWebContents()) : |
| 1288 InfoBarService::FromWebContents(web_contents_), | 1245 InfoBarService::FromWebContents(web_contents_), |
| 1289 callback, message); | 1246 callback, message); |
| 1290 } | 1247 } |
| 1291 | 1248 |
| 1292 void DevToolsWindow::CreateDevToolsBrowser() { | 1249 void DevToolsWindow::CreateDevToolsBrowser() { |
| 1293 std::string wp_key = GetDevToolsWindowPlacementPrefKey(); | 1250 std::string wp_key = GetDevToolsWindowPlacementPrefKey(); |
| 1294 PrefService* prefs = profile_->GetPrefs(); | 1251 PrefService* prefs = profile_->GetPrefs(); |
| 1295 const base::DictionaryValue* wp_pref = prefs->GetDictionary(wp_key.c_str()); | 1252 const base::DictionaryValue* wp_pref = prefs->GetDictionary(wp_key.c_str()); |
| 1296 if (!wp_pref || wp_pref->empty()) { | 1253 if (!wp_pref || wp_pref->empty()) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1333 } | 1290 } |
| 1334 | 1291 |
| 1335 BrowserWindow* DevToolsWindow::GetInspectedBrowserWindow() { | 1292 BrowserWindow* DevToolsWindow::GetInspectedBrowserWindow() { |
| 1336 Browser* browser = NULL; | 1293 Browser* browser = NULL; |
| 1337 int tab; | 1294 int tab; |
| 1338 return FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), | 1295 return FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), |
| 1339 &browser, &tab) ? | 1296 &browser, &tab) ? |
| 1340 browser->window() : NULL; | 1297 browser->window() : NULL; |
| 1341 } | 1298 } |
| 1342 | 1299 |
| 1343 bool DevToolsWindow::IsInspectedBrowserPopup() { | 1300 void DevToolsWindow::DoAction(const DevToolsToggleAction& action) { |
| 1344 Browser* browser = NULL; | 1301 switch (action.type()) { |
| 1345 int tab; | |
| 1346 return FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), | |
| 1347 &browser, &tab) && | |
| 1348 browser->is_type_popup(); | |
| 1349 } | |
| 1350 | |
| 1351 void DevToolsWindow::UpdateFrontendDockSide() { | |
| 1352 base::StringValue dock_side(SideToString(dock_side_)); | |
| 1353 CallClientFunction("InspectorFrontendAPI.setDockSide", &dock_side, NULL, | |
| 1354 NULL); | |
| 1355 base::FundamentalValue docked(IsDocked()); | |
| 1356 CallClientFunction("InspectorFrontendAPI.setAttachedWindow", &docked, NULL, | |
| 1357 NULL); | |
| 1358 } | |
| 1359 | |
| 1360 void DevToolsWindow::ScheduleAction(const DevToolsToggleAction& action) { | |
| 1361 action_on_load_ = action; | |
| 1362 if (is_loaded_) | |
| 1363 DoAction(); | |
| 1364 } | |
| 1365 | |
| 1366 void DevToolsWindow::DoAction() { | |
| 1367 UpdateFrontendDockSide(); | |
| 1368 switch (action_on_load_.type()) { | |
| 1369 case DevToolsToggleAction::kShowConsole: | 1302 case DevToolsToggleAction::kShowConsole: |
| 1370 CallClientFunction("InspectorFrontendAPI.showConsole", NULL, NULL, NULL); | 1303 CallClientFunction("InspectorFrontendAPI.showConsole", NULL, NULL, NULL); |
| 1371 break; | 1304 break; |
| 1372 | 1305 |
| 1373 case DevToolsToggleAction::kInspect: | 1306 case DevToolsToggleAction::kInspect: |
| 1374 CallClientFunction("InspectorFrontendAPI.enterInspectElementMode", NULL, | 1307 CallClientFunction("InspectorFrontendAPI.enterInspectElementMode", NULL, |
| 1375 NULL, NULL); | 1308 NULL, NULL); |
| 1376 break; | 1309 break; |
| 1377 | 1310 |
| 1378 case DevToolsToggleAction::kShow: | 1311 case DevToolsToggleAction::kShow: |
| 1379 case DevToolsToggleAction::kToggle: | 1312 case DevToolsToggleAction::kToggle: |
| 1380 // Do nothing. | 1313 // Do nothing. |
| 1381 break; | 1314 break; |
| 1382 | 1315 |
| 1383 case DevToolsToggleAction::kReveal: { | 1316 case DevToolsToggleAction::kReveal: { |
| 1384 const DevToolsToggleAction::RevealParams* params = | 1317 const DevToolsToggleAction::RevealParams* params = |
| 1385 action_on_load_.params(); | 1318 action.params(); |
| 1386 CHECK(params); | 1319 CHECK(params); |
| 1387 base::StringValue url_value(params->url); | 1320 base::StringValue url_value(params->url); |
| 1388 base::FundamentalValue line_value(static_cast<int>(params->line_number)); | 1321 base::FundamentalValue line_value(static_cast<int>(params->line_number)); |
| 1389 base::FundamentalValue column_value( | 1322 base::FundamentalValue column_value( |
| 1390 static_cast<int>(params->column_number)); | 1323 static_cast<int>(params->column_number)); |
| 1391 CallClientFunction("InspectorFrontendAPI.revealSourceLine", | 1324 CallClientFunction("InspectorFrontendAPI.revealSourceLine", |
| 1392 &url_value, | 1325 &url_value, |
| 1393 &line_value, | 1326 &line_value, |
| 1394 &column_value); | 1327 &column_value); |
| 1395 break; | 1328 break; |
| 1396 } | 1329 } |
| 1397 default: | 1330 default: |
| 1398 NOTREACHED(); | 1331 NOTREACHED(); |
| 1399 break; | 1332 break; |
| 1400 } | 1333 } |
| 1401 action_on_load_ = DevToolsToggleAction::Show(); | |
| 1402 } | 1334 } |
| 1403 | 1335 |
| 1404 void DevToolsWindow::UpdateTheme() { | 1336 void DevToolsWindow::UpdateTheme() { |
| 1405 ThemeService* tp = ThemeServiceFactory::GetForProfile(profile_); | 1337 ThemeService* tp = ThemeServiceFactory::GetForProfile(profile_); |
| 1406 DCHECK(tp); | 1338 DCHECK(tp); |
| 1407 | 1339 |
| 1408 std::string command("InspectorFrontendAPI.setToolbarColors(\"" + | 1340 std::string command("InspectorFrontendAPI.setToolbarColors(\"" + |
| 1409 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_TOOLBAR)) + | 1341 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_TOOLBAR)) + |
| 1410 "\", \"" + | 1342 "\", \"" + |
| 1411 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)) + | 1343 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)) + |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1476 web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame( | 1408 web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame( |
| 1477 base::string16(), javascript); | 1409 base::string16(), javascript); |
| 1478 } | 1410 } |
| 1479 | 1411 |
| 1480 void DevToolsWindow::UpdateBrowserToolbar() { | 1412 void DevToolsWindow::UpdateBrowserToolbar() { |
| 1481 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 1413 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 1482 if (inspected_window) | 1414 if (inspected_window) |
| 1483 inspected_window->UpdateToolbar(NULL); | 1415 inspected_window->UpdateToolbar(NULL); |
| 1484 } | 1416 } |
| 1485 | 1417 |
| 1486 bool DevToolsWindow::IsDocked() { | |
| 1487 return dock_side_ != DEVTOOLS_DOCK_SIDE_UNDOCKED; | |
| 1488 } | |
| 1489 | |
| 1490 void DevToolsWindow::Restore() { | |
| 1491 if (dock_side_ == DEVTOOLS_DOCK_SIDE_MINIMIZED) | |
| 1492 SetDockSide(SideToString(dock_side_before_minimized_)); | |
| 1493 } | |
| 1494 | |
| 1495 content::WebContents* DevToolsWindow::GetInspectedWebContents() { | 1418 content::WebContents* DevToolsWindow::GetInspectedWebContents() { |
| 1496 return inspected_contents_observer_ ? | 1419 return inspected_contents_observer_ ? |
| 1497 inspected_contents_observer_->web_contents() : NULL; | 1420 inspected_contents_observer_->web_contents() : NULL; |
| 1498 } | 1421 } |
| 1499 | 1422 |
| 1500 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { | 1423 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { |
| 1501 is_loaded_ = true; | 1424 load_state_mask_ |= kOnLoadFired; |
| 1425 if (load_state_mask_ == kLoadCompleted) | |
| 1426 LoadCompleted(); | |
| 1427 } | |
| 1428 | |
| 1429 void DevToolsWindow::LoadCompleted() { | |
| 1430 Show(action_on_load_); | |
| 1431 action_on_load_ = DevToolsToggleAction::Nothing(); | |
| 1502 UpdateTheme(); | 1432 UpdateTheme(); |
| 1503 DoAction(); | |
| 1504 AddDevToolsExtensionsToClient(); | 1433 AddDevToolsExtensionsToClient(); |
| 1434 if (set_is_docked_for_test_on_load_) { | |
| 1435 set_is_docked_for_test_on_load_ = false; | |
| 1436 base::FundamentalValue docked(is_docked_); | |
| 1437 CallClientFunction("InspectorFrontendAPI.setIsDocked", &docked, NULL, NULL); | |
| 1438 } | |
| 1505 } | 1439 } |
| OLD | NEW |