OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 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 "chrome/browser/web_app_launcher.h" | |
6 | |
7 #include "base/string_util.h" | |
8 #include "chrome/browser/browser.h" | |
9 #include "chrome/browser/profile.h" | |
10 #include "chrome/browser/web_app.h" | |
11 | |
12 // static | |
13 void WebAppLauncher::Launch(Profile* profile, const GURL& url) { | |
14 (new WebAppLauncher(profile, url))->Run(); | |
15 } | |
16 | |
17 WebAppLauncher::WebAppLauncher(Profile* profile, const GURL& url) | |
18 : profile_(profile), | |
19 url_(url) { | |
20 } | |
21 | |
22 void WebAppLauncher::Run() { | |
23 GearsQueryShortcuts(NewCallback(this, &WebAppLauncher::OnGotApps)); | |
24 } | |
25 | |
26 void WebAppLauncher::OnGotApps(GearsShortcutList* apps) { | |
27 WebApp* app = NULL; | |
28 | |
29 if (apps) { | |
30 for (size_t i = 0; i < apps->num_shortcuts; ++i) { | |
31 if (apps->shortcuts[i].url && GURL(apps->shortcuts[i].url) == url_) { | |
32 app = new WebApp(profile_, apps->shortcuts[i]); | |
33 break; | |
34 } | |
35 } | |
36 } | |
37 | |
38 if (!app) { | |
39 // Gears doesn't know about this app. Create one anyway. | |
40 app = new WebApp(profile_, url_, std::wstring()); | |
41 } | |
42 | |
43 Browser::OpenWebApplication(profile_, app); | |
44 | |
45 delete this; | |
46 } | |
47 | |
OLD | NEW |