OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/app_list/app_list_view_delegate.h" | 5 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "apps/custom_launcher_page_contents.h" | 9 #include "apps/custom_launcher_page_contents.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 for (size_t i = 0; i < count; ++i) { | 96 for (size_t i = 0; i < count; ++i) { |
97 app_list::AppListViewDelegate::User user; | 97 app_list::AppListViewDelegate::User user; |
98 user.name = profile_info.GetNameOfProfileAtIndex(i); | 98 user.name = profile_info.GetNameOfProfileAtIndex(i); |
99 user.email = profile_info.GetUserNameOfProfileAtIndex(i); | 99 user.email = profile_info.GetUserNameOfProfileAtIndex(i); |
100 user.profile_path = profile_info.GetPathOfProfileAtIndex(i); | 100 user.profile_path = profile_info.GetPathOfProfileAtIndex(i); |
101 user.active = active_profile_path == user.profile_path; | 101 user.active = active_profile_path == user.profile_path; |
102 users->push_back(user); | 102 users->push_back(user); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
| 106 // Gets a list of URLs of the custom launcher pages to show in the launcher. |
| 107 // Returns a URL for each installed launcher page. If --custom-launcher-page is |
| 108 // specified and valid, also includes that URL. |
| 109 void GetCustomLauncherPageUrls(std::vector<GURL>* urls) { |
| 110 // First, check the command line. |
| 111 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 112 if (app_list::switches::IsExperimentalAppListEnabled() && |
| 113 command_line->HasSwitch(switches::kCustomLauncherPage)) { |
| 114 GURL custom_launcher_page_url( |
| 115 command_line->GetSwitchValueASCII(switches::kCustomLauncherPage)); |
| 116 |
| 117 if (custom_launcher_page_url.SchemeIs(extensions::kExtensionScheme)) { |
| 118 urls->push_back(custom_launcher_page_url); |
| 119 } else { |
| 120 LOG(ERROR) << "Invalid custom launcher page URL: " |
| 121 << custom_launcher_page_url.possibly_invalid_spec(); |
| 122 } |
| 123 } |
| 124 |
| 125 // TODO(mgiuca): Search the list of installed extensions and add any with a |
| 126 // 'launcher_page' attribute in its manifest. |
| 127 } |
| 128 |
106 } // namespace | 129 } // namespace |
107 | 130 |
108 AppListViewDelegate::AppListViewDelegate(Profile* profile, | 131 AppListViewDelegate::AppListViewDelegate(Profile* profile, |
109 AppListControllerDelegate* controller) | 132 AppListControllerDelegate* controller) |
110 : controller_(controller), | 133 : controller_(controller), |
111 profile_(profile), | 134 profile_(profile), |
112 model_(NULL), | 135 model_(NULL), |
113 scoped_observer_(this) { | 136 scoped_observer_(this) { |
114 CHECK(controller_); | 137 CHECK(controller_); |
115 // The SigninManagerFactor and the SigninManagers are observed to keep the | 138 // The SigninManagerFactor and the SigninManagers are observed to keep the |
(...skipping 25 matching lines...) Expand all Loading... |
141 #if defined(GOOGLE_CHROME_BUILD) | 164 #if defined(GOOGLE_CHROME_BUILD) |
142 speech_ui_->set_logo( | 165 speech_ui_->set_logo( |
143 *ui::ResourceBundle::GetSharedInstance(). | 166 *ui::ResourceBundle::GetSharedInstance(). |
144 GetImageSkiaNamed(IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH)); | 167 GetImageSkiaNamed(IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH)); |
145 #endif | 168 #endif |
146 | 169 |
147 OnProfileChanged(); // sets model_ | 170 OnProfileChanged(); // sets model_ |
148 if (service) | 171 if (service) |
149 service->AddObserver(this); | 172 service->AddObserver(this); |
150 | 173 |
151 // Set up the custom launcher page. There is currently only a single custom | 174 // Set up the custom launcher pages. |
152 // page allowed, which is specified as a command-line flag. In the future, | 175 std::vector<GURL> custom_launcher_page_urls; |
153 // arbitrary extensions may be able to specify their own custom pages. | 176 GetCustomLauncherPageUrls(&custom_launcher_page_urls); |
154 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 177 for (std::vector<GURL>::const_iterator it = custom_launcher_page_urls.begin(); |
155 if (app_list::switches::IsExperimentalAppListEnabled() && | 178 it != custom_launcher_page_urls.end(); |
156 command_line->HasSwitch(switches::kCustomLauncherPage)) { | 179 ++it) { |
157 GURL custom_launcher_page_url( | 180 std::string extension_id = it->host(); |
158 command_line->GetSwitchValueASCII(switches::kCustomLauncherPage)); | 181 apps::CustomLauncherPageContents* page_contents = |
159 if (!custom_launcher_page_url.SchemeIs(extensions::kExtensionScheme)) { | 182 new apps::CustomLauncherPageContents( |
160 LOG(ERROR) << "Invalid custom launcher page URL: " | 183 scoped_ptr<apps::AppDelegate>(new ChromeAppDelegate), extension_id); |
161 << custom_launcher_page_url.possibly_invalid_spec(); | 184 page_contents->Initialize(profile, *it); |
162 } else { | 185 custom_page_contents_.push_back(page_contents); |
163 std::string extension_id = custom_launcher_page_url.host(); | |
164 custom_page_contents_.reset(new apps::CustomLauncherPageContents( | |
165 scoped_ptr<apps::AppDelegate>(new ChromeAppDelegate), extension_id)); | |
166 custom_page_contents_->Initialize(profile, custom_launcher_page_url); | |
167 } | |
168 } | 186 } |
169 } | 187 } |
170 | 188 |
171 AppListViewDelegate::~AppListViewDelegate() { | 189 AppListViewDelegate::~AppListViewDelegate() { |
172 app_list::StartPageService* service = | 190 app_list::StartPageService* service = |
173 app_list::StartPageService::Get(profile_); | 191 app_list::StartPageService::Get(profile_); |
174 if (service) | 192 if (service) |
175 service->RemoveObserver(this); | 193 service->RemoveObserver(this); |
176 g_browser_process-> | 194 g_browser_process-> |
177 profile_manager()->GetProfileInfoCache().RemoveObserver(this); | 195 profile_manager()->GetProfileInfoCache().RemoveObserver(this); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 return NULL; | 486 return NULL; |
469 | 487 |
470 DCHECK_EQ(profile_, web_contents->GetBrowserContext()); | 488 DCHECK_EQ(profile_, web_contents->GetBrowserContext()); |
471 views::WebView* web_view = new views::WebView( | 489 views::WebView* web_view = new views::WebView( |
472 web_contents->GetBrowserContext()); | 490 web_contents->GetBrowserContext()); |
473 web_view->SetPreferredSize(size); | 491 web_view->SetPreferredSize(size); |
474 web_view->SetWebContents(web_contents); | 492 web_view->SetWebContents(web_contents); |
475 return web_view; | 493 return web_view; |
476 } | 494 } |
477 | 495 |
478 views::View* AppListViewDelegate::CreateCustomPageWebView( | 496 std::vector<views::View*> AppListViewDelegate::CreateCustomPageWebViews( |
479 const gfx::Size& size) { | 497 const gfx::Size& size) { |
480 if (!custom_page_contents_) | 498 std::vector<views::View*> web_views; |
481 return NULL; | |
482 | 499 |
483 content::WebContents* web_contents = custom_page_contents_->web_contents(); | 500 for (ScopedVector<apps::CustomLauncherPageContents>::const_iterator it = |
484 // TODO(mgiuca): DCHECK_EQ(profile_, web_contents->GetBrowserContext()) after | 501 custom_page_contents_.begin(); |
485 // http://crbug.com/392763 resolved. | 502 it != custom_page_contents_.end(); |
486 views::WebView* web_view = | 503 ++it) { |
487 new views::WebView(web_contents->GetBrowserContext()); | 504 content::WebContents* web_contents = (*it)->web_contents(); |
488 web_view->SetPreferredSize(size); | 505 // TODO(mgiuca): DCHECK_EQ(profile_, web_contents->GetBrowserContext()) |
489 web_view->SetWebContents(web_contents); | 506 // after http://crbug.com/392763 resolved. |
490 return web_view; | 507 views::WebView* web_view = |
| 508 new views::WebView(web_contents->GetBrowserContext()); |
| 509 web_view->SetPreferredSize(size); |
| 510 web_view->SetWebContents(web_contents); |
| 511 web_views.push_back(web_view); |
| 512 } |
| 513 |
| 514 return web_views; |
491 } | 515 } |
492 #endif | 516 #endif |
493 | 517 |
494 bool AppListViewDelegate::IsSpeechRecognitionEnabled() { | 518 bool AppListViewDelegate::IsSpeechRecognitionEnabled() { |
495 app_list::StartPageService* service = | 519 app_list::StartPageService* service = |
496 app_list::StartPageService::Get(profile_); | 520 app_list::StartPageService::Get(profile_); |
497 return service && service->GetSpeechRecognitionContents(); | 521 return service && service->GetSpeechRecognitionContents(); |
498 } | 522 } |
499 | 523 |
500 const app_list::AppListViewDelegate::Users& | 524 const app_list::AppListViewDelegate::Users& |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 | 556 |
533 void AppListViewDelegate::AddObserver( | 557 void AppListViewDelegate::AddObserver( |
534 app_list::AppListViewDelegateObserver* observer) { | 558 app_list::AppListViewDelegateObserver* observer) { |
535 observers_.AddObserver(observer); | 559 observers_.AddObserver(observer); |
536 } | 560 } |
537 | 561 |
538 void AppListViewDelegate::RemoveObserver( | 562 void AppListViewDelegate::RemoveObserver( |
539 app_list::AppListViewDelegateObserver* observer) { | 563 app_list::AppListViewDelegateObserver* observer) { |
540 observers_.RemoveObserver(observer); | 564 observers_.RemoveObserver(observer); |
541 } | 565 } |
OLD | NEW |