22
22
#include " chrome/browser/ui/views/side_panel/side_panel_util.h"
23
23
#include " chrome/grit/generated_resources.h"
24
24
#include " components/grit/brave_components_strings.h"
25
+ #include " content/public/browser/visibility.h"
26
+ #include " content/public/browser/web_contents.h"
25
27
#include " ui/base/l10n/l10n_util.h"
26
28
#include " ui/base/models/image_model.h"
27
29
#include " ui/views/vector_icons.h"
@@ -88,22 +90,34 @@ std::unique_ptr<views::View> PlaylistSidePanelCoordinator::CreateWebView(
88
90
89
91
Proxy::CreateForWebContents (contents_wrapper_->web_contents (),
90
92
weak_ptr_factory_.GetWeakPtr ());
91
- }
92
93
93
- auto web_view = std::make_unique<PlaylistSidePanelWebView>(
94
- &GetBrowser (), scope, base::DoNothing (), contents_wrapper_.get ());
95
- side_panel_web_view_ = web_view->GetWeakPtr ();
94
+ // |web_view_| is also created and cached together with |contents_wrapper_|.
95
+ // Why caching webview also? When SidePanelWebView is created, its contents
96
+ // is marked as side panel to make its loading faster at
97
+ // SidePanelLoadingVoter::MarkAsSidePanel(). However, upstream has
98
+ // assumption that it should have initial state(not url loaded before)
99
+ // except it's preloaded side panel. If we create PlaylistSidePanelWebView
100
+ // whenever opening, we conflict with it as playlist could still play even
101
+ // it's closed. By caching webview also, we could avoid that conflict.
102
+ CHECK (!side_panel_web_view_);
103
+ side_panel_web_view_ = std::make_unique<PlaylistSidePanelWebView>(
104
+ &GetBrowser (), scope, base::DoNothing (), contents_wrapper_.get ());
105
+ side_panel_web_view_->set_owned_by_client ();
106
+ }
96
107
97
108
if (!should_create_contents_wrapper) {
98
109
// SidePanelWebView's initial visibility is hidden. Thus, we need to
99
110
// call this manually when we don't reload the web contents.
100
111
// Calling this will also mark that the web contents is ready to go.
101
- web_view ->ShowUI ();
112
+ side_panel_web_view_ ->ShowUI ();
102
113
}
103
114
104
- view_observation_.Observe (web_view.get ());
115
+ auto view = std::make_unique<views::View>();
116
+ view->SetUseDefaultFillLayout (true );
117
+ view->AddChildViewRaw (side_panel_web_view_.get ());
118
+ view_observation_.Observe (view.get ());
105
119
106
- return web_view ;
120
+ return view ;
107
121
}
108
122
109
123
BrowserView* PlaylistSidePanelCoordinator::GetBrowserView () {
@@ -118,8 +132,10 @@ void PlaylistSidePanelCoordinator::OnViewIsDeleting(views::View* view) {
118
132
119
133
void PlaylistSidePanelCoordinator::DestroyWebContentsIfNeeded () {
120
134
DCHECK (contents_wrapper_);
121
- if (!contents_wrapper_->web_contents ()->IsCurrentlyAudible ()) {
135
+ if (!is_audible_for_testing_ &&
136
+ !contents_wrapper_->web_contents ()->IsCurrentlyAudible ()) {
122
137
contents_wrapper_.reset ();
138
+ side_panel_web_view_.reset ();
123
139
}
124
140
}
125
141
0 commit comments