Skip to content

Commit

Permalink
refactor: move devtools from brightray to atom
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Oct 18, 2018
1 parent dffe4fd commit db13c23
Show file tree
Hide file tree
Showing 58 changed files with 311 additions and 396 deletions.
2 changes: 1 addition & 1 deletion atom/browser/api/atom_api_browser_window.h
Expand Up @@ -82,7 +82,7 @@ class BrowserWindow : public TopLevelWindow,

private:
#if defined(OS_MACOSX)
void OverrideNSWindowContentView(brightray::InspectableWebContents* iwc);
void OverrideNSWindowContentView(InspectableWebContents* iwc);
#endif

// Helpers.
Expand Down
5 changes: 2 additions & 3 deletions atom/browser/api/atom_api_browser_window_mac.mm
Expand Up @@ -8,9 +8,9 @@

#include "atom/browser/native_browser_view.h"
#include "atom/browser/native_window_mac.h"
#include "atom/browser/ui/inspectable_web_contents_view.h"
#include "atom/common/draggable_region.h"
#include "base/mac/scoped_nsobject.h"
#include "brightray/browser/inspectable_web_contents_view.h"

@interface NSView (WebContentsView)
- (void)setMouseDownCanMoveWindow:(BOOL)can_move;
Expand Down Expand Up @@ -55,8 +55,7 @@ - (NSView*)hitTest:(NSPoint)aPoint {

} // namespace

