OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/webui/ntp/app_launcher_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/callback_old.h" | 13 #include "base/callback_old.h" |
| 14 #include "base/i18n/rtl.h" |
14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
15 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
16 #include "base/string_split.h" | 17 #include "base/string_split.h" |
17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
20 #include "chrome/browser/extensions/app_notification_manager.h" | 21 #include "chrome/browser/extensions/app_notification_manager.h" |
21 #include "chrome/browser/extensions/apps_promo.h" | 22 #include "chrome/browser/extensions/apps_promo.h" |
22 #include "chrome/browser/extensions/crx_installer.h" | 23 #include "chrome/browser/extensions/crx_installer.h" |
23 #include "chrome/browser/extensions/extension_prefs.h" | 24 #include "chrome/browser/extensions/extension_prefs.h" |
(...skipping 19 matching lines...) Expand all Loading... |
43 #include "content/browser/tab_contents/tab_contents.h" | 44 #include "content/browser/tab_contents/tab_contents.h" |
44 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
45 #include "googleurl/src/gurl.h" | 46 #include "googleurl/src/gurl.h" |
46 #include "grit/browser_resources.h" | 47 #include "grit/browser_resources.h" |
47 #include "grit/generated_resources.h" | 48 #include "grit/generated_resources.h" |
48 #include "net/base/escape.h" | 49 #include "net/base/escape.h" |
49 #include "ui/base/animation/animation.h" | 50 #include "ui/base/animation/animation.h" |
50 #include "ui/base/l10n/l10n_util.h" | 51 #include "ui/base/l10n/l10n_util.h" |
51 #include "ui/gfx/codec/png_codec.h" | 52 #include "ui/gfx/codec/png_codec.h" |
52 | 53 |
| 54 using content::WebContents; |
| 55 |
53 namespace { | 56 namespace { |
54 | 57 |
55 const net::UnescapeRule::Type kUnescapeRules = | 58 const net::UnescapeRule::Type kUnescapeRules = |
56 net::UnescapeRule::NORMAL | net::UnescapeRule::URL_SPECIAL_CHARS; | 59 net::UnescapeRule::NORMAL | net::UnescapeRule::URL_SPECIAL_CHARS; |
57 | 60 |
58 extension_misc::AppLaunchBucket ParseLaunchSource( | 61 extension_misc::AppLaunchBucket ParseLaunchSource( |
59 const std::string& launch_source) { | 62 const std::string& launch_source) { |
60 int bucket_num = extension_misc::APP_LAUNCH_BUCKET_INVALID; | 63 int bucket_num = extension_misc::APP_LAUNCH_BUCKET_INVALID; |
61 base::StringToInt(launch_source, &bucket_num); | 64 base::StringToInt(launch_source, &bucket_num); |
62 extension_misc::AppLaunchBucket bucket = | 65 extension_misc::AppLaunchBucket bucket = |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 app_launch_ordinal = extension->id() == extension_misc::kWebStoreAppId ? | 188 app_launch_ordinal = extension->id() == extension_misc::kWebStoreAppId ? |
186 prefs->CreateFirstAppLaunchOrdinal(page_ordinal) : | 189 prefs->CreateFirstAppLaunchOrdinal(page_ordinal) : |
187 prefs->CreateNextAppLaunchOrdinal(page_ordinal); | 190 prefs->CreateNextAppLaunchOrdinal(page_ordinal); |
188 prefs->SetAppLaunchOrdinal(extension->id(), app_launch_ordinal); | 191 prefs->SetAppLaunchOrdinal(extension->id(), app_launch_ordinal); |
189 } | 192 } |
190 value->SetString("app_launch_ordinal", app_launch_ordinal.ToString()); | 193 value->SetString("app_launch_ordinal", app_launch_ordinal.ToString()); |
191 } | 194 } |
192 | 195 |
193 void AppLauncherHandler::RegisterMessages() { | 196 void AppLauncherHandler::RegisterMessages() { |
194 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, | 197 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, |
195 content::Source<TabContents>(web_ui()->tab_contents())); | 198 content::Source<WebContents>(web_ui()->web_contents())); |
196 | 199 |
197 web_ui()->RegisterMessageCallback("getApps", | 200 web_ui()->RegisterMessageCallback("getApps", |
198 base::Bind(&AppLauncherHandler::HandleGetApps, | 201 base::Bind(&AppLauncherHandler::HandleGetApps, |
199 base::Unretained(this))); | 202 base::Unretained(this))); |
200 web_ui()->RegisterMessageCallback("launchApp", | 203 web_ui()->RegisterMessageCallback("launchApp", |
201 base::Bind(&AppLauncherHandler::HandleLaunchApp, | 204 base::Bind(&AppLauncherHandler::HandleLaunchApp, |
202 base::Unretained(this))); | 205 base::Unretained(this))); |
203 web_ui()->RegisterMessageCallback("setLaunchType", | 206 web_ui()->RegisterMessageCallback("setLaunchType", |
204 base::Bind(&AppLauncherHandler::HandleSetLaunchType, | 207 base::Bind(&AppLauncherHandler::HandleSetLaunchType, |
205 base::Unretained(this))); | 208 base::Unretained(this))); |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 | 982 |
980 void AppLauncherHandler::UninstallDefaultApps() { | 983 void AppLauncherHandler::UninstallDefaultApps() { |
981 AppsPromo* apps_promo = extension_service_->apps_promo(); | 984 AppsPromo* apps_promo = extension_service_->apps_promo(); |
982 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 985 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
983 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 986 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
984 iter != app_ids.end(); ++iter) { | 987 iter != app_ids.end(); ++iter) { |
985 if (extension_service_->GetExtensionById(*iter, true)) | 988 if (extension_service_->GetExtensionById(*iter, true)) |
986 extension_service_->UninstallExtension(*iter, false, NULL); | 989 extension_service_->UninstallExtension(*iter, false, NULL); |
987 } | 990 } |
988 } | 991 } |
OLD | NEW |