Web is the core view class in the WebKit framework that manages interactions between the
Web classes. To embed web content in your application, you just create a
Web object, attach it to a window, and send a
load(_:) message to its main frame.
- macOS 10.3–10.14Deprecated
Behind the scenes,
Web objects encapsulate the content contained in a single frame element. A hierarchy of
Web objects is used to model an entire webpage where the root is called the main frame. There is a
Web object per
Web object used to display the frame content. Therefore, there is a parallel hierarchy of
Web objects used to render an entire page. The
Web object is also the parent view of this hierarchy. You do not need to create
Web objects directly. These objects are automatically created when the page loads, either programmatically or by the user clicking a link.
You customize your embedded web content by implementing
Web delegates to handle certain aspects of the process.
Web objects have multiple delegates because the process of loading a webpage is asynchronous and complicated if errors occur. All the
Web delegates use informal protocols so you only need to implement only the delegates and methods that define the behavior you wish to change—default implementations are already provided.
For example, you might want to implement the frame load and resource load delegates to monitor the load progress and display status messages. Applications that use multiple windows may want to implement a user interface delegate. See the individual informal delegate protocols for more details: WebFrameLoadDelegate, WebPolicyDelegate,
Another way to monitor load progress with less control is to observe the
Web notifications. For example, you could observe these notifications to implement a simple progress indicator in your application. You update the progress indicator by invoking the
estimated method to get an estimate of the amount of content that is currently loaded.
Web object is intended to support most features you would expect in a web browser except that it doesn’t implement the specific user interface for those features. You are responsible for implementing the user interface objects such as status bars, toolbars, buttons, and text fields. For example, a
Web object manages a back-forward list by default, and has
go action methods. It is your responsibility to create the buttons that would send theses action messages. Note, there is some overhead in maintaining a back-forward list and page cache, so you should disable it if your application doesn’t use it.
You use a
Web object to encapsulate the preferences of a
Web object, such as the font, text encoding, and image settings. You can modify the preferences for individual
Web objects or specify a shared
Web object using the
preferences method. Use the
Web method to specify whether the preferences should be automatically saved to the user defaults database.
You can also extend WebKit by implementing your own document view and representation classes for specific MIME types. Use the
register class method to register your custom classes with a