void BrowserWindow::OverrideNSWindowContentView(
brightray::InspectableWebContents* iwc) {
void BrowserWindow::OverrideNSWindowContentView(InspectableWebContents* iwc) {
// Make NativeWindow use a NSView as content view.
static_cast<NativeWindowMac*>(window())->OverrideNSWindowContentView();
// Add webview to contentView.
Expand Down
4 changes: 2 additions & 2 deletions atom/browser/api/atom_api_web_contents.cc
Expand Up @@ -22,6 +22,8 @@
#include "atom/browser/native_window.h"
#include "atom/browser/net/atom_network_delegate.h"
#include "atom/browser/ui/drag_util.h"
#include "atom/browser/ui/inspectable_web_contents.h"
#include "atom/browser/ui/inspectable_web_contents_view.h"
#include "atom/browser/web_contents_permission_helper.h"
#include "atom/browser/web_contents_preferences.h"
#include "atom/browser/web_contents_zoom_controller.h"
Expand All @@ -48,8 +50,6 @@
#include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h"
#include "brightray/browser/inspectable_web_contents.h"
#include "brightray/browser/inspectable_web_contents_view.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/ssl/security_state_tab_helper.h"
#include "content/browser/frame_host/frame_tree_node.h"
Expand Down
5 changes: 1 addition & 4 deletions atom/browser/api/atom_api_web_contents.h
Expand Up @@ -29,10 +29,6 @@ namespace blink {
struct WebDeviceEmulationParams;
}

namespace brightray {
class InspectableWebContents;
}

namespace mate {
class Arguments;
class Dictionary;
Expand All @@ -46,6 +42,7 @@ namespace atom {

class AtomBrowserContext;
class AtomJavaScriptDialogManager;
class InspectableWebContents;
class WebContentsZoomController;
class WebViewGuestDelegate;
class FrameSubscriber;
Expand Down
4 changes: 2 additions & 2 deletions atom/browser/api/atom_api_web_contents_view.cc
Expand Up @@ -5,8 +5,8 @@
#include "atom/browser/api/atom_api_web_contents_view.h"

#include "atom/browser/api/atom_api_web_contents.h"
#include "atom/browser/ui/inspectable_web_contents_view.h"
#include "atom/common/api/constructor.h"
#include "brightray/browser/inspectable_web_contents_view.h"
#include "content/public/browser/web_contents_user_data.h"
#include "native_mate/dictionary.h"

Expand Down Expand Up @@ -43,7 +43,7 @@ namespace api {

WebContentsView::WebContentsView(v8::Isolate* isolate,
mate::Handle<WebContents> web_contents,
brightray::InspectableWebContents* iwc)
InspectableWebContents* iwc)
#if defined(OS_MACOSX)
: View(new DelayedNativeViewHost(iwc->GetView()->GetNativeView())),
#else
Expand Down
8 changes: 3 additions & 5 deletions atom/browser/api/atom_api_web_contents_view.h
Expand Up @@ -9,12 +9,10 @@
#include "content/public/browser/web_contents_observer.h"
#include "native_mate/handle.h"

namespace brightray {
class InspectableWebContents;
}

namespace atom {

class InspectableWebContents;

namespace api {

class WebContents;
Expand All @@ -30,7 +28,7 @@ class WebContentsView : public View, public content::WebContentsObserver {
protected:
WebContentsView(v8::Isolate* isolate,
mate::Handle<WebContents> web_contents,
brightray::InspectableWebContents* iwc);
InspectableWebContents* iwc);
~WebContentsView() override;

// content::WebContentsObserver:
Expand Down
11 changes: 11 additions & 0 deletions atom/browser/atom_browser_client.cc
Expand Up @@ -26,6 +26,7 @@
#include "atom/browser/notifications/notification_presenter.h"
#include "atom/browser/notifications/platform_notification_service.h"
#include "atom/browser/session_preferences.h"
#include "atom/browser/ui/devtools_manager_delegate.h"
#include "atom/browser/web_contents_permission_helper.h"
#include "atom/browser/web_contents_preferences.h"
#include "atom/browser/window_list.h"
Expand Down Expand Up @@ -494,6 +495,11 @@ void AtomBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
additional_schemes->push_back(content::kChromeDevToolsScheme);
}

void AtomBrowserClient::GetAdditionalWebUISchemes(
std::vector<std::string>* additional_schemes) {
additional_schemes->push_back(content::kChromeDevToolsScheme);
}

void AtomBrowserClient::SiteInstanceDeleting(
content::SiteInstance* site_instance) {
// We are storing weak_ptr, is it fundamental to maintain the map up-to-date
Expand Down Expand Up @@ -677,6 +683,11 @@ AtomBrowserClient::CreateThrottlesForNavigation(
return throttles;
}

content::DevToolsManagerDelegate*
AtomBrowserClient::GetDevToolsManagerDelegate() {
return new DevToolsManagerDelegate;
}

NotificationPresenter* AtomBrowserClient::GetNotificationPresenter() {
if (!notification_presenter_) {
notification_presenter_.reset(NotificationPresenter::Create());
Expand Down
5 changes: 4 additions & 1 deletion atom/browser/atom_browser_client.h
Expand Up @@ -111,7 +111,9 @@ class AtomBrowserClient : public brightray::BrowserClient,
bool opener_suppressed,
bool* no_javascript_access) override;
void GetAdditionalAllowedSchemesForFileSystem(
std::vector<std::string>* schemes) override;
std::vector<std::string>* additional_schemes) override;
void GetAdditionalWebUISchemes(
std::vector<std::string>* additional_schemes) override;
void SiteInstanceDeleting(content::SiteInstance* site_instance) override;
std::unique_ptr<net::ClientCertStore> CreateClientCertStore(
content::ResourceContext* resource_context) override;
Expand All @@ -125,6 +127,7 @@ class AtomBrowserClient : public brightray::BrowserClient,
std::unique_ptr<base::Value> GetServiceManifestOverlay(
base::StringPiece name) override;
net::NetLog* GetNetLog() override;
content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override;
content::PlatformNotificationService* GetPlatformNotificationService()
override;

Expand Down
4 changes: 2 additions & 2 deletions atom/browser/atom_browser_context.cc
Expand Up @@ -15,6 +15,7 @@
#include "atom/browser/net/resolve_proxy_helper.h"
#include "atom/browser/pref_store_delegate.h"
#include "atom/browser/special_storage_policy.h"
#include "atom/browser/ui/inspectable_web_contents_impl.h"
#include "atom/browser/web_view_manager.h"
#include "atom/common/atom_version.h"
#include "atom/common/chrome_version.h"
Expand All @@ -27,7 +28,6 @@
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_restrictions.h"
#include "brightray/browser/brightray_paths.h"
#include "brightray/browser/inspectable_web_contents_impl.h"
#include "brightray/browser/zoom_level_delegate.h"
#include "brightray/common/application_info.h"
#include "chrome/common/chrome_paths.h"
Expand Down Expand Up @@ -152,7 +152,7 @@ void AtomBrowserContext::InitPrefs() {
registry->RegisterFilePathPref(prefs::kDownloadDefaultDirectory,
download_dir);
registry->RegisterDictionaryPref(prefs::kDevToolsFileSystemPaths);
brightray::InspectableWebContentsImpl::RegisterPrefs(registry.get());
InspectableWebContentsImpl::RegisterPrefs(registry.get());
brightray::MediaDeviceIDSalt::RegisterPrefs(registry.get());
brightray::ZoomLevelDelegate::RegisterPrefs(registry.get());
PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get());
Expand Down
19 changes: 10 additions & 9 deletions atom/browser/atom_browser_main_parts.cc
Expand Up @@ -10,10 +10,12 @@
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/atom_browser_client.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_web_ui_controller_factory.h"
#include "atom/browser/browser.h"
#include "atom/browser/io_thread.h"
#include "atom/browser/javascript_environment.h"
#include "atom/browser/node_debugger.h"
#include "atom/browser/ui/devtools_manager_delegate.h"
#include "atom/common/api/atom_bindings.h"
#include "atom/common/asar/asar_util.h"
#include "atom/common/node_bindings.h"
Expand All @@ -25,6 +27,8 @@
#include "components/net_log/chrome_net_log.h"
#include "components/net_log/net_export_file_writer.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/web_ui_controller_factory.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/service_manager_connection.h"
#include "electron/buildflags/buildflags.h"
Expand All @@ -39,14 +43,10 @@
#include "ui/events/devices/x11/touch_factory_x11.h"
#endif

#if BUILDFLAG(ENABLE_PDF_VIEWER)
#include "atom/browser/atom_web_ui_controller_factory.h"
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)

#if defined(OS_MACOSX)
#include "atom/browser/ui/cocoa/views_delegate_mac.h"
#else
#include "brightray/browser/views/views_delegate.h"
#include "atom/browser/ui/views/atom_views_delegate.h"
#endif

// Must be included after all other headers.
Expand Down Expand Up @@ -212,7 +212,7 @@ void AtomBrowserMainParts::ToolkitInitialized() {
#if defined(OS_MACOSX)
views_delegate_.reset(new ViewsDelegateMac);
#else
views_delegate_.reset(new brightray::ViewsDelegate);
views_delegate_.reset(new ViewsDelegate);
#endif
}

Expand All @@ -231,12 +231,13 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() {
base::Bind(&v8::Isolate::LowMemoryNotification,
base::Unretained(js_env_->isolate())));

#if BUILDFLAG(ENABLE_PDF_VIEWER)
content::WebUIControllerFactory::RegisterFactory(
AtomWebUIControllerFactory::GetInstance());
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)

brightray::BrowserMainParts::PreMainMessageLoopRun();
// --remote-debugging-port
auto* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kRemoteDebuggingPort))
DevToolsManagerDelegate::StartHttpHandler();

#if defined(USE_X11)
libgtkui::GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess());
Expand Down
12 changes: 5 additions & 7 deletions atom/browser/atom_browser_main_parts.h
Expand Up @@ -19,12 +19,6 @@
class BrowserProcess;
class IconManager;

#if defined(TOOLKIT_VIEWS)
namespace brightray {
class ViewsDelegate;
}
#endif

namespace net_log {
class ChromeNetLog;
}
Expand All @@ -40,6 +34,10 @@ class NodeDebugger;
class NodeEnvironment;
class BridgeTaskRunner;

#if defined(TOOLKIT_VIEWS)
class ViewsDelegate;
#endif

#if defined(OS_MACOSX)
class ViewsDelegateMac;
#endif
Expand Down Expand Up @@ -103,7 +101,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
#if defined(OS_MACOSX)
std::unique_ptr<ViewsDelegateMac> views_delegate_;
#else
std::unique_ptr<brightray::ViewsDelegate> views_delegate_;
std::unique_ptr<ViewsDelegate> views_delegate_;
#endif

// A fake BrowserProcess object that used to feed the source code from chrome.
Expand Down
17 changes: 16 additions & 1 deletion atom/browser/atom_web_ui_controller_factory.cc
Expand Up @@ -13,12 +13,20 @@
#include "atom/common/atom_constants.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "content/public/browser/web_contents.h"
#include "net/base/escape.h"
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)

