Chromium 前端window对象c++实现定义

news2024/11/24 17:20:07

前端中window.document window.alert()等一些列方法和对象在c++对应定义如下:

1、window对象接口定义文件window.idl

third_party\blink\renderer\core\frame\window.idl


// https://html.spec.whatwg.org/C/#the-window-object

// FIXME: explain all uses of [CrossOrigin]
// NOTE: In the spec, Window inherits from EventTarget. We inject an additional
// layer to implement window's named properties object.
[
    ImplementedAs=DOMWindow,
    Global=Window,
    Exposed=Window
] interface Window : WindowProperties {
    // the current browsing context
    // FIXME: The spec uses the WindowProxy type for this and many other attributes.
    [LegacyUnforgeable, CrossOrigin, CachedAccessor=kWindowProxy] readonly attribute Window window;
    [Replaceable, CrossOrigin, CachedAccessor=kWindowProxy] readonly attribute Window self;
    [LegacyUnforgeable, CachedAccessor=kWindowDocument] readonly attribute Document document;
    attribute DOMString name;
    [PutForwards=href, LegacyUnforgeable, CrossOrigin=(Getter,Setter)] readonly attribute Location location;
    [CallWith=ScriptState] readonly attribute CustomElementRegistry customElements;
    readonly attribute History history;
    [Replaceable] readonly attribute Navigation navigation;
    [Replaceable, MeasureAs=BarPropLocationbar] readonly attribute BarProp locationbar;
    [Replaceable, MeasureAs=BarPropMenubar] readonly attribute BarProp menubar;
    [Replaceable, MeasureAs=BarPropPersonalbar] readonly attribute BarProp personalbar;
    [Replaceable, MeasureAs=BarPropScrollbars] readonly attribute BarProp scrollbars;
    [Replaceable, MeasureAs=BarPropStatusbar] readonly attribute BarProp statusbar;
    [Replaceable, MeasureAs=BarPropToolbar] readonly attribute BarProp toolbar;
    attribute DOMString status;
    [CrossOrigin, CallWith=Isolate] void close();
    [MeasureAs=WindowClosed, CrossOrigin] readonly attribute boolean closed;
    void stop();
    [CrossOrigin, CallWith=Isolate] void focus();
    [CrossOrigin] void blur();

    // other browsing contexts
    [Replaceable, CrossOrigin, CachedAccessor=kWindowProxy] readonly attribute Window frames;
    [Replaceable, CrossOrigin] readonly attribute unsigned long length;
    [LegacyUnforgeable, CrossOrigin] readonly attribute Window? top;
    // FIXME: opener should be of type any.
    [CrossOrigin, ImplementedAs=openerForBindings, CallWith=Isolate, RaisesException=Setter] attribute any opener;
    [Replaceable, CrossOrigin] readonly attribute Window? parent;
    [CheckSecurity=ReturnValue] readonly attribute Element? frameElement;

    [CallWith=Isolate, RaisesException] Window? open(optional USVString url="", optional DOMString target = "_blank", optional [LegacyNullToEmptyString] DOMString features = "");

    // indexed properties
    // https://html.spec.whatwg.org/C/browsers.html#windowproxy-getownproperty
    [NotEnumerable, CrossOrigin] getter Window (unsigned long index);

    // named properties
    // The spec defines the named getter on the Window interface, but we inject
    // the named properties object as its own interface that Window inherits
    // from.
    // getter object (DOMString name);

    // the user agent
    [LogActivity=GetterOnly] readonly attribute Navigator navigator;

    [RuntimeEnabled=OriginIsolationHeader] readonly attribute boolean originAgentCluster;

    // user prompts
    [Measure, CallWith=ScriptState] void alert();
    [Measure, CallWith=ScriptState] void alert(DOMString message);
    [Measure, CallWith=ScriptState] boolean confirm(optional DOMString message = "");
    [Measure, CallWith=ScriptState] DOMString? prompt(optional DOMString message = "", optional DOMString defaultValue = "");
    [Measure, CallWith=ScriptState] void print();

    [CrossOrigin, CallWith=Isolate, RaisesException] void postMessage(any message, USVString targetOrigin, optional sequence<object> transfer = []);

    [CrossOrigin, CallWith=Isolate, RaisesException] void postMessage(any message, optional WindowPostMessageOptions options = {});

    // WindowOrWorkerGlobalScope mixin
    // https://html.spec.whatwg.org/C/#windoworworkerglobalscope-mixin
    // https://wicg.github.io/origin-policy/#monkeypatch-html-windoworworkerglobalscope
    [Replaceable] readonly attribute DOMString origin;
    void queueMicrotask(VoidFunction callback);

    // AnimationFrameProvider mixin
    // https://html.spec.whatwg.org/C/#animation-frames
    [MeasureAs=UnprefixedRequestAnimationFrame] long requestAnimationFrame(FrameRequestCallback callback);
    void cancelAnimationFrame(long handle);

    // HTML obsolete features
    // https://html.spec.whatwg.org/C/#Window-partial
    [MeasureAs=WindowCaptureEvents] void captureEvents();
    [MeasureAs=WindowReleaseEvents] void releaseEvents();

    [Replaceable, SameObject] readonly attribute External external;

    // CSS Object Model (CSSOM)
    // https://drafts.csswg.org/cssom/#extensions-to-the-window-interface
    [Affects=Nothing, NewObject] CSSStyleDeclaration getComputedStyle(Element elt, optional DOMString? pseudoElt);

    // CSSOM View Module
    // https://drafts.csswg.org/cssom-view/#extensions-to-the-window-interface
    [HighEntropy, Measure, NewObject] MediaQueryList matchMedia(DOMString query);
    [SameObject, Replaceable] readonly attribute Screen screen;

    // browsing context
    [MeasureAs=WindowMove] void moveTo(long x, long y);
    [MeasureAs=WindowMove] void moveBy(long x, long y);
    [MeasureAs=WindowResize, RaisesException] void resizeTo(long x, long y);
    [MeasureAs=WindowResize, RaisesException] void resizeBy(long x, long y);

    // viewport
    [HighEntropy=Direct, MeasureAs=WindowInnerWidth, Replaceable] readonly attribute long innerWidth;
    [HighEntropy=Direct, MeasureAs=WindowInnerHeight, Replaceable] readonly attribute long innerHeight;

    // viewport scrolling
    [HighEntropy=Direct, MeasureAs=WindowScrollX, Replaceable] readonly attribute double scrollX;
    [HighEntropy=Direct, MeasureAs=WindowPageXOffset, Replaceable] readonly attribute double pageXOffset;
    [HighEntropy=Direct, MeasureAs=WindowScrollY, Replaceable] readonly attribute double scrollY;
    [HighEntropy=Direct, MeasureAs=WindowPageYOffset, Replaceable] readonly attribute double pageYOffset;
    void scroll(optional ScrollToOptions options = {});
    void scroll(unrestricted double x, unrestricted double y);
    void scrollTo(optional ScrollToOptions options = {});
    void scrollTo(unrestricted double x, unrestricted double y);
    void scrollBy(optional ScrollToOptions options = {});
    void scrollBy(unrestricted double x, unrestricted double y);

    // Visual Viewport API
    // https://github.com/WICG/ViewportAPI
    [Replaceable, SameObject] readonly attribute VisualViewport visualViewport;

    // client
    [HighEntropy=Direct, MeasureAs=WindowScreenX, Replaceable] readonly attribute long screenX;
    [HighEntropy=Direct, MeasureAs=WindowScreenY, Replaceable] readonly attribute long screenY;
    [HighEntropy=Direct, MeasureAs=WindowOuterWidth, Replaceable] readonly attribute long outerWidth;
    [HighEntropy=Direct, MeasureAs=WindowOuterHeight, Replaceable] readonly attribute long outerHeight;
    [HighEntropy=Direct, MeasureAs=WindowDevicePixelRatio, Replaceable] readonly attribute double devicePixelRatio;

    // Selection API
    // https://w3c.github.io/selection-api/#extensions-to-window-interface
    [Affects=Nothing] Selection? getSelection();

    // Console API
    // https://console.spec.whatwg.org/#console-interface
    // [Replaceable] readonly attribute Console console;
    // Console is installed by v8 inspector when context is created
    // and is left commented here just for documentation.

    // Compatibility
    // https://compat.spec.whatwg.org/#windoworientation-interface
    [RuntimeEnabled=OrientationEvent] attribute EventHandler onorientationchange;
    // This is the interface orientation in degrees. Some examples are:
    //  0 is straight up; -90 is when the device is rotated 90 clockwise;
    //  90 is when rotated counter clockwise.
    [HighEntropy=Direct, MeasureAs=WindowOrientation, RuntimeEnabled=OrientationEvent] readonly attribute long orientation;

    // Event handler attribute for the pagereveal event.
    // https://drafts.csswg.org/css-view-transitions-2/#reveal-event
    [RuntimeEnabled=PageRevealEvent] attribute EventHandler onpagereveal;

    // Accessibility Object Model
    // https://github.com/WICG/aom/blob/HEAD/explainer.md
    [RuntimeEnabled=AccessibilityObjectModel, CallWith=ScriptState] Promise<ComputedAccessibleNode> getComputedAccessibleNode(Element element);

    // https://dom.spec.whatwg.org/#interface-window-extensions
    [Replaceable, GetterCallWith=ScriptState, MeasureAs=WindowEvent, NotEnumerable] readonly attribute any event;

    // Non-standard APIs
    [MeasureAs=WindowClientInformation, Replaceable] readonly attribute Navigator clientInformation;
    [MeasureAs=WindowFind] boolean find(optional DOMString string = "",
                                        optional boolean caseSensitive = false,
                                        optional boolean backwards = false,
                                        optional boolean wrap = false,
                                        optional boolean wholeWord = false,
                                        optional boolean searchInFrames = false,
                                        optional boolean showDialog = false);
    [MeasureAs=WindowOffscreenBuffering, Replaceable, NotEnumerable] readonly attribute boolean offscreenBuffering;
    [HighEntropy=Direct, MeasureAs=WindowScreenLeft, Replaceable] readonly attribute long screenLeft;
    [HighEntropy=Direct, MeasureAs=WindowScreenTop, Replaceable] readonly attribute long screenTop;
    [RuntimeEnabled=WindowDefaultStatus,MeasureAs=WindowDefaultStatus] attribute DOMString defaultStatus;
    [RuntimeEnabled=WindowDefaultStatus,MeasureAs=WindowDefaultstatus, ImplementedAs=defaultStatus] attribute DOMString defaultstatus;
    [MeasureAs=StyleMedia] readonly attribute StyleMedia styleMedia;
    [DeprecateAs=PrefixedRequestAnimationFrame] long webkitRequestAnimationFrame(FrameRequestCallback callback);
    [DeprecateAs=PrefixedCancelAnimationFrame, ImplementedAs=cancelAnimationFrame] void webkitCancelAnimationFrame(long id);

    // Event handler attributes
    attribute EventHandler onsearch;

    // https://w3c.github.io/webappsec-secure-contexts/#monkey-patching-global-object
    readonly attribute boolean isSecureContext;

    // TrustedTypes API: http://github.com/w3c/trusted-types
    [CallWith=ScriptState] readonly attribute TrustedTypePolicyFactory trustedTypes;

    // Anonymous iframe:
    // https://github.com/WICG/anonymous-iframe
    [RuntimeEnabled=AnonymousIframe] readonly attribute boolean credentialless;

    // Collection of fenced frame APIs
    // https://github.com/shivanigithub/fenced-frame/issues/14
    [RuntimeEnabled=FencedFrames] readonly attribute Fence? fence;
};

