| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "apps/shell/web_view_window.h" | |
| 6 | |
| 7 #include "content/public/browser/web_contents.h" | |
| 8 #include "content/public/browser/web_contents_view.h" | |
| 9 #include "ui/aura/window.h" | |
| 10 #include "ui/views/controls/webview/webview.h" | |
| 11 #include "ui/views/layout/fill_layout.h" | |
| 12 #include "ui/views/widget/widget.h" | |
| 13 #include "ui/views/widget/widget_delegate.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 // A simple window containing a single web view. | |
| 18 class WebViewWindowContents : public views::WidgetDelegateView { | |
| 19 public: | |
| 20 explicit WebViewWindowContents(content::BrowserContext* browser_context) | |
| 21 : browser_context_(browser_context) {} | |
| 22 virtual ~WebViewWindowContents() {} | |
| 23 | |
| 24 // views::WidgetDelegateView overrides: | |
| 25 virtual views::View* GetContentsView() OVERRIDE; | |
| 26 virtual void WindowClosing() OVERRIDE; | |
| 27 | |
| 28 // views::View overrides: | |
| 29 virtual void ViewHierarchyChanged( | |
| 30 const ViewHierarchyChangedDetails& details) OVERRIDE; | |
| 31 | |
| 32 private: | |
| 33 // Initialize this view's children. | |
| 34 void InitChildViews(); | |
| 35 | |
| 36 content::BrowserContext* browser_context_; | |
| 37 | |
| 38 DISALLOW_COPY_AND_ASSIGN(WebViewWindowContents); | |
| 39 }; | |
| 40 | |
| 41 views::View* WebViewWindowContents::GetContentsView() { | |
| 42 return this; | |
| 43 } | |
| 44 | |
| 45 void WebViewWindowContents::WindowClosing() { | |
| 46 // Close the app when the window is closed. | |
| 47 base::MessageLoopForUI::current()->Quit(); | |
| 48 } | |
| 49 | |
| 50 void WebViewWindowContents::ViewHierarchyChanged( | |
| 51 const ViewHierarchyChangedDetails& details) { | |
| 52 // Initialize child views when this view is attached. | |
| 53 if (details.is_add && details.child == this) | |
| 54 InitChildViews(); | |
| 55 } | |
| 56 | |
| 57 void WebViewWindowContents::InitChildViews() { | |
| 58 // Create a WebView that fills the window. | |
| 59 SetLayoutManager(new views::FillLayout); | |
| 60 views::WebView* web_view = new views::WebView(browser_context_); | |
| 61 AddChildView(web_view); | |
| 62 | |
| 63 web_view->LoadInitialURL(GURL("http://www.google.com/")); | |
| 64 web_view->web_contents()->GetView()->Focus(); | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| 68 | |
| 69 namespace apps { | |
| 70 | |
| 71 void ShowWebViewWindow(content::BrowserContext* browser_context, | |
| 72 aura::Window* window_context) { | |
| 73 views::Widget* widget = new views::Widget; | |
| 74 views::Widget::InitParams params; | |
| 75 params.delegate = new WebViewWindowContents(browser_context); | |
| 76 params.context = window_context; | |
| 77 params.bounds = window_context->bounds(); | |
| 78 params.top_level = true; | |
| 79 widget->Init(params); | |
| 80 widget->Show(); | |
| 81 } | |
| 82 | |
| 83 } // namespace apps | |
| OLD | NEW |