Skip to content

Commit

Permalink
Fix namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
elliette committed Aug 9, 2022
1 parent e5814d7 commit 7ffb9fa
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 20 deletions.
10 changes: 5 additions & 5 deletions dwds/debug_extension/web/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ enum DebuggerTrigger { extensionIcon, dartPanel, dwds }

void main() {
// Start debugging when a user clicks the Dart Debug Extension:
ChromeBrowserAction.onClickedAddListener(allowInterop((_) {
ChromeBrowserActionOnClicked.addListener(allowInterop((_) {
_startDebugging(DebuggerTrigger.extensionIcon);
}));

Expand All @@ -141,14 +141,14 @@ void main() {

// Attaches a debug session to the app when the extension receives a
// Runtime.executionContextCreated event from Chrome:
ChromeDebugger.onEventAddListener(allowInterop(_maybeAttachDebugSession));
ChromeDebuggerOnEvent.addListener(allowInterop(_maybeAttachDebugSession));

// When a Dart application tab is closed, detach the corresponding debug
// session:
tabsOnRemovedAddListener(allowInterop(_removeAndDetachDebugSessionForTab));

// When a debug session is detached, remove the reference to it:
ChromeDebugger.onDetachAddListener(
ChromeDebuggerOnDetach.addListener(
allowInterop((Debuggee source, DetachReason reason) {
_removeDebugSessionForTab(source.tabId);
}));
Expand All @@ -157,7 +157,7 @@ void main() {
tabsOnCreatedAddListener(allowInterop(_maybeSaveDevToolsTabId));

// Forward debugger events to the backend if applicable.
ChromeDebugger.onEventAddListener(allowInterop(_filterAndForwardToBackend));
ChromeDebuggerOnEvent.addListener(allowInterop(_filterAndForwardToBackend));

// Maybe update the extension icon when a user clicks the tab:
tabsOnActivatedAddListener(allowInterop((ActiveInfo info) {
Expand All @@ -169,7 +169,7 @@ void main() {
allowInterop(_handleMessageFromExternalExtensions));

// Message forwarder enabling communication with external Chrome extensions:
ChromeDebugger.onEventAddListener(
ChromeDebuggerOnEvent.addListener(
allowInterop(_forwardMessageToExternalExtensions));

// Maybe update the extension icon when the window focus changes:
Expand Down
82 changes: 82 additions & 0 deletions dwds/debug_extension/web/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
(function() {
var _currentDirectory = (function () {
var _url;
var lines = new Error().stack.split('\n');
function lookupUrl() {
if (lines.length > 2) {
var match = lines[1].match(/^\s+at (.+):\d+:\d+$/);
// Chrome.
if (match) return match[1];
// Chrome nested eval case.
match = lines[1].match(/^\s+at eval [(](.+):\d+:\d+[)]$/);
if (match) return match[1];
// Edge.
match = lines[1].match(/^\s+at.+\((.+):\d+:\d+\)$/);
if (match) return match[1];
// Firefox.
match = lines[0].match(/[<][@](.+):\d+:\d+$/)
if (match) return match[1];
}
// Safari.
return lines[0].match(/(.+):\d+:\d+$/)[1];
}
_url = lookupUrl();
var lastSlash = _url.lastIndexOf('/');
if (lastSlash == -1) return _url;
var currentDirectory = _url.substring(0, lastSlash + 1);
return currentDirectory;
})();

var baseUrl = (function () {
// Attempt to detect --precompiled mode for tests, and set the base url
// appropriately, otherwise set it to '/'.
var pathParts = location.pathname.split("/");
if (pathParts[0] == "") {
pathParts.shift();
}
if (pathParts.length > 1 && pathParts[1] == "test") {
return "/" + pathParts.slice(0, 2).join("/") + "/";
}
// Attempt to detect base url using <base href> html tag
// base href should start and end with "/"
if (typeof document !== 'undefined') {
var el = document.getElementsByTagName('base');
if (el && el[0] && el[0].getAttribute("href") && el[0].getAttribute
("href").startsWith("/") && el[0].getAttribute("href").endsWith("/")){
return el[0].getAttribute("href");
}
}
// return default value
return "/";
}());


var mapperUri = baseUrl + "packages/build_web_compilers/src/" +
"dev_compiler_stack_trace/stack_trace_mapper.dart.js";
var requireUri = baseUrl +
"packages/build_web_compilers/src/dev_compiler/require.js";
var mainUri = _currentDirectory + "background.dart.bootstrap";

if (typeof document != 'undefined') {
var el = document.createElement("script");
el.defer = true;
el.async = false;
el.src = mapperUri;
document.head.appendChild(el);

el = document.createElement("script");
el.defer = true;
el.async = false;
el.src = requireUri;
el.setAttribute("data-main", mainUri);
document.head.appendChild(el);
} else {
importScripts(mapperUri, requireUri);
require.config({
baseUrl: baseUrl,
});
// TODO: update bootstrap code to take argument - dart-lang/build#1115
window = self;
require([mainUri + '.js']);
}
})();
13 changes: 8 additions & 5 deletions dwds/debug_extension/web_api/chrome_browser_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

import 'package:js/js.dart';

@JS()
@JS('chrome.browserAction')
class ChromeBrowserAction {
@JS('chrome.browserAction.onClicked.addListener')
external static void onClickedAddListener(Function callback);

@JS('chrome.browserAction.setIcon')
@JS('setIcon')
external static void setIcon(IconInfo iconInfo);
}

@JS('chrome.browserAction.onClicked')
class ChromeBrowserActionOnClicked {
@JS('addListener')
external static void addListener(Function callback);
}

@JS()
@anonymous
class IconInfo {
Expand Down
26 changes: 16 additions & 10 deletions dwds/debug_extension/web_api/chrome_debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@

import 'package:js/js.dart';

@JS()
@JS('chrome.debugger')
class ChromeDebugger {
@JS('chrome.debugger.attach')
@JS('attach')
external static void attach(
Debuggee target, String requiredVersion, Function callback);

@JS('chrome.debugger.detach')
@JS('detach')
external static void detach(Debuggee target, Function callback);

@JS('chrome.debugger.onDetach.addListener')
external static dynamic onDetachAddListener(Function callback);

@JS('chrome.debugger.onEvent.addListener')
external static dynamic onEventAddListener(Function callback);

@JS('chrome.debugger.sendCommand')
@JS('sendCommand')
external static void sendCommand(
Debuggee target, String method, Object? commandParams, Function callback);
}

@JS('chrome.debugger.onDetach')
class ChromeDebuggerOnDetach {
@JS('addListener')
external static dynamic addListener(Function callback);
}

@JS('chrome.debugger.onEvent')
class ChromeDebuggerOnEvent {
@JS('addListener')
external static dynamic addListener(Function callback);
}

@JS()
@anonymous
class Debuggee {
Expand Down

0 comments on commit 7ffb9fa

Please sign in to comment.