From 1f65b47e8e0ca737fec59b995449419da23f34a0 Mon Sep 17 00:00:00 2001 From: Robo Date: Fri, 7 Aug 2015 14:30:49 +0530 Subject: [PATCH] allow updating devtools title in undocked mode --- .../browser/inspectable_web_contents_impl.cc | 4 +++ .../browser/inspectable_web_contents_view.h | 2 ++ .../inspectable_web_contents_view_views.cc | 28 +++++++++++++------ .../inspectable_web_contents_view_views.h | 10 +++++++ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index c3df837943e..f66c23b81f3 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -23,6 +23,7 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/host_zoom_map.h" +#include "content/public/browser/navigation_entry.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_view_host.h" #include "net/http/http_response_headers.h" @@ -49,6 +50,7 @@ const char kDevToolsZoomPref[] = "brightray.devtools.zoom"; const char kFrontendHostId[] = "id"; const char kFrontendHostMethod[] = "method"; const char kFrontendHostParams[] = "params"; +const char kTitleFormat[] = "Developer Tools - %s"; const char kDevToolsActionTakenHistogram[] = "DevTools.ActionTaken"; const int kDevToolsActionTakenBoundary = 100; @@ -346,6 +348,8 @@ void InspectableWebContentsImpl::InspectElementCompleted() { } void InspectableWebContentsImpl::InspectedURLChanged(const std::string& url) { + view_->SetTitle(base::UTF8ToUTF16(base::StringPrintf(kTitleFormat, + url.c_str()))); } void InspectableWebContentsImpl::LoadNetworkResource( diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index 31c30e1f328..469677a1ae6 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -1,6 +1,7 @@ #ifndef BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_H_ #define BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_H_ +#include "base/strings/string16.h" #include "ui/gfx/native_widget_types.h" class DevToolsContentsResizingStrategy; @@ -46,6 +47,7 @@ class InspectableWebContentsView { virtual void SetIsDocked(bool docked) = 0; virtual void SetContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy) = 0; + virtual void SetTitle(const base::string16& title) = 0; private: InspectableWebContentsViewDelegate* delegate_; // weak references. diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 8cae49db41e..6a7dd75aa6f 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -33,6 +33,8 @@ class DevToolsWindowDelegate : public views::ClientView, } virtual ~DevToolsWindowDelegate() {} + void SetWindowTitle(const base::string16& title) { title_ = title; } + // views::WidgetDelegate: void DeleteDelegate() override { delete this; } views::View* GetInitiallyFocusedView() override { return view_; } @@ -73,10 +75,11 @@ InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsViewViews::InspectableWebContentsViewViews( InspectableWebContentsImpl* inspectable_web_contents) : inspectable_web_contents_(inspectable_web_contents), - devtools_window_web_view_(NULL), - contents_web_view_(new views::WebView(NULL)), - devtools_web_view_(new views::WebView(NULL)), - devtools_visible_(false) { + devtools_window_web_view_(nullptr), + contents_web_view_(new views::WebView(nullptr)), + devtools_web_view_(new views::WebView(nullptr)), + devtools_visible_(false), + devtools_window_delegate_(nullptr) { set_owned_by_client(); devtools_web_view_->SetVisible(false); @@ -127,7 +130,8 @@ void InspectableWebContentsViewViews::CloseDevTools() { if (devtools_window_) { inspectable_web_contents()->SaveDevToolsBounds(devtools_window_->GetWindowBoundsInScreen()); devtools_window_.reset(); - devtools_window_web_view_ = NULL; + devtools_window_web_view_ = nullptr; + devtools_window_delegate_ = nullptr; } else { devtools_web_view_->SetVisible(false); devtools_web_view_->SetWebContents(NULL); @@ -147,12 +151,13 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { if (!docked) { devtools_window_.reset(new views::Widget); devtools_window_web_view_ = new views::WebView(NULL); + devtools_window_delegate_ = new DevToolsWindowDelegate(this, + devtools_window_web_view_, + devtools_window_.get()); views::Widget::InitParams params; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - params.delegate = new DevToolsWindowDelegate(this, - devtools_window_web_view_, - devtools_window_.get()); + params.delegate = GetDevToolsWindowDelegate(); params.bounds = inspectable_web_contents()->GetDevToolsBounds(); #if defined(USE_X11) @@ -174,6 +179,13 @@ void InspectableWebContentsViewViews::SetContentsResizingStrategy( Layout(); } +void InspectableWebContentsViewViews::SetTitle(const base::string16& title) { + if (devtools_window_) { + GetDevToolsWindowDelegate()->SetWindowTitle(title); + devtools_window_->UpdateWindowTitle(); + } +} + void InspectableWebContentsViewViews::Layout() { if (!devtools_web_view_->visible()) { contents_web_view_->SetBoundsRect(GetContentsBounds()); diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index 4e250350463..a6c3ae62f8c 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -14,6 +14,10 @@ class Widget; namespace brightray { +namespace { +class DevToolsWindowDelegate; +} + class InspectableWebContentsImpl; class InspectableWebContentsViewViews : public InspectableWebContentsView, @@ -23,6 +27,10 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, InspectableWebContentsImpl* inspectable_web_contents_impl); ~InspectableWebContentsViewViews(); + DevToolsWindowDelegate* GetDevToolsWindowDelegate() const { + return devtools_window_delegate_; + } + // InspectableWebContentsView: views::View* GetView() override; views::View* GetWebView() override; @@ -32,6 +40,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, void SetIsDocked(bool docked) override; void SetContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy) override; + void SetTitle(const base::string16& title) override; InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; @@ -51,6 +60,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, DevToolsContentsResizingStrategy strategy_; bool devtools_visible_; + DevToolsWindowDelegate* devtools_window_delegate_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewViews); };