| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 233 |
| 234 const char kDockSideBottom[] = "bottom"; | 234 const char kDockSideBottom[] = "bottom"; |
| 235 const char kDockSideRight[] = "right"; | 235 const char kDockSideRight[] = "right"; |
| 236 const char kDockSideUndocked[] = "undocked"; | 236 const char kDockSideUndocked[] = "undocked"; |
| 237 const char kDockSideMinimized[] = "minimized"; | 237 const char kDockSideMinimized[] = "minimized"; |
| 238 | 238 |
| 239 static const char kFrontendHostId[] = "id"; | 239 static const char kFrontendHostId[] = "id"; |
| 240 static const char kFrontendHostMethod[] = "method"; | 240 static const char kFrontendHostMethod[] = "method"; |
| 241 static const char kFrontendHostParams[] = "params"; | 241 static const char kFrontendHostParams[] = "params"; |
| 242 | 242 |
| 243 const int kMinContentsSize = 50; | |
| 244 | |
| 245 std::string SkColorToRGBAString(SkColor color) { | 243 std::string SkColorToRGBAString(SkColor color) { |
| 246 // We avoid StringPrintf because it will use locale specific formatters for | 244 // We avoid StringPrintf because it will use locale specific formatters for |
| 247 // the double (e.g. ',' instead of '.' in German). | 245 // the double (e.g. ',' instead of '.' in German). |
| 248 return "rgba(" + base::IntToString(SkColorGetR(color)) + "," + | 246 return "rgba(" + base::IntToString(SkColorGetR(color)) + "," + |
| 249 base::IntToString(SkColorGetG(color)) + "," + | 247 base::IntToString(SkColorGetG(color)) + "," + |
| 250 base::IntToString(SkColorGetB(color)) + "," + | 248 base::IntToString(SkColorGetB(color)) + "," + |
| 251 base::DoubleToString(SkColorGetA(color) / 255.0) + ")"; | 249 base::DoubleToString(SkColorGetA(color) / 255.0) + ")"; |
| 252 } | 250 } |
| 253 | 251 |
| 254 DictionaryValue* CreateFileSystemValue( | 252 DictionaryValue* CreateFileSystemValue( |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 int y) { | 453 int y) { |
| 456 scoped_refptr<DevToolsAgentHost> agent( | 454 scoped_refptr<DevToolsAgentHost> agent( |
| 457 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); | 455 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); |
| 458 agent->InspectElement(x, y); | 456 agent->InspectElement(x, y); |
| 459 // TODO(loislo): we should initiate DevTools window opening from within | 457 // TODO(loislo): we should initiate DevTools window opening from within |
| 460 // renderer. Otherwise, we still can hit a race condition here. | 458 // renderer. Otherwise, we still can hit a race condition here. |
| 461 OpenDevToolsWindow(inspected_rvh); | 459 OpenDevToolsWindow(inspected_rvh); |
| 462 } | 460 } |
| 463 | 461 |
| 464 // static | 462 // static |
| 465 int DevToolsWindow::GetMinimumWidth() { | |
| 466 const int kMinDevToolsWidth = 150; | |
| 467 return kMinDevToolsWidth; | |
| 468 } | |
| 469 | |
| 470 // static | |
| 471 int DevToolsWindow::GetMinimumHeight() { | |
| 472 // Minimal height of devtools pane or content pane when devtools are docked | |
| 473 // to the browser window. | |
| 474 const int kMinDevToolsHeight = 50; | |
| 475 return kMinDevToolsHeight; | |
| 476 } | |
| 477 | |
| 478 // static | |
| 479 int DevToolsWindow::GetMinimizedHeight() { | 463 int DevToolsWindow::GetMinimizedHeight() { |
| 480 const int kMinimizedDevToolsHeight = 24; | 464 const int kMinimizedDevToolsHeight = 24; |
| 481 return kMinimizedDevToolsHeight; | 465 return kMinimizedDevToolsHeight; |
| 482 } | 466 } |
| 483 | 467 |
| 484 void DevToolsWindow::InspectedContentsClosing() { | 468 void DevToolsWindow::InspectedContentsClosing() { |
| 485 intercepted_page_beforeunload_ = false; | 469 intercepted_page_beforeunload_ = false; |
| 486 web_contents_->GetRenderViewHost()->ClosePage(); | 470 web_contents_->GetRenderViewHost()->ClosePage(); |
| 487 } | 471 } |
| 488 | 472 |
| 489 content::RenderViewHost* DevToolsWindow::GetRenderViewHost() { | 473 content::RenderViewHost* DevToolsWindow::GetRenderViewHost() { |
| 490 return web_contents_->GetRenderViewHost(); | 474 return web_contents_->GetRenderViewHost(); |
| 491 } | 475 } |
| 492 | 476 |
| 493 content::DevToolsClientHost* DevToolsWindow::GetDevToolsClientHostForTest() { | 477 content::DevToolsClientHost* DevToolsWindow::GetDevToolsClientHostForTest() { |
| 494 return frontend_host_.get(); | 478 return frontend_host_.get(); |
| 495 } | 479 } |
| 496 | 480 |
| 497 int DevToolsWindow::GetWidth(int container_width) { | 481 gfx::Insets DevToolsWindow::GetContentsInsets() const { |
| 498 if (width_ == -1) { | 482 return contents_insets_; |
| 499 width_ = profile_->GetPrefs()-> | |
| 500 GetInteger(prefs::kDevToolsVSplitLocation); | |
| 501 } | |
| 502 | |
| 503 // By default, size devtools as 1/3 of the browser window. | |
| 504 if (width_ == -1) | |
| 505 width_ = container_width / 3; | |
| 506 | |
| 507 // Respect the minimum devtools width preset. | |
| 508 width_ = std::max(GetMinimumWidth(), width_); | |
| 509 | |
| 510 // But it should never compromise the content window size unless the entire | |
| 511 // window is tiny. | |
| 512 width_ = std::min(container_width - kMinContentsSize, width_); | |
| 513 return width_; | |
| 514 } | 483 } |
| 515 | 484 |
| 516 int DevToolsWindow::GetHeight(int container_height) { | 485 gfx::Size DevToolsWindow::GetMinimumSize() const { |
| 517 if (height_ == -1) { | 486 const gfx::Size kMinDevToolsSize = gfx::Size(200, 100); |
| 518 height_ = profile_->GetPrefs()-> | 487 return kMinDevToolsSize; |
| 519 GetInteger(prefs::kDevToolsHSplitLocation); | |
| 520 } | |
| 521 | |
| 522 // By default, size devtools as 1/3 of the browser window. | |
| 523 if (height_ == -1) | |
| 524 height_ = container_height / 3; | |
| 525 | |
| 526 // Respect the minimum devtools width preset. | |
| 527 height_ = std::max(GetMinimumHeight(), height_); | |
| 528 | |
| 529 // But it should never compromise the content window size. | |
| 530 height_ = std::min(container_height - kMinContentsSize, height_); | |
| 531 return height_; | |
| 532 } | |
| 533 | |
| 534 void DevToolsWindow::SetWidth(int width) { | |
| 535 width_ = width; | |
| 536 profile_->GetPrefs()->SetInteger(prefs::kDevToolsVSplitLocation, width); | |
| 537 } | |
| 538 | |
| 539 void DevToolsWindow::SetHeight(int height) { | |
| 540 height_ = height; | |
| 541 profile_->GetPrefs()->SetInteger(prefs::kDevToolsHSplitLocation, height); | |
| 542 } | 488 } |
| 543 | 489 |
| 544 void DevToolsWindow::Show(const DevToolsToggleAction& action) { | 490 void DevToolsWindow::Show(const DevToolsToggleAction& action) { |
| 545 if (IsDocked()) { | 491 if (IsDocked()) { |
| 546 Browser* inspected_browser = NULL; | 492 Browser* inspected_browser = NULL; |
| 547 int inspected_tab_index = -1; | 493 int inspected_tab_index = -1; |
| 548 // Tell inspected browser to update splitter and switch to inspected panel. | 494 // Tell inspected browser to update splitter and switch to inspected panel. |
| 549 if (!IsInspectedBrowserPopup() && | 495 if (!IsInspectedBrowserPopup() && |
| 550 FindInspectedBrowserAndTabIndex(&inspected_browser, | 496 FindInspectedBrowserAndTabIndex(&inspected_browser, |
| 551 &inspected_tab_index)) { | 497 &inspected_tab_index)) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 | 603 |
| 658 DevToolsWindow::DevToolsWindow(Profile* profile, | 604 DevToolsWindow::DevToolsWindow(Profile* profile, |
| 659 const GURL& url, | 605 const GURL& url, |
| 660 content::RenderViewHost* inspected_rvh, | 606 content::RenderViewHost* inspected_rvh, |
| 661 DevToolsDockSide dock_side) | 607 DevToolsDockSide dock_side) |
| 662 : profile_(profile), | 608 : profile_(profile), |
| 663 browser_(NULL), | 609 browser_(NULL), |
| 664 dock_side_(dock_side), | 610 dock_side_(dock_side), |
| 665 is_loaded_(false), | 611 is_loaded_(false), |
| 666 action_on_load_(DevToolsToggleAction::Show()), | 612 action_on_load_(DevToolsToggleAction::Show()), |
| 667 width_(-1), | |
| 668 height_(-1), | |
| 669 dock_side_before_minimized_(dock_side), | 613 dock_side_before_minimized_(dock_side), |
| 670 intercepted_page_beforeunload_(false), | 614 intercepted_page_beforeunload_(false), |
| 671 weak_factory_(this) { | 615 weak_factory_(this) { |
| 672 web_contents_ = | 616 web_contents_ = |
| 673 content::WebContents::Create(content::WebContents::CreateParams(profile)); | 617 content::WebContents::Create(content::WebContents::CreateParams(profile)); |
| 674 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 618 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
| 675 | 619 |
| 676 web_contents_->GetController().LoadURL(url, content::Referrer(), | 620 web_contents_->GetController().LoadURL(url, content::Referrer(), |
| 677 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 621 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
| 678 | 622 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 "&textColor=" + | 686 "&textColor=" + |
| 743 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT))); | 687 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT))); |
| 744 if (shared_worker_frontend) | 688 if (shared_worker_frontend) |
| 745 url_string += "&isSharedWorker=true"; | 689 url_string += "&isSharedWorker=true"; |
| 746 if (external_frontend) | 690 if (external_frontend) |
| 747 url_string += "&remoteFrontend=true"; | 691 url_string += "&remoteFrontend=true"; |
| 748 if (CommandLine::ForCurrentProcess()->HasSwitch( | 692 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 749 switches::kEnableDevToolsExperiments)) | 693 switches::kEnableDevToolsExperiments)) |
| 750 url_string += "&experiments=true"; | 694 url_string += "&experiments=true"; |
| 751 url_string += "&updateAppcache"; | 695 url_string += "&updateAppcache"; |
| 696 url_string += "&overlayContents=true"; |
| 752 return GURL(url_string); | 697 return GURL(url_string); |
| 753 } | 698 } |
| 754 | 699 |
| 755 // static | 700 // static |
| 756 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( | 701 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( |
| 757 DevToolsAgentHost* agent_host) { | 702 DevToolsAgentHost* agent_host) { |
| 758 DevToolsWindows* instances = &g_instances.Get(); | 703 DevToolsWindows* instances = &g_instances.Get(); |
| 759 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); | 704 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); |
| 760 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); | 705 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); |
| 761 ++it) { | 706 ++it) { |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 } else { | 953 } else { |
| 1009 browser_->window()->Activate(); | 954 browser_->window()->Activate(); |
| 1010 } | 955 } |
| 1011 } | 956 } |
| 1012 | 957 |
| 1013 void DevToolsWindow::CloseWindow() { | 958 void DevToolsWindow::CloseWindow() { |
| 1014 DCHECK(IsDocked()); | 959 DCHECK(IsDocked()); |
| 1015 web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); | 960 web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); |
| 1016 } | 961 } |
| 1017 | 962 |
| 1018 void DevToolsWindow::SetWindowBounds(int x, int y, int width, int height) { | 963 void DevToolsWindow::SetContentsInsets( |
| 1019 if (!IsDocked()) | 964 int top, int left, int bottom, int right) { |
| 1020 browser_->window()->SetBounds(gfx::Rect(x, y, width, height)); | 965 if (contents_insets_.top() == top && |
| 966 contents_insets_.left() == left && |
| 967 contents_insets_.bottom() == bottom && |
| 968 contents_insets_.right() == right) { |
| 969 return; |
| 970 } |
| 971 |
| 972 contents_insets_ = gfx::Insets(top, left, bottom, right); |
| 973 if (IsDocked()) { |
| 974 // Update inspected window. |
| 975 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 976 if (inspected_window) |
| 977 inspected_window->UpdateDevTools(); |
| 978 } |
| 1021 } | 979 } |
| 1022 | 980 |
| 1023 void DevToolsWindow::MoveWindow(int x, int y) { | 981 void DevToolsWindow::MoveWindow(int x, int y) { |
| 1024 if (!IsDocked()) { | 982 if (!IsDocked()) { |
| 1025 gfx::Rect bounds = browser_->window()->GetBounds(); | 983 gfx::Rect bounds = browser_->window()->GetBounds(); |
| 1026 bounds.Offset(x, y); | 984 bounds.Offset(x, y); |
| 1027 browser_->window()->SetBounds(bounds); | 985 browser_->window()->SetBounds(bounds); |
| 1028 } | 986 } |
| 1029 } | 987 } |
| 1030 | 988 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1513 return inspected_contents_observer_ ? | 1471 return inspected_contents_observer_ ? |
| 1514 inspected_contents_observer_->web_contents() : NULL; | 1472 inspected_contents_observer_->web_contents() : NULL; |
| 1515 } | 1473 } |
| 1516 | 1474 |
| 1517 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { | 1475 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { |
| 1518 is_loaded_ = true; | 1476 is_loaded_ = true; |
| 1519 UpdateTheme(); | 1477 UpdateTheme(); |
| 1520 DoAction(); | 1478 DoAction(); |
| 1521 AddDevToolsExtensionsToClient(); | 1479 AddDevToolsExtensionsToClient(); |
| 1522 } | 1480 } |
| OLD | NEW |