Bug 1544813: Show sources regardless devtools.chrome.enabled even in case of web extension. r=jdescottes,jlast
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Fri, 17 May 2019 01:02:11 +0000
changeset 474278 a61d0f7aa588f29a0a30d86fd887b1267bd6f95c
parent 474277 d146d0379fd23b0551f5d99399d99da629071b81
child 474279 edd9b8f1a0badea3cd7216b6f4db7a44bd77106c
push id36027
push usershindli@mozilla.com
push dateFri, 17 May 2019 16:24:38 +0000
treeherdermozilla-central@c94c54aff466 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes, jlast
bugs1544813
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1544813: Show sources regardless devtools.chrome.enabled even in case of web extension. r=jdescottes,jlast Differential Revision: https://phabricator.services.mozilla.com/D31223
devtools/client/debugger/src/actions/navigation.js
devtools/client/debugger/src/actions/tests/navigation.spec.js
devtools/client/debugger/src/actions/types/index.js
devtools/client/debugger/src/client/firefox.js
devtools/client/debugger/src/reducers/debuggee.js
devtools/client/debugger/src/reducers/sources.js
devtools/client/debugger/src/reducers/tests/sources.spec.js
--- a/devtools/client/debugger/src/actions/navigation.js
+++ b/devtools/client/debugger/src/actions/navigation.js
@@ -43,24 +43,30 @@ export function willNavigate(event: Obje
 
     dispatch({
       type: "NAVIGATE",
       mainThread: { ...thread, url: event.url }
     });
   };
 }
 
