summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/dom_view.cc
blob: ebb63e3b774d939ab882546ade9e396f92d251b4 (plain)
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
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/views/dom_view.h"

#include "chrome/browser/dom_ui/dom_ui_host.h"
#include "chrome/views/container.h"

DOMView::DOMView(const GURL& contents)
    : contents_(contents), initialized_(false), host_(NULL) {
}

DOMView::~DOMView() {
  if (host_) {
    Detach();
    host_->Destroy();
    host_ = NULL;
  }
}

bool DOMView::Init(Profile* profile, SiteInstance* instance) {
  if (initialized_)
    return true;
  initialized_ = true;

  // TODO(timsteele): This should use a separate factory method; e.g
  // a DOMUIHostFactory rather than TabContentsFactory, because DOMView's
  // should only be associated with instances of DOMUIHost.
  TabContentsType type = TabContents::TypeForURL(&contents_);
  TabContents* tab_contents =  TabContents::CreateWithType(type,
      GetContainer()->GetHWND(), profile, instance);
  host_ = tab_contents->AsDOMUIHost();
  DCHECK(host_);

  views::HWNDView::Attach(host_->GetContainerHWND());
  host_->SetupController(profile);
  host_->controller()->LoadURL(contents_, GURL(), PageTransition::START_PAGE);
  return true;
}