1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
|
/*
* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights
* reserved.
* Copyright (C) 2008 Torch Mobile Inc. All rights reserved.
* (http://www.torchmobile.com/)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_PAGE_PAGE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_PAGE_PAGE_H_
#include <memory>
#include "base/macros.h"
#include "third_party/blink/public/mojom/devtools/inspector_issue.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/page/page_visibility_state.mojom-blink.h"
#include "third_party/blink/public/platform/scheduler/web_scoped_virtual_time_pauser.h"
#include "third_party/blink/public/platform/web_text_autosizer_page_info.h"
#include "third_party/blink/public/web/web_window_features.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/vision_deficiency.h"
#include "third_party/blink/renderer/core/frame/deprecation.h"
#include "third_party/blink/renderer/core/frame/settings_delegate.h"
#include "third_party/blink/renderer/core/page/page_animator.h"
#include "third_party/blink/renderer/core/page/page_visibility_observer.h"
#include "third_party/blink/renderer/core/page/viewport_description.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/heap_observer_list.h"
#include "third_party/blink/renderer/platform/scheduler/public/page_lifecycle_state.h"
#include "third_party/blink/renderer/platform/scheduler/public/page_scheduler.h"
#include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace cc {
class AnimationHost;
}
namespace blink {
class AgentMetricsCollector;
class AutoscrollController;
class BrowserControls;
class ChromeClient;
class ConsoleMessageStorage;
class InspectorIssueStorage;
class ContextMenuController;
class Document;
class DragCaret;
class DragController;
class FocusController;
class Frame;
class LinkHighlight;
class LocalFrame;
class LocalFrameView;
class MediaFeatureOverrides;
class OverscrollController;
struct PageScaleConstraints;
class PageScaleConstraintsSet;
class PluginData;
class PluginsChangedObserver;
class PointerLockController;
class ScopedPagePauser;
class ScrollingCoordinator;
class ScrollbarTheme;
class SecurityOrigin;
class Settings;
class SpatialNavigationController;
class TopDocumentRootScrollerController;
class ValidationMessageClient;
class VisualViewport;
typedef uint64_t LinkHash;
float DeviceScaleFactorDeprecated(LocalFrame*);
class CORE_EXPORT Page final : public GarbageCollected<Page>,
public Supplementable<Page>,
public SettingsDelegate,
public PageScheduler::Delegate {
USING_GARBAGE_COLLECTED_MIXIN(Page);
friend class Settings;
public:
// It is up to the platform to ensure that non-null clients are provided where
// required.
struct CORE_EXPORT PageClients final {
STACK_ALLOCATED();
public:
PageClients();
ChromeClient* chrome_client;
DISALLOW_COPY_AND_ASSIGN(PageClients);
};
// Any pages not owned by a web view should be created using this method.
static Page* CreateNonOrdinary(PageClients& pages_clients);
// An "ordinary" page is a fully-featured page owned by a web view.
static Page* CreateOrdinary(PageClients&, Page* opener);
explicit Page(PageClients&);
~Page() override;
void CloseSoon();
bool IsClosing() const { return is_closing_; }
using PageSet = HeapHashSet<WeakMember<Page>>;
// Return the current set of full-fledged, ordinary pages.
// Each created and owned by a WebView.
//
// This set does not include Pages created for other, internal purposes
// (SVGImages, inspector overlays, page popups etc.)
static PageSet& OrdinaryPages();
static void InsertOrdinaryPageForTesting(Page*);
// Returns pages related to the current browsing context (excluding the
// current page). See also
// https://html.spec.whatwg.org/C/#unit-of-related-browsing-contexts
HeapVector<Member<Page>> RelatedPages();
static void PlatformColorsChanged();
static void ColorSchemeChanged();
void InitialStyleChanged();
void UpdateAcceleratedCompositingSettings();
ViewportDescription GetViewportDescription() const;
// Returns the plugin data associated with |main_frame_origin|.
PluginData* GetPluginData(const SecurityOrigin* main_frame_origin);
// Resets the plugin data for all pages in the renderer process and notifies
// PluginsChangedObservers.
static void ResetPluginData();
// When this method is called, page_scheduler_->SetIsMainFrameLocal should
// also be called to update accordingly.
// TODO(npm): update the |page_scheduler_| directly in this method.
void SetMainFrame(Frame*);
Frame* MainFrame() const { return main_frame_; }
// Escape hatch for existing code that assumes that the root frame is
// always a LocalFrame. With OOPI, this is not always the case. Code that
// depends on this will generally have to be rewritten to propagate any
// necessary state through all renderer processes for that page and/or
// coordinate/rely on the browser process to help dispatch/coordinate work.
LocalFrame* DeprecatedLocalMainFrame() const;
void DocumentDetached(Document*);
bool OpenedByDOM() const;
void SetOpenedByDOM();
PageAnimator& Animator() { return *animator_; }
ChromeClient& GetChromeClient() const {
DCHECK(chrome_client_) << "No chrome client";
return *chrome_client_;
}
AutoscrollController& GetAutoscrollController() const {
return *autoscroll_controller_;
}
DragCaret& GetDragCaret() const { return *drag_caret_; }
DragController& GetDragController() const { return *drag_controller_; }
FocusController& GetFocusController() const { return *focus_controller_; }
SpatialNavigationController& GetSpatialNavigationController();
ContextMenuController& GetContextMenuController() const {
return *context_menu_controller_;
}
PointerLockController& GetPointerLockController() const {
return *pointer_lock_controller_;
}
ValidationMessageClient& GetValidationMessageClient() const {
return *validation_message_client_;
}
AgentMetricsCollector* GetAgentMetricsCollector() const {
return agent_metrics_collector_.Get();
}
void SetValidationMessageClientForTesting(ValidationMessageClient*);
ScrollingCoordinator* GetScrollingCoordinator();
Settings& GetSettings() const { return *settings_; }
Deprecation& GetDeprecation() { return deprecation_; }
void SetWindowFeatures(const WebWindowFeatures& features) {
window_features_ = features;
}
const WebWindowFeatures& GetWindowFeatures() const {
return window_features_;
}
PageScaleConstraintsSet& GetPageScaleConstraintsSet();
const PageScaleConstraintsSet& GetPageScaleConstraintsSet() const;
BrowserControls& GetBrowserControls();
const BrowserControls& GetBrowserControls() const;
ConsoleMessageStorage& GetConsoleMessageStorage();
const ConsoleMessageStorage& GetConsoleMessageStorage() const;
InspectorIssueStorage& GetInspectorIssueStorage();
const InspectorIssueStorage& GetInspectorIssueStorage() const;
TopDocumentRootScrollerController& GlobalRootScrollerController() const;
VisualViewport& GetVisualViewport();
const VisualViewport& GetVisualViewport() const;
LinkHighlight& GetLinkHighlight();
OverscrollController& GetOverscrollController();
const OverscrollController& GetOverscrollController() const;
void SetTabKeyCyclesThroughElements(bool b) {
tab_key_cycles_through_elements_ = b;
}
bool TabKeyCyclesThroughElements() const {
return tab_key_cycles_through_elements_;
}
// Pausing is used to implement the "Optionally, pause while waiting for
// the user to acknowledge the message" step of simple dialog processing:
// https://html.spec.whatwg.org/C/#simple-dialogs
//
// Per https://html.spec.whatwg.org/C/#pause, no loads
// are allowed to start/continue in this state, and all background processing
// is also paused.
bool Paused() const { return paused_; }
void SetPaused(bool);
// Frozen state corresponds to "lifecycle state for CPU suspension"
// https://wicg.github.io/page-lifecycle/#sec-lifecycle-states
bool Frozen() const { return frozen_; }
void SetPageScaleFactor(float);
float PageScaleFactor() const;
// Corresponds to pixel density of the device where this Page is
// being displayed. In multi-monitor setups this can vary between pages.
// This value does not account for Page zoom, use LocalFrame::devicePixelRatio
// instead. This is to be deprecated. Use this with caution.
// 1) If you need to scale the content per device scale factor, this is still
// valid. In use-zoom-for-dsf mode, this is always 1, and will be remove
// when transition is complete.
// 2) If you want to compute the device related measure (such as device pixel
// height, or the scale factor for drag image), use
// ChromeClient::screenInfo() instead.
float DeviceScaleFactorDeprecated() const { return device_scale_factor_; }
void SetDeviceScaleFactorDeprecated(float);
static void AllVisitedStateChanged(bool invalidate_visited_link_hashes);
static void VisitedStateChanged(LinkHash visited_hash);
void SetVisibilityState(mojom::blink::PageVisibilityState visibility_state,
bool is_initial_state);
mojom::blink::PageVisibilityState GetVisibilityState() const;
bool IsPageVisible() const;
bool IsCursorVisible() const;
void SetIsCursorVisible(bool is_visible) { is_cursor_visible_ = is_visible; }
// Don't allow more than a certain number of frames in a page.
static int MaxNumberOfFrames();
static void SetMaxNumberOfFramesToTenForTesting(bool enabled);
void IncrementSubframeCount() { ++subframe_count_; }
void DecrementSubframeCount() {
DCHECK_GT(subframe_count_, 0);
--subframe_count_;
}
int SubframeCount() const;
void SetDefaultPageScaleLimits(float min_scale, float max_scale);
void SetUserAgentPageScaleConstraints(
const PageScaleConstraints& new_constraints);
#if DCHECK_IS_ON()
void SetIsPainting(bool painting) { is_painting_ = painting; }
bool IsPainting() const { return is_painting_; }
#endif
void DidCommitLoad(LocalFrame*);
void AcceptLanguagesChanged();
void Trace(Visitor*) const override;
void AnimationHostInitialized(cc::AnimationHost&, LocalFrameView*);
void WillCloseAnimationHost(LocalFrameView*);
void WillBeDestroyed();
void RegisterPluginsChangedObserver(PluginsChangedObserver*);
ScrollbarTheme& GetScrollbarTheme() const;
PageScheduler* GetPageScheduler() const;
// PageScheduler::Delegate implementation.
bool IsOrdinary() const override;
void ReportIntervention(const String& message) override;
bool RequestBeginMainFrameNotExpected(bool new_state) override;
void OnSetPageFrozen(bool is_frozen) override;
bool LocalMainFrameNetworkIsAlmostIdle() const override;
void AddAutoplayFlags(int32_t flags);
void ClearAutoplayFlags();
int32_t AutoplayFlags() const;
void SetInsidePortal(bool inside_portal);
bool InsidePortal() const;
void SetTextAutosizerPageInfo(const WebTextAutosizerPageInfo& page_info) {
web_text_autosizer_page_info_ = page_info;
}
const WebTextAutosizerPageInfo& TextAutosizerPageInfo() const {
return web_text_autosizer_page_info_;
}
void SetMediaFeatureOverride(const AtomicString& media_feature,
const String& value);
const MediaFeatureOverrides* GetMediaFeatureOverrides() const {
return media_feature_overrides_.get();
}
void ClearMediaFeatureOverrides();
void SetVisionDeficiency(VisionDeficiency new_vision_deficiency);
VisionDeficiency GetVisionDeficiency() const { return vision_deficiency_; }
WebScopedVirtualTimePauser& HistoryNavigationVirtualTimePauser() {
return history_navigation_virtual_time_pauser_;
}
HeapObserverList<PageVisibilityObserver>& PageVisibilityObserverList() {
return page_visibility_observer_list_;
}
static void PrepareForLeakDetection();
private:
friend class ScopedPagePauser;
void InitGroup();
// SettingsDelegate overrides.
void SettingsChanged(SettingsDelegate::ChangeType) override;
// Notify |plugins_changed_observers_| that plugins have changed.
void NotifyPluginsChanged() const;
void SetPageScheduler(std::unique_ptr<PageScheduler>);
void InvalidateColorScheme();
void InvalidatePaint();
// Typically, the main frame and Page should both be owned by the embedder,
// which must call Page::willBeDestroyed() prior to destroying Page. This
// call detaches the main frame and clears this pointer, thus ensuring that
// this field only references a live main frame.
//
// However, there are several locations (InspectorOverlay, SVGImage, and
// WebPagePopupImpl) which don't hold a reference to the main frame at all
// after creating it. These are still safe because they always create a
// Frame with a LocalFrameView. LocalFrameView and Frame hold references to
// each other, thus keeping each other alive. The call to willBeDestroyed()
// breaks this cycle, so the frame is still properly destroyed once no
// longer needed.
Member<Frame> main_frame_;
Member<PageAnimator> animator_;
const Member<AutoscrollController> autoscroll_controller_;
Member<ChromeClient> chrome_client_;
const Member<DragCaret> drag_caret_;
const Member<DragController> drag_controller_;
const Member<FocusController> focus_controller_;
const Member<ContextMenuController> context_menu_controller_;
const Member<PageScaleConstraintsSet> page_scale_constraints_set_;
HeapObserverList<PageVisibilityObserver> page_visibility_observer_list_;
const Member<PointerLockController> pointer_lock_controller_;
Member<ScrollingCoordinator> scrolling_coordinator_;
const Member<BrowserControls> browser_controls_;
const Member<ConsoleMessageStorage> console_message_storage_;
const Member<InspectorIssueStorage> inspector_issue_storage_;
const Member<TopDocumentRootScrollerController>
global_root_scroller_controller_;
const Member<VisualViewport> visual_viewport_;
const Member<OverscrollController> overscroll_controller_;
const Member<LinkHighlight> link_highlight_;
Member<SpatialNavigationController> spatial_navigation_controller_;
Member<PluginData> plugin_data_;
Member<ValidationMessageClient> validation_message_client_;
// Stored only for ordinary pages to avoid adding metrics from things like
// overlays, popups and SVG.
Member<AgentMetricsCollector> agent_metrics_collector_;
Deprecation deprecation_;
WebWindowFeatures window_features_;
bool opened_by_dom_;
// Set to true when window.close() has been called and the Page will be
// destroyed. The browsing contexts in this page should no longer be
// discoverable via JS.
// TODO(dcheng): Try to remove |DOMWindow::m_windowIsClosing| in favor of
// this. However, this depends on resolving https://crbug.com/674641
bool is_closing_;
bool tab_key_cycles_through_elements_;
float device_scale_factor_;
mojom::blink::PageVisibilityState visibility_state_;
bool is_ordinary_;
bool is_cursor_visible_;
// See Page::Paused and Page::Frozen for the detailed description of paused
// and frozen state. The main distinction is that "frozen" state is
// web-exposed (onfreeze / onresume) and controlled from the browser process,
// while "paused" state is an implementation detail of handling sync IPCs and
// controlled from the renderer.
bool paused_ = false;
bool frozen_ = false;
#if DCHECK_IS_ON()
bool is_painting_ = false;
#endif
int subframe_count_;
HeapHashSet<WeakMember<PluginsChangedObserver>> plugins_changed_observers_;
// A circular, double-linked list of pages that are related to the current
// browsing context. See also RelatedPages method.
Member<Page> next_related_page_;
Member<Page> prev_related_page_;
// A handle to notify the scheduler whether this page has other related
// pages or not.
FrameScheduler::SchedulingAffectingFeatureHandle has_related_pages_;
std::unique_ptr<PageScheduler> page_scheduler_;
// Overrides for various media features, set from DevTools.
std::unique_ptr<MediaFeatureOverrides> media_feature_overrides_;
// Emulated vision deficiency, set from DevTools.
VisionDeficiency vision_deficiency_ = VisionDeficiency::kNoVisionDeficiency;
int32_t autoplay_flags_;
// Accessed by frames to determine whether to expose the PortalHost object.
bool inside_portal_ = false;
WebTextAutosizerPageInfo web_text_autosizer_page_info_;
WebScopedVirtualTimePauser history_navigation_virtual_time_pauser_;
DISALLOW_COPY_AND_ASSIGN(Page);
};
extern template class CORE_EXTERN_TEMPLATE_EXPORT Supplement<Page>;
class CORE_EXPORT InternalSettingsPageSupplementBase : public Supplement<Page> {
public:
using Supplement<Page>::Supplement;
static const char kSupplementName[];
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_PAGE_PAGE_H_
|