diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 26fcc2b0f0f4..79143aa122c9 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -15,6 +15,7 @@ #include "base/prefs/pref_service.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" +#include "base/values.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_client_host.h" #include "content/public/browser/devtools_http_handler.h" @@ -27,22 +28,45 @@ namespace brightray { namespace { const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?can_dock=true"; -const char kIsDockedPref[] = "brightray.devtools.isDocked"; +const char kDevToolsBoundsPref[] = "brightray.devtools.bounds"; +void RectToDictionary(const gfx::Rect& bounds, base::DictionaryValue* dict) { + dict->SetInteger("x", bounds.x()); + dict->SetInteger("y", bounds.y()); + dict->SetInteger("width", bounds.width()); + dict->SetInteger("height", bounds.height()); } +void DictionaryToRect(const base::DictionaryValue& dict, gfx::Rect* bounds) { + int x = 0, y = 0, width = 800, height = 600; + dict.GetInteger("x", &x); + dict.GetInteger("y", &y); + dict.GetInteger("width", &width); + dict.GetInteger("height", &height); + *bounds = gfx::Rect(x, y, width, height); +} + +} // namespace + // Implemented separately on each platform. InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsImpl* inspectable_web_contents_impl); void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { - registry->RegisterBooleanPref(kIsDockedPref, true); + scoped_ptr bounds_dict(new base::DictionaryValue); + RectToDictionary(gfx::Rect(0, 0, 800, 600), bounds_dict.get()); + registry->RegisterDictionaryPref(kDevToolsBoundsPref, bounds_dict.release()); } InspectableWebContentsImpl::InspectableWebContentsImpl( content::WebContents* web_contents) : web_contents_(web_contents), delegate_(nullptr) { + auto context = static_cast(web_contents_->GetBrowserContext()); + auto bounds_dict = context->prefs()->GetDictionary(kDevToolsBoundsPref); + if (bounds_dict) + DictionaryToRect(*bounds_dict, &devtools_bounds_); + view_.reset(CreateInspectableContentsView(this)); } @@ -102,6 +126,18 @@ bool InspectableWebContentsImpl::IsDevToolsViewShowing() { return devtools_web_contents_ && view_->IsDevToolsViewShowing(); } +gfx::Rect InspectableWebContentsImpl::GetDevToolsBounds() const { + return devtools_bounds_; +} + +void InspectableWebContentsImpl::SaveDevToolsBounds(const gfx::Rect& bounds) { + auto context = static_cast(web_contents_->GetBrowserContext()); + base::DictionaryValue bounds_dict; + RectToDictionary(bounds, &bounds_dict); + context->prefs()->Set(kDevToolsBoundsPref, bounds_dict); + devtools_bounds_ = bounds; +} + void InspectableWebContentsImpl::ActivateWindow() { } diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 5c030a449f66..d02fd75400f0 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -14,6 +14,7 @@ #include "content/public/browser/devtools_frontend_host_delegate.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" +#include "ui/gfx/rect.h" class PrefRegistrySimple; @@ -46,6 +47,10 @@ class InspectableWebContentsImpl : virtual void CloseDevTools() OVERRIDE; virtual bool IsDevToolsViewShowing() OVERRIDE; + // Return the last position and size of devtools window. + gfx::Rect GetDevToolsBounds() const; + void SaveDevToolsBounds(const gfx::Rect& bounds); + virtual void SetDelegate(InspectableWebContentsDelegate* delegate) { delegate_ = delegate; } @@ -106,6 +111,7 @@ class InspectableWebContentsImpl : scoped_refptr agent_host_; DevToolsContentsResizingStrategy contents_resizing_strategy_; + gfx::Rect devtools_bounds_; scoped_ptr embedder_message_dispatcher_; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 99c2e4179a06..045f389f72be 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -95,7 +95,7 @@ using namespace brightray; backing:NSBackingStoreBuffered defer:YES]); [devtools_window_ setDelegate:self]; - [devtools_window_ setFrameAutosaveName:@"brightray.developer.tools"]; + [devtools_window_ setFrameAutosaveName:@"brightray.devtools"]; [devtools_window_ setTitle:@"Developer Tools"]; [devtools_window_ setReleasedWhenClosed:NO]; [devtools_window_ setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge]; diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index b2013dc85e7f..03a052b1f792 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -29,7 +29,7 @@ class DevToolsWindowDelegate : public views::ClientView, // views::WidgetDelegate: virtual views::View* GetInitiallyFocusedView() OVERRIDE { return view_; } virtual bool CanResize() const OVERRIDE { return true; } - virtual bool CanMaximize() const OVERRIDE { return true; } + virtual bool CanMaximize() const OVERRIDE { return false; } virtual base::string16 GetWindowTitle() const OVERRIDE { return title_; } virtual views::Widget* GetWidget() OVERRIDE { return widget_; } virtual const views::Widget* GetWidget() const OVERRIDE { return widget_; } @@ -74,6 +74,8 @@ InspectableWebContentsViewViews::InspectableWebContentsViewViews( } InspectableWebContentsViewViews::~InspectableWebContentsViewViews() { + if (devtools_window_) + inspectable_web_contents()->SaveDevToolsBounds(devtools_window_->GetWindowBoundsInScreen()); } views::View* InspectableWebContentsViewViews::GetView() { @@ -95,7 +97,7 @@ void InspectableWebContentsViewViews::ShowDevTools() { devtools_visible_ = true; if (devtools_window_) { devtools_window_web_view_->SetWebContents(inspectable_web_contents_->devtools_web_contents()); - devtools_window_->CenterWindow(gfx::Size(800, 600)); + devtools_window_->SetBounds(inspectable_web_contents()->GetDevToolsBounds()); devtools_window_->Show(); } else { devtools_web_view_->SetVisible(true); @@ -111,6 +113,7 @@ void InspectableWebContentsViewViews::CloseDevTools() { devtools_visible_ = false; if (devtools_window_) { + inspectable_web_contents()->SaveDevToolsBounds(devtools_window_->GetWindowBoundsInScreen()); devtools_window_.reset(); devtools_window_web_view_ = NULL; } else {