Skip to content

Commit

Permalink
fix: devtools allow restoring saved dock state on Windows (#39768)
Browse files Browse the repository at this point in the history
* fix: devtools allow restoring saved dock state on Windows

Co-authored-by: deepak1556 <hop2deep@gmail.com>

* chore: address feedback

Co-authored-by: deepak1556 <hop2deep@gmail.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
  • Loading branch information
trop[bot] and deepak1556 committed Sep 7, 2023
1 parent c9d2d69 commit a3acea9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
8 changes: 0 additions & 8 deletions shell/browser/api/electron_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2671,14 +2671,6 @@ void WebContents::OpenDevTools(gin::Arguments* args) {
state = "detach";
}

#if BUILDFLAG(IS_WIN)
auto* win = static_cast<NativeWindowViews*>(owner_window());
// Force a detached state when WCO is enabled to match Chrome
// behavior and prevent occlusion of DevTools.
if (win && win->IsWindowControlsOverlayEnabled())
state = "detach";
#endif

bool activate = true;
if (args && args->Length() == 1) {
gin_helper::Dictionary options;
Expand Down
7 changes: 0 additions & 7 deletions shell/browser/browser_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@

namespace {

bool IsAppRTL() {
const std::string& locale = g_browser_process->GetApplicationLocale();
base::i18n::TextDirection text_direction =
base::i18n::GetTextDirectionForLocaleInStartUp(locale.c_str());
return text_direction == base::i18n::RIGHT_TO_LEFT;
}

NSString* GetAppPathForProtocol(const GURL& url) {
NSURL* ns_url = [NSURL
URLWithString:base::SysUTF8ToNSString(url.possibly_invalid_spec())];
Expand Down
19 changes: 19 additions & 0 deletions shell/browser/ui/inspectable_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
#include "shell/browser/api/electron_api_web_contents.h"
#include "shell/browser/native_window_views.h"
#include "shell/browser/net/asar/asar_url_loader_factory.h"
#include "shell/browser/protocol_registry.h"
#include "shell/browser/ui/inspectable_web_contents_delegate.h"
#include "shell/browser/ui/inspectable_web_contents_view.h"
#include "shell/browser/ui/inspectable_web_contents_view_delegate.h"
#include "shell/common/application_info.h"
#include "shell/common/platform_util.h"
#include "third_party/blink/public/common/logging/logging_utils.h"
#include "third_party/blink/public/common/page/page_zoom.h"
Expand Down Expand Up @@ -573,6 +575,23 @@ void InspectableWebContents::LoadCompleted() {
prefs.FindString("currentDockState");
base::RemoveChars(*current_dock_state, "\"", &dock_state_);
}
#if BUILDFLAG(IS_WIN)
auto* api_web_contents = api::WebContents::From(GetWebContents());
if (api_web_contents) {
auto* win =
static_cast<NativeWindowViews*>(api_web_contents->owner_window());
// When WCO is enabled, undock the devtools if the current dock
// position overlaps with the position of window controls to avoid
// broken layout.
if (win && win->IsWindowControlsOverlayEnabled()) {
if (IsAppRTL() && dock_state_ == "left") {
dock_state_ = "undocked";
} else if (dock_state_ == "right") {
dock_state_ = "undocked";
}
}
}
#endif
std::u16string javascript = base::UTF8ToUTF16(
"UI.DockController.instance().setDockSide(\"" + dock_state_ + "\");");
GetDevToolsWebContents()->GetPrimaryMainFrame()->ExecuteJavaScript(
Expand Down
9 changes: 9 additions & 0 deletions shell/common/application_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#include "shell/common/application_info.h"

#include "base/i18n/rtl.h"
#include "base/no_destructor.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_version.h"
#include "content/public/common/user_agent.h"
#include "electron/electron_version.h"
Expand Down Expand Up @@ -47,4 +49,11 @@ std::string GetApplicationUserAgent() {
return content::BuildUserAgentFromProduct(user_agent);
}

bool IsAppRTL() {
const std::string& locale = g_browser_process->GetApplicationLocale();
base::i18n::TextDirection text_direction =
base::i18n::GetTextDirectionForLocaleInStartUp(locale.c_str());
return text_direction == base::i18n::RIGHT_TO_LEFT;
}

} // namespace electron
2 changes: 2 additions & 0 deletions shell/common/application_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ std::string GetApplicationVersion();
// Returns the user agent of Electron.
std::string GetApplicationUserAgent();

bool IsAppRTL();

#if BUILDFLAG(IS_WIN)
PCWSTR GetRawAppUserModelID();
bool GetAppUserModelID(ScopedHString* app_id);
Expand Down

0 comments on commit a3acea9

Please sign in to comment.