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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 | 234 |
235 const char kDockSideBottom[] = "bottom"; | 235 const char kDockSideBottom[] = "bottom"; |
236 const char kDockSideRight[] = "right"; | 236 const char kDockSideRight[] = "right"; |
237 const char kDockSideUndocked[] = "undocked"; | 237 const char kDockSideUndocked[] = "undocked"; |
238 const char kDockSideMinimized[] = "minimized"; | 238 const char kDockSideMinimized[] = "minimized"; |
239 | 239 |
240 static const char kFrontendHostId[] = "id"; | 240 static const char kFrontendHostId[] = "id"; |
241 static const char kFrontendHostMethod[] = "method"; | 241 static const char kFrontendHostMethod[] = "method"; |
242 static const char kFrontendHostParams[] = "params"; | 242 static const char kFrontendHostParams[] = "params"; |
243 | 243 |
244 const int kMinContentsSize = 50; | |
245 | |
246 std::string SkColorToRGBAString(SkColor color) { | 244 std::string SkColorToRGBAString(SkColor color) { |
247 // We avoid StringPrintf because it will use locale specific formatters for | 245 // We avoid StringPrintf because it will use locale specific formatters for |
248 // the double (e.g. ',' instead of '.' in German). | 246 // the double (e.g. ',' instead of '.' in German). |
249 return "rgba(" + base::IntToString(SkColorGetR(color)) + "," + | 247 return "rgba(" + base::IntToString(SkColorGetR(color)) + "," + |
250 base::IntToString(SkColorGetG(color)) + "," + | 248 base::IntToString(SkColorGetG(color)) + "," + |
251 base::IntToString(SkColorGetB(color)) + "," + | 249 base::IntToString(SkColorGetB(color)) + "," + |
252 base::DoubleToString(SkColorGetA(color) / 255.0) + ")"; | 250 base::DoubleToString(SkColorGetA(color) / 255.0) + ")"; |
253 } | 251 } |
254 | 252 |
255 DictionaryValue* CreateFileSystemValue( | 253 DictionaryValue* CreateFileSystemValue( |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 int y) { | 455 int y) { |
458 scoped_refptr<DevToolsAgentHost> agent( | 456 scoped_refptr<DevToolsAgentHost> agent( |
459 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); | 457 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); |
460 agent->InspectElement(x, y); | 458 agent->InspectElement(x, y); |
461 // TODO(loislo): we should initiate DevTools window opening from within | 459 // TODO(loislo): we should initiate DevTools window opening from within |
462 // renderer. Otherwise, we still can hit a race condition here. | 460 // renderer. Otherwise, we still can hit a race condition here. |
463 OpenDevToolsWindow(inspected_rvh); | 461 OpenDevToolsWindow(inspected_rvh); |
464 } | 462 } |
465 | 463 |
466 // static | 464 // static |
467 int DevToolsWindow::GetMinimumWidth() { | |
468 const int kMinDevToolsWidth = 150; | |
469 return kMinDevToolsWidth; | |
470 } | |
471 | |
472 // static | |
473 int DevToolsWindow::GetMinimumHeight() { | |
474 // Minimal height of devtools pane or content pane when devtools are docked | |
475 // to the browser window. | |
476 const int kMinDevToolsHeight = 50; | |
477 return kMinDevToolsHeight; | |
478 } | |
479 | |
480 // static | |
481 int DevToolsWindow::GetMinimizedHeight() { | 465 int DevToolsWindow::GetMinimizedHeight() { |
482 const int kMinimizedDevToolsHeight = 24; | 466 const int kMinimizedDevToolsHeight = 24; |
483 return kMinimizedDevToolsHeight; | 467 return kMinimizedDevToolsHeight; |
484 } | 468 } |
485 | 469 |
486 void DevToolsWindow::InspectedContentsClosing() { | 470 void DevToolsWindow::InspectedContentsClosing() { |
487 intercepted_page_beforeunload_ = false; | 471 intercepted_page_beforeunload_ = false; |
488 web_contents_->GetRenderViewHost()->ClosePage(); | 472 web_contents_->GetRenderViewHost()->ClosePage(); |
489 } | 473 } |
490 | 474 |
491 content::RenderViewHost* DevToolsWindow::GetRenderViewHost() { | 475 content::RenderViewHost* DevToolsWindow::GetRenderViewHost() { |
492 return web_contents_->GetRenderViewHost(); | 476 return web_contents_->GetRenderViewHost(); |
493 } | 477 } |
494 | 478 |
495 content::DevToolsClientHost* DevToolsWindow::GetDevToolsClientHostForTest() { | 479 content::DevToolsClientHost* DevToolsWindow::GetDevToolsClientHostForTest() { |
496 return frontend_host_.get(); | 480 return frontend_host_.get(); |
497 } | 481 } |
498 | 482 |
499 int DevToolsWindow::GetWidth(int container_width) { | 483 gfx::Insets DevToolsWindow::GetContentsInsets() const { |
500 if (width_ == -1) { | 484 return contents_insets_; |
501 width_ = profile_->GetPrefs()-> | |
502 GetInteger(prefs::kDevToolsVSplitLocation); | |
503 } | |
504 | |
505 // By default, size devtools as 1/3 of the browser window. | |
506 if (width_ == -1) | |
507 width_ = container_width / 3; | |
508 | |
509 // Respect the minimum devtools width preset. | |
510 width_ = std::max(GetMinimumWidth(), width_); | |
511 | |
512 // But it should never compromise the content window size unless the entire | |
513 // window is tiny. | |
514 width_ = std::min(container_width - kMinContentsSize, width_); | |
515 return width_; | |
516 } | 485 } |
517 | 486 |
518 int DevToolsWindow::GetHeight(int container_height) { | 487 gfx::Size DevToolsWindow::GetMinimumSize() const { |
519 if (height_ == -1) { | 488 const gfx::Size kMinDevToolsSize = gfx::Size(200, 100); |
520 height_ = profile_->GetPrefs()-> | 489 return kMinDevToolsSize; |
521 GetInteger(prefs::kDevToolsHSplitLocation); | |
522 } | |
523 | |
524 // By default, size devtools as 1/3 of the browser window. | |
525 if (height_ == -1) | |
526 height_ = container_height / 3; | |
527 | |
528 // Respect the minimum devtools width preset. | |
529 height_ = std::max(GetMinimumHeight(), height_); | |
530 | |
531 // But it should never compromise the content window size. | |
532 height_ = std::min(container_height - kMinContentsSize, height_); | |
533 return height_; | |
534 } | |
535 | |
536 void DevToolsWindow::SetWidth(int width) { | |
537 width_ = width; | |
538 profile_->GetPrefs()->SetInteger(prefs::kDevToolsVSplitLocation, width); | |
539 } | |
540 | |
541 void DevToolsWindow::SetHeight(int height) { | |
542 height_ = height; | |
543 profile_->GetPrefs()->SetInteger(prefs::kDevToolsHSplitLocation, height); | |
544 } | 490 } |
545 | 491 |
546 void DevToolsWindow::Show(const DevToolsToggleAction& action) { | 492 void DevToolsWindow::Show(const DevToolsToggleAction& action) { |
547 if (IsDocked()) { | 493 if (IsDocked()) { |
548 Browser* inspected_browser = NULL; | 494 Browser* inspected_browser = NULL; |
549 int inspected_tab_index = -1; | 495 int inspected_tab_index = -1; |
550 // Tell inspected browser to update splitter and switch to inspected panel. | 496 // Tell inspected browser to update splitter and switch to inspected panel. |
551 if (!IsInspectedBrowserPopup() && | 497 if (!IsInspectedBrowserPopup() && |
552 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), | 498 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), |
553 &inspected_browser, | 499 &inspected_browser, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 | 606 |
661 DevToolsWindow::DevToolsWindow(Profile* profile, | 607 DevToolsWindow::DevToolsWindow(Profile* profile, |
662 const GURL& url, | 608 const GURL& url, |
663 content::RenderViewHost* inspected_rvh, | 609 content::RenderViewHost* inspected_rvh, |
664 DevToolsDockSide dock_side) | 610 DevToolsDockSide dock_side) |
665 : profile_(profile), | 611 : profile_(profile), |
666 browser_(NULL), | 612 browser_(NULL), |
667 dock_side_(dock_side), | 613 dock_side_(dock_side), |
668 is_loaded_(false), | 614 is_loaded_(false), |
669 action_on_load_(DevToolsToggleAction::Show()), | 615 action_on_load_(DevToolsToggleAction::Show()), |
670 width_(-1), | |
671 height_(-1), | |
672 dock_side_before_minimized_(dock_side), | 616 dock_side_before_minimized_(dock_side), |
673 intercepted_page_beforeunload_(false), | 617 intercepted_page_beforeunload_(false), |
674 weak_factory_(this) { | 618 weak_factory_(this) { |
675 web_contents_ = | 619 web_contents_ = |
676 content::WebContents::Create(content::WebContents::CreateParams(profile)); | 620 content::WebContents::Create(content::WebContents::CreateParams(profile)); |
677 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 621 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
678 | 622 |
679 web_contents_->GetController().LoadURL(url, content::Referrer(), | 623 web_contents_->GetController().LoadURL(url, content::Referrer(), |
680 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 624 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
681 | 625 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 if (shared_worker_frontend) | 707 if (shared_worker_frontend) |
764 url_string += "&isSharedWorker=true"; | 708 url_string += "&isSharedWorker=true"; |
765 if (external_frontend) | 709 if (external_frontend) |
766 url_string += "&remoteFrontend=true"; | 710 url_string += "&remoteFrontend=true"; |
767 if (can_dock) | 711 if (can_dock) |
768 url_string += "&can_dock=true"; | 712 url_string += "&can_dock=true"; |
769 if (CommandLine::ForCurrentProcess()->HasSwitch( | 713 if (CommandLine::ForCurrentProcess()->HasSwitch( |
770 switches::kEnableDevToolsExperiments)) | 714 switches::kEnableDevToolsExperiments)) |
771 url_string += "&experiments=true"; | 715 url_string += "&experiments=true"; |
772 url_string += "&updateAppcache"; | 716 url_string += "&updateAppcache"; |
| 717 url_string += "&overlayContents=true"; |
773 return GURL(url_string); | 718 return GURL(url_string); |
774 } | 719 } |
775 | 720 |
776 // static | 721 // static |
777 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( | 722 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( |
778 DevToolsAgentHost* agent_host) { | 723 DevToolsAgentHost* agent_host) { |
779 DevToolsWindows* instances = &g_instances.Get(); | 724 DevToolsWindows* instances = &g_instances.Get(); |
780 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); | 725 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); |
781 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); | 726 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); |
782 ++it) { | 727 ++it) { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 } else { | 975 } else { |
1031 browser_->window()->Activate(); | 976 browser_->window()->Activate(); |
1032 } | 977 } |
1033 } | 978 } |
1034 | 979 |
1035 void DevToolsWindow::CloseWindow() { | 980 void DevToolsWindow::CloseWindow() { |
1036 DCHECK(IsDocked()); | 981 DCHECK(IsDocked()); |
1037 web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); | 982 web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); |
1038 } | 983 } |
1039 | 984 |
1040 void DevToolsWindow::SetWindowBounds(int x, int y, int width, int height) { | 985 void DevToolsWindow::SetContentsInsets( |
1041 if (!IsDocked()) | 986 int top, int left, int bottom, int right) { |
1042 browser_->window()->SetBounds(gfx::Rect(x, y, width, height)); | 987 if (contents_insets_.top() == top && |
| 988 contents_insets_.left() == left && |
| 989 contents_insets_.bottom() == bottom && |
| 990 contents_insets_.right() == right) { |
| 991 return; |
| 992 } |
| 993 |
| 994 contents_insets_ = gfx::Insets(top, left, bottom, right); |
| 995 if (IsDocked()) { |
| 996 // Update inspected window. |
| 997 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 998 if (inspected_window) |
| 999 inspected_window->UpdateDevTools(); |
| 1000 } |
1043 } | 1001 } |
1044 | 1002 |
1045 void DevToolsWindow::MoveWindow(int x, int y) { | 1003 void DevToolsWindow::MoveWindow(int x, int y) { |
1046 if (!IsDocked()) { | 1004 if (!IsDocked()) { |
1047 gfx::Rect bounds = browser_->window()->GetBounds(); | 1005 gfx::Rect bounds = browser_->window()->GetBounds(); |
1048 bounds.Offset(x, y); | 1006 bounds.Offset(x, y); |
1049 browser_->window()->SetBounds(bounds); | 1007 browser_->window()->SetBounds(bounds); |
1050 } | 1008 } |
1051 } | 1009 } |
1052 | 1010 |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 return inspected_contents_observer_ ? | 1495 return inspected_contents_observer_ ? |
1538 inspected_contents_observer_->web_contents() : NULL; | 1496 inspected_contents_observer_->web_contents() : NULL; |
1539 } | 1497 } |
1540 | 1498 |
1541 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { | 1499 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { |
1542 is_loaded_ = true; | 1500 is_loaded_ = true; |
1543 UpdateTheme(); | 1501 UpdateTheme(); |
1544 DoAction(); | 1502 DoAction(); |
1545 AddDevToolsExtensionsToClient(); | 1503 AddDevToolsExtensionsToClient(); |
1546 } | 1504 } |
OLD | NEW |