Window includes GlobalEventHandlers;
Window includes WindowEventHandlers;
Window includes WindowOrWorkerGlobalScope;

2、window对象接口定义实现文件(blink):

third_party\blink\renderer\core\frame\dom_window.h

third_party\blink\renderer\core\frame\dom_window.cc

third_party\blink\renderer\core\frame\local_dom_window.h

third_party\blink\renderer\core\frame\local_dom_window.cc

继承关系:

// Note: if you're thinking of returning something DOM-related by reference,
// please ping dcheng@chromium.org first. You probably don't want to do that.
class CORE_EXPORT LocalDOMWindow final : public DOMWindow,
                                         public ExecutionContext,
                                         public WindowOrWorkerGlobalScope,
                                         public WindowEventHandlers,
                                         public Supplementable<LocalDOMWindow>

在local_dom_window.h  LocalDOMWindow类中对应这前端window所有方法和对象实现


#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_LOCAL_DOM_WINDOW_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_LOCAL_DOM_WINDOW_H_

#include <memory>

#include "base/task/single_thread_task_runner.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "services/network/public/mojom/content_security_policy.mojom-blink.h"
#include "third_party/blink/public/common/frame/delegated_capability_request_token.h"
#include "third_party/blink/public/common/frame/history_user_activation_state.h"
#include "third_party/blink/public/common/metrics/post_message_counter.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/events/event_target.h"
#include "third_party/blink/renderer/core/editing/spellcheck/spell_checker.h"
#include "third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/use_counter_impl.h"
#include "third_party/blink/renderer/core/frame/window_event_handlers.h"
#include "third_party/blink/renderer/core/frame/window_or_worker_global_scope.h"
#include "third_party/blink/renderer/core/html/closewatcher/close_watcher.h"
#include "third_party/blink/renderer/core/loader/frame_loader.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_map.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_set.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/prefinalizer.h"
#include "third_party/blink/renderer/platform/storage/blink_storage_key.h"
#include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/uuid.h"

