allow updating devtools title in undocked mode

This commit is contained in:
Robo 2015-08-07 14:30:49 +05:30
parent 97cf8ca609
commit 1f65b47e8e
4 changed files with 36 additions and 8 deletions

View file

@ -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(

View file

@ -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.

View file

@ -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());

View file

@ -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);
};