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