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 #include "chrome/browser/devtools/devtools_window.h" | 4 #include "chrome/browser/devtools/devtools_window.h" |
| 5 | 5 |
| 6 #include <algorithm> | 6 #include <algorithm> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 | 232 |
| 233 const char kDockSideBottom[] = "bottom"; | 233 const char kDockSideBottom[] = "bottom"; |
| 234 const char kDockSideRight[] = "right"; | 234 const char kDockSideRight[] = "right"; |
| 235 const char kDockSideUndocked[] = "undocked"; | 235 const char kDockSideUndocked[] = "undocked"; |
| 236 const char kDockSideMinimized[] = "minimized"; | 236 const char kDockSideMinimized[] = "minimized"; |
| 237 | 237 |
| 238 static const char kFrontendHostId[] = "id"; | 238 static const char kFrontendHostId[] = "id"; |
| 239 static const char kFrontendHostMethod[] = "method"; | 239 static const char kFrontendHostMethod[] = "method"; |
| 240 static const char kFrontendHostParams[] = "params"; | 240 static const char kFrontendHostParams[] = "params"; |
| 241 | 241 |
| 242 const int kMinContentsSize = 50; | |
| 243 | |
| 244 std::string SkColorToRGBAString(SkColor color) { | 242 std::string SkColorToRGBAString(SkColor color) { |
| 245 // We avoid StringPrintf because it will use locale specific formatters for | 243 // We avoid StringPrintf because it will use locale specific formatters for |
| 246 // the double (e.g. ',' instead of '.' in German). | 244 // the double (e.g. ',' instead of '.' in German). |
| 247 return "rgba(" + base::IntToString(SkColorGetR(color)) + "," + | 245 return "rgba(" + base::IntToString(SkColorGetR(color)) + "," + |
| 248 base::IntToString(SkColorGetG(color)) + "," + | 246 base::IntToString(SkColorGetG(color)) + "," + |
| 249 base::IntToString(SkColorGetB(color)) + "," + | 247 base::IntToString(SkColorGetB(color)) + "," + |
| 250 base::DoubleToString(SkColorGetA(color) / 255.0) + ")"; | 248 base::DoubleToString(SkColorGetA(color) / 255.0) + ")"; |
| 251 } | 249 } |
| 252 | 250 |
| 253 DictionaryValue* CreateFileSystemValue( | 251 DictionaryValue* CreateFileSystemValue( |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 int y) { | 452 int y) { |
| 455 scoped_refptr<DevToolsAgentHost> agent( | 453 scoped_refptr<DevToolsAgentHost> agent( |
| 456 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); | 454 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); |
| 457 agent->InspectElement(x, y); | 455 agent->InspectElement(x, y); |
| 458 // TODO(loislo): we should initiate DevTools window opening from within | 456 // TODO(loislo): we should initiate DevTools window opening from within |
| 459 // renderer. Otherwise, we still can hit a race condition here. | 457 // renderer. Otherwise, we still can hit a race condition here. |
| 460 OpenDevToolsWindow(inspected_rvh); | 458 OpenDevToolsWindow(inspected_rvh); |
| 461 } | 459 } |
| 462 | 460 |
| 463 // static | 461 // static |
| 464 int DevToolsWindow::GetMinimumWidth() { | |
| 465 const int kMinDevToolsWidth = 150; | |
| 466 return kMinDevToolsWidth; | |
| 467 } | |
| 468 | |
| 469 // static | |
| 470 int DevToolsWindow::GetMinimumHeight() { | |
| 471 // Minimal height of devtools pane or content pane when devtools are docked | |
| 472 // to the browser window. | |
| 473 const int kMinDevToolsHeight = 50; | |
| 474 return kMinDevToolsHeight; | |
| 475 } | |
| 476 | |
| 477 // static | |
| 478 int DevToolsWindow::GetMinimizedHeight() { | 462 int DevToolsWindow::GetMinimizedHeight() { |
| 479 const int kMinimizedDevToolsHeight = 24; | 463 const int kMinimizedDevToolsHeight = 24; |
| 480 return kMinimizedDevToolsHeight; | 464 return kMinimizedDevToolsHeight; |
| 481 } | 465 } |
| 482 | 466 |
| 483 void DevToolsWindow::InspectedContentsClosing() { | 467 void DevToolsWindow::InspectedContentsClosing() { |
| 484 web_contents_->GetRenderViewHost()->ClosePage(); | 468 web_contents_->GetRenderViewHost()->ClosePage(); |
| 485 } | 469 } |
| 486 | 470 |
| 487 content::RenderViewHost* DevToolsWindow::GetRenderViewHost() { | 471 content::RenderViewHost* DevToolsWindow::GetRenderViewHost() { |
| 488 return web_contents_->GetRenderViewHost(); | 472 return web_contents_->GetRenderViewHost(); |
| 489 } | 473 } |
| 490 | 474 |
| 491 content::DevToolsClientHost* DevToolsWindow::GetDevToolsClientHostForTest() { | 475 content::DevToolsClientHost* DevToolsWindow::GetDevToolsClientHostForTest() { |
| 492 return frontend_host_.get(); | 476 return frontend_host_.get(); |
| 493 } | 477 } |
| 494 | 478 |
| 495 int DevToolsWindow::GetWidth(int container_width) { | 479 gfx::Size DevToolsWindow::GetTopLeftContentsOffset() const { |
| 496 if (width_ == -1) { | 480 return top_left_contents_offset_; |
| 497 width_ = profile_->GetPrefs()-> | |
| 498 GetInteger(prefs::kDevToolsVSplitLocation); | |
| 499 } | |
| 500 | |
| 501 // By default, size devtools as 1/3 of the browser window. | |
| 502 if (width_ == -1) | |
| 503 width_ = container_width / 3; | |
| 504 | |
| 505 // Respect the minimum devtools width preset. | |
| 506 width_ = std::max(GetMinimumWidth(), width_); | |
| 507 | |
| 508 // But it should never compromise the content window size unless the entire | |
| 509 // window is tiny. | |
| 510 width_ = std::min(container_width - kMinContentsSize, width_); | |
| 511 return width_; | |
| 512 } | 481 } |
| 513 | 482 |
| 514 int DevToolsWindow::GetHeight(int container_height) { | 483 gfx::Size DevToolsWindow::GetBottomRightContentsOffset() const { |
| 515 if (height_ == -1) { | 484 return bottom_right_contents_offset_; |
| 516 height_ = profile_->GetPrefs()-> | |
| 517 GetInteger(prefs::kDevToolsHSplitLocation); | |
| 518 } | |
| 519 | |
| 520 // By default, size devtools as 1/3 of the browser window. | |
| 521 if (height_ == -1) | |
| 522 height_ = container_height / 3; | |
| 523 | |
| 524 // Respect the minimum devtools width preset. | |
| 525 height_ = std::max(GetMinimumHeight(), height_); | |
| 526 | |
| 527 // But it should never compromise the content window size. | |
| 528 height_ = std::min(container_height - kMinContentsSize, height_); | |
| 529 return height_; | |
| 530 } | 485 } |
| 531 | 486 |
| 532 void DevToolsWindow::SetWidth(int width) { | 487 gfx::Size DevToolsWindow::GetMinimumSize() const { |
| 533 width_ = width; | 488 int min_width = 150; |
|
pfeldman
2013/11/18 14:18:27
Extract constants for these.
| |
| 534 profile_->GetPrefs()->SetInteger(prefs::kDevToolsVSplitLocation, width); | 489 int min_height = 50; |
| 535 } | 490 // Add minimum 50x50 size for inspected WebContents. |
| 536 | 491 if (dock_side_ == DEVTOOLS_DOCK_SIDE_BOTTOM) { |
|
pfeldman
2013/11/18 14:18:27
drop {}
| |
| 537 void DevToolsWindow::SetHeight(int height) { | 492 min_height += 50; |
| 538 height_ = height; | 493 } else if (dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT) { |
| 539 profile_->GetPrefs()->SetInteger(prefs::kDevToolsHSplitLocation, height); | 494 min_width += 50; |
| 495 } | |
| 496 return gfx::Size(min_width, min_height); | |
|
pfeldman
2013/11/18 14:18:27
DevTools window should not be aware of dock side a
| |
| 540 } | 497 } |
| 541 | 498 |
| 542 void DevToolsWindow::Show(const DevToolsToggleAction& action) { | 499 void DevToolsWindow::Show(const DevToolsToggleAction& action) { |
| 543 if (IsDocked()) { | 500 if (IsDocked()) { |
| 544 Browser* inspected_browser = NULL; | 501 Browser* inspected_browser = NULL; |
| 545 int inspected_tab_index = -1; | 502 int inspected_tab_index = -1; |
| 546 // Tell inspected browser to update splitter and switch to inspected panel. | 503 // Tell inspected browser to update splitter and switch to inspected panel. |
| 547 if (!IsInspectedBrowserPopup() && | 504 if (!IsInspectedBrowserPopup() && |
| 548 FindInspectedBrowserAndTabIndex(&inspected_browser, | 505 FindInspectedBrowserAndTabIndex(&inspected_browser, |
| 549 &inspected_tab_index)) { | 506 &inspected_tab_index)) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 | 610 |
| 654 DevToolsWindow::DevToolsWindow(Profile* profile, | 611 DevToolsWindow::DevToolsWindow(Profile* profile, |
| 655 const GURL& url, | 612 const GURL& url, |
| 656 content::RenderViewHost* inspected_rvh, | 613 content::RenderViewHost* inspected_rvh, |
| 657 DevToolsDockSide dock_side) | 614 DevToolsDockSide dock_side) |
| 658 : profile_(profile), | 615 : profile_(profile), |
| 659 browser_(NULL), | 616 browser_(NULL), |
| 660 dock_side_(dock_side), | 617 dock_side_(dock_side), |
| 661 is_loaded_(false), | 618 is_loaded_(false), |
| 662 action_on_load_(DevToolsToggleAction::Show()), | 619 action_on_load_(DevToolsToggleAction::Show()), |
| 663 width_(-1), | |
| 664 height_(-1), | |
| 665 dock_side_before_minimized_(dock_side), | 620 dock_side_before_minimized_(dock_side), |
| 666 intercepted_page_beforeunload_(false), | 621 intercepted_page_beforeunload_(false), |
| 667 weak_factory_(this) { | 622 weak_factory_(this) { |
| 668 web_contents_ = | 623 web_contents_ = |
| 669 content::WebContents::Create(content::WebContents::CreateParams(profile)); | 624 content::WebContents::Create(content::WebContents::CreateParams(profile)); |
| 670 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 625 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
| 671 | 626 |
| 672 web_contents_->GetController().LoadURL(url, content::Referrer(), | 627 web_contents_->GetController().LoadURL(url, content::Referrer(), |
| 673 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); | 628 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); |
| 674 | 629 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 738 "&textColor=" + | 693 "&textColor=" + |
| 739 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT))); | 694 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT))); |
| 740 if (shared_worker_frontend) | 695 if (shared_worker_frontend) |
| 741 url_string += "&isSharedWorker=true"; | 696 url_string += "&isSharedWorker=true"; |
| 742 if (external_frontend) | 697 if (external_frontend) |
| 743 url_string += "&remoteFrontend=true"; | 698 url_string += "&remoteFrontend=true"; |
| 744 if (CommandLine::ForCurrentProcess()->HasSwitch( | 699 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 745 switches::kEnableDevToolsExperiments)) | 700 switches::kEnableDevToolsExperiments)) |
| 746 url_string += "&experiments=true"; | 701 url_string += "&experiments=true"; |
| 747 url_string += "&updateAppcache"; | 702 url_string += "&updateAppcache"; |
| 703 url_string += "&overlayContents=true"; | |
| 748 return GURL(url_string); | 704 return GURL(url_string); |
| 749 } | 705 } |
| 750 | 706 |
| 751 // static | 707 // static |
| 752 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( | 708 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( |
| 753 DevToolsAgentHost* agent_host) { | 709 DevToolsAgentHost* agent_host) { |
| 754 DevToolsWindows* instances = &g_instances.Get(); | 710 DevToolsWindows* instances = &g_instances.Get(); |
| 755 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); | 711 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); |
| 756 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); | 712 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); |
| 757 ++it) { | 713 ++it) { |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1003 } else { | 959 } else { |
| 1004 browser_->window()->Activate(); | 960 browser_->window()->Activate(); |
| 1005 } | 961 } |
| 1006 } | 962 } |
| 1007 | 963 |
| 1008 void DevToolsWindow::CloseWindow() { | 964 void DevToolsWindow::CloseWindow() { |
| 1009 DCHECK(IsDocked()); | 965 DCHECK(IsDocked()); |
| 1010 web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); | 966 web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); |
| 1011 } | 967 } |
| 1012 | 968 |
| 1013 void DevToolsWindow::SetWindowBounds(int x, int y, int width, int height) { | 969 void DevToolsWindow::SetContentsOffsets( |
| 1014 if (!IsDocked()) | 970 int left, int top, int right, int bottom) { |
| 1015 browser_->window()->SetBounds(gfx::Rect(x, y, width, height)); | 971 top_left_contents_offset_ = gfx::Size(left, top); |
| 972 bottom_right_contents_offset_ = gfx::Size(right, bottom); | |
| 973 if (IsDocked()) { | |
| 974 // Update inspected window. | |
| 975 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | |
| 976 if (inspected_window) | |
| 977 inspected_window->UpdateDevTools(); | |
| 978 } | |
| 1016 } | 979 } |
| 1017 | 980 |
| 1018 void DevToolsWindow::MoveWindow(int x, int y) { | 981 void DevToolsWindow::MoveWindow(int x, int y) { |
| 1019 if (!IsDocked()) { | 982 if (!IsDocked()) { |
| 1020 gfx::Rect bounds = browser_->window()->GetBounds(); | 983 gfx::Rect bounds = browser_->window()->GetBounds(); |
| 1021 bounds.Offset(x, y); | 984 bounds.Offset(x, y); |
| 1022 browser_->window()->SetBounds(bounds); | 985 browser_->window()->SetBounds(bounds); |
| 1023 } | 986 } |
| 1024 } | 987 } |
| 1025 | 988 |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1501 return inspected_contents_observer_ ? | 1464 return inspected_contents_observer_ ? |
| 1502 inspected_contents_observer_->web_contents() : NULL; | 1465 inspected_contents_observer_->web_contents() : NULL; |
| 1503 } | 1466 } |
| 1504 | 1467 |
| 1505 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { | 1468 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { |
| 1506 is_loaded_ = true; | 1469 is_loaded_ = true; |
| 1507 UpdateTheme(); | 1470 UpdateTheme(); |
| 1508 DoAction(); | 1471 DoAction(); |
| 1509 AddDevToolsExtensionsToClient(); | 1472 AddDevToolsExtensionsToClient(); |
| 1510 } | 1473 } |
| OLD | NEW |