-export function connect(url: string, actor: string, canRewind: boolean) {
+export function connect(
+  url: string,
+  actor: string,
+  canRewind: boolean,
+  isWebExtension: boolean
+) {
   return async function({ dispatch }: ThunkArgs) {
     await dispatch(updateWorkers());
     dispatch(
       ({
         type: "CONNECT",
         mainThread: { url, actor, type: -1, name: "" },
-        canRewind
+        canRewind,
+        isWebExtension
       }: Action)
     );
   };
 }
 
 /**
  * @memberof actions/navigation
  * @static
--- a/devtools/client/debugger/src/actions/tests/navigation.spec.js
+++ b/devtools/client/debugger/src/actions/tests/navigation.spec.js
@@ -37,16 +37,17 @@ describe("navigation", () => {
     const { dispatch, getState } = createStore({
       fetchWorkers: () => Promise.resolve([]),
       getMainThread: () => "FakeThread"
     });
     await dispatch(
       actions.connect(
         "http://test.com/foo",
         "actor",
+        false,
         false
       )
     );
     expect(selectors.getDebuggeeUrl(getState())).toEqual("http://test.com/foo");
   });
 
   it("navigation closes project-search", async () => {
     const { dispatch, getState, cx } = createStore(threadClient);
--- a/devtools/client/debugger/src/actions/types/index.js
+++ b/devtools/client/debugger/src/actions/types/index.js
@@ -66,17 +66,22 @@ type UpdateTabAction = {|
   +type: "UPDATE_TAB",
   +url: string,
   +framework?: string,
   +isOriginal?: boolean,
   +sourceId?: string
 |};
 
 type NavigateAction =
-  | {| +type: "CONNECT", +mainThread: MainThread, +canRewind: boolean |}
+  | {|
+      +type: "CONNECT",
+      +mainThread: MainThread,
+      +canRewind: boolean,
+      +isWebExtension: boolean
+    |}
   | {| +type: "NAVIGATE", +mainThread: MainThread |};
 
 export type FocusItem = TreeNode;
 
 export type SourceTreeAction =
   | {| +type: "SET_EXPANDED_STATE", +thread: string, +expanded: any |}
   | {| +type: "SET_FOCUSED_SOURCE_ITEM", +cx: Context, item: FocusItem |};
 
--- a/devtools/client/debugger/src/client/firefox.js
+++ b/devtools/client/debugger/src/client/firefox.js
@@ -53,17 +53,18 @@ export async function onConnect(connecti
   // the debugger (if it's paused already, or if loading the page from
   // bfcache) so explicity fire `newSource` events for all returned
   // sources.
   const sourceInfo = await clientCommands.fetchSources();
   const traits = tabTarget.traits;
   await actions.connect(
     tabTarget.url,
     threadClient.actor,
-    traits && traits.canRewind
+    traits && traits.canRewind,
+    tabTarget.isWebExtension
   );
   await actions.newGeneratedSources(sourceInfo);
 
   // If the threadClient is already paused, make sure to show a
   // paused state.
   const pausedPacket = threadClient.getLastPausePacket();
   if (pausedPacket) {
     clientEvents.paused(threadClient, "paused", pausedPacket);
--- a/devtools/client/debugger/src/reducers/debuggee.js
+++ b/devtools/client/debugger/src/reducers/debuggee.js
@@ -15,35 +15,38 @@ import { createSelector } from "reselect
 import { getDisplayName } from "../utils/workers";
 
 import type { Selector } from "./types";
 import type { MainThread, WorkerList, Thread } from "../types";
 import type { Action } from "../actions/types";
 
 export type DebuggeeState = {
   workers: WorkerList,
-  mainThread: MainThread
+  mainThread: MainThread,
+  isWebExtension: boolean
 };
 
 export function initialDebuggeeState(): DebuggeeState {
   return {
     workers: [],
-    mainThread: { actor: "", url: "", type: -1, name: "" }
+    mainThread: { actor: "", url: "", type: -1, name: "" },
+    isWebExtension: false
   };
 }
 
 export default function debuggee(
   state: DebuggeeState = initialDebuggeeState(),
   action: Action
 ): DebuggeeState {
   switch (action.type) {
     case "CONNECT":
       return {
         ...state,
-        mainThread: { ...action.mainThread, name: L10N.getStr("mainThread") }
+        mainThread: { ...action.mainThread, name: L10N.getStr("mainThread") },
+        isWebExtension: action.isWebExtension
       };
     case "INSERT_WORKERS":
       return insertWorkers(state, action.workers);
     case "REMOVE_WORKERS":
       const { workers } = action;
       return {
         ...state,
         workers: state.workers.filter(w => !workers.includes(w.actor))
--- a/devtools/client/debugger/src/reducers/sources.js
+++ b/devtools/client/debugger/src/reducers/sources.js
@@ -57,16 +57,17 @@ import type {
   SourceWithContent,
   ThreadId,
   MappedLocation,
   BreakpointPositions
 } from "../types";
 import type { PendingSelectedLocation, Selector } from "./types";
 import type { Action, DonePromiseAction, FocusItem } from "../actions/types";
 import type { LoadSourceAction } from "../actions/types/SourceAction";
+import type { DebuggeeState } from "./debuggee";
 import { uniq } from "lodash";
 
 export type SourcesMap = { [SourceId]: Source };
 type SourcesContentMap = {
   [SourceId]: AsyncValue<SourceContent> | null
 };
 export type SourcesMapByThread = { [ThreadId]: SourcesMap };
 
@@ -489,16 +490,17 @@ export function getBlackBoxList() {
 // Unfortunately, it's really hard to make these functions accept just
 // the state that we care about and still type it with Flow. The
 // problem is that we want to re-export all selectors from a single
 // module for the UI, and all of those selectors should take the
 // top-level app state, so we'd have to "wrap" them to automatically
 // pick off the piece of state we're interested in. It's impossible
 // (right now) to type those wrapped functions.
 type OuterState = { sources: SourcesState };
+type DebuggeeOuterState = { debuggee: DebuggeeState };
 
 const getSourcesState = (state: OuterState) => state.sources;
 
 export function getSourceThreads(
   state: OuterState & SourceActorOuterState,
   source: Source
 ): ThreadId[] {
   return uniq(
@@ -683,17 +685,17 @@ export function getPlainUrls(state: Oute
   return state.sources.plainUrls;
 }
 
 export function getSourceList(state: OuterState): Source[] {
   return querySourceList(getSources(state));
 }
 
 export function getDisplayedSourcesList(
-  state: OuterState & SourceActorOuterState
+  state: OuterState & SourceActorOuterState & DebuggeeOuterState
 ): Source[] {
   return ((Object.values(getDisplayedSources(state)): any).flatMap(
     Object.values
   ): any);
 }
 
 export function getSourceCount(state: OuterState) {
   return getSourceList(state).length;
@@ -792,49 +794,62 @@ export function getSelectedSourceId(stat
 }
 
 export function getProjectDirectoryRoot(state: OuterState): string {
   return state.sources.projectDirectoryRoot;
 }
 
 const queryAllDisplayedSources: ReduceQuery<
   SourceResource,
-  {| projectDirectoryRoot: string, chromeAndExtensionsEnabled: boolean |},
+  {|
+    projectDirectoryRoot: string,
+    chromeAndExtensionsEnabled: boolean,
+    debuggeeIsWebExtension: boolean
+  |},
   Array<SourceId>
 > = makeReduceQuery(
   makeMapWithArgs(
     (
       resource,
       ident,
-      { projectDirectoryRoot, chromeAndExtensionsEnabled }
+      {
+        projectDirectoryRoot,
+        chromeAndExtensionsEnabled,
+        debuggeeIsWebExtension
+      }
     ) => ({
       id: resource.id,
       displayed:
         underRoot(resource, projectDirectoryRoot) &&
-        (!resource.isExtension || chromeAndExtensionsEnabled)
+        (!resource.isExtension ||
+          chromeAndExtensionsEnabled ||
+          debuggeeIsWebExtension)
     })
   ),
   items =>
     items.reduce((acc, { id, displayed }) => {
       if (displayed) {
         acc.push(id);
       }
       return acc;
     }, [])
 );
 
-function getAllDisplayedSources(state: OuterState): Array<SourceId> {
+function getAllDisplayedSources(
+  state: OuterState & DebuggeeOuterState
+): Array<SourceId> {
   return queryAllDisplayedSources(state.sources.sources, {
     projectDirectoryRoot: state.sources.projectDirectoryRoot,
-    chromeAndExtensionsEnabled: state.sources.chromeAndExtenstionsEnabled
+    chromeAndExtensionsEnabled: state.sources.chromeAndExtenstionsEnabled,
+    debuggeeIsWebExtension: state.debuggee.isWebExtension
   });
 }
 
 type GetDisplayedSourceIDsSelector = (
-  OuterState & SourceActorOuterState
+  OuterState & SourceActorOuterState & DebuggeeOuterState
 ) => { [ThreadId]: Set<SourceId> };
 const getDisplayedSourceIDs: GetDisplayedSourceIDsSelector = createSelector(
   getThreadsBySource,
   getAllDisplayedSources,
   (threadsBySource, displayedSources) => {
     const sourceIDsByThread = {};
 
     for (const sourceId of displayedSources) {
@@ -850,17 +865,17 @@ const getDisplayedSourceIDs: GetDisplaye
         sourceIDsByThread[thread].add(sourceId);
       }
     }
     return sourceIDsByThread;
   }
 );
 
 type GetDisplayedSourcesSelector = (
-  OuterState & SourceActorOuterState
+  OuterState & SourceActorOuterState & DebuggeeOuterState
 ) => SourcesMapByThread;
 export const getDisplayedSources: GetDisplayedSourcesSelector = createSelector(
   state => state.sources.sources,
   getDisplayedSourceIDs,
   (sources, idsByThread) => {
     const result = {};
 
     for (const thread of Object.keys(idsByThread)) {
--- a/devtools/client/debugger/src/reducers/tests/sources.spec.js
+++ b/devtools/client/debugger/src/reducers/tests/sources.spec.js
@@ -3,16 +3,17 @@
  * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
 
 // @flow
 declare var describe: (name: string, func: () => void) => void;
 declare var it: (desc: string, func: () => void) => void;
 declare var expect: (value: any) => any;
 
 import update, { initialSourcesState, getDisplayedSources } from "../sources";
+import { initialDebuggeeState } from "../debuggee";
 import updateSourceActors from "../source-actors";
 import type { Source, SourceActor } from "../../types";
 import { prefs } from "../../utils/prefs";
 import { makeMockSource, mockcx } from "../../utils/test-mockup";
 import { getResourceIds } from "../../utils/resource";
 
 const extensionSource = {
   ...makeMockSource(),
@@ -86,17 +87,18 @@ describe("sources selectors", () => {
       sourceActors: undefined
     };
     const insertAction = {
       type: "INSERT_SOURCE_ACTORS",
       items: mockSourceActors
     };
     state = {
       sources: update(state.sources, insertAction),
-      sourceActors: updateSourceActors(state.sourceActors, insertAction)
+      sourceActors: updateSourceActors(state.sourceActors, insertAction),
+      debuggee: initialDebuggeeState()
     };
     const threadSources = getDisplayedSources(state);
     expect(Object.values(threadSources.foo)).toHaveLength(3);
   });
 
   it("should omit all extensions when chrome preference enabled", () => {
     prefs.chromeAndExtenstionsEnabled = false;
     let state = initialSourcesState();
@@ -111,14 +113,15 @@ describe("sources selectors", () => {
 
     const insertAction = {
       type: "INSERT_SOURCE_ACTORS",
       items: mockSourceActors
     };
 
     state = {
       sources: update(state.sources, insertAction),
-      sourceActors: updateSourceActors(state.sourceActors, insertAction)
+      sourceActors: updateSourceActors(state.sourceActors, insertAction),
+      debuggee: initialDebuggeeState()
     };
     const threadSources = getDisplayedSources(state);
     expect(Object.values(threadSources.foo)).toHaveLength(1);
   });
 });