| 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/aura/app_list_ui.h" | 5 #include "chrome/browser/ui/webui/aura/app_list_ui.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/google/google_util.h" | 8 #include "chrome/browser/google/google_util.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 11 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 12 #include "chrome/browser/ui/webui/aura/app_list_ui_delegate.h" |
| 12 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 13 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 13 #include "chrome/common/extensions/extension_constants.h" | 14 #include "chrome/common/extensions/extension_constants.h" |
| 14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 16 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
| 17 #include "grit/browser_resources.h" | 18 #include "grit/browser_resources.h" |
| 18 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
| 19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 21 | 22 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 int shown_page = prefs->GetInteger(prefs::kNTPShownPage); | 70 int shown_page = prefs->GetInteger(prefs::kNTPShownPage); |
| 70 localized_strings.SetInteger("shown_page_type", shown_page & ~kIndexMask); | 71 localized_strings.SetInteger("shown_page_type", shown_page & ~kIndexMask); |
| 71 localized_strings.SetInteger("shown_page_index", shown_page & kIndexMask); | 72 localized_strings.SetInteger("shown_page_index", shown_page & kIndexMask); |
| 72 | 73 |
| 73 source->AddLocalizedStrings(localized_strings); | 74 source->AddLocalizedStrings(localized_strings); |
| 74 source->set_json_path("strings.js"); | 75 source->set_json_path("strings.js"); |
| 75 source->set_default_resource(IDR_APP_LIST_HTML); | 76 source->set_default_resource(IDR_APP_LIST_HTML); |
| 76 return source; | 77 return source; |
| 77 } | 78 } |
| 78 | 79 |
| 80 class AppListHandler : public WebUIMessageHandler { |
| 81 public: |
| 82 AppListHandler() {} |
| 83 virtual ~AppListHandler() {} |
| 84 |
| 85 // WebUIMessageHandler |
| 86 virtual void RegisterMessages() OVERRIDE; |
| 87 |
| 88 private: |
| 89 AppListUI* app_list_ui() const { |
| 90 return static_cast<AppListUI*>(web_ui_); |
| 91 } |
| 92 |
| 93 void HandleClose(const base::ListValue* args); |
| 94 void HandleAppsLoaded(const base::ListValue* args); |
| 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(AppListHandler); |
| 97 }; |
| 98 |
| 99 void AppListHandler::RegisterMessages() { |
| 100 web_ui_->RegisterMessageCallback("close", |
| 101 base::Bind(&AppListHandler::HandleClose, base::Unretained(this))); |
| 102 web_ui_->RegisterMessageCallback("onAppsLoaded", |
| 103 base::Bind(&AppListHandler::HandleAppsLoaded, base::Unretained(this))); |
| 104 } |
| 105 |
| 106 void AppListHandler::HandleClose(const base::ListValue* args) { |
| 107 DCHECK(app_list_ui()->delegate()); |
| 108 app_list_ui()->delegate()->Close(); |
| 109 } |
| 110 |
| 111 void AppListHandler::HandleAppsLoaded(const base::ListValue* args) { |
| 112 DCHECK(app_list_ui()->delegate()); |
| 113 app_list_ui()->delegate()->OnAppsLoaded(); |
| 114 } |
| 115 |
| 79 } // namespace | 116 } // namespace |
| 80 | 117 |
| 81 AppListUI::AppListUI(TabContents* contents) | 118 AppListUI::AppListUI(TabContents* contents) |
| 82 : ChromeWebUI(contents) { | 119 : ChromeWebUI(contents), |
| 120 delegate_(NULL) { |
| 121 AddMessageHandler((new AppListHandler)->Attach(this)); |
| 122 |
| 83 ExtensionService* service = GetProfile()->GetExtensionService(); | 123 ExtensionService* service = GetProfile()->GetExtensionService(); |
| 84 if (service) | 124 if (service) |
| 85 AddMessageHandler((new AppLauncherHandler(service))->Attach(this)); | 125 AddMessageHandler((new AppLauncherHandler(service))->Attach(this)); |
| 86 | 126 |
| 87 // Set up the source. | 127 // Set up the source. |
| 88 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 128 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
| 89 PrefService* prefs = profile->GetPrefs(); | 129 PrefService* prefs = profile->GetPrefs(); |
| 90 profile->GetChromeURLDataManager()->AddDataSource( | 130 profile->GetChromeURLDataManager()->AddDataSource( |
| 91 CreateAppListUIHTMLSource(prefs)); | 131 CreateAppListUIHTMLSource(prefs)); |
| 92 } | 132 } |
| OLD | NEW |