namespace blink {

class BarProp;
class CSSStyleDeclaration;
class CustomElementRegistry;
class Document;
class DocumentInit;
class DOMSelection;
class DOMVisualViewport;
class Element;
class ExceptionState;
class External;
class Fence;
class FrameConsole;
class History;
class InputMethodController;
class LocalFrame;
class MediaQueryList;
class MessageEvent;
class Modulator;
class NavigationApi;
class Navigator;
class Screen;
class ScriptController;
class ScriptPromise;
class ScriptState;
class ScrollToOptions;
class SecurityOrigin;
class SerializedScriptValue;
class SourceLocation;
class StyleMedia;
class TrustedTypePolicyFactory;
class V8FrameRequestCallback;
class V8VoidFunction;
struct WebPictureInPictureWindowOptions;
class WindowAgent;

namespace scheduler {
class TaskAttributionInfo;
}

enum PageTransitionEventPersistence {
  kPageTransitionEventNotPersisted = 0,
  kPageTransitionEventPersisted = 1
};

// Note: if you're thinking of returning something DOM-related by reference,
// please ping dcheng@chromium.org first. You probably don't want to do that.
class CORE_EXPORT LocalDOMWindow final : public DOMWindow,
                                         public ExecutionContext,
                                         public WindowOrWorkerGlobalScope,
                                         public WindowEventHandlers,
                                         public Supplementable<LocalDOMWindow> {
  USING_PRE_FINALIZER(LocalDOMWindow, Dispose);

 public:
  class CORE_EXPORT EventListenerObserver : public GarbageCollectedMixin {
   public:
    virtual void DidAddEventListener(LocalDOMWindow*, const AtomicString&) = 0;
    virtual void DidRemoveEventListener(LocalDOMWindow*,
                                        const AtomicString&) = 0;
    virtual void DidRemoveAllEventListeners(LocalDOMWindow*) = 0;
  };

  static LocalDOMWindow* From(const ScriptState*);

  LocalDOMWindow(LocalFrame&, WindowAgent*);
  ~LocalDOMWindow() override;

  // Returns the token identifying the frame that this ExecutionContext was
  // associated with at the moment of its creation. This remains valid even
  // after the frame has been destroyed and the ExecutionContext is detached.
  // This is used as a stable and persistent identifier for attributing detached
  // context memory usage.
  const LocalFrameToken& GetLocalFrameToken() const { return token_; }
  ExecutionContextToken GetExecutionContextToken() const final {
    return token_;
  }

  LocalFrame* GetFrame() const {
    // UnsafeTo<> is safe here because DOMWindow's frame can only change to
    // nullptr, and it was constructed with a LocalFrame in the constructor.
    return UnsafeTo<LocalFrame>(DOMWindow::GetFrame());
  }

  ScriptController& GetScriptController() const { return *script_controller_; }

  void Initialize();
  void ClearForReuse() { document_ = nullptr; }

  void ResetWindowAgent(WindowAgent*);

  mojom::blink::V8CacheOptions GetV8CacheOptions() const override;

  // Bind Content Security Policy to this window. This will cause the
  // CSP to resolve the 'self' attribute and all policies will then be
  // applied to this document.
  void BindContentSecurityPolicy();

  void Trace(Visitor*) const override;

  // ExecutionContext overrides:
  bool IsWindow() const final { return true; }
  bool IsContextThread() const final;
  bool ShouldInstallV8Extensions() const final;
  ContentSecurityPolicy* GetContentSecurityPolicyForWorld(
      const DOMWrapperWorld* world) final;
  const KURL& Url() const final;
  const KURL& BaseURL() const final;
  KURL CompleteURL(const String&) const final;
  void DisableEval(const String& error_message) final;
  void SetWasmEvalErrorMessage(const String& error_message) final;
  String UserAgent() const final;
  UserAgentMetadata GetUserAgentMetadata() const final;
  HttpsState GetHttpsState() const final;
  ResourceFetcher* Fetcher() final;
  bool CanExecuteScripts(ReasonForCallingCanExecuteScripts) final;
  void ExceptionThrown(ErrorEvent*) final;
  void AddInspectorIssue(AuditsIssue) final;
  EventTarget* ErrorEventTarget() final { return this; }
  String OutgoingReferrer() const final;
  CoreProbeSink* GetProbeSink() final;
  const BrowserInterfaceBrokerProxy& GetBrowserInterfaceBroker() const final;
  FrameOrWorkerScheduler* GetScheduler() final;
  scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner(TaskType) final;
  TrustedTypePolicyFactory* GetTrustedTypes() const final {
    return GetTrustedTypesForWorld(*GetCurrentWorld());
  }
  ScriptWrappable* ToScriptWrappable() final { return this; }
  void ReportPermissionsPolicyViolation(
      mojom::blink::PermissionsPolicyFeature,
      mojom::blink::PolicyDisposition,
      const absl::optional<String>& reporting_endpoint,
      const String& message = g_empty_string) const final;
  void ReportDocumentPolicyViolation(
      mojom::blink::DocumentPolicyFeature,
      mojom::blink::PolicyDisposition,
      const String& message = g_empty_string,
      // If source_file is set to empty string,
      // current JS file would be used as source_file instead.
      const String& source_file = g_empty_string) const final;
  void SetIsInBackForwardCache(bool) final;
  bool HasStorageAccess() const final;

  void AddConsoleMessageImpl(ConsoleMessage*, bool discard_duplicates) final;

  scoped_refptr<base::SingleThreadTaskRunner>
  GetAgentGroupSchedulerCompositorTaskRunner() final;

  // UseCounter orverrides:
  void CountUse(mojom::WebFeature feature) final;

  // Count |feature| only when this window is associated with a cross-origin
  // iframe.
  void CountUseOnlyInCrossOriginIframe(mojom::blink::WebFeature feature);

  // Count |feature| only when this window is associated with a same-origin
  // iframe with the outermost main frame.
  void CountUseOnlyInSameOriginIframe(mojom::blink::WebFeature feature);

  // Count |feature| only when this window is associated with a cross-site
  // iframe. A "site" is a scheme and registrable domain.
  void CountUseOnlyInCrossSiteIframe(mojom::blink::WebFeature feature) override;

  // Count permissions policy feature usage through use counter.
  void CountPermissionsPolicyUsage(
      mojom::blink::PermissionsPolicyFeature feature,
      UseCounterImpl::PermissionsPolicyUsageType type);

  // Checks if navigation to Javascript URL is allowed. This check should run
  // before any action is taken (e.g. creating new window) for all
  // same-origin navigations.
  String CheckAndGetJavascriptUrl(
      const DOMWrapperWorld* world,
      const KURL& url,
      Element* element,
      network::mojom::CSPDisposition csp_disposition =
          network::mojom::CSPDisposition::CHECK);

  Document* InstallNewDocument(const DocumentInit&);

  // EventTarget overrides:
  ExecutionContext* GetExecutionContext() const override;
  const LocalDOMWindow* ToLocalDOMWindow() const override;
  LocalDOMWindow* ToLocalDOMWindow() override;

  // Same-origin DOM Level 0
  Screen* screen();
  History* history();
  BarProp* locationbar();
  BarProp* menubar();
  BarProp* personalbar();
  BarProp* scrollbars();
  BarProp* statusbar();
  BarProp* toolbar();
  Navigator* navigator();
  Navigator* clientInformation() { return navigator(); }

  bool offscreenBuffering() const;

  int outerHeight() const;
  int outerWidth() const;
  int innerHeight() const;
  int innerWidth() const;
  int screenX() const;
  int screenY() const;
  int screenLeft() const { return screenX(); }
  int screenTop() const { return screenY(); }
  double scrollX() const;
  double scrollY() const;
  double pageXOffset() const { return scrollX(); }
  double pageYOffset() const { return scrollY(); }

  DOMVisualViewport* visualViewport();

  const AtomicString& name() const;
  void setName(const AtomicString&);

  String status() const;
  void setStatus(const String&);
  String defaultStatus() const;
  void setDefaultStatus(const String&);
  String origin() const;

  // DOM Level 2 AbstractView Interface
  Document* document() const;

  // CSSOM View Module
  StyleMedia* styleMedia();

  // WebKit extensions
  double devicePixelRatio() const;

  // This is the interface orientation in degrees. Some examples are:
  //  0 is straight up; -90 is when the device is rotated 90 clockwise;
  //  90 is when rotated counter clockwise.
  int orientation() const;

  DOMSelection* getSelection();

  void print(ScriptState*);
  void stop();

  void alert(ScriptState*, const String& message = String());
  bool confirm(ScriptState*, const String& message);
  String prompt(ScriptState*,
                const String& message,
                const String& default_value);

  bool find(const String&,
            bool case_sensitive,
            bool backwards,
            bool wrap,
            bool whole_word,
            bool search_in_frames,
            bool show_dialog) const;

  // FIXME: ScrollBehaviorSmooth is currently unsupported in VisualViewport.
  // crbug.com/434497
  void scrollBy(double x, double y) const;
  void scrollBy(const ScrollToOptions*) const;
  void scrollTo(double x, double y) const;
  void scrollTo(const ScrollToOptions*) const;
  void scroll(double x, double y) const { scrollTo(x, y); }
  void scroll(const ScrollToOptions* scroll_to_options) const {
    scrollTo(scroll_to_options);
  }
  void moveBy(int x, int y) const;
  void moveTo(int x, int y) const;

  void resizeBy(int x, int y, ExceptionState&) const;
  void resizeTo(int width, int height, ExceptionState&) const;

  MediaQueryList* matchMedia(const String&);

  // DOM Level 2 Style Interface
  CSSStyleDeclaration* getComputedStyle(
      Element*,
      const String& pseudo_elt = String()) const;

  // Acessibility Object Model
  ScriptPromise getComputedAccessibleNode(ScriptState*, Element*);

  // WebKit animation extensions
  int requestAnimationFrame(V8FrameRequestCallback*);
  int webkitRequestAnimationFrame(V8FrameRequestCallback*);
  void cancelAnimationFrame(int id);

  // https://html.spec.whatwg.org/C/#windoworworkerglobalscope-mixin
  void queueMicrotask(V8VoidFunction*);

  // https://html.spec.whatwg.org/C/#dom-originagentcluster
  bool originAgentCluster() const;

  // Custom elements
  CustomElementRegistry* customElements(ScriptState*) const;
  CustomElementRegistry* customElements() const;
  CustomElementRegistry* MaybeCustomElements() const;

  void SetModulator(Modulator*);

  // Obsolete APIs
  void captureEvents() {}
  void releaseEvents() {}
  External* external();

  bool isSecureContext() const;

  DEFINE_ATTRIBUTE_EVENT_LISTENER(search, kSearch)

  DEFINE_ATTRIBUTE_EVENT_LISTENER(orientationchange, kOrientationchange)

  DEFINE_ATTRIBUTE_EVENT_LISTENER(pagereveal, kPagereveal)

  void RegisterEventListenerObserver(EventListenerObserver*);

  void FrameDestroyed();
  void Reset();

  Element* frameElement() const;

  DOMWindow* open(v8::Isolate*,
                  const String& url_string,
                  const AtomicString& target,
                  const String& features,
                  ExceptionState&);

  DOMWindow* openPictureInPictureWindow(v8::Isolate*,
                                        const WebPictureInPictureWindowOptions&,
                                        ExceptionState&);

  FrameConsole* GetFrameConsole() const;

  void PrintErrorMessage(const String&) const;

  void DispatchPostMessage(
      MessageEvent* event,
      scoped_refptr<const SecurityOrigin> intended_target_origin,
      std::unique_ptr<SourceLocation> location,
      const base::UnguessableToken& source_agent_cluster_id);

  void DispatchMessageEventWithOriginCheck(
      const SecurityOrigin* intended_target_origin,
      MessageEvent*,
      std::unique_ptr<SourceLocation>,
      const base::UnguessableToken& source_agent_cluster_id);

  // Events
  // EventTarget API
  void RemoveAllEventListeners() override;

  using EventTarget::DispatchEvent;
  DispatchEventResult DispatchEvent(Event&, EventTarget*);

  void FinishedLoading(FrameLoader::NavigationFinishState);

  // Dispatch the (deprecated) orientationchange event to this DOMWindow and
  // recurse on its child frames.
  void SendOrientationChangeEvent();

  void EnqueueWindowEvent(Event&, TaskType);
  void EnqueueDocumentEvent(Event&, TaskType);
  void EnqueueNonPersistedPageshowEvent();
  void EnqueueHashchangeEvent(const String& old_url, const String& new_url);
  void DispatchPopstateEvent(scoped_refptr<SerializedScriptValue>,
                             scheduler::TaskAttributionInfo* parent_task);
  void DispatchWindowLoadEvent();
  void DocumentWasClosed();

  void AcceptLanguagesChanged();

  // https://dom.spec.whatwg.org/#dom-window-event
  ScriptValue event(ScriptState*);
  Event* CurrentEvent() const;
  void SetCurrentEvent(Event*);

  TrustedTypePolicyFactory* trustedTypes(ScriptState*) const;
  TrustedTypePolicyFactory* GetTrustedTypesForWorld(
      const DOMWrapperWorld&) const;

  // Returns true if this window is cross-site to the outermost main frame.
  // Defaults to false in a detached window. Note: This uses an outdated
  // definition of "site" which only includes the registrable domain and not the
  // scheme. IsCrossSiteSubframeIncludingScheme() uses HTML's definition of
  // "site" as a registrable domain and scheme.
  bool IsCrossSiteSubframe() const;

  bool IsCrossSiteSubframeIncludingScheme() const;

  void DispatchPersistedPageshowEvent(base::TimeTicks navigation_start);

  void DispatchPagehideEvent(PageTransitionEventPersistence persistence);

  InputMethodController& GetInputMethodController() const {
    return *input_method_controller_;
  }
  TextSuggestionController& GetTextSuggestionController() const {
    return *text_suggestion_controller_;
  }
  SpellChecker& GetSpellChecker() const { return *spell_checker_; }

  void ClearIsolatedWorldCSPForTesting(int32_t world_id);

  bool CrossOriginIsolatedCapability() const override;
  bool IsIsolatedContext() const override;

  // These delegate to the document_.
  ukm::UkmRecorder* UkmRecorder() override;
  ukm::SourceId UkmSourceID() const override;

  const BlinkStorageKey& GetStorageKey() const { return storage_key_; }
  void SetStorageKey(const BlinkStorageKey& storage_key);

  // This storage key must only be used when binding session storage.
  //
  // TODO(crbug.com/1407150): Remove this when deprecation trial is complete.
  const BlinkStorageKey& GetSessionStorageKey() const {
    return session_storage_key_;
  }
  void SetSessionStorageKey(const BlinkStorageKey& session_storage_key);

  void DidReceiveUserActivation();

  // Returns the state of the |payment_request_token_| in this document.
  bool IsPaymentRequestTokenActive() const;

  // Consumes the |payment_request_token_| if it was active in this document.
  bool ConsumePaymentRequestToken();

  // Returns the state of the |fullscreen_request_token_| in this document.
  bool IsFullscreenRequestTokenActive() const;

  // Consumes the |fullscreen_request_token_| if it was active in this document.
  bool ConsumeFullscreenRequestToken();

  // Returns the state of the |display_capture_request_token_| in this document.
  bool IsDisplayCaptureRequestTokenActive() const;

  // Consumes the |display_capture_request_token_| if it was active in this
  // document.
  bool ConsumeDisplayCaptureRequestToken();

  // Called when a network request buffered an additional `num_bytes` while this
  // frame is in back-forward cache.
  void DidBufferLoadWhileInBackForwardCache(bool update_process_wide_count,
                                            size_t num_bytes);

  // Whether the window is credentialless or not.
  bool credentialless() const;

  bool IsInFencedFrame() const override;

  Fence* fence();

  CloseWatcher::WatcherStack* closewatcher_stack() {
    return closewatcher_stack_.Get();
  }

  void GenerateNewNavigationId();

  String GetNavigationId() const { return navigation_id_; }

  NavigationApi* navigation();

  // Is this a Document Picture in Picture window?
  bool IsPictureInPictureWindow() const;

  void set_is_picture_in_picture_window_for_testing(
      bool is_picture_in_picture) {
    is_picture_in_picture_window_ = is_picture_in_picture;
  }

  // Sets the HasStorageAccess member. Note that it can only be granted for a
  // given window, it cannot be taken away.
  void SetHasStorageAccess();

 protected:
  // EventTarget overrides.
  void AddedEventListener(const AtomicString& event_type,
                          RegisteredEventListener&) override;
  void RemovedEventListener(const AtomicString& event_type,
                            const RegisteredEventListener&) override;

  // Protected DOMWindow overrides.
  void SchedulePostMessage(PostedMessage*) override;

 private:
  class NetworkStateObserver;

  // Intentionally private to prevent redundant checks.
  bool IsLocalDOMWindow() const override { return true; }

  bool HasInsecureContextInAncestors() const override;

  Document& GetDocumentForWindowEventHandler() const override {
    return *document();
  }

  void Dispose();

  void DispatchLoadEvent();

  void SetIsPictureInPictureWindow();

  // Return the viewport size including scrollbars.
  gfx::Size GetViewportSize() const;

  Member<ScriptController> script_controller_;

  Member<Document> document_;
  Member<DOMVisualViewport> visualViewport_;

  bool should_print_when_finished_loading_;

  mutable Member<Screen> screen_;
  mutable Member<History> history_;
  mutable Member<BarProp> locationbar_;
  mutable Member<BarProp> menubar_;
  mutable Member<BarProp> personalbar_;
  mutable Member<BarProp> scrollbars_;
  mutable Member<BarProp> statusbar_;
  mutable Member<BarProp> toolbar_;
  mutable Member<Navigator> navigator_;
  mutable Member<StyleMedia> media_;
  mutable Member<CustomElementRegistry> custom_elements_;
  Member<External> external_;

  Member<NavigationApi> navigation_;

  String status_;
  String default_status_;

  HeapHashSet<WeakMember<EventListenerObserver>> event_listener_observers_;

  // Trackers for delegated payment, fullscreen, and display-capture requests.
  // These are related to |Frame::user_activation_state_|.
  DelegatedCapabilityRequestToken payment_request_token_;
  DelegatedCapabilityRequestToken fullscreen_request_token_;
  DelegatedCapabilityRequestToken display_capture_request_token_;

  // https://dom.spec.whatwg.org/#window-current-event
  // We represent the "undefined" value as nullptr.
  Member<Event> current_event_;

  // Store TrustedTypesPolicyFactory, per DOMWrapperWorld.
  mutable HeapHashMap<scoped_refptr<const DOMWrapperWorld>,
                      Member<TrustedTypePolicyFactory>>
      trusted_types_map_;

  // A dummy scheduler to return when the window is detached.
  // All operations on it result in no-op, but due to this it's safe to
  // use the returned value of GetScheduler() without additional checks.
  // A task posted to a task runner obtained from one of its task runners
  // will be forwarded to the default task runner.
  // TODO(altimin): We should be able to remove it after we complete
  // frame:document lifetime refactoring.
  std::unique_ptr<FrameOrWorkerScheduler> detached_scheduler_;

  Member<InputMethodController> input_method_controller_;
  Member<SpellChecker> spell_checker_;
  Member<TextSuggestionController> text_suggestion_controller_;

  // Map from isolated world IDs to their ContentSecurityPolicy instances.
  Member<HeapHashMap<int, Member<ContentSecurityPolicy>>>
      isolated_world_csp_map_;

  // Tracks which features have already been potentially violated in this
  // document. This helps to count them only once per page load.
  // We don't use std::bitset to avoid to include
  // permissions_policy.mojom-blink.h.
  mutable Vector<bool> potentially_violated_features_;

  // Token identifying the LocalFrame that this window was associated with at
  // creation. Remains valid even after the frame is destroyed and the context
  // is detached.
  const LocalFrameToken token_;

  // Tracks which document policy violation reports have already been sent in
  // this document, to avoid reporting duplicates. The value stored comes
  // from |DocumentPolicyViolationReport::MatchId()|.
  mutable HashSet<unsigned> document_policy_violation_reports_sent_;

  // Tracks metrics related to postMessage usage.
  // TODO(crbug.com/1159586): Remove when no longer needed.
  PostMessageCounter post_message_counter_;

  // The storage key for this LocalDomWindow.
  BlinkStorageKey storage_key_;

  // The storage key here is the one to use when binding session storage. This
  // may differ from `storage_key_` as a deprecation trial can prevent the
  // partitioning of session storage.
  //
  // TODO(crbug.com/1407150): Remove this when deprecation trial is complete.
  BlinkStorageKey session_storage_key_;

  // Fire "online" and "offline" events.
  Member<NetworkStateObserver> network_state_observer_;

  // The total bytes buffered by all network requests in this frame while frozen
  // due to back-forward cache. This number gets reset when the frame gets out
  // of the back-forward cache.
  size_t total_bytes_buffered_while_in_back_forward_cache_ = 0;

  // Collection of fenced frame APIs.
  // https://github.com/shivanigithub/fenced-frame/issues/14
  Member<Fence> fence_;

  Member<CloseWatcher::WatcherStack> closewatcher_stack_;

  // If set, this window is a Document Picture in Picture window.
  // https://wicg.github.io/document-picture-in-picture/
  bool is_picture_in_picture_window_ = false;

  // The navigation id of a document is to identify navigation of special types
  // like bfcache navigation or soft navigation. It changes when navigations
  // of these types occur.
  String navigation_id_;

  // Records whether this window has obtained storage access. It cannot be
  // revoked once set to true.
  bool has_storage_access_ = false;

  // Tracks whether this window has shown a payment request without a user
  // activation. It cannot be revoked once set to true.
  // TODO(crbug.com/1439565): Move this bit to a new payments-specific
  // per-LocalDOMWindow class in the payments module.
  bool had_activationless_payment_request_ = false;
};

template <>
struct DowncastTraits<LocalDOMWindow> {
  static bool AllowFrom(const ExecutionContext& context) {
    return context.IsWindow();
  }
  static bool AllowFrom(const DOMWindow& window) {
    return window.IsLocalDOMWindow();
  }
};

inline String LocalDOMWindow::status() const {
  return status_;
}

inline String LocalDOMWindow::defaultStatus() const {
  DCHECK(RuntimeEnabledFeatures::WindowDefaultStatusEnabled());
  return default_status_;
}

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_LOCAL_DOM_WINDOW_H_

3、window对象接口定义实现文件(v8):

out\Debug\gen\third_party\blink\renderer\bindings\modules\v8\v8_window.cc

out\Debug\gen\third_party\blink\renderer\bindings\modules\v8\v8_window.h

部分定义:

void SelfAttributeSetCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
  
RUNTIME_CALL_TIMER_SCOPE_DISABLED_BY_DEFAULT(info.GetIsolate(), "Blink_DOMWindow_self_Setter");
BLINK_BINDINGS_TRACE_EVENT("Window.self.set");

v8::Isolate* isolate = info.GetIsolate();
const char* const property_name = "self";
if (UNLIKELY(info.Length() < 1)) {
  const ExceptionContextType exception_context_type = ExceptionContextType::kAttributeSet;
const char* const class_like_name = "Window";
ExceptionState exception_state(isolate, exception_context_type, class_like_name, property_name);
exception_state.ThrowTypeError(ExceptionMessages::NotEnoughArguments(1, info.Length()));
return;
}

// [Replaceable]
bool did_create;
v8::Local<v8::Object> v8_receiver = info.This();
v8::Local<v8::Context> current_context = isolate->GetCurrentContext();
v8::Local<v8::Value> v8_property_value = info[0];
if (!v8_receiver->CreateDataProperty(current_context, V8AtomicString(isolate, property_name), v8_property_value).To(&did_create)) {
  return;
}
}

void DocumentAttributeGetCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
  
RUNTIME_CALL_TIMER_SCOPE_DISABLED_BY_DEFAULT(info.GetIsolate(), "Blink_DOMWindow_document_Getter");
BLINK_BINDINGS_TRACE_EVENT("Window.document.get");



v8::Local<v8::Object> v8_receiver = info.This();
LocalDOMWindow* blink_receiver = &UnsafeTo<LocalDOMWindow>(*V8Window::ToWrappableUnsafe(v8_receiver));
auto&& return_value = blink_receiver->document();
bindings::V8SetReturnValue(info, return_value, blink_receiver);
}

4、控制台输入window看下和c++代码对比效果:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2211105.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【原创】java+springboot+mysql在线课程学习网设计与实现

个人主页&#xff1a;程序猿小小杨 个人简介&#xff1a;从事开发多年&#xff0c;Java、Php、Python、前端开发均有涉猎 博客内容&#xff1a;Java项目实战、项目演示、技术分享 文末有作者名片&#xff0c;希望和大家一起共同进步&#xff0c;你只管努力&#xff0c;剩下的交…

陪诊小程序搭建:打造便利的陪诊环境

陪诊行业作为一个新兴行业&#xff0c;随着老龄化的严重&#xff0c;在近几年中需求量日益旺盛。陪诊师为大众的就医提供了极大的便利性&#xff0c;在看病难、医疗资源紧张方面发挥了积极作用。 在陪诊行业的快速发展下&#xff0c;陪诊小程序为行业带来了便捷的模式&#xf…

