diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 6d2f24fae4cf..1aa442f09d08 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -50,6 +50,7 @@ const char kDevToolsPreferences[] = "brightray.devtools.preferences"; 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; @@ -348,6 +349,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 31c30e1f3286..469677a1ae69 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/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index fbe19adaebda..0dbb7beb82ca 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -24,6 +24,7 @@ class InspectableWebContentsViewMac : 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_; diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index 6cd08da2f6aa..e676653953eb 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -50,4 +50,8 @@ void InspectableWebContentsViewMac::SetContentsResizingStrategy( [view_ setContentsResizingStrategy:strategy]; } +void InspectableWebContentsViewMac::SetTitle(const base::string16& title) { + [view_ setTitle:title]; +} + } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index ea6e3f9a8115..c3c5a1ada0f1 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -32,5 +32,6 @@ using brightray::InspectableWebContentsViewMac; - (BOOL)isDevToolsVisible; - (void)setIsDocked:(BOOL)docked; - (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy; +- (void)setTitle:(const base::string16&)title; @end diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index a7f4134b4fae..f2dac929739a 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -2,6 +2,7 @@ #import +#include "base/strings/sys_string_conversions.h" #include "browser/inspectable_web_contents_impl.h" #include "browser/inspectable_web_contents_view_mac.h" @@ -174,6 +175,13 @@ const CGFloat kRoundedCornerRadius = 4; [contentsView setFrame:[self flipRectToNSRect:new_contents_bounds]]; } +- (void)setTitle:(const base::string16&)title { + if (devtools_window_) { + NSString* title_string = base::SysUTF16ToNSString(title); + [devtools_window_ setTitle:title_string]; + } +} + // Creates a path whose bottom two corners are rounded. // Caller takes ownership of the path. - (CGPathRef)createRoundedBottomCornersPath:(NSSize)size { diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 8cae49db41e2..6a7dd75aa6f2 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 4e2503504632..a6c3ae62f8c5 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); };