Commit 816c828f authored by Daniel Nicoara's avatar Daniel Nicoara Committed by Commit Bot

cast: webview: Update default initialization

* aura::Window default property values return 0 as the default value if
  the property isn't defined. So we can't initialize the IDs to 0 by
  default otherwise we could get matches on un-initialized Webviews.
* Register the WebviewWindowManager::Observer when the Webview is
  created since this is when we have the Webview to parent. If it
  happens that we get a parenting request without a valid Webview it
  will crash the browser process.

Bug: b/132811925
Test: Try to register Webview with ID=0
Change-Id: Ieb82c97be3850633b02894cb2a805272d38d227e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1827582Reviewed-by: default avatarAlex Sakhartchouk <alexst@chromium.org>
Commit-Queue: Daniel Nicoara <dnicoara@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700293}
parent ca285c94
......@@ -82,8 +82,10 @@ class WebviewRpcInstance : public WebviewController::Client,
WebviewWindowManager* window_manager_;
int app_id_ = 0;
int window_id_ = 0;
// Initialize to negative values since the aura::Window properties use 0 as
// the default value if the property isn't found.
int app_id_ = -1;
int window_id_ = -1;
DISALLOW_COPY_AND_ASSIGN(WebviewRpcInstance);
};
......@@ -111,7 +113,6 @@ WebviewRpcInstance::WebviewRpcInstance(
base::Unretained(this));
service_->RequestCreateWebview(&ctx_, &io_, cq_, cq_, &init_callback_);
window_manager_->AddObserver(this);
}
WebviewRpcInstance::~WebviewRpcInstance() {
......@@ -181,6 +182,10 @@ bool WebviewRpcInstance::Initialize() {
void WebviewRpcInstance::CreateWebview(int app_id, int window_id) {
app_id_ = app_id;
window_id_ = window_id;
// Only start listening for window events after the Webview is created. It
// doesn't make sense to listen before since there wouldn't be a Webview to
// parent.
window_manager_->AddObserver(this);
content::BrowserContext* browser_context =
shell::CastBrowserProcess::GetInstance()->browser_context();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment