OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 app_list::AppListView* DemoAppListViewDelegate::InitView( | 54 app_list::AppListView* DemoAppListViewDelegate::InitView( |
55 gfx::NativeWindow window_context) { | 55 gfx::NativeWindow window_context) { |
56 gfx::NativeView container = NULL; | 56 gfx::NativeView container = NULL; |
57 // On Ash, the app list is placed into an aura::Window container. For the demo | 57 // On Ash, the app list is placed into an aura::Window container. For the demo |
58 // use the root window context as the parent. This only works on Aura since an | 58 // use the root window context as the parent. This only works on Aura since an |
59 // aura::Window is also a NativeView. | 59 // aura::Window is also a NativeView. |
60 #if defined(USE_AURA) | 60 #if defined(USE_AURA) |
61 container = window_context; | 61 container = window_context; |
62 #endif | 62 #endif |
63 | 63 |
64 // Note AppListView takes ownership of |this| on the next line. | |
65 view_ = new app_list::AppListView(this); | 64 view_ = new app_list::AppListView(this); |
66 view_->InitAsBubbleAtFixedLocation(container, | 65 view_->InitAsBubbleAtFixedLocation(container, |
67 0, | 66 0, |
68 gfx::Point(300, 300), | 67 gfx::Point(300, 300), |
69 views::BubbleBorder::FLOAT, | 68 views::BubbleBorder::FLOAT, |
70 false /* border_accepts_events */); | 69 false /* border_accepts_events */); |
71 | 70 |
72 // Populate some apps. | 71 // Populate some apps. |
73 GetTestModel()->PopulateApps(kInitialItems); | 72 GetTestModel()->PopulateApps(kInitialItems); |
74 app_list::AppListItemList* item_list = GetTestModel()->top_level_item_list(); | 73 app_list::AppListItemList* item_list = GetTestModel()->top_level_item_list(); |
75 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 74 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
76 gfx::Image test_image = rb.GetImageNamed(IDR_DEFAULT_FAVICON_32); | 75 gfx::Image test_image = rb.GetImageNamed(IDR_DEFAULT_FAVICON_32); |
77 for (size_t i = 0; i < item_list->item_count(); ++i) { | 76 for (size_t i = 0; i < item_list->item_count(); ++i) { |
78 app_list::AppListItem* item = item_list->item_at(i); | 77 app_list::AppListItem* item = item_list->item_at(i); |
79 // Alternate images with shadows and images without. | 78 // Alternate images with shadows and images without. |
80 item->SetIcon(*test_image.ToImageSkia(), i & 1); | 79 item->SetIcon(*test_image.ToImageSkia(), i & 1); |
81 } | 80 } |
82 return view_; | 81 return view_; |
83 } | 82 } |
84 | 83 |
85 void DemoAppListViewDelegate::Dismiss() { | 84 void DemoAppListViewDelegate::Dismiss() { |
86 view_->GetWidget()->Close(); | 85 view_->GetWidget()->Close(); |
87 } | 86 } |
88 | 87 |
89 void DemoAppListViewDelegate::ViewClosing() { | 88 void DemoAppListViewDelegate::ViewClosing() { |
90 web_contents_.reset(); | 89 base::MessageLoop* message_loop = base::MessageLoopForUI::current(); |
91 view_ = NULL; | 90 message_loop->DeleteSoon(FROM_HERE, this); |
92 base::MessageLoopForUI::current()->Quit(); | 91 message_loop->QuitWhenIdle(); |
93 } | 92 } |
94 | 93 |
95 views::View* DemoAppListViewDelegate::CreateStartPageWebView( | 94 views::View* DemoAppListViewDelegate::CreateStartPageWebView( |
96 const gfx::Size& size) { | 95 const gfx::Size& size) { |
97 web_contents_.reset(content::WebContents::Create( | 96 web_contents_.reset(content::WebContents::Create( |
98 content::WebContents::CreateParams(browser_context_))); | 97 content::WebContents::CreateParams(browser_context_))); |
99 web_contents_->GetController().LoadURL(GURL("http://www.google.com/"), | 98 web_contents_->GetController().LoadURL(GURL("http://www.google.com/"), |
100 content::Referrer(), | 99 content::Referrer(), |
101 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 100 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
102 std::string()); | 101 std::string()); |
(...skipping 21 matching lines...) Expand all Loading... |
124 content::InitializeSandboxInfo(&sandbox_info); | 123 content::InitializeSandboxInfo(&sandbox_info); |
125 ui::ViewsContentClient views_content_client(instance, &sandbox_info); | 124 ui::ViewsContentClient views_content_client(instance, &sandbox_info); |
126 #else | 125 #else |
127 int main(int argc, const char** argv) { | 126 int main(int argc, const char** argv) { |
128 ui::ViewsContentClient views_content_client(argc, argv); | 127 ui::ViewsContentClient views_content_client(argc, argv); |
129 #endif | 128 #endif |
130 | 129 |
131 views_content_client.set_task(base::Bind(&ShowAppList)); | 130 views_content_client.set_task(base::Bind(&ShowAppList)); |
132 return views_content_client.RunMain(); | 131 return views_content_client.RunMain(); |
133 } | 132 } |
OLD | NEW |