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

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

Powered by Google App Engine
This is Rietveld 408576698