From 4c9870e75333c720018e71c0ed3bea9b548217d5 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 4 Jun 2013 14:17:16 -0400 Subject: [PATCH 1/2] Fix debug assertion about performing IO on the UI thread We were querying the application's FILEVERSIONINFO every time we needed to figure out the path for storing BrowserContext data. Now we cache the path the first time we need it, which is during application initialization and before IO prohibitions begin. --- brightray/browser/browser_context.cc | 6 +++++- brightray/browser/browser_context.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index c8b923977d..17ff9b2269 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -72,9 +72,13 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::Prot } base::FilePath BrowserContext::GetPath() { + if (!path_.empty()) + return path_; + base::FilePath path; CHECK(PathService::Get(base::DIR_APP_DATA, &path)); - return path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); + path_ = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); + return path_; } bool BrowserContext::IsOffTheRecord() const { diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 47feccd042..a83e016e43 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -46,6 +46,7 @@ private: virtual content::SpeechRecognitionPreferences* GetSpeechRecognitionPreferences() OVERRIDE; virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; + base::FilePath path_; scoped_ptr resource_context_; scoped_refptr url_request_getter_; scoped_ptr prefs_; From 9ad77c4a3803060cef8ec8f21db870075c550076 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 4 Jun 2013 14:31:37 -0400 Subject: [PATCH 2/2] Implement undocked dev tools on Windows DevToolsWindow represents a vanilla top-level window that shows the dev tools. It uses ui::WindowImpl to implement window functionality, which requires a newer libchromiumcontent which contains the necessary headers for using that class, and requires some modifications to brightray.gypi to make WTL's headers available. * vendor/libchromiumcontent 2f53a96...fc02d93 (4): > Export third_party/wtl/include headers > Export test_support_base.pdb and test_support_content.pdb > Fix linker errors with test_support_base on Windows > Fix linker errors with base_prefs_test_support on Windows --- brightray/brightray.gyp | 2 + brightray/brightray.gypi | 7 +++ brightray/browser/win/devtools_window.cc | 47 +++++++++++++++++++ brightray/browser/win/devtools_window.h | 36 ++++++++++++++ .../win/inspectable_web_contents_view_win.cc | 25 ++++++++++ .../win/inspectable_web_contents_view_win.h | 4 ++ brightray/vendor/libchromiumcontent | 2 +- 7 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 brightray/browser/win/devtools_window.cc create mode 100644 brightray/browser/win/devtools_window.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 2ac4227220..71616f36a5 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -50,6 +50,8 @@ 'browser/notification_presenter_mac.mm', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', + 'browser/win/devtools_window.cc', + 'browser/win/devtools_window.h', 'browser/win/inspectable_web_contents_view_win.cc', 'browser/win/inspectable_web_contents_view_win.h', 'common/application_info.h', diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 69513546df..828fc55046 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -171,6 +171,9 @@ 'conditions': [ ['OS=="win"', { 'target_defaults': { + 'include_dirs': [ + '<(libchromiumcontent_include_dir)/third_party/wtl/include', + ], 'defines': [ '_WIN32_WINNT=0x0602', 'WINVER=0x0602', @@ -182,6 +185,10 @@ 'CERT_CHAIN_PARA_HAS_EXTRA_FIELDS', 'WIN32_LEAN_AND_MEAN', '_ATL_NO_OPENGL', + '_SECURE_ATL', + ], + 'msvs_system_include_dirs': [ + '$(VSInstallDir)/VC/atlmfc/include', ], 'msvs_settings': { 'VCCLCompilerTool': { diff --git a/brightray/browser/win/devtools_window.cc b/brightray/browser/win/devtools_window.cc new file mode 100644 index 0000000000..8bed3e89f7 --- /dev/null +++ b/brightray/browser/win/devtools_window.cc @@ -0,0 +1,47 @@ +#include "browser/win/devtools_window.h" + +#include "browser/inspectable_web_contents_impl.h" +#include "browser/win/inspectable_web_contents_view_win.h" + +#include "content/public/browser/web_contents_view.h" +#include "ui/base/win/hidden_window.h" + +namespace brightray { + +DevToolsWindow* DevToolsWindow::Create(InspectableWebContentsViewWin* controller) { + return new DevToolsWindow(controller); +} + +DevToolsWindow::DevToolsWindow(InspectableWebContentsViewWin* controller) + : controller_(controller) { +} + +DevToolsWindow::~DevToolsWindow() { +} + +LRESULT DevToolsWindow::OnCreate(UINT, WPARAM, LPARAM, BOOL&) { + SetParent(controller_->inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(), hwnd()); + SetWindowText(hwnd(), L"Developer Tools"); + return 0; +} + +LRESULT DevToolsWindow::OnDestroy(UINT, WPARAM, LPARAM, BOOL&) { + SetParent(controller_->inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(), ui::GetHiddenWindow()); + delete this; + return 0; +} + +LRESULT DevToolsWindow::OnSize(UINT, WPARAM, LPARAM, BOOL&) { + RECT rect; + GetClientRect(hwnd(), &rect); + + SetWindowPos(controller_->inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(), + nullptr, + rect.left, rect.top, + rect.right - rect.left, rect.bottom - rect.top, + SWP_NOZORDER | SWP_SHOWWINDOW); + + return 0; +} + +} diff --git a/brightray/browser/win/devtools_window.h b/brightray/browser/win/devtools_window.h new file mode 100644 index 0000000000..7181ab8e4d --- /dev/null +++ b/brightray/browser/win/devtools_window.h @@ -0,0 +1,36 @@ +#ifndef BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_ +#define BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_ + +#include "base/memory/weak_ptr.h" +#include "ui/base/win/window_impl.h" + +namespace brightray { + +class InspectableWebContentsViewWin; + +class DevToolsWindow : public ui::WindowImpl, public base::SupportsWeakPtr { + public: + static DevToolsWindow* Create(InspectableWebContentsViewWin*); + + BEGIN_MSG_MAP_EX(DevToolsWindow) + MESSAGE_HANDLER(WM_CREATE, OnCreate) + MESSAGE_HANDLER(WM_DESTROY, OnDestroy) + MESSAGE_HANDLER(WM_SIZE, OnSize) + END_MSG_MAP() + + private: + DevToolsWindow(InspectableWebContentsViewWin*); + ~DevToolsWindow(); + + LRESULT OnCreate(UINT message, WPARAM, LPARAM, BOOL& handled); + LRESULT OnDestroy(UINT message, WPARAM, LPARAM, BOOL& handled); + LRESULT OnSize(UINT message, WPARAM, LPARAM, BOOL& handled); + + InspectableWebContentsViewWin* controller_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); +}; + +} + +#endif diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index deab04590c..c6161286c2 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -1,11 +1,20 @@ #include "browser/win/inspectable_web_contents_view_win.h" +#include "browser/browser_client.h" #include "browser/inspectable_web_contents_impl.h" +#include "browser/win/devtools_window.h" #include "content/public/browser/web_contents_view.h" +#include "ui/base/win/hwnd_util.h" namespace brightray { +namespace { + +const int kWindowInset = 100; + +} + InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) { return new InspectableWebContentsViewWin(inspectable_web_contents); } @@ -15,6 +24,8 @@ InspectableWebContentsViewWin::InspectableWebContentsViewWin(InspectableWebConte } InspectableWebContentsViewWin::~InspectableWebContentsViewWin() { + if (devtools_window_) + DestroyWindow(devtools_window_->hwnd()); } gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { @@ -22,9 +33,23 @@ gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { } void InspectableWebContentsViewWin::ShowDevTools() { + if (!devtools_window_) { + devtools_window_ = DevToolsWindow::Create(this)->AsWeakPtr(); + devtools_window_->Init(HWND_DESKTOP, gfx::Rect()); + } + + auto contents_view = inspectable_web_contents_->GetWebContents()->GetView(); + auto size = contents_view->GetContainerSize(); + size.Enlarge(-kWindowInset, -kWindowInset); + ui::CenterAndSizeWindow(contents_view->GetNativeView(), devtools_window_->hwnd(), size); + + ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL); } void InspectableWebContentsViewWin::CloseDevTools() { + if (!devtools_window_) + return; + SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); } bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) { diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index 801eb93136..8f5816fb4e 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -4,9 +4,11 @@ #include "browser/inspectable_web_contents_view.h" #include "base/compiler_specific.h" +#include "base/memory/weak_ptr.h" namespace brightray { +class DevToolsWindow; class InspectableWebContentsImpl; class InspectableWebContentsViewWin : public InspectableWebContentsView { @@ -25,6 +27,8 @@ private: // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; + base::WeakPtr devtools_window_; + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewWin); }; diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 2f53a96fc6..fc02d9380a 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 2f53a96fc665176d7e07b67bac6d861295587ce8 +Subproject commit fc02d9380a52ed648196ea6a0d9053483f233658