tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

AIChatContentParent.sys.mjs (1180B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 const lazy = {};
      6 ChromeUtils.defineESModuleGetters(lazy, {
      7  AIWindow:
      8    "moz-src:///browser/components/aiwindow/ui/modules/AIWindow.sys.mjs",
      9 });
     10 
     11 /**
     12 * JSWindowActor to pass data between AIChatContent singleton and content pages.
     13 */
     14 export class AIChatContentParent extends JSWindowActorParent {
     15  dispatchMessageToChatContent(response) {
     16    this.sendAsyncMessage("AIChatContent:DispatchMessage", response);
     17  }
     18 
     19  receiveMessage({ data, name }) {
     20    switch (name) {
     21      case "aiChatContentActor:search":
     22        this.#handleSearchFromChild(data);
     23        break;
     24 
     25      default:
     26        console.warn(`AIChatContentParent received unknown message: ${name}`);
     27        break;
     28    }
     29    return undefined;
     30  }
     31 
     32  #handleSearchFromChild(data) {
     33    try {
     34      const { topChromeWindow } = this.browsingContext;
     35      lazy.AIWindow.performSearch(data, topChromeWindow);
     36    } catch (e) {
     37      console.warn("Could not perform search from AI Window chat", e);
     38    }
     39  }
     40 }