~osomon/oxide/bug1290821

« back to all changes in this revision

Viewing changes to shared/browser/oxide_web_view.cc

  • Committer: Chris Coulson
  • Date: 2014-02-20 14:42:23 UTC
  • Revision ID: chris.coulson@canonical.com-20140220144223-cm4jsx5sfhm1movd
Implement WebPreferenceObserver, as this will make testing easier. Also, get rid of the default preferences hack and don't lazy initialize the default WebPreferences

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
  }
65
65
}
66
66
 
67
 
void WebView::BrowserContextDestroyed(BrowserContext* context) {
 
67
void WebView::BrowserContextDestroyed() {
68
68
  CHECK(0) << "The browser context was destroyed whilst still in use";
69
69
}
70
70
 
74
74
  web_contents_->SetUserAgentOverride(browser_context()->GetUserAgent());
75
75
}
76
76
 
 
77
void WebView::WebPreferencesDestroyed() {
 
78
  OnWebPreferencesChanged();
 
79
  WebPreferencesValueChanged();
 
80
}
 
81
 
 
82
void WebView::WebPreferencesValueChanged() {
 
83
  if (!web_contents_) {
 
84
    return;
 
85
  }
 
86
  content::RenderViewHost* rvh = web_contents_->GetRenderViewHost();
 
87
  rvh->UpdateWebkitPreferences(rvh->GetWebkitPreferences());
 
88
}
 
89
 
77
90
void WebView::Observe(int type,
78
91
                      const content::NotificationSource& source,
79
92
                      const content::NotificationDetails& details) {
275
288
void WebView::OnNavigationListPruned(bool from_front, int count) {}
276
289
void WebView::OnNavigationEntryChanged(int index) {}
277
290
 
 
291
void WebView::OnWebPreferencesChanged() {}
 
292
 
278
293
WebView::WebView() :
279
 
    root_frame_(NULL),
280
 
    web_preferences_(NULL) {}
 
294
    root_frame_(NULL) {}
281
295
 
282
296
WebView::~WebView() {
283
 
  if (web_preferences_) {
284
 
    web_preferences_->RemoveWebView(this);
285
 
  }
286
 
 
287
297
  if (web_contents_) {
288
298
    web_contents_->SetDelegate(NULL);
289
299
  }
537
547
}
538
548
 
539
549
WebPreferences* WebView::GetWebPreferences() {
540
 
  if (!web_preferences_) {
541
 
    SetWebPreferences(
542
 
        ContentClient::instance()->browser()->GetDefaultWebPreferences(),
543
 
        false);
544
 
  }
545
 
 
546
 
  return web_preferences_;
 
550
  return web_preferences();
547
551
}
548
552
 
549
 
void WebView::SetWebPreferences(WebPreferences* prefs, bool send_update) {
550
 
  if (web_preferences_) {
551
 
    web_preferences_->RemoveWebView(this);
552
 
  }
553
 
 
554
 
  web_preferences_ = prefs;
555
 
  if (prefs) {
556
 
    prefs->AddWebView(this);
557
 
  }
558
 
 
559
 
  if (!send_update || !web_contents_) {
 
553
void WebView::SetWebPreferences(WebPreferences* prefs) {
 
554
  if (prefs == web_preferences()) {
560
555
    return;
561
556
  }
562
557
 
563
 
  web_contents()->GetRenderViewHost()->UpdateWebkitPreferences(
564
 
      web_contents()->GetRenderViewHost()->GetWebkitPreferences());
 
558
  WebPreferencesObserver::Observe(prefs);
 
559
  OnWebPreferencesChanged();
 
560
  WebPreferencesValueChanged();
565
561
}
566
562
 
567
563
WebPopupMenu* WebView::CreatePopupMenu(content::RenderViewHost* rvh) {