使用 three.js和 shader 实现一个五星红旗 飘扬得着色器

使用 three.js和 shader 实现一个五星红旗 飘扬得着色器 源链接&#xff1a;https://threehub.cn/#/codeMirror?navigationThreeJS&classifyshader&idchinaFlag 国内站点预览&#xff1a;http://threehub.cn github地址: https://github.com/z2586300277/three-ce…

数学建模算法与应用 第6章 微分方程建模及其求解方法

目录 6.1 微分方程建模概述 6.2 发射卫星与三阶火箭建模 Matlab代码示例&#xff1a;火箭发射模拟 6.3 微分方程数值解法 Matlab代码示例&#xff1a;欧拉法与龙格-库塔法 6.4 放射性废料的处理 Matlab代码示例&#xff1a;放射性衰变 6.5 初值问题的Matlab数值求解 习…

Java项目:149 基于SSM的毕业设计管理系统

作者主页&#xff1a;源码空间codegym 简介&#xff1a;Java领域优质创作者、Java项目、学习资料、技术互助 文中获取源码 毕业设计管理系统 介绍 毕业设计是本科教育的最后一个环节&#xff0c;整个过程包括课题拟定与审核、师生双选、开题报告、文档审核、中期检查、毕业答…

C++ 比大小

//输入两个可能有前导 0 的大整数&#xff0c;a,b请输出他们谁大谁小#include <iostream> #include <string> #include <string.h> using namespace std; #define M 100005 int main() {char a[M], b[M];char *pa, *pb;pa a;pb b;cin >> a >> …

