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
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PRELOADING_PREVIEW_PREVIEW_TAB_H_
#define CHROME_BROWSER_PRELOADING_PREVIEW_PREVIEW_TAB_H_
#include <memory>
#include "base/memory/weak_ptr.h"
#include "content/public/browser/web_contents_delegate.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/views/widget/widget_observer.h"
#include "url/gurl.h"
namespace blink {
class WebInputEvent;
} // namespace blink
namespace content {
class WebContents;
class PreviewCancelReason;
} // namespace content
namespace views {
class WebView;
class Widget;
} // namespace views
class PreviewManager;
class PreviewZoomController;
// Hosts a WebContents for preview until a user decides to navigate to it.
class PreviewTab final : public content::WebContentsDelegate,
public ui::AcceleratorTarget,
public views::WidgetObserver {
public:
PreviewTab(PreviewManager* preview_manager,
content::WebContents& parent,
const GURL& url);
~PreviewTab() override;
PreviewTab(const PreviewTab&) = delete;
PreviewTab& operator=(const PreviewTab&) = delete;
PreviewZoomController* preview_zoom_controller() const {
return preview_zoom_controller_.get();
}
// Opens the previewed WebContents as a new tab.
//
// This attaches remaining all tab helpers as for the ordinal navigation,
// promote WebContents as a tab, and activates the page.
void PromoteToNewTab(content::WebContents& initiator_web_contents);
// This performs activation steps for tab promotion. This will relax the
// capability control, and send an IPC to relevant renderers to perform
// the prerendering activation algorithm that updates document.prerendering
// and runs queued suspended tasks such as resolving promises, releasing
// AudioContext, etc.
// This is not fully implemented, and the progress is tracked at b:305000959.
void Activate(base::WeakPtr<content::WebContents> web_contents);
// content::WebContentsDelegate implementation:
void CancelPreview(content::PreviewCancelReason reason) override;
base::WeakPtr<content::WebContents> GetWebContents();
private:
void AttachTabHelpersForInit();
bool AuditWebInputEvent(const blink::WebInputEvent& event);
// content::WebContentsDelegate implementation:
content::PreloadingEligibility IsPrerender2Supported(
content::WebContents& web_contents,
content::PreloadingTriggerType trigger_type) override;
void RegisterKeyboardAccelerators();
// ui::AcceleratorTarget implementation:
bool CanHandleAccelerators() const override;
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
// views::WidgetObserver implementation:
void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
// Outlives because `PreviewManager` has `PreviewTab`.
raw_ptr<PreviewManager> preview_manager_;
std::unique_ptr<content::WebContents> web_contents_;
std::optional<content::WebContents::ScopedIgnoreInputEvents>
scoped_ignore_web_inputs_;
std::unique_ptr<views::Widget> widget_;
std::unique_ptr<views::WebView> view_;
std::unique_ptr<PreviewZoomController> preview_zoom_controller_;
GURL url_;
std::optional<content::PreviewCancelReason> cancel_reason_ = std::nullopt;
// A mapping between accelerators and command IDs.
base::flat_map<ui::Accelerator, int> accelerator_table_;
};
#endif // CHROME_BROWSER_PRELOADING_PREVIEW_PREVIEW_TAB_H_
|