Remember where the dev tools were docked between launches

This commit is contained in:
Adam Roben 2013-04-08 13:53:53 -04:00
parent a2a2cd1936
commit 3c513d6ae8
5 changed files with 62 additions and 4 deletions

View file

@ -4,6 +4,7 @@
#include "browser_context.h"
#include "browser/inspectable_web_contents_impl.h"
#include "common/application_info.h"
#include "base/files/file_path.h"
@ -46,6 +47,7 @@ BrowserContext::BrowserContext() : resource_context_(new ResourceContext) {
JsonPrefStore::GetTaskRunnerForFile(prefs_path, content::BrowserThread::GetBlockingPool()));
auto registry = make_scoped_refptr(new PrefRegistrySimple);
RegisterInternalPrefs(registry);
RegisterPrefs(registry);
prefs_.reset(builder.Create(registry));
@ -54,6 +56,10 @@ BrowserContext::BrowserContext() : resource_context_(new ResourceContext) {
BrowserContext::~BrowserContext() {
}
void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) {
InspectableWebContentsImpl::RegisterPrefs(registry);
}
net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::ProtocolHandlerMap* protocol_handlers) {
DCHECK(!url_request_getter_);
url_request_getter_ = new URLRequestContextGetter(

View file

@ -31,6 +31,8 @@ protected:
private:
class ResourceContext;
void RegisterInternalPrefs(PrefRegistrySimple*);
virtual base::FilePath GetPath() OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;

View file

@ -6,9 +6,12 @@
#include "browser/inspectable_web_contents_impl.h"
#include "browser/browser_client.h"
#include "browser/browser_context.h"
#include "browser/browser_main_parts.h"
#include "browser/inspectable_web_contents_view.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "content/public/browser/devtools_agent_host.h"
@ -20,11 +23,24 @@
namespace brightray {
namespace {
const char kDockSidePref[] = "brightray.devtools.dockside";
}
// Implemented separately on each platform.
InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl*);
void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterStringPref(kDockSidePref, "bottom");
}
InspectableWebContentsImpl::InspectableWebContentsImpl(const content::WebContents::CreateParams& create_params)
: web_contents_(content::WebContents::Create(create_params)) {
auto context = static_cast<BrowserContext*>(web_contents_->GetBrowserContext());
dock_side_ = context->prefs()->GetString(kDockSidePref);
view_.reset(CreateInspectableContentsView(this));
}
@ -54,9 +70,15 @@ void InspectableWebContentsImpl::ShowDevTools() {
devtools_web_contents_->GetController().LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
}
view_->SetDockSide(dock_side_);
view_->ShowDevTools();
}
void InspectableWebContentsImpl::UpdateFrontendDockSide() {
auto javascript = base::StringPrintf("InspectorFrontendAPI.setDockSide(\"%s\")", dock_side_.c_str());
devtools_web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(javascript));
}
void InspectableWebContentsImpl::ActivateWindow() {
}
@ -76,8 +98,12 @@ void InspectableWebContentsImpl::SetDockSide(const std::string& side) {
if (!view_->SetDockSide(side))
return;
auto javascript = base::StringPrintf("InspectorFrontendAPI.setDockSide(\"%s\")", side.c_str());
devtools_web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(javascript));
dock_side_ = side;
auto context = static_cast<BrowserContext*>(web_contents_->GetBrowserContext());
context->prefs()->SetString(kDockSidePref, side);
UpdateFrontendDockSide();
}
void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) {
@ -106,6 +132,13 @@ void InspectableWebContentsImpl::RenderViewCreated(content::RenderViewHost* rend
content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get());
}
void InspectableWebContentsImpl::DidFinishLoad(int64, const GURL&, bool is_main_frame, content::RenderViewHost*) {
if (!is_main_frame)
return;
UpdateFrontendDockSide();
}
void InspectableWebContentsImpl::WebContentsDestroyed(content::WebContents*) {
content::DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_.get());
Observe(nullptr);

View file

@ -1,3 +1,8 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2013 Adam Roben <adam@roben.org>. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-CHROMIUM file.
#ifndef BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_IMPL_H_
#define BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_IMPL_H_
@ -7,6 +12,8 @@
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
class PrefRegistrySimple;
namespace content {
class DevToolsAgentHost;
class DevToolsClientHost;
@ -22,6 +29,8 @@ class InspectableWebContentsImpl :
content::WebContentsObserver,
content::WebContentsDelegate {
public:
static void RegisterPrefs(PrefRegistrySimple*);
InspectableWebContentsImpl(const content::WebContents::CreateParams&);
virtual ~InspectableWebContentsImpl() OVERRIDE;
@ -33,6 +42,8 @@ public:
content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); }
private:
void UpdateFrontendDockSide();
// content::DevToolsFrontendHostDelegate
virtual void ActivateWindow() OVERRIDE;
@ -54,6 +65,10 @@ private:
// content::WebContentsObserver
virtual void RenderViewCreated(content::RenderViewHost*) OVERRIDE;
virtual void DidFinishLoad(int64 frame_id,
const GURL& validated_url,
bool is_main_frame,
content::RenderViewHost*) OVERRIDE;
virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE;
// content::WebContentsDelegate
@ -65,6 +80,7 @@ private:
scoped_ptr<InspectableWebContentsView> view_;
scoped_refptr<content::DevToolsAgentHost> agent_host_;
scoped_ptr<content::DevToolsClientHost> frontend_host_;
std::string dock_side_;
DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl);
};

View file

@ -13,6 +13,7 @@ using namespace brightray;
InspectableWebContentsViewMac *inspectableWebContentsView;
NSSplitView *splitView;
NSWindow *window;
BOOL visible;
}
@end
@ -58,9 +59,9 @@ NSRect devtoolsWindowFrame(NSView *referenceView) {
}
- (void)setDevToolsVisible:(BOOL)visible {
BOOL wasVisible = _private->splitView.subviews.count == 2;
if (wasVisible == visible)
if (_private->visible == visible)
return;
_private->visible = visible;
auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents();
auto devToolsView = devToolsWebContents->GetView()->GetNativeView();