| Index: chrome/browser/devtools/devtools_window.cc
|
| diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc
|
| index 23e8e80c37c36bf2ef95d56918a4c12f6bcaa05a..5c2b4fb3e9ecf06b95d4b7a4cdac5384c405b2bb 100644
|
| --- a/chrome/browser/devtools/devtools_window.cc
|
| +++ b/chrome/browser/devtools/devtools_window.cc
|
| @@ -20,6 +20,7 @@
|
| #include "chrome/browser/task_management/web_contents_tags.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_dialogs.h"
|
| +#include "chrome/browser/ui/browser_finder.h"
|
| #include "chrome/browser/ui/browser_iterator.h"
|
| #include "chrome/browser/ui/browser_list.h"
|
| #include "chrome/browser/ui/browser_tabstrip.h"
|
| @@ -353,14 +354,14 @@ content::WebContents* DevToolsWindow::GetInTabWebContents(
|
| return NULL;
|
|
|
| // Undocked window should have toolbox web contents.
|
| - if (!window->is_docked_ && !window->toolbox_web_contents_)
|
| + if (!window->IsDocked() && !window->toolbox_web_contents_)
|
| return NULL;
|
|
|
| if (out_strategy)
|
| out_strategy->CopyFrom(window->contents_resizing_strategy_);
|
|
|
| - return window->is_docked_ ? window->main_web_contents_ :
|
| - window->toolbox_web_contents_;
|
| + return window->IsDocked() ? window->main_web_contents_
|
| + : window->toolbox_web_contents_;
|
| }
|
|
|
| // static
|
| @@ -503,7 +504,7 @@ void DevToolsWindow::ToggleDevToolsWindow(
|
|
|
| // If window is docked and visible, we hide it on toggle. If window is
|
| // undocked, we show (activate) it.
|
| - if (!window->is_docked_ || do_open)
|
| + if (!window->IsDocked() || do_open)
|
| window->ScheduleShow(action);
|
| else
|
| window->CloseWindow();
|
| @@ -539,7 +540,7 @@ void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) {
|
|
|
| if (!can_dock_) {
|
| // No harm to show always-undocked window right away.
|
| - is_docked_ = false;
|
| + dock_requested_ = false;
|
| Show(DevToolsToggleAction::Show());
|
| }
|
| }
|
| @@ -551,7 +552,7 @@ void DevToolsWindow::Show(const DevToolsToggleAction& action) {
|
| if (action.type() == DevToolsToggleAction::kNoOp)
|
| return;
|
|
|
| - if (is_docked_) {
|
| + if (IsDocked()) {
|
| DCHECK(can_dock_);
|
| Browser* inspected_browser = NULL;
|
| int inspected_tab_index = -1;
|
| @@ -585,14 +586,15 @@ void DevToolsWindow::Show(const DevToolsToggleAction& action) {
|
|
|
| // Avoid consecutive window switching if the devtools window has been opened
|
| // and the Inspect Element shortcut is pressed in the inspected tab.
|
| + Browser* browser = GetBrowser();
|
| bool should_show_window =
|
| - !browser_ || (action.type() != DevToolsToggleAction::kInspect);
|
| + !browser || (action.type() != DevToolsToggleAction::kInspect);
|
|
|
| - if (!browser_)
|
| - CreateDevToolsBrowser();
|
| + if (!browser)
|
| + browser = CreateDevToolsBrowser();
|
|
|
| if (should_show_window) {
|
| - browser_->window()->Show();
|
| + browser->window()->Show();
|
| main_web_contents_->SetInitialFocus();
|
| }
|
| if (toolbox_web_contents_)
|
| @@ -679,8 +681,7 @@ DevToolsWindow::DevToolsWindow(Profile* profile,
|
| main_web_contents_(main_web_contents),
|
| toolbox_web_contents_(nullptr),
|
| bindings_(bindings),
|
| - browser_(nullptr),
|
| - is_docked_(true),
|
| + dock_requested_(true),
|
| can_dock_(can_dock),
|
| // This initialization allows external front-end to work without changes.
|
| // We don't wait for docking call, but instead immediately show undocked.
|
| @@ -846,12 +847,13 @@ WebContents* DevToolsWindow::OpenURLFromTab(
|
| }
|
|
|
| void DevToolsWindow::ActivateContents(WebContents* contents) {
|
| - if (is_docked_) {
|
| + Browser* browser = GetBrowser();
|
| + if (browser == nullptr) {
|
| WebContents* inspected_tab = GetInspectedWebContents();
|
| if (inspected_tab)
|
| inspected_tab->GetDelegate()->ActivateContents(inspected_tab);
|
| - } else if (browser_) {
|
| - browser_->window()->Activate();
|
| + } else {
|
| + browser->window()->Activate();
|
| }
|
| }
|
|
|
| @@ -903,7 +905,7 @@ void DevToolsWindow::WebContentsCreated(WebContents* source_contents,
|
| }
|
|
|
| void DevToolsWindow::CloseContents(WebContents* source) {
|
| - CHECK(is_docked_);
|
| + CHECK(IsDocked());
|
| life_stage_ = kClosing;
|
| UpdateBrowserWindow();
|
| // In case of docked main_web_contents_, we own it so delete here.
|
| @@ -913,7 +915,7 @@ void DevToolsWindow::CloseContents(WebContents* source) {
|
| }
|
|
|
| void DevToolsWindow::ContentsZoomChange(bool zoom_in) {
|
| - DCHECK(is_docked_);
|
| + DCHECK(IsDocked());
|
| ui_zoom::PageZoom::Zoom(main_web_contents_, zoom_in ? content::PAGE_ZOOM_IN
|
| : content::PAGE_ZOOM_OUT);
|
| }
|
| @@ -998,14 +1000,18 @@ bool DevToolsWindow::PreHandleGestureEvent(
|
| void DevToolsWindow::ActivateWindow() {
|
| if (life_stage_ != kLoadCompleted)
|
| return;
|
| - if (is_docked_ && GetInspectedBrowserWindow())
|
| + bool is_docked = IsDocked();
|
| + if (is_docked && GetInspectedBrowserWindow()) {
|
| main_web_contents_->Focus();
|
| - else if (!is_docked_ && !browser_->window()->IsActive())
|
| - browser_->window()->Activate();
|
| + } else if (!is_docked) {
|
| + Browser* browser = GetBrowser();
|
| + if (!browser->window()->IsActive())
|
| + browser->window()->Activate();
|
| + }
|
| }
|
|
|
| void DevToolsWindow::CloseWindow() {
|
| - DCHECK(is_docked_);
|
| + DCHECK(IsDocked());
|
| life_stage_ = kClosing;
|
| main_web_contents_->DispatchBeforeUnload(false);
|
| }
|
| @@ -1035,8 +1041,8 @@ void DevToolsWindow::SetIsDocked(bool dock_requested) {
|
| if (!can_dock_)
|
| dock_requested = false;
|
|
|
| - bool was_docked = is_docked_;
|
| - is_docked_ = dock_requested;
|
| + bool was_docked = IsDocked();
|
| + dock_requested_ = dock_requested;
|
|
|
| if (life_stage_ != kLoadCompleted) {
|
| // This is a first time call we waited for to initialize.
|
| @@ -1050,12 +1056,7 @@ void DevToolsWindow::SetIsDocked(bool dock_requested) {
|
| return;
|
|
|
| if (dock_requested && !was_docked) {
|
| - // Detach window from the external devtools browser. It will lead to
|
| - // the browser object's close and delete. Remove observer first.
|
| - TabStripModel* tab_strip_model = browser_->tab_strip_model();
|
| - tab_strip_model->DetachWebContentsAt(
|
| - tab_strip_model->GetIndexOfWebContents(main_web_contents_));
|
| - browser_ = NULL;
|
| + DetachFromBrowser();
|
| } else if (!dock_requested && was_docked) {
|
| UpdateBrowserWindow();
|
| }
|
| @@ -1069,8 +1070,9 @@ void DevToolsWindow::OpenInNewTab(const std::string& url) {
|
| ui::PAGE_TRANSITION_LINK, false);
|
| WebContents* inspected_web_contents = GetInspectedWebContents();
|
| if (!inspected_web_contents || !inspected_web_contents->OpenURL(params)) {
|
| + Browser* browser = GetBrowser();
|
| chrome::HostDesktopType host_desktop_type =
|
| - browser_ ? browser_->host_desktop_type() : chrome::GetActiveDesktop();
|
| + browser ? browser->host_desktop_type() : chrome::GetActiveDesktop();
|
|
|
| chrome::ScopedTabbedBrowserDisplayer displayer(profile_, host_desktop_type);
|
| chrome::AddSelectedTabWithURL(displayer.browser(), GURL(url),
|
| @@ -1090,19 +1092,18 @@ void DevToolsWindow::InspectedContentsClosing() {
|
| }
|
|
|
| InfoBarService* DevToolsWindow::GetInfoBarService() {
|
| - return is_docked_ ?
|
| - InfoBarService::FromWebContents(GetInspectedWebContents()) :
|
| - InfoBarService::FromWebContents(main_web_contents_);
|
| + return IsDocked() ? InfoBarService::FromWebContents(GetInspectedWebContents())
|
| + : InfoBarService::FromWebContents(main_web_contents_);
|
| }
|
|
|
| void DevToolsWindow::RenderProcessGone(bool crashed) {
|
| // Docked DevToolsWindow owns its main_web_contents_ and must delete it.
|
| // Undocked main_web_contents_ are owned and handled by browser.
|
| // see crbug.com/369932
|
| - if (is_docked_) {
|
| + if (IsDocked()) {
|
| CloseContents(main_web_contents_);
|
| - } else if (browser_ && crashed) {
|
| - browser_->window()->Close();
|
| + } else if (crashed) {
|
| + DetachFromBrowser();
|
| }
|
| }
|
|
|
| @@ -1132,7 +1133,7 @@ void DevToolsWindow::OnLoadCompleted() {
|
| LoadCompleted();
|
| }
|
|
|
| -void DevToolsWindow::CreateDevToolsBrowser() {
|
| +Browser* DevToolsWindow::CreateDevToolsBrowser() {
|
| PrefService* prefs = profile_->GetPrefs();
|
| if (!prefs->GetDictionary(prefs::kAppWindowPlacement)->HasKey(kDevToolsApp)) {
|
| DictionaryPrefUpdate update(prefs, prefs::kAppWindowPlacement);
|
| @@ -1147,14 +1148,14 @@ void DevToolsWindow::CreateDevToolsBrowser() {
|
| dev_tools_defaults->SetBoolean("always_on_top", false);
|
| }
|
|
|
| - browser_ = new Browser(Browser::CreateParams::CreateForDevTools(
|
| - profile_,
|
| - chrome::GetHostDesktopTypeForNativeView(
|
| - main_web_contents_->GetNativeView())));
|
| - browser_->tab_strip_model()->AddWebContents(
|
| - main_web_contents_, -1, ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
|
| - TabStripModel::ADD_ACTIVE);
|
| + Browser* browser = new Browser(Browser::CreateParams::CreateForDevTools(
|
| + profile_, chrome::GetHostDesktopTypeForNativeView(
|
| + main_web_contents_->GetNativeView())));
|
| + browser->tab_strip_model()->AddWebContents(main_web_contents_, -1,
|
| + ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
|
| + TabStripModel::ADD_ACTIVE);
|
| main_web_contents_->GetRenderViewHost()->SyncRendererPrefs();
|
| + return browser;
|
| }
|
|
|
| BrowserWindow* DevToolsWindow::GetInspectedBrowserWindow() {
|
| @@ -1212,6 +1213,27 @@ void DevToolsWindow::UpdateBrowserWindow() {
|
| inspected_window->UpdateDevTools();
|
| }
|
|
|
| +Browser* DevToolsWindow::GetBrowser() {
|
| + return chrome::FindBrowserWithWebContents(main_web_contents_);
|
| +}
|
| +
|
| +bool DevToolsWindow::IsDocked() {
|
| + if (GetBrowser() != nullptr)
|
| + return false;
|
| + return dock_requested_;
|
| +}
|
| +
|
| +void DevToolsWindow::DetachFromBrowser() {
|
| + Browser* browser = GetBrowser();
|
| + if (browser) {
|
| + // Detach window from the external devtools browser. It will lead to
|
| + // the browser object's close and delete. Remove observer first.
|
| + TabStripModel* tab_strip_model = browser->tab_strip_model();
|
| + tab_strip_model->DetachWebContentsAt(
|
| + tab_strip_model->GetIndexOfWebContents(main_web_contents_));
|
| + }
|
| +}
|
| +
|
| WebContents* DevToolsWindow::GetInspectedWebContents() {
|
| return inspected_contents_observer_
|
| ? inspected_contents_observer_->web_contents()
|
|
|