Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/browser/devtools/devtools_window.cc

Issue 63173016: DevTools: place DevTools WebContents underneath inspected WebContents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/devtools/devtools_window.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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::Size DevToolsWindow::GetTopLeftContentsOffset() const {
498 if (width_ == -1) { 482 return top_left_contents_offset_;
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::GetBottomRightContentsOffset() const {
517 if (height_ == -1) { 486 return bottom_right_contents_offset_;
518 height_ = profile_->GetPrefs()->
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 } 487 }
533 488
534 void DevToolsWindow::SetWidth(int width) { 489 gfx::Size DevToolsWindow::GetMinimumSize() const {
535 width_ = width; 490 const gfx::Size kMinDevToolsSize = gfx::Size(200, 100);
536 profile_->GetPrefs()->SetInteger(prefs::kDevToolsVSplitLocation, width); 491 return kMinDevToolsSize;
537 }
538
539 void DevToolsWindow::SetHeight(int height) {
540 height_ = height;
541 profile_->GetPrefs()->SetInteger(prefs::kDevToolsHSplitLocation, height);
542 } 492 }
543 493
544 void DevToolsWindow::Show(const DevToolsToggleAction& action) { 494 void DevToolsWindow::Show(const DevToolsToggleAction& action) {
545 if (IsDocked()) { 495 if (IsDocked()) {
546 Browser* inspected_browser = NULL; 496 Browser* inspected_browser = NULL;
547 int inspected_tab_index = -1; 497 int inspected_tab_index = -1;
548 // Tell inspected browser to update splitter and switch to inspected panel. 498 // Tell inspected browser to update splitter and switch to inspected panel.
549 if (!IsInspectedBrowserPopup() && 499 if (!IsInspectedBrowserPopup() &&
550 FindInspectedBrowserAndTabIndex(&inspected_browser, 500 FindInspectedBrowserAndTabIndex(&inspected_browser,
551 &inspected_tab_index)) { 501 &inspected_tab_index)) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 607
658 DevToolsWindow::DevToolsWindow(Profile* profile, 608 DevToolsWindow::DevToolsWindow(Profile* profile,
659 const GURL& url, 609 const GURL& url,
660 content::RenderViewHost* inspected_rvh, 610 content::RenderViewHost* inspected_rvh,
661 DevToolsDockSide dock_side) 611 DevToolsDockSide dock_side)
662 : profile_(profile), 612 : profile_(profile),
663 browser_(NULL), 613 browser_(NULL),
664 dock_side_(dock_side), 614 dock_side_(dock_side),
665 is_loaded_(false), 615 is_loaded_(false),
666 action_on_load_(DevToolsToggleAction::Show()), 616 action_on_load_(DevToolsToggleAction::Show()),
667 width_(-1),
668 height_(-1),
669 dock_side_before_minimized_(dock_side), 617 dock_side_before_minimized_(dock_side),
670 intercepted_page_beforeunload_(false), 618 intercepted_page_beforeunload_(false),
671 weak_factory_(this) { 619 weak_factory_(this) {
672 web_contents_ = 620 web_contents_ =
673 content::WebContents::Create(content::WebContents::CreateParams(profile)); 621 content::WebContents::Create(content::WebContents::CreateParams(profile));
674 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); 622 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this));
675 623
676 web_contents_->GetController().LoadURL(url, content::Referrer(), 624 web_contents_->GetController().LoadURL(url, content::Referrer(),
677 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); 625 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
678 626
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 "&textColor=" + 690 "&textColor=" +
743 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT))); 691 SkColorToRGBAString(tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)));
744 if (shared_worker_frontend) 692 if (shared_worker_frontend)
745 url_string += "&isSharedWorker=true"; 693 url_string += "&isSharedWorker=true";
746 if (external_frontend) 694 if (external_frontend)
747 url_string += "&remoteFrontend=true"; 695 url_string += "&remoteFrontend=true";
748 if (CommandLine::ForCurrentProcess()->HasSwitch( 696 if (CommandLine::ForCurrentProcess()->HasSwitch(
749 switches::kEnableDevToolsExperiments)) 697 switches::kEnableDevToolsExperiments))
750 url_string += "&experiments=true"; 698 url_string += "&experiments=true";
751 url_string += "&updateAppcache"; 699 url_string += "&updateAppcache";
700 #if defined(OS_MACOSX) || defined(USE_AURA)
pfeldman 2013/12/05 15:54:07 You probably want this everywhere or nowhere.
701 url_string += "&overlayContents=true";
702 #endif
752 return GURL(url_string); 703 return GURL(url_string);
753 } 704 }
754 705
755 // static 706 // static
756 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( 707 DevToolsWindow* DevToolsWindow::FindDevToolsWindow(
757 DevToolsAgentHost* agent_host) { 708 DevToolsAgentHost* agent_host) {
758 DevToolsWindows* instances = &g_instances.Get(); 709 DevToolsWindows* instances = &g_instances.Get();
759 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); 710 content::DevToolsManager* manager = content::DevToolsManager::GetInstance();
760 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); 711 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end();
761 ++it) { 712 ++it) {
(...skipping 13 matching lines...) Expand all
775 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); 726 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end();
776 ++it) { 727 ++it) {
777 if ((*it)->web_contents_->GetRenderViewHost() == window_rvh) 728 if ((*it)->web_contents_->GetRenderViewHost() == window_rvh)
778 return *it; 729 return *it;
779 } 730 }
780 return NULL; 731 return NULL;
781 } 732 }
782 733
783 // static 734 // static
784 DevToolsDockSide DevToolsWindow::GetDockSideFromPrefs(Profile* profile) { 735 DevToolsDockSide DevToolsWindow::GetDockSideFromPrefs(Profile* profile) {
736 #if !defined(OS_MACOSX) && !defined(USE_AURA)
pfeldman 2013/12/05 15:54:07 ditto
737 return DEVTOOLS_DOCK_SIDE_UNDOCKED;
738 #endif
739
785 std::string dock_side = 740 std::string dock_side =
786 profile->GetPrefs()->GetString(prefs::kDevToolsDockSide); 741 profile->GetPrefs()->GetString(prefs::kDevToolsDockSide);
787 742
788 // Migrate prefs. 743 // Migrate prefs.
789 const char kOldPrefBottom[] = "bottom"; 744 const char kOldPrefBottom[] = "bottom";
790 const char kOldPrefRight[] = "right"; 745 const char kOldPrefRight[] = "right";
791 if ((dock_side == kOldPrefBottom) || (dock_side == kOldPrefRight)) { 746 if ((dock_side == kOldPrefBottom) || (dock_side == kOldPrefRight)) {
792 if (!profile->GetPrefs()->GetBoolean(prefs::kDevToolsOpenDocked)) 747 if (!profile->GetPrefs()->GetBoolean(prefs::kDevToolsOpenDocked))
793 return DEVTOOLS_DOCK_SIDE_UNDOCKED; 748 return DEVTOOLS_DOCK_SIDE_UNDOCKED;
794 return (dock_side == kOldPrefBottom) ? 749 return (dock_side == kOldPrefBottom) ?
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 } else { 963 } else {
1009 browser_->window()->Activate(); 964 browser_->window()->Activate();
1010 } 965 }
1011 } 966 }
1012 967
1013 void DevToolsWindow::CloseWindow() { 968 void DevToolsWindow::CloseWindow() {
1014 DCHECK(IsDocked()); 969 DCHECK(IsDocked());
1015 web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); 970 web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false);
1016 } 971 }
1017 972
1018 void DevToolsWindow::SetWindowBounds(int x, int y, int width, int height) { 973 void DevToolsWindow::SetContentsOffsets(
1019 if (!IsDocked()) 974 int left, int top, int right, int bottom) {
1020 browser_->window()->SetBounds(gfx::Rect(x, y, width, height)); 975 if (top_left_contents_offset_.width() == left &&
976 top_left_contents_offset_.height() == top &&
977 bottom_right_contents_offset_.width() == right &&
978 bottom_right_contents_offset_.height() == bottom) {
979 return;
980 }
981
982 top_left_contents_offset_ = gfx::Size(left, top);
983 bottom_right_contents_offset_ = gfx::Size(right, bottom);
984 if (IsDocked()) {
985 // Update inspected window.
986 BrowserWindow* inspected_window = GetInspectedBrowserWindow();
987 if (inspected_window)
988 inspected_window->UpdateDevTools();
989 }
1021 } 990 }
1022 991
1023 void DevToolsWindow::MoveWindow(int x, int y) { 992 void DevToolsWindow::MoveWindow(int x, int y) {
1024 if (!IsDocked()) { 993 if (!IsDocked()) {
1025 gfx::Rect bounds = browser_->window()->GetBounds(); 994 gfx::Rect bounds = browser_->window()->GetBounds();
1026 bounds.Offset(x, y); 995 bounds.Offset(x, y);
1027 browser_->window()->SetBounds(bounds); 996 browser_->window()->SetBounds(bounds);
1028 } 997 }
1029 } 998 }
1030 999
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 base::string16(), javascript); 1463 base::string16(), javascript);
1495 } 1464 }
1496 1465
1497 void DevToolsWindow::UpdateBrowserToolbar() { 1466 void DevToolsWindow::UpdateBrowserToolbar() {
1498 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); 1467 BrowserWindow* inspected_window = GetInspectedBrowserWindow();
1499 if (inspected_window) 1468 if (inspected_window)
1500 inspected_window->UpdateToolbar(NULL); 1469 inspected_window->UpdateToolbar(NULL);
1501 } 1470 }
1502 1471
1503 bool DevToolsWindow::IsDocked() { 1472 bool DevToolsWindow::IsDocked() {
1473 #if !defined(OS_MACOSX) && !defined(USE_AURA)
pfeldman 2013/12/05 15:54:07 ditto
1474 return false;
1475 #endif
1504 return dock_side_ != DEVTOOLS_DOCK_SIDE_UNDOCKED; 1476 return dock_side_ != DEVTOOLS_DOCK_SIDE_UNDOCKED;
1505 } 1477 }
1506 1478
1507 void DevToolsWindow::Restore() { 1479 void DevToolsWindow::Restore() {
1508 if (dock_side_ == DEVTOOLS_DOCK_SIDE_MINIMIZED) 1480 if (dock_side_ == DEVTOOLS_DOCK_SIDE_MINIMIZED)
1509 SetDockSide(SideToString(dock_side_before_minimized_)); 1481 SetDockSide(SideToString(dock_side_before_minimized_));
1510 } 1482 }
1511 1483
1512 content::WebContents* DevToolsWindow::GetInspectedWebContents() { 1484 content::WebContents* DevToolsWindow::GetInspectedWebContents() {
1513 return inspected_contents_observer_ ? 1485 return inspected_contents_observer_ ?
1514 inspected_contents_observer_->web_contents() : NULL; 1486 inspected_contents_observer_->web_contents() : NULL;
1515 } 1487 }
1516 1488
1517 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { 1489 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() {
1518 is_loaded_ = true; 1490 is_loaded_ = true;
1519 UpdateTheme(); 1491 UpdateTheme();
1520 DoAction(); 1492 DoAction();
1521 AddDevToolsExtensionsToClient(); 1493 AddDevToolsExtensionsToClient();
1522 } 1494 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_window.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698