#include "atom/browser/ui/devtools_ui.h"
#include "content/public/browser/web_contents.h"

namespace atom {

namespace {

const char kChromeUIDevToolsBundledHost[] = "devtools";

} // namespace

// static
AtomWebUIControllerFactory* AtomWebUIControllerFactory::GetInstance() {
return base::Singleton<AtomWebUIControllerFactory>::get();
Expand All @@ -36,6 +44,9 @@ content::WebUI::TypeID AtomWebUIControllerFactory::GetWebUIType(
return const_cast<AtomWebUIControllerFactory*>(this);
}
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
if (url.host() == kChromeUIDevToolsBundledHost) {
return const_cast<AtomWebUIControllerFactory*>(this);
}

return content::WebUI::kNoWebUI;
}
Expand Down Expand Up @@ -78,6 +89,10 @@ AtomWebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui,
return new PdfViewerUI(browser_context, web_ui, src);
}
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
if (url.host() == kChromeUIDevToolsBundledHost) {
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
return std::make_unique<DevToolsUI>(browser_context, web_ui);
}
return std::unique_ptr<content::WebUIController>();
}

Expand Down
13 changes: 7 additions & 6 deletions atom/browser/common_web_contents_delegate.cc
Expand Up @@ -188,7 +188,7 @@ void CommonWebContentsDelegate::InitWithWebContents(
!web_preferences || web_preferences->IsEnabled(options::kOffscreen);

// Create InspectableWebContents.
web_contents_.reset(brightray::InspectableWebContents::Create(
web_contents_.reset(InspectableWebContents::Create(
web_contents, browser_context->prefs(), is_guest));
web_contents_->SetDelegate(this);
}
Expand Down Expand Up @@ -229,11 +229,12 @@ void CommonWebContentsDelegate::ResetManagedWebContents(bool async) {
// is required to get the right quit closure for the main message loop.
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
FROM_HERE,
base::BindOnce([](scoped_refptr<AtomBrowserContext> browser_context,
std::unique_ptr<brightray::InspectableWebContents>
web_contents) { web_contents.reset(); },
base::RetainedRef(browser_context_),
std::move(web_contents_)));
base::BindOnce(
[](scoped_refptr<AtomBrowserContext> browser_context,
std::unique_ptr<InspectableWebContents> web_contents) {
web_contents.reset();
},
base::RetainedRef(browser_context_), std::move(web_contents_)));
} else {
web_contents_.reset();
}
Expand Down
17 changes: 8 additions & 9 deletions atom/browser/common_web_contents_delegate.h
Expand Up @@ -10,10 +10,10 @@
#include <string>
#include <vector>