Linux的pinctrl和gpio子系统

上一章我们编写了基于设备树的 LED 驱动&#xff0c;但是驱动的本质还是没变&#xff0c;都是配置 LED 灯所使用的 GPIO 寄存器&#xff0c;驱动开发方式中硬件初始化这一部分和裸机基本没啥区别。Linux 是一个庞大而完善的系统&#xff0c;尤其是驱动框架&#xff0c;像 GPIO …

软考《信息系统运行管理员》- 4.1信息系统软件运维概述

4.1信息系统软件运维概述 文章目录 4.1信息系统软件运维概述信息系统软件运维的概念信息系统软件的可维护性及维护类型对软件可维护性的度量可以从以下几个方面进行&#xff1a;软件维护分类&#xff1a; 信息系统软件运维的体系1.**需求驱动**2.**运维流程**3.**运维过程**4.*…

ApiPost7一键压测

首先我们需要确认apipost已登录所需测试接口的后端 这边有个一键压测功能&#xff0c;可以帮助我们未下测试工具的同学直接进行接口测试 第一步&#xff1a;修改调试参数 首先我们需要在调试中把要传的参数设计成以下格式&#xff0c;确保后续压测功能成功执行 第二步&am…

MySQL-05.DDL-图形化界面工具

一.数据库图形化界面工具介绍 datagrip是Oracle公司所提供的一款专门用于操作数据库的图形化界面工具&#xff0c;目前已经被集成在了idea中&#xff0c;可以直接通过idea进行操作而不需要下载安装datagrip。 二.在idea中使用datagrip操作数据库 1.首先创建一个空项目 2.接着…

