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

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

Issue 294903014: [DevTools] Add toolbox web contents to show in undocked mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mac fixes Created 6 years, 6 months 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 | Annotate | Revision Log
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/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 }; 197 };
198 198
199 DevToolsWindow::InspectedWebContentsObserver::InspectedWebContentsObserver( 199 DevToolsWindow::InspectedWebContentsObserver::InspectedWebContentsObserver(
200 WebContents* web_contents) 200 WebContents* web_contents)
201 : WebContentsObserver(web_contents) { 201 : WebContentsObserver(web_contents) {
202 } 202 }
203 203
204 DevToolsWindow::InspectedWebContentsObserver::~InspectedWebContentsObserver() { 204 DevToolsWindow::InspectedWebContentsObserver::~InspectedWebContentsObserver() {
205 } 205 }
206 206
207 class DevToolsToolboxDelegate
208 : public content::WebContentsObserver,
209 public content::WebContentsDelegate {
210 public:
211 explicit DevToolsToolboxDelegate(WebContents* web_contents)
212 : WebContentsObserver(web_contents) { }
213 virtual ~DevToolsToolboxDelegate() { }
214
215 virtual content::WebContents* OpenURLFromTab(
216 content::WebContents* source,
217 const content::OpenURLParams& params) OVERRIDE {
218 DCHECK(source == web_contents());
219 if (!params.url.SchemeIs(content::kChromeDevToolsScheme))
220 return NULL;
221 content::NavigationController::LoadURLParams load_url_params(params.url);
222 source->GetController().LoadURLWithParams(load_url_params);
223 return source;
224 }
225
226 private:
227 DISALLOW_COPY_AND_ASSIGN(DevToolsToolboxDelegate);
228 };
229
207 // DevToolsWindow ------------------------------------------------------------- 230 // DevToolsWindow -------------------------------------------------------------
208 231
209 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; 232 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp";
210 233
211 DevToolsWindow::~DevToolsWindow() { 234 DevToolsWindow::~DevToolsWindow() {
235 if (toolbox_web_contents_)
236 delete toolbox_web_contents_;
237 UpdateBrowserWindow();
212 UpdateBrowserToolbar(); 238 UpdateBrowserToolbar();
213 239
214 DevToolsWindows* instances = g_instances.Pointer(); 240 DevToolsWindows* instances = g_instances.Pointer();
215 DevToolsWindows::iterator it( 241 DevToolsWindows::iterator it(
216 std::find(instances->begin(), instances->end(), this)); 242 std::find(instances->begin(), instances->end(), this));
217 DCHECK(it != instances->end()); 243 DCHECK(it != instances->end());
218 instances->erase(it); 244 instances->erase(it);
219 } 245 }
220 246
221 // static 247 // static
(...skipping 30 matching lines...) Expand all
252 registry->RegisterBooleanPref( 278 registry->RegisterBooleanPref(
253 prefs::kDevToolsPortForwardingDefaultSet, 279 prefs::kDevToolsPortForwardingDefaultSet,
254 false, 280 false,
255 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 281 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
256 registry->RegisterDictionaryPref( 282 registry->RegisterDictionaryPref(
257 prefs::kDevToolsPortForwardingConfig, 283 prefs::kDevToolsPortForwardingConfig,
258 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 284 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
259 } 285 }
260 286
261 // static 287 // static
262 DevToolsWindow* DevToolsWindow::GetDockedInstanceForInspectedTab( 288 content::WebContents* DevToolsWindow::GetWebContentsToShowForInspectedTab(
263 WebContents* inspected_web_contents) { 289 WebContents* inspected_web_contents,
264 DevToolsWindow* window = GetInstanceForInspectedRenderViewHost( 290 DevToolsContentsResizingStrategy* out_strategy) {
265 inspected_web_contents->GetRenderViewHost()); 291 DevToolsWindow* window = GetInstanceForInspectedWebContents(
292 inspected_web_contents);
266 if (!window) 293 if (!window)
267 return NULL; 294 return NULL;
295
268 // Not yet loaded window is treated as docked, but we should not present it 296 // Not yet loaded window is treated as docked, but we should not present it
269 // until we decided on docking. 297 // until we decided on docking.
270 bool is_docked_set = window->load_state_ == kLoadCompleted || 298 bool is_docked_set = window->load_state_ == kLoadCompleted ||
271 window->load_state_ == kIsDockedSet; 299 window->load_state_ == kIsDockedSet;
272 return window->is_docked_ && is_docked_set ? window : NULL; 300 if (!is_docked_set)
301 return NULL;
302
303 // Undocked window should have toolbox web contents.
304 if (!window->is_docked_ && !window->toolbox_web_contents_)
305 return NULL;
306
307 if (out_strategy)
308 out_strategy->CopyFrom(window->contents_resizing_strategy_);
309
310 return window->is_docked_ ? window->main_web_contents_ :
311 window->toolbox_web_contents_;
273 } 312 }
274 313
275 // static 314 // static
276 DevToolsWindow* DevToolsWindow::GetInstanceForInspectedRenderViewHost( 315 DevToolsWindow* DevToolsWindow::GetInstanceForInspectedRenderViewHost(
277 content::RenderViewHost* inspected_rvh) { 316 content::RenderViewHost* inspected_rvh) {
278 if (!inspected_rvh || !DevToolsAgentHost::HasFor(inspected_rvh)) 317 if (!inspected_rvh || !DevToolsAgentHost::HasFor(inspected_rvh))
279 return NULL; 318 return NULL;
280 319
281 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor( 320 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor(
282 inspected_rvh)); 321 inspected_rvh));
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 agent->InspectElement(x, y); 464 agent->InspectElement(x, y);
426 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; 465 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL;
427 base::TimeTicks start_time = base::TimeTicks::Now(); 466 base::TimeTicks start_time = base::TimeTicks::Now();
428 // TODO(loislo): we should initiate DevTools window opening from within 467 // TODO(loislo): we should initiate DevTools window opening from within
429 // renderer. Otherwise, we still can hit a race condition here. 468 // renderer. Otherwise, we still can hit a race condition here.
430 DevToolsWindow* window = OpenDevToolsWindow(inspected_rvh); 469 DevToolsWindow* window = OpenDevToolsWindow(inspected_rvh);
431 if (should_measure_time) 470 if (should_measure_time)
432 window->inspect_element_start_time_ = start_time; 471 window->inspect_element_start_time_ = start_time;
433 } 472 }
434 473
435 const DevToolsContentsResizingStrategy&
436 DevToolsWindow::GetContentsResizingStrategy() const {
437 return contents_resizing_strategy_;
438 }
439
440 gfx::Size DevToolsWindow::GetMinimumSize() const {
441 const gfx::Size kMinDevToolsSize = gfx::Size(230, 100);
442 return kMinDevToolsSize;
443 }
444
445 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) { 474 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) {
446 if (load_state_ == kLoadCompleted) { 475 if (load_state_ == kLoadCompleted) {
447 Show(action); 476 Show(action);
448 return; 477 return;
449 } 478 }
450 479
451 // Action will be done only after load completed. 480 // Action will be done only after load completed.
452 action_on_load_ = action; 481 action_on_load_ = action;
453 482
454 if (!can_dock_) { 483 if (!can_dock_) {
(...skipping 12 matching lines...) Expand all
467 Browser* inspected_browser = NULL; 496 Browser* inspected_browser = NULL;
468 int inspected_tab_index = -1; 497 int inspected_tab_index = -1;
469 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), 498 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(),
470 &inspected_browser, 499 &inspected_browser,
471 &inspected_tab_index); 500 &inspected_tab_index);
472 DCHECK(inspected_browser); 501 DCHECK(inspected_browser);
473 DCHECK(inspected_tab_index != -1); 502 DCHECK(inspected_tab_index != -1);
474 503
475 // Tell inspected browser to update splitter and switch to inspected panel. 504 // Tell inspected browser to update splitter and switch to inspected panel.
476 BrowserWindow* inspected_window = inspected_browser->window(); 505 BrowserWindow* inspected_window = inspected_browser->window();
477 web_contents_->SetDelegate(this); 506 main_web_contents_->SetDelegate(this);
478 507
479 TabStripModel* tab_strip_model = inspected_browser->tab_strip_model(); 508 TabStripModel* tab_strip_model = inspected_browser->tab_strip_model();
480 tab_strip_model->ActivateTabAt(inspected_tab_index, true); 509 tab_strip_model->ActivateTabAt(inspected_tab_index, true);
481 510
482 inspected_window->UpdateDevTools(); 511 inspected_window->UpdateDevTools();
483 web_contents_->SetInitialFocus(); 512 main_web_contents_->SetInitialFocus();
484 inspected_window->Show(); 513 inspected_window->Show();
485 // On Aura, focusing once is not enough. Do it again. 514 // On Aura, focusing once is not enough. Do it again.
486 // Note that focusing only here but not before isn't enough either. We just 515 // Note that focusing only here but not before isn't enough either. We just
487 // need to focus twice. 516 // need to focus twice.
488 web_contents_->SetInitialFocus(); 517 main_web_contents_->SetInitialFocus();
489 518
490 PrefsTabHelper::CreateForWebContents(web_contents_); 519 PrefsTabHelper::CreateForWebContents(main_web_contents_);
491 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); 520 main_web_contents_->GetRenderViewHost()->SyncRendererPrefs();
492 521
493 DoAction(action); 522 DoAction(action);
494 return; 523 return;
495 } 524 }
496 525
497 // Avoid consecutive window switching if the devtools window has been opened 526 // Avoid consecutive window switching if the devtools window has been opened
498 // and the Inspect Element shortcut is pressed in the inspected tab. 527 // and the Inspect Element shortcut is pressed in the inspected tab.
499 bool should_show_window = 528 bool should_show_window =
500 !browser_ || (action.type() != DevToolsToggleAction::kInspect); 529 !browser_ || (action.type() != DevToolsToggleAction::kInspect);
501 530
502 if (!browser_) 531 if (!browser_)
503 CreateDevToolsBrowser(); 532 CreateDevToolsBrowser();
504 533
505 if (should_show_window) { 534 if (should_show_window) {
506 browser_->window()->Show(); 535 browser_->window()->Show();
507 web_contents_->SetInitialFocus(); 536 main_web_contents_->SetInitialFocus();
508 } 537 }
538 if (toolbox_web_contents_)
539 UpdateBrowserWindow();
509 540
510 DoAction(action); 541 DoAction(action);
511 } 542 }
512 543
513 // static 544 // static
514 bool DevToolsWindow::HandleBeforeUnload(WebContents* frontend_contents, 545 bool DevToolsWindow::HandleBeforeUnload(WebContents* frontend_contents,
515 bool proceed, bool* proceed_to_fire_unload) { 546 bool proceed, bool* proceed_to_fire_unload) {
516 DevToolsWindow* window = AsDevToolsWindow( 547 DevToolsWindow* window = AsDevToolsWindow(
517 frontend_contents->GetRenderViewHost()); 548 frontend_contents->GetRenderViewHost());
518 if (!window) 549 if (!window)
(...skipping 13 matching lines...) Expand all
532 if (!window || window->intercepted_page_beforeunload_) 563 if (!window || window->intercepted_page_beforeunload_)
533 return false; 564 return false;
534 565
535 // Not yet loaded frontend will not handle beforeunload. 566 // Not yet loaded frontend will not handle beforeunload.
536 if (window->load_state_ != kLoadCompleted) 567 if (window->load_state_ != kLoadCompleted)
537 return false; 568 return false;
538 569
539 window->intercepted_page_beforeunload_ = true; 570 window->intercepted_page_beforeunload_ = true;
540 // Handle case of devtools inspecting another devtools instance by passing 571 // Handle case of devtools inspecting another devtools instance by passing
541 // the call up to the inspecting devtools instance. 572 // the call up to the inspecting devtools instance.
542 if (!DevToolsWindow::InterceptPageBeforeUnload(window->web_contents_)) { 573 if (!DevToolsWindow::InterceptPageBeforeUnload(window->main_web_contents_)) {
543 window->web_contents_->DispatchBeforeUnload(false); 574 window->main_web_contents_->DispatchBeforeUnload(false);
544 } 575 }
545 return true; 576 return true;
546 } 577 }
547 578
548 // static 579 // static
549 bool DevToolsWindow::NeedsToInterceptBeforeUnload( 580 bool DevToolsWindow::NeedsToInterceptBeforeUnload(
550 WebContents* contents) { 581 WebContents* contents) {
551 DevToolsWindow* window = 582 DevToolsWindow* window =
552 DevToolsWindow::GetInstanceForInspectedRenderViewHost( 583 DevToolsWindow::GetInstanceForInspectedRenderViewHost(
553 contents->GetRenderViewHost()); 584 contents->GetRenderViewHost());
(...skipping 19 matching lines...) Expand all
573 604
574 // static 605 // static
575 void DevToolsWindow::OnPageCloseCanceled(WebContents* contents) { 606 void DevToolsWindow::OnPageCloseCanceled(WebContents* contents) {
576 DevToolsWindow *window = 607 DevToolsWindow *window =
577 DevToolsWindow::GetInstanceForInspectedRenderViewHost( 608 DevToolsWindow::GetInstanceForInspectedRenderViewHost(
578 contents->GetRenderViewHost()); 609 contents->GetRenderViewHost());
579 if (!window) 610 if (!window)
580 return; 611 return;
581 window->intercepted_page_beforeunload_ = false; 612 window->intercepted_page_beforeunload_ = false;
582 // Propagate to devtools opened on devtools if any. 613 // Propagate to devtools opened on devtools if any.
583 DevToolsWindow::OnPageCloseCanceled(window->web_contents_); 614 DevToolsWindow::OnPageCloseCanceled(window->main_web_contents_);
584 } 615 }
585 616
586 DevToolsWindow::DevToolsWindow(Profile* profile, 617 DevToolsWindow::DevToolsWindow(Profile* profile,
587 const GURL& url, 618 const GURL& url,
588 content::RenderViewHost* inspected_rvh, 619 content::RenderViewHost* inspected_rvh,
589 bool can_dock) 620 bool can_dock)
590 : profile_(profile), 621 : profile_(profile),
591 web_contents_(WebContents::Create(WebContents::CreateParams(profile))), 622 main_web_contents_(
623 WebContents::Create(WebContents::CreateParams(profile))),
624 toolbox_web_contents_(NULL),
592 bindings_(NULL), 625 bindings_(NULL),
593 browser_(NULL), 626 browser_(NULL),
594 is_docked_(true), 627 is_docked_(true),
595 can_dock_(can_dock), 628 can_dock_(can_dock),
596 // This initialization allows external front-end to work without changes. 629 // This initialization allows external front-end to work without changes.
597 // We don't wait for docking call, but instead immediately show undocked. 630 // We don't wait for docking call, but instead immediately show undocked.
598 // Passing "dockSide=undocked" parameter ensures proper UI. 631 // Passing "dockSide=undocked" parameter ensures proper UI.
599 load_state_(can_dock ? kNotLoaded : kIsDockedSet), 632 load_state_(can_dock ? kNotLoaded : kIsDockedSet),
600 action_on_load_(DevToolsToggleAction::NoOp()), 633 action_on_load_(DevToolsToggleAction::NoOp()),
601 ignore_set_is_docked_(false), 634 ignore_set_is_docked_(false),
602 intercepted_page_beforeunload_(false) { 635 intercepted_page_beforeunload_(false) {
603 // Set up delegate, so we get fully-functional window immediately. 636 // Set up delegate, so we get fully-functional window immediately.
604 // It will not appear in UI though until |load_state_ == kLoadCompleted|. 637 // It will not appear in UI though until |load_state_ == kLoadCompleted|.
605 web_contents_->SetDelegate(this); 638 main_web_contents_->SetDelegate(this);
606 bindings_ = new DevToolsUIBindings( 639 bindings_ = new DevToolsUIBindings(
607 web_contents_, 640 main_web_contents_,
608 DevToolsUIBindings::ApplyThemeToURL(profile, url)); 641 DevToolsUIBindings::ApplyThemeToURL(profile, url));
609 // Bindings take ownership over devtools as its delegate. 642 // Bindings take ownership over devtools as its delegate.
610 bindings_->SetDelegate(this); 643 bindings_->SetDelegate(this);
611 644
612 g_instances.Get().push_back(this); 645 g_instances.Get().push_back(this);
613 646
614 // There is no inspected_rvh in case of shared workers. 647 // There is no inspected_rvh in case of shared workers.
615 if (inspected_rvh) 648 if (inspected_rvh)
616 inspected_contents_observer_.reset(new InspectedWebContentsObserver( 649 inspected_contents_observer_.reset(new InspectedWebContentsObserver(
617 content::WebContents::FromRenderViewHost(inspected_rvh))); 650 content::WebContents::FromRenderViewHost(inspected_rvh)));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 } 721 }
689 722
690 // static 723 // static
691 DevToolsWindow* DevToolsWindow::AsDevToolsWindow( 724 DevToolsWindow* DevToolsWindow::AsDevToolsWindow(
692 content::RenderViewHost* window_rvh) { 725 content::RenderViewHost* window_rvh) {
693 if (g_instances == NULL) 726 if (g_instances == NULL)
694 return NULL; 727 return NULL;
695 DevToolsWindows* instances = g_instances.Pointer(); 728 DevToolsWindows* instances = g_instances.Pointer();
696 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); 729 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end();
697 ++it) { 730 ++it) {
698 if ((*it)->web_contents_->GetRenderViewHost() == window_rvh) 731 if ((*it)->main_web_contents_->GetRenderViewHost() == window_rvh)
699 return *it; 732 return *it;
700 } 733 }
701 return NULL; 734 return NULL;
702 } 735 }
703 736
704 WebContents* DevToolsWindow::OpenURLFromTab( 737 WebContents* DevToolsWindow::OpenURLFromTab(
705 WebContents* source, 738 WebContents* source,
706 const content::OpenURLParams& params) { 739 const content::OpenURLParams& params) {
707 DCHECK(source == web_contents_); 740 DCHECK(source == main_web_contents_);
708 if (!params.url.SchemeIs(content::kChromeDevToolsScheme)) { 741 if (!params.url.SchemeIs(content::kChromeDevToolsScheme)) {
709 WebContents* inspected_web_contents = GetInspectedWebContents(); 742 WebContents* inspected_web_contents = GetInspectedWebContents();
710 return inspected_web_contents ? 743 return inspected_web_contents ?
711 inspected_web_contents->OpenURL(params) : NULL; 744 inspected_web_contents->OpenURL(params) : NULL;
712 } 745 }
713 746
714 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); 747 content::DevToolsManager* manager = content::DevToolsManager::GetInstance();
715 scoped_refptr<DevToolsAgentHost> agent_host( 748 scoped_refptr<DevToolsAgentHost> agent_host(
716 manager->GetDevToolsAgentHostFor(bindings_->frontend_host())); 749 manager->GetDevToolsAgentHostFor(bindings_->frontend_host()));
717 if (!agent_host.get()) 750 if (!agent_host.get())
718 return NULL; 751 return NULL;
719 manager->ClientHostClosing(bindings_->frontend_host()); 752 manager->ClientHostClosing(bindings_->frontend_host());
720 manager->RegisterDevToolsClientHostFor(agent_host.get(), 753 manager->RegisterDevToolsClientHostFor(agent_host.get(),
721 bindings_->frontend_host()); 754 bindings_->frontend_host());
722 755
723 content::NavigationController::LoadURLParams load_url_params(params.url); 756 content::NavigationController::LoadURLParams load_url_params(params.url);
724 web_contents_->GetController().LoadURLWithParams(load_url_params); 757 main_web_contents_->GetController().LoadURLWithParams(load_url_params);
725 return web_contents_; 758 return main_web_contents_;
726 } 759 }
727 760
728 void DevToolsWindow::ActivateContents(WebContents* contents) { 761 void DevToolsWindow::ActivateContents(WebContents* contents) {
729 if (is_docked_) { 762 if (is_docked_) {
730 WebContents* inspected_tab = GetInspectedWebContents(); 763 WebContents* inspected_tab = GetInspectedWebContents();
731 inspected_tab->GetDelegate()->ActivateContents(inspected_tab); 764 inspected_tab->GetDelegate()->ActivateContents(inspected_tab);
732 } else { 765 } else {
733 browser_->window()->Activate(); 766 browser_->window()->Activate();
734 } 767 }
735 } 768 }
736 769
737 void DevToolsWindow::AddNewContents(WebContents* source, 770 void DevToolsWindow::AddNewContents(WebContents* source,
738 WebContents* new_contents, 771 WebContents* new_contents,
739 WindowOpenDisposition disposition, 772 WindowOpenDisposition disposition,
740 const gfx::Rect& initial_pos, 773 const gfx::Rect& initial_pos,
741 bool user_gesture, 774 bool user_gesture,
742 bool* was_blocked) { 775 bool* was_blocked) {
776 if (new_contents == toolbox_web_contents_) {
777 toolbox_web_contents_->SetDelegate(
778 new DevToolsToolboxDelegate(toolbox_web_contents_));
pfeldman 2014/05/27 15:26:19 When is the delegate deleted?
dgozman 2014/05/29 11:22:23 Done.
779 UpdateBrowserWindow();
780 return;
781 }
782
743 WebContents* inspected_web_contents = GetInspectedWebContents(); 783 WebContents* inspected_web_contents = GetInspectedWebContents();
744 if (inspected_web_contents) { 784 if (inspected_web_contents) {
745 inspected_web_contents->GetDelegate()->AddNewContents( 785 inspected_web_contents->GetDelegate()->AddNewContents(
746 source, new_contents, disposition, initial_pos, user_gesture, 786 source, new_contents, disposition, initial_pos, user_gesture,
747 was_blocked); 787 was_blocked);
748 } 788 }
749 } 789 }
750 790
791 void DevToolsWindow::WebContentsCreated(WebContents* source_contents,
792 int opener_render_frame_id,
793 const base::string16& frame_name,
794 const GURL& target_url,
795 WebContents* new_contents) {
796 if (target_url.SchemeIs(content::kChromeDevToolsScheme) &&
797 target_url.query().find("toolbox=true") != std::string::npos) {
798 CHECK(can_dock_);
799 toolbox_web_contents_ = new_contents;
800 }
801 }
802
751 void DevToolsWindow::CloseContents(WebContents* source) { 803 void DevToolsWindow::CloseContents(WebContents* source) {
752 CHECK(is_docked_); 804 CHECK(is_docked_);
753 // Do this first so that when GetDockedInstanceForInspectedTab is called 805 // Do this first so that when GetDockedInstanceForInspectedTab is called
754 // from UpdateDevTools it won't return this instance 806 // from UpdateDevTools it won't return this instance
755 // see crbug.com/372504 807 // see crbug.com/372504
756 content::DevToolsManager::GetInstance()->ClientHostClosing( 808 content::DevToolsManager::GetInstance()->ClientHostClosing(
757 bindings_->frontend_host()); 809 bindings_->frontend_host());
758 // This will prevent any activity after frontend is loaded. 810 // This will prevent any activity after frontend is loaded.
759 action_on_load_ = DevToolsToggleAction::NoOp(); 811 action_on_load_ = DevToolsToggleAction::NoOp();
760 ignore_set_is_docked_ = true; 812 ignore_set_is_docked_ = true;
761 // Update dev tools to reflect removed dev tools window. 813 UpdateBrowserWindow();
762 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); 814 // In case of docked main_web_contents_, we own it so delete here.
763 if (inspected_window)
764 inspected_window->UpdateDevTools();
765 // In case of docked web_contents_, we own it so delete here.
766 // Embedding DevTools window will be deleted as a result of 815 // Embedding DevTools window will be deleted as a result of
767 // DevToolsUIBindings destruction. 816 // DevToolsUIBindings destruction.
768 delete web_contents_; 817 delete main_web_contents_;
769 } 818 }
770 819
771 void DevToolsWindow::ContentsZoomChange(bool zoom_in) { 820 void DevToolsWindow::ContentsZoomChange(bool zoom_in) {
772 DCHECK(is_docked_); 821 DCHECK(is_docked_);
773 chrome_page_zoom::Zoom(web_contents_, 822 chrome_page_zoom::Zoom(main_web_contents_,
774 zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT); 823 zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT);
775 } 824 }
776 825
777 void DevToolsWindow::BeforeUnloadFired(WebContents* tab, 826 void DevToolsWindow::BeforeUnloadFired(WebContents* tab,
778 bool proceed, 827 bool proceed,
779 bool* proceed_to_fire_unload) { 828 bool* proceed_to_fire_unload) {
780 if (!intercepted_page_beforeunload_) { 829 if (!intercepted_page_beforeunload_) {
781 // Docked devtools window closed directly. 830 // Docked devtools window closed directly.
782 if (proceed) { 831 if (proceed) {
783 content::DevToolsManager::GetInstance()->ClientHostClosing( 832 content::DevToolsManager::GetInstance()->ClientHostClosing(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 WebContents* source, 908 WebContents* source,
860 const blink::WebGestureEvent& event) { 909 const blink::WebGestureEvent& event) {
861 // Disable pinch zooming. 910 // Disable pinch zooming.
862 return event.type == blink::WebGestureEvent::GesturePinchBegin || 911 return event.type == blink::WebGestureEvent::GesturePinchBegin ||
863 event.type == blink::WebGestureEvent::GesturePinchUpdate || 912 event.type == blink::WebGestureEvent::GesturePinchUpdate ||
864 event.type == blink::WebGestureEvent::GesturePinchEnd; 913 event.type == blink::WebGestureEvent::GesturePinchEnd;
865 } 914 }
866 915
867 void DevToolsWindow::ActivateWindow() { 916 void DevToolsWindow::ActivateWindow() {
868 if (is_docked_ && GetInspectedBrowserWindow()) 917 if (is_docked_ && GetInspectedBrowserWindow())
869 web_contents_->Focus(); 918 main_web_contents_->Focus();
870 else if (!is_docked_ && !browser_->window()->IsActive()) 919 else if (!is_docked_ && !browser_->window()->IsActive())
871 browser_->window()->Activate(); 920 browser_->window()->Activate();
872 } 921 }
873 922
874 void DevToolsWindow::CloseWindow() { 923 void DevToolsWindow::CloseWindow() {
875 DCHECK(is_docked_); 924 DCHECK(is_docked_);
876 // This will prevent any activity after frontend is loaded. 925 // This will prevent any activity after frontend is loaded.
877 action_on_load_ = DevToolsToggleAction::NoOp(); 926 action_on_load_ = DevToolsToggleAction::NoOp();
878 ignore_set_is_docked_ = true; 927 ignore_set_is_docked_ = true;
879 web_contents_->DispatchBeforeUnload(false); 928 main_web_contents_->DispatchBeforeUnload(false);
880 } 929 }
881 930
882 void DevToolsWindow::SetInspectedPageBounds(const gfx::Rect& rect) { 931 void DevToolsWindow::SetInspectedPageBounds(const gfx::Rect& rect) {
883 DevToolsContentsResizingStrategy strategy(rect); 932 DevToolsContentsResizingStrategy strategy(rect);
884 if (contents_resizing_strategy_.Equals(strategy)) 933 if (contents_resizing_strategy_.Equals(strategy))
885 return; 934 return;
886 935
887 contents_resizing_strategy_.CopyFrom(strategy); 936 contents_resizing_strategy_.CopyFrom(strategy);
888 if (is_docked_) { 937 UpdateBrowserWindow();
889 // Update inspected window.
890 BrowserWindow* inspected_window = GetInspectedBrowserWindow();
891 if (inspected_window)
892 inspected_window->UpdateDevTools();
893 }
894 } 938 }
895 939
896 void DevToolsWindow::SetContentsResizingStrategy( 940 void DevToolsWindow::SetContentsResizingStrategy(
897 const gfx::Insets& insets, const gfx::Size& min_size) { 941 const gfx::Insets& insets, const gfx::Size& min_size) {
898 DevToolsContentsResizingStrategy strategy(insets, min_size); 942 DevToolsContentsResizingStrategy strategy(insets, min_size);
899 if (contents_resizing_strategy_.Equals(strategy)) 943 if (contents_resizing_strategy_.Equals(strategy))
900 return; 944 return;
901 945
902 contents_resizing_strategy_.CopyFrom(strategy); 946 contents_resizing_strategy_.CopyFrom(strategy);
903 if (is_docked_) { 947 UpdateBrowserWindow();
904 // Update inspected window.
905 BrowserWindow* inspected_window = GetInspectedBrowserWindow();
906 if (inspected_window)
907 inspected_window->UpdateDevTools();
908 }
909 } 948 }
910 949
911 void DevToolsWindow::InspectElementCompleted() { 950 void DevToolsWindow::InspectElementCompleted() {
912 if (!inspect_element_start_time_.is_null()) { 951 if (!inspect_element_start_time_.is_null()) {
913 UMA_HISTOGRAM_TIMES("DevTools.InspectElement", 952 UMA_HISTOGRAM_TIMES("DevTools.InspectElement",
914 base::TimeTicks::Now() - inspect_element_start_time_); 953 base::TimeTicks::Now() - inspect_element_start_time_);
915 inspect_element_start_time_ = base::TimeTicks(); 954 inspect_element_start_time_ = base::TimeTicks();
916 } 955 }
917 } 956 }
918 957
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 } 1001 }
963 1002
964 if (dock_requested == was_docked) 1003 if (dock_requested == was_docked)
965 return; 1004 return;
966 1005
967 if (dock_requested && !was_docked) { 1006 if (dock_requested && !was_docked) {
968 // Detach window from the external devtools browser. It will lead to 1007 // Detach window from the external devtools browser. It will lead to
969 // the browser object's close and delete. Remove observer first. 1008 // the browser object's close and delete. Remove observer first.
970 TabStripModel* tab_strip_model = browser_->tab_strip_model(); 1009 TabStripModel* tab_strip_model = browser_->tab_strip_model();
971 tab_strip_model->DetachWebContentsAt( 1010 tab_strip_model->DetachWebContentsAt(
972 tab_strip_model->GetIndexOfWebContents(web_contents_)); 1011 tab_strip_model->GetIndexOfWebContents(main_web_contents_));
973 browser_ = NULL; 1012 browser_ = NULL;
974 } else if (!dock_requested && was_docked) { 1013 } else if (!dock_requested && was_docked) {
975 // Update inspected window to hide split and reset it. 1014 UpdateBrowserWindow();
976 BrowserWindow* inspected_window = GetInspectedBrowserWindow();
977 if (inspected_window)
978 inspected_window->UpdateDevTools();
979 } 1015 }
980 1016
981 Show(DevToolsToggleAction::Show()); 1017 Show(DevToolsToggleAction::Show());
982 } 1018 }
983 1019
984 void DevToolsWindow::OpenInNewTab(const std::string& url) { 1020 void DevToolsWindow::OpenInNewTab(const std::string& url) {
985 content::OpenURLParams params( 1021 content::OpenURLParams params(
986 GURL(url), content::Referrer(), NEW_FOREGROUND_TAB, 1022 GURL(url), content::Referrer(), NEW_FOREGROUND_TAB,
987 content::PAGE_TRANSITION_LINK, false); 1023 content::PAGE_TRANSITION_LINK, false);
988 WebContents* inspected_web_contents = GetInspectedWebContents(); 1024 WebContents* inspected_web_contents = GetInspectedWebContents();
(...skipping 25 matching lines...) Expand all
1014 void DevToolsWindow::SetWhitelistedShortcuts( 1050 void DevToolsWindow::SetWhitelistedShortcuts(
1015 const std::string& message) { 1051 const std::string& message) {
1016 event_forwarder_->SetWhitelistedShortcuts(message); 1052 event_forwarder_->SetWhitelistedShortcuts(message);
1017 } 1053 }
1018 1054
1019 void DevToolsWindow::InspectedContentsClosing() { 1055 void DevToolsWindow::InspectedContentsClosing() {
1020 intercepted_page_beforeunload_ = false; 1056 intercepted_page_beforeunload_ = false;
1021 // This will prevent any activity after frontend is loaded. 1057 // This will prevent any activity after frontend is loaded.
1022 action_on_load_ = DevToolsToggleAction::NoOp(); 1058 action_on_load_ = DevToolsToggleAction::NoOp();
1023 ignore_set_is_docked_ = true; 1059 ignore_set_is_docked_ = true;
1024 web_contents_->GetRenderViewHost()->ClosePage(); 1060 main_web_contents_->GetRenderViewHost()->ClosePage();
1025 } 1061 }
1026 1062
1027 InfoBarService* DevToolsWindow::GetInfoBarService() { 1063 InfoBarService* DevToolsWindow::GetInfoBarService() {
1028 return is_docked_ ? 1064 return is_docked_ ?
1029 InfoBarService::FromWebContents(GetInspectedWebContents()) : 1065 InfoBarService::FromWebContents(GetInspectedWebContents()) :
1030 InfoBarService::FromWebContents(web_contents_); 1066 InfoBarService::FromWebContents(main_web_contents_);
1031 } 1067 }
1032 1068
1033 void DevToolsWindow::RenderProcessGone() { 1069 void DevToolsWindow::RenderProcessGone() {
1034 // Docked DevToolsWindow owns its web_contents_ and must delete it. 1070 // Docked DevToolsWindow owns its main_web_contents_ and must delete it.
1035 // Undocked web_contents_ are owned and handled by browser. 1071 // Undocked main_web_contents_ are owned and handled by browser.
1036 // see crbug.com/369932 1072 // see crbug.com/369932
1037 if (is_docked_) 1073 if (is_docked_)
1038 CloseContents(web_contents_); 1074 CloseContents(main_web_contents_);
1039 } 1075 }
1040 1076
1041 void DevToolsWindow::OnLoadCompleted() { 1077 void DevToolsWindow::OnLoadCompleted() {
1042 // First seed inspected tab id for extension APIs. 1078 // First seed inspected tab id for extension APIs.
1043 WebContents* inspected_web_contents = GetInspectedWebContents(); 1079 WebContents* inspected_web_contents = GetInspectedWebContents();
1044 if (inspected_web_contents) { 1080 if (inspected_web_contents) {
1045 SessionTabHelper* session_tab_helper = 1081 SessionTabHelper* session_tab_helper =
1046 SessionTabHelper::FromWebContents(inspected_web_contents); 1082 SessionTabHelper::FromWebContents(inspected_web_contents);
1047 if (session_tab_helper) { 1083 if (session_tab_helper) {
1048 base::FundamentalValue tabId(session_tab_helper->session_id().id()); 1084 base::FundamentalValue tabId(session_tab_helper->session_id().id());
(...skipping 23 matching lines...) Expand all
1072 defaults->SetInteger("top", 100); 1108 defaults->SetInteger("top", 100);
1073 defaults->SetInteger("right", 740); 1109 defaults->SetInteger("right", 740);
1074 defaults->SetInteger("bottom", 740); 1110 defaults->SetInteger("bottom", 740);
1075 defaults->SetBoolean("maximized", false); 1111 defaults->SetBoolean("maximized", false);
1076 defaults->SetBoolean("always_on_top", false); 1112 defaults->SetBoolean("always_on_top", false);
1077 } 1113 }
1078 1114
1079 browser_ = new Browser(Browser::CreateParams::CreateForDevTools( 1115 browser_ = new Browser(Browser::CreateParams::CreateForDevTools(
1080 profile_, 1116 profile_,
1081 chrome::GetHostDesktopTypeForNativeView( 1117 chrome::GetHostDesktopTypeForNativeView(
1082 web_contents_->GetNativeView()))); 1118 main_web_contents_->GetNativeView())));
1083 browser_->tab_strip_model()->AddWebContents( 1119 browser_->tab_strip_model()->AddWebContents(
1084 web_contents_, -1, content::PAGE_TRANSITION_AUTO_TOPLEVEL, 1120 main_web_contents_, -1, content::PAGE_TRANSITION_AUTO_TOPLEVEL,
1085 TabStripModel::ADD_ACTIVE); 1121 TabStripModel::ADD_ACTIVE);
1086 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); 1122 main_web_contents_->GetRenderViewHost()->SyncRendererPrefs();
1087 } 1123 }
1088 1124
1089 // static 1125 // static
1090 bool DevToolsWindow::FindInspectedBrowserAndTabIndex( 1126 bool DevToolsWindow::FindInspectedBrowserAndTabIndex(
1091 WebContents* inspected_web_contents, Browser** browser, int* tab) { 1127 WebContents* inspected_web_contents, Browser** browser, int* tab) {
1092 if (!inspected_web_contents) 1128 if (!inspected_web_contents)
1093 return false; 1129 return false;
1094 1130
1095 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 1131 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
1096 int tab_index = it->tab_strip_model()->GetIndexOfWebContents( 1132 int tab_index = it->tab_strip_model()->GetIndexOfWebContents(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 break; 1182 break;
1147 } 1183 }
1148 } 1184 }
1149 1185
1150 void DevToolsWindow::UpdateBrowserToolbar() { 1186 void DevToolsWindow::UpdateBrowserToolbar() {
1151 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); 1187 BrowserWindow* inspected_window = GetInspectedBrowserWindow();
1152 if (inspected_window) 1188 if (inspected_window)
1153 inspected_window->UpdateToolbar(NULL); 1189 inspected_window->UpdateToolbar(NULL);
1154 } 1190 }
1155 1191
1192 void DevToolsWindow::UpdateBrowserWindow() {
1193 BrowserWindow* inspected_window = GetInspectedBrowserWindow();
1194 if (inspected_window)
1195 inspected_window->UpdateDevTools();
1196 }
1197
1156 WebContents* DevToolsWindow::GetInspectedWebContents() { 1198 WebContents* DevToolsWindow::GetInspectedWebContents() {
1157 return inspected_contents_observer_ ? 1199 return inspected_contents_observer_ ?
1158 inspected_contents_observer_->web_contents() : NULL; 1200 inspected_contents_observer_->web_contents() : NULL;
1159 } 1201 }
1160 1202
1161 void DevToolsWindow::LoadCompleted() { 1203 void DevToolsWindow::LoadCompleted() {
1162 Show(action_on_load_); 1204 Show(action_on_load_);
1163 action_on_load_ = DevToolsToggleAction::NoOp(); 1205 action_on_load_ = DevToolsToggleAction::NoOp();
1164 if (!load_completed_callback_.is_null()) { 1206 if (!load_completed_callback_.is_null()) {
1165 load_completed_callback_.Run(); 1207 load_completed_callback_.Run();
1166 load_completed_callback_ = base::Closure(); 1208 load_completed_callback_ = base::Closure();
1167 } 1209 }
1168 } 1210 }
1169 1211
1170 void DevToolsWindow::SetLoadCompletedCallback(const base::Closure& closure) { 1212 void DevToolsWindow::SetLoadCompletedCallback(const base::Closure& closure) {
1171 if (load_state_ == kLoadCompleted) { 1213 if (load_state_ == kLoadCompleted) {
1172 if (!closure.is_null()) 1214 if (!closure.is_null())
1173 closure.Run(); 1215 closure.Run();
1174 return; 1216 return;
1175 } 1217 }
1176 load_completed_callback_ = closure; 1218 load_completed_callback_ = closure;
1177 } 1219 }
1178 1220
1179 bool DevToolsWindow::ForwardKeyboardEvent( 1221 bool DevToolsWindow::ForwardKeyboardEvent(
1180 const content::NativeWebKeyboardEvent& event) { 1222 const content::NativeWebKeyboardEvent& event) {
1181 return event_forwarder_->ForwardEvent(event); 1223 return event_forwarder_->ForwardEvent(event);
1182 } 1224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698