#include "atom/browser/ui/inspectable_web_contents_delegate.h"
#include "atom/browser/ui/inspectable_web_contents_impl.h"
#include "atom/browser/ui/inspectable_web_contents_view_delegate.h"
#include "base/memory/weak_ptr.h"
#include "brightray/browser/inspectable_web_contents_delegate.h"
#include "brightray/browser/inspectable_web_contents_impl.h"
#include "brightray/browser/inspectable_web_contents_view_delegate.h"
#include "chrome/browser/devtools/devtools_file_system_indexer.h"
#include "content/public/browser/web_contents_delegate.h"
#include "electron/buildflags/buildflags.h"
Expand All @@ -36,10 +36,9 @@ class WebDialogHelper;
class OffScreenRenderWidgetHostView;
#endif

class CommonWebContentsDelegate
: public content::WebContentsDelegate,
public brightray::InspectableWebContentsDelegate,
public brightray::InspectableWebContentsViewDelegate {
class CommonWebContentsDelegate : public content::WebContentsDelegate,
public InspectableWebContentsDelegate,
public InspectableWebContentsViewDelegate {
public:
CommonWebContentsDelegate();
~CommonWebContentsDelegate() override;
Expand All @@ -61,7 +60,7 @@ class CommonWebContentsDelegate
// Returns the WebContents of devtools.
content::WebContents* GetDevToolsWebContents() const;

brightray::InspectableWebContents* managed_web_contents() const {
InspectableWebContents* managed_web_contents() const {
return web_contents_.get();
}

Expand Down Expand Up @@ -189,7 +188,7 @@ class CommonWebContentsDelegate
// Notice that web_contents_ must be placed after dialog_manager_, so we can
// make sure web_contents_ is destroyed before dialog_manager_, otherwise a
// crash would happen.
std::unique_ptr<brightray::InspectableWebContents> web_contents_;
std::unique_ptr<InspectableWebContents> web_contents_;

// Maps url to file path, used by the file requests sent from devtools.
typedef std::map<std::string, base::FilePath> PathsMap;
Expand Down

0 comments on commit db13c23

Please sign in to comment.