标准Netty框架的云快充协议+桩直连协议+云快充1.5 -1.6

软件架构 1、提供云快充底层桩直连协议&#xff0c;版本为云快充1.5&#xff0c;对于没有对接过充电桩系统的开发者尤为合适&#xff1b; 2、包含&#xff1a;启动充电、结束充电、充电中实时数据获取、报文解析、Netty通讯框架、包解析工具、调试器模拟器软件等&#xff1b;…

selenium的IDE插件进行录制和回放并导出为python/java脚本(10)

Selenium IDE&#xff1a;Selenium Suite下的开源Web自动化测试工具&#xff0c;是Firefox或者chrome的一个插件&#xff0c;具有记录和回放功能&#xff0c;无需编程即可创建测试用例&#xff0c;并且可以将用例直接导出为可用的python/java等编程语言的脚本。 我们以chrome浏…

数字化装备场管理系统|DW-S301-A系统主要功能介绍

数字化装备场系统DW-S301-A以物联网技术为核心&#xff0c;通过软硬件集成建设&#xff0c;总体上实现动用管控、维护保养、故障维修、物资管理、电子履历、场区管理、态势展现等功能。 1.动用管控功能 通过应用软件与单装自动识别铭牌、车辆门禁等硬件设备联动&#xff0c;实…

