~osomon/oxide/bug1290821

« back to all changes in this revision

Viewing changes to qt/quick/api/oxideqquickwebview.cc

  • Committer: Chris Coulson
  • Date: 2014-02-20 15:03:48 UTC
  • Revision ID: chris.coulson@canonical.com-20140220150348-qr1a1z8xb5hf1oe0
Get rid of oxide::WebView::Shutdown. Instead, keep the default context alive whilst its destructor is called

Show diffs side-by-side

added added

removed removed

Lines of Context:
166
166
 
167
167
  Q_ASSERT(init_props_);
168
168
 
169
 
  if (!context) {
170
 
    // Ok, we handle the default context a bit differently. If our context
171
 
    // comes from setContext(), then we don't hold a strong reference to it
172
 
    // because it will be owned by someone else in the QML object
173
 
    // hierarchy. However, the default context is not in this hierarchy and
174
 
    // has no QObject parent, so we use reference counting for it instead to
175
 
    // ensure that it is freed once all webviews are closed
 
169
  OxideQQuickWebContext* context_in_use = context;
 
170
  if (!context_in_use) {
 
171
    // The default context is reference counted and not exposed to the
 
172
    // embedder
176
173
    default_context_ = OxideQQuickWebContext::defaultContext();
177
 
    context = default_context_.data();
 
174
    context_in_use = default_context_.data();
178
175
  }
179
176
 
180
 
  init(OxideQQuickWebContextPrivate::get(context),
 
177
  init(OxideQQuickWebContextPrivate::get(context_in_use),
181
178
       QSizeF(q->width(), q->height()).toSize(),
182
179
       init_props_->incognito,
183
180
       init_props_->url,
282
279
OxideQQuickWebView::~OxideQQuickWebView() {
283
280
  Q_D(OxideQQuickWebView);
284
281
 
285
 
  // This is a bit hacky, but when we are using the default context,
286
 
  // we hold a reference to it. We release this reference before
287
 
  // the oxide::WebView destructor is called, so we have to ensure our
288
 
  // WebContents is destroyed now
289
 
  d->shutdown();
 
282
  // The default context is reference counted, and OxideQQuickWebViewPrivate
 
283
  // (our d_ptr) holds our reference to it. When destroying the d_ptr,
 
284
  // we need to hold a temporary reference to the default context to stop
 
285
  // it from being destroyed before the destructor for WebViewAdapter is
 
286
  // called, otherwise our oxide::WebView will outlive its context (and
 
287
  // this is not allowed)
 
288
  QSharedPointer<OxideQQuickWebContext> death_grip;
 
289
  if (!d->context) {
 
290
    death_grip = OxideQQuickWebContext::defaultContext();
 
291
  }
290
292
 
291
293
  delete d_ptr;
292
294
  d_ptr = NULL;