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

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

Issue 890463003: [DevTools] Fix crash in DevToolsWindow::Create (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | no next file » | 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/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 return false; 387 return false;
388 } 388 }
389 389
390 // static 390 // static
391 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( 391 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker(
392 Profile* profile, 392 Profile* profile,
393 const scoped_refptr<DevToolsAgentHost>& worker_agent) { 393 const scoped_refptr<DevToolsAgentHost>& worker_agent) {
394 DevToolsWindow* window = FindDevToolsWindow(worker_agent.get()); 394 DevToolsWindow* window = FindDevToolsWindow(worker_agent.get());
395 if (!window) { 395 if (!window) {
396 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); 396 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile);
397 DCHECK(window);
397 window->bindings_->AttachTo(worker_agent); 398 window->bindings_->AttachTo(worker_agent);
398 } 399 }
399 window->ScheduleShow(DevToolsToggleAction::Show()); 400 window->ScheduleShow(DevToolsToggleAction::Show());
400 return window; 401 return window;
401 } 402 }
402 403
403 // static 404 // static
404 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( 405 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker(
405 Profile* profile) { 406 Profile* profile) {
406 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); 407 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker"));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 439 }
439 440
440 // static 441 // static
441 void DevToolsWindow::OpenExternalFrontend( 442 void DevToolsWindow::OpenExternalFrontend(
442 Profile* profile, 443 Profile* profile,
443 const std::string& frontend_url, 444 const std::string& frontend_url,
444 const scoped_refptr<content::DevToolsAgentHost>& agent_host, 445 const scoped_refptr<content::DevToolsAgentHost>& agent_host,
445 bool isWorker) { 446 bool isWorker) {
446 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); 447 DevToolsWindow* window = FindDevToolsWindow(agent_host.get());
447 if (!window) { 448 if (!window) {
448 window = Create(profile, GURL(), NULL, isWorker, 449 window = Create(profile, GURL(), nullptr, isWorker,
449 DevToolsUI::GetProxyURL(frontend_url).spec(), false, ""); 450 DevToolsUI::GetProxyURL(frontend_url).spec(), false, std::string());
450 window->bindings_->AttachTo(agent_host); 451 if (window)
dgozman 2015/01/30 13:02:08 I'd just |if (!window) return;|.
452 window->bindings_->AttachTo(agent_host);
451 } 453 }
452 window->ScheduleShow(DevToolsToggleAction::Show()); 454 if (window)
455 window->ScheduleShow(DevToolsToggleAction::Show());
453 } 456 }
454 457
455 // static 458 // static
456 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( 459 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
457 content::WebContents* inspected_web_contents, 460 content::WebContents* inspected_web_contents,
458 bool force_open, 461 bool force_open,
459 const DevToolsToggleAction& action, 462 const DevToolsToggleAction& action,
460 const std::string& settings) { 463 const std::string& settings) {
461 scoped_refptr<DevToolsAgentHost> agent( 464 scoped_refptr<DevToolsAgentHost> agent(
462 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); 465 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents));
463 DevToolsWindow* window = FindDevToolsWindow(agent.get()); 466 DevToolsWindow* window = FindDevToolsWindow(agent.get());
464 bool do_open = force_open; 467 bool do_open = force_open;
465 if (!window) { 468 if (!window) {
466 Profile* profile = Profile::FromBrowserContext( 469 Profile* profile = Profile::FromBrowserContext(
467 inspected_web_contents->GetBrowserContext()); 470 inspected_web_contents->GetBrowserContext());
468 content::RecordAction( 471 content::RecordAction(
469 base::UserMetricsAction("DevTools_InspectRenderer")); 472 base::UserMetricsAction("DevTools_InspectRenderer"));
470 window = Create(profile, GURL(), inspected_web_contents, 473 window = Create(profile, GURL(), inspected_web_contents,
471 false, std::string(), true, settings); 474 false, std::string(), true, settings);
475 DCHECK(window);
472 window->bindings_->AttachTo(agent.get()); 476 window->bindings_->AttachTo(agent.get());
473 do_open = true; 477 do_open = true;
474 } 478 }
475 479
476 // Update toolbar to reflect DevTools changes. 480 // Update toolbar to reflect DevTools changes.
477 window->UpdateBrowserToolbar(); 481 window->UpdateBrowserToolbar();
478 482
479 // If window is docked and visible, we hide it on toggle. If window is 483 // If window is docked and visible, we hide it on toggle. If window is
480 // undocked, we show (activate) it. 484 // undocked, we show (activate) it.
481 if (!window->is_docked_ || do_open) 485 if (!window->is_docked_ || do_open)
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 intercepted_page_beforeunload_(false) { 669 intercepted_page_beforeunload_(false) {
666 // Set up delegate, so we get fully-functional window immediately. 670 // Set up delegate, so we get fully-functional window immediately.
667 // It will not appear in UI though until |life_stage_ == kLoadCompleted|. 671 // It will not appear in UI though until |life_stage_ == kLoadCompleted|.
668 main_web_contents_->SetDelegate(this); 672 main_web_contents_->SetDelegate(this);
669 673
670 main_web_contents_->GetController().LoadURL( 674 main_web_contents_->GetController().LoadURL(
671 DevToolsUIBindings::ApplyThemeToURL(profile, url), content::Referrer(), 675 DevToolsUIBindings::ApplyThemeToURL(profile, url), content::Referrer(),
672 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); 676 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
673 677
674 bindings_ = DevToolsUIBindings::ForWebContents(main_web_contents_); 678 bindings_ = DevToolsUIBindings::ForWebContents(main_web_contents_);
675 DCHECK(bindings_); 679 if (!bindings_)
680 return;
676 681
677 // Bindings take ownership over devtools as its delegate. 682 // Bindings take ownership over devtools as its delegate.
678 bindings_->SetDelegate(this); 683 bindings_->SetDelegate(this);
679 // DevTools uses PageZoom::Zoom(), so main_web_contents_ requires a 684 // DevTools uses PageZoom::Zoom(), so main_web_contents_ requires a
680 // ZoomController. 685 // ZoomController.
681 ui_zoom::ZoomController::CreateForWebContents(main_web_contents_); 686 ui_zoom::ZoomController::CreateForWebContents(main_web_contents_);
682 ui_zoom::ZoomController::FromWebContents(main_web_contents_) 687 ui_zoom::ZoomController::FromWebContents(main_web_contents_)
683 ->SetShowsNotificationBubble(false); 688 ->SetShowsNotificationBubble(false);
684 689
685 g_instances.Get().push_back(this); 690 g_instances.Get().push_back(this);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 browser->is_type_popup()) { 725 browser->is_type_popup()) {
721 can_dock = false; 726 can_dock = false;
722 } 727 }
723 } 728 }
724 729
725 // Create WebContents with devtools. 730 // Create WebContents with devtools.
726 GURL url(GetDevToolsURL(profile, frontend_url, 731 GURL url(GetDevToolsURL(profile, frontend_url,
727 shared_worker_frontend, 732 shared_worker_frontend,
728 remote_frontend, 733 remote_frontend,
729 can_dock, settings)); 734 can_dock, settings));
730 return new DevToolsWindow(profile, url, inspected_web_contents, can_dock); 735 DevToolsWindow* window =
736 new DevToolsWindow(profile, url, inspected_web_contents, can_dock);
737 if (!window->bindings_) {
738 delete window;
739 window = nullptr;
740 }
741 return window;
731 } 742 }
732 743
733 // static 744 // static
734 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, 745 GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
735 const GURL& base_url, 746 const GURL& base_url,
736 bool shared_worker_frontend, 747 bool shared_worker_frontend,
737 const std::string& remote_frontend, 748 const std::string& remote_frontend,
738 bool can_dock, 749 bool can_dock,
739 const std::string& settings) { 750 const std::string& settings) {
740 // Compatibility errors are encoded with data urls, pass them 751 // Compatibility errors are encoded with data urls, pass them
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 closure.Run(); 1205 closure.Run();
1195 return; 1206 return;
1196 } 1207 }
1197 load_completed_callback_ = closure; 1208 load_completed_callback_ = closure;
1198 } 1209 }
1199 1210
1200 bool DevToolsWindow::ForwardKeyboardEvent( 1211 bool DevToolsWindow::ForwardKeyboardEvent(
1201 const content::NativeWebKeyboardEvent& event) { 1212 const content::NativeWebKeyboardEvent& event) {
1202 return event_forwarder_->ForwardEvent(event); 1213 return event_forwarder_->ForwardEvent(event);
1203 } 1214 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698