进程间通信 —— 《命名管道》

文章目录 前言&#xff1a;命名管道的原理&#xff1a;代码编写&#xff1a; 前言&#xff1a; 在前面的一文&#xff0c;我们主要介绍了关于进程间的通信是如何实现的&#xff0c;以及引入了进程间通信的前提——“要让两个进程在OS中看到同一份资源”&#xff0c;而对于父子…

Spring Boot知识管理:智能搜索与分析

3系统分析 3.1可行性分析 通过对本知识管理系统实行的目的初步调查和分析&#xff0c;提出可行性方案并对其一一进行论证。我们在这里主要从技术可行性、经济可行性、操作可行性等方面进行分析。 3.1.1技术可行性 本知识管理系统采用JAVA作为开发语言&#xff0c;Spring Boot框…

HTML+CSS实现固定的半透明底部导航栏

实现固定的半透明底部导航栏 在网页设计中&#xff0c;固定底部导航栏是一种常见的设计模式&#xff0c;尤其适用于移动端或简洁的网页布局。通过CSS&#xff0c;我们可以轻松实现固定位置、半透明效果、以及图片的动态缩放。本文将详细介绍如何使用HTML和CSS实现一个固定且具…

stderr和磁盘理解

1.stderr stderr文件默认的文件标识符是2&#xff0c;指向显示器&#xff0c;用来输出错误信息 #include<stdio.h>int main() {fprintf(stdout,"hello stdout\n");fprintf(stderr,"hello stderr\n");return 0; }stdout和stderr默认是指向显示器的&…

Postman发送GET、POST请求

Postman发送GET、POST请求 GET请求 在这里选择GET请求&#xff0c;接着输入请求的URL&#xff0c;点击发送即可看到服务端返回的数据。 POST请求 post请求通常会携带body数据&#xff0c;比get请求麻烦一点的是需要在Body里输入要携带的body数据&#xff0c;按照箭头所指示的…

千万级的大表,是如何产生的?

千万级的大表&#xff0c;是如何产生的? 我们小公司没有大表。。。 大家好&#xff0c;我是皇子。 前面的文章在介绍了《设计支持千万级的大表&#xff0c;有哪些数据库规范&#xff1f;》&#xff0c;实际上不管是否到达千万级&#xff0c;这些规范都是适用的。 那有人会…

git合并冲突未解决完导致Rebasing,无法切分支解决方案

分支前面出现Rebasing 进入项目目录中.git目录&#xff0c;手动删除index.lock文件&#xff08;相当于分支的锁&#xff0c;有这个就是不让你动&#xff0c;得删了&#xff09; 然后在git控制台输入git rebase --abort命令回滚到本地合并处理之前&#xff0c;然后再进行其他处…