diff options
author | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-26 18:34:51 +0000 |
---|---|---|
committer | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-26 18:34:51 +0000 |
commit | aefdb477a4fb4ee11b85d2e8fa265aea531d8bf5 (patch) | |
tree | b2b2e0fe070505b2a8145988afa320b8cbe4ed5a /chrome | |
parent | 30ebee97923efa86769332a801f92efcd6aa8121 (diff) | |
download | chromium_src-aefdb477a4fb4ee11b85d2e8fa265aea531d8bf5.zip chromium_src-aefdb477a4fb4ee11b85d2e8fa265aea531d8bf5.tar.gz chromium_src-aefdb477a4fb4ee11b85d2e8fa265aea531d8bf5.tar.bz2 |
Initial add of app launcher DOM UI.
BUG=None
TEST=Go to chrome://apps
Review URL: http://codereview.chromium.org/1353005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42786 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_resources.grd | 1 | ||||
-rw-r--r-- | chrome/browser/dom_ui/app_launcher_ui.cc | 169 | ||||
-rw-r--r-- | chrome/browser/dom_ui/app_launcher_ui.h | 70 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_factory.cc | 5 | ||||
-rw-r--r-- | chrome/browser/resources/app_launcher.html | 108 | ||||
-rw-r--r-- | chrome/browser/views/app_launcher.cc | 6 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 4 | ||||
-rw-r--r-- | chrome/common/url_constants.cc | 2 | ||||
-rw-r--r-- | chrome/common/url_constants.h | 2 |
9 files changed, 361 insertions, 6 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index 5d6c33e..8184f06 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -24,6 +24,7 @@ without changes to the corresponding grd file. fbt1 --> </if> <include name="IDR_ABOUT_STATS_HTML" file="resources\about_stats.html" type="BINDATA" /> + <include name="IDR_APP_LAUNCHER_HTML" file="resources\app_launcher.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_SSL_ROAD_BLOCK_HTML" file="security\resources\ssl_roadblock.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_SSL_ERROR_HTML" file="security\resources\ssl_error.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_NEW_TAB_THEME_CSS" file="resources\new_tab_theme.css" flattenhtml="true" type="BINDATA" /> diff --git a/chrome/browser/dom_ui/app_launcher_ui.cc b/chrome/browser/dom_ui/app_launcher_ui.cc new file mode 100644 index 0000000..607e170 --- /dev/null +++ b/chrome/browser/dom_ui/app_launcher_ui.cc @@ -0,0 +1,169 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/dom_ui/app_launcher_ui.h" + +#include "app/resource_bundle.h" +#include "base/base64.h" +#include "base/message_loop.h" +#include "base/ref_counted_memory.h" +#include "base/singleton.h" +#include "base/string_piece.h" +#include "base/string_util.h" +#include "base/values.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/dom_ui/chrome_url_data_manager.h" +#include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/notification_type.h" +#include "chrome/common/jstemplate_builder.h" +#include "chrome/common/url_constants.h" +#include "grit/browser_resources.h" +#include "grit/theme_resources.h" + +namespace { + +bool TreatAsApp(const Extension* extension) { + return !extension->GetFullLaunchURL().is_empty(); +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// +// +// AppLauncherUIHTMLSource +// +//////////////////////////////////////////////////////////////////////////////// + +AppLauncherUIHTMLSource::AppLauncherUIHTMLSource() + : DataSource(chrome::kChromeUIAppsHost, MessageLoop::current()) { +} + +void AppLauncherUIHTMLSource::StartDataRequest(const std::string& path, + bool is_off_the_record, int request_id) { + DictionaryValue localized_strings; + // TODO(arv): What strings do we need? + localized_strings.SetString(L"title", L"App Launcher"); + SetFontAndTextDirection(&localized_strings); + + static const base::StringPiece app_launcher_html( + ResourceBundle::GetSharedInstance().GetRawDataResource( + IDR_APP_LAUNCHER_HTML)); + std::string full_html = jstemplate_builder::GetI18nTemplateHtml( + app_launcher_html, &localized_strings); + jstemplate_builder::AppendJsTemplateSourceHtml(&full_html); + + scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); + html_bytes->data.resize(full_html.size()); + std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); + + SendResponse(request_id, html_bytes); +} + +std::string AppLauncherUIHTMLSource::GetMimeType( + const std::string& path) const { + return "text/html"; +} + +//////////////////////////////////////////////////////////////////////////////// +// +// AppLauncherHandler +// +//////////////////////////////////////////////////////////////////////////////// + +AppLauncherDOMHandler::AppLauncherDOMHandler( + ExtensionsService* extension_service) + : extensions_service_(extension_service) { +} + +AppLauncherDOMHandler::~AppLauncherDOMHandler() {} + +DOMMessageHandler* AppLauncherDOMHandler::Attach(DOMUI* dom_ui) { + // TODO(arv): Add initialization code to the Apps store etc. + return DOMMessageHandler::Attach(dom_ui); +} + +void AppLauncherDOMHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("getAll", + NewCallback(this, &AppLauncherDOMHandler::HandleGetAll)); + dom_ui_->RegisterMessageCallback("launch", + NewCallback(this, &AppLauncherDOMHandler::HandleLaunch)); +} + +// static +void AppLauncherDOMHandler::CreateAppInfo(Extension* extension, + DictionaryValue* value) { + value->Clear(); + value->SetString(L"id", extension->id()); + value->SetString(L"name", extension->name()); + value->SetString(L"description", extension->description()); + value->SetString(L"launch_url", extension->GetFullLaunchURL().spec()); + + // TODO(arv): Get the icon from the extension + std::string file_contents = + ResourceBundle::GetSharedInstance().GetDataResource( + IDR_EXTENSION_DEFAULT_ICON); + std::string base64_encoded; + base::Base64Encode(file_contents, &base64_encoded); + GURL icon_url("data:image/png;base64," + base64_encoded); + value->SetString(L"icon", icon_url.spec()); +} + +void AppLauncherDOMHandler::HandleGetAll(const Value* value) { + ListValue list; + const ExtensionList* extensions = extensions_service_->extensions(); + for (ExtensionList::const_iterator it = extensions->begin(); + it != extensions->end(); ++it) { + if (TreatAsApp(*it)) { + DictionaryValue* app_info = new DictionaryValue(); + CreateAppInfo(*it, app_info); + list.Append(app_info); + } + } + + dom_ui_->CallJavascriptFunction(L"getAllCallback", list); +} + +void AppLauncherDOMHandler::HandleLaunch(const Value* value) { + if (!value->IsType(Value::TYPE_LIST)) { + NOTREACHED(); + return; + } + + std::string url; + const ListValue* list = static_cast<const ListValue*>(value); + if (list->GetSize() == 0 || !list->GetString(0, &url)) { + NOTREACHED(); + return; + } + + TabContents* tab_contents = dom_ui_->tab_contents(); + tab_contents->OpenURL(GURL(url), GURL(), NEW_FOREGROUND_TAB, + PageTransition::LINK); +} +//////////////////////////////////////////////////////////////////////////////// +// +// AppLauncherUI +// +//////////////////////////////////////////////////////////////////////////////// + +AppLauncherUI::AppLauncherUI(TabContents* contents) : DOMUI(contents) { + ExtensionsService *extension_service = + GetProfile()->GetOriginalProfile()->GetExtensionsService(); + + AppLauncherDOMHandler* handler = new AppLauncherDOMHandler(extension_service); + AddMessageHandler(handler); + handler->Attach(this); + + AppLauncherUIHTMLSource* html_source = new AppLauncherUIHTMLSource(); + + // Set up the chrome://bookmarks/ source. + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + Singleton<ChromeURLDataManager>::get(), + &ChromeURLDataManager::AddDataSource, + make_scoped_refptr(html_source))); +} diff --git a/chrome/browser/dom_ui/app_launcher_ui.h b/chrome/browser/dom_ui/app_launcher_ui.h new file mode 100644 index 0000000..9a0e31d --- /dev/null +++ b/chrome/browser/dom_ui/app_launcher_ui.h @@ -0,0 +1,70 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_DOM_UI_APP_LAUNCHER_UI_H_ +#define CHROME_BROWSER_DOM_UI_APP_LAUNCHER_UI_H_ + +#include <string> + +#include "base/ref_counted.h" +#include "chrome/browser/dom_ui/chrome_url_data_manager.h" +#include "chrome/browser/dom_ui/dom_ui.h" + +class Extension; +class ExtensionsService; +class GURL; +class RefCountedMemory; + +// The HTML source for the apps view. +class AppLauncherUIHTMLSource : public ChromeURLDataManager::DataSource { + public: + AppLauncherUIHTMLSource(); + + // Called when the network layer has requested a resource underneath + // the path we registered. + virtual void StartDataRequest(const std::string& path, + bool is_off_the_record, + int request_id); + virtual std::string GetMimeType(const std::string& path) const; + + private: + DISALLOW_COPY_AND_ASSIGN(AppLauncherUIHTMLSource); +}; + +// The handler for Javascript messages related to the "apps" view. +class AppLauncherDOMHandler : public DOMMessageHandler { + public: + explicit AppLauncherDOMHandler(ExtensionsService* extension_service); + virtual ~AppLauncherDOMHandler(); + + // DOMMessageHandler implementation. + virtual DOMMessageHandler* Attach(DOMUI* dom_ui); + virtual void RegisterMessages(); + + // Populate a dictionary with the information from an extension. + static void CreateAppInfo(Extension* extension, DictionaryValue* value); + + // Callback for the "getAll" message. + void HandleGetAll(const Value* value); + + // Callback for the "launch" message. + void HandleLaunch(const Value* value); + + private: + // The apps are represented in the extensions model. + scoped_refptr<ExtensionsService> extensions_service_; + + DISALLOW_COPY_AND_ASSIGN(AppLauncherDOMHandler); +}; + +// This class is used to hook up chrome://applauncher/. +class AppLauncherUI : public DOMUI { + public: + explicit AppLauncherUI(TabContents* contents); + + private: + DISALLOW_COPY_AND_ASSIGN(AppLauncherUI); +}; + +#endif // CHROME_BROWSER_DOM_UI_APP_LAUNCHER_UI_H_ diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc index dbf3729..a108213 100644 --- a/chrome/browser/dom_ui/dom_ui_factory.cc +++ b/chrome/browser/dom_ui/dom_ui_factory.cc @@ -5,6 +5,7 @@ #include "chrome/browser/dom_ui/dom_ui_factory.h" #include "chrome/browser/chrome_thread.h" +#include "chrome/browser/dom_ui/app_launcher_ui.h" #include "chrome/browser/dom_ui/bookmarks_ui.h" #include "chrome/browser/dom_ui/downloads_ui.h" #include "chrome/browser/dom_ui/devtools_ui.h" @@ -89,7 +90,9 @@ static DOMUIFactoryFunction GetDOMUIFactoryFunction(const GURL& url) { // We must compare hosts only since some of the DOM UIs append extra stuff // after the host name. - if (url.host() == chrome::kChromeUIBookmarksHost) + if (url.host() == chrome::kChromeUIAppsHost) + return &NewDOMUI<AppLauncherUI>; + if (url.host() == chrome::kChromeUIBookmarksHost) return &NewDOMUI<BookmarksUI>; if (url.host() == chrome::kChromeUIDevToolsHost) return &NewDOMUI<DevToolsUI>; diff --git a/chrome/browser/resources/app_launcher.html b/chrome/browser/resources/app_launcher.html new file mode 100644 index 0000000..50ec2c3 --- /dev/null +++ b/chrome/browser/resources/app_launcher.html @@ -0,0 +1,108 @@ +<!DOCTYPE html> +<html i18n-values="dir:textdirection;"> +<head> +<meta charset="utf-8"> +<title i18n-content="title"></title> +<style> + +/* This is work in progress. */ + +* { + -webkit-user-select: none; +} + +body { + margin: 10px; +} + +#app-list { + margin: 0; + padding: 0; +} + +#app-list img { + width: 64px; + height: 64px; +} + +#app-list > li { + display: inline-block; + margin: 2px; + padding: 0; + text-align: center; + width: 108px; +} + +#app-list a { + display: block; + text-decoration: none; + font-weight: bold; + color: navy; + border-radius: 5px; + padding: 5px; + background-color: rgba(255, 255, 255, 0); /* transparent white */ + -webkit-transition: background-color .15s; +} + +#app-list a:hover { + background: rgba(200, 200, 255, 0.3); +} + +</style> +<script> + +var exampleAppList = [ + { + 'id': '000000000000000000000000000000000000000000000000000000', + 'name': 'Hello A', + 'launch_url': 'http://www.example.com/a/', + 'description': 'Description of A', + 'icon': 'file:///C:/src/chrome/src/chrome/app/theme/extensions_section.png' + }, + { + 'id': '000000000000000000000000000000000000000000000000000001', + 'name': 'Hello B', + 'launch_url': 'http://www.example.com/b/', + 'description': 'Description of B', + 'icon': 'file:///C:/src/chrome/src/chrome/app/theme/extensions_section.png' + } +]; + +chrome.send('getAll', []); + +function getAllCallback(value) { + var context = new JsEvalContext(value); + var template = document.getElementById('template-root'); + jstProcess(context, template); +} + +function launch(uri) { + chrome.send('launch', [uri]); +} + +</script> +</head> +<body i18n-values=".style.fontFamily:fontfamily;.style.fontSize:fontsize"> + +<p>UI under development. Designs are subject to +<a href="http://www.chromium.org/chromium-os/user-experience/">change</a>. + +<div id="template-root"> + +<ul id="app-list" jsdisplay="$this.length"> + <li jsselect="$this"> + + <a jsvalues="href:launch_url;title:description" + onclick="launch(this.href); return false"> + <img jsvalues="src:icon"> + <div jscontent="name">NAME</div> + </a> + </li> +</ul> + +<p jsdisplay="!$this.length">Go install some apps... + +</div> + +</body> +</html> diff --git a/chrome/browser/views/app_launcher.cc b/chrome/browser/views/app_launcher.cc index 1342910..fd55086 100644 --- a/chrome/browser/views/app_launcher.cc +++ b/chrome/browser/views/app_launcher.cc @@ -28,6 +28,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/views/info_bubble.h" #include "chrome/browser/views/frame/browser_view.h" +#include "chrome/common/url_constants.h" #include "views/controls/native/native_view_host.h" #include "views/widget/root_view.h" #include "views/widget/widget.h" @@ -62,16 +63,13 @@ const int kAutocompleteEditFontDelta = 3; // Command line switch for specifying url of the page. const wchar_t kURLSwitch[] = L"main-menu-url"; -// URL of the page to load. This is ignored if kURLSwitch is specified. -const char kMenuURL[] = "http://goto.ext.google.com/crux-home"; - // Returns the URL of the menu. static GURL GetMenuURL() { std::wstring url_string = CommandLine::ForCurrentProcess()->GetSwitchValue(kURLSwitch); if (!url_string.empty()) return GURL(WideToUTF8(url_string)); - return GURL(kMenuURL); + return GURL(chrome::kChromeUIAppsURL); } // RenderWidgetHostViewGtk propagates the mouse press events (see diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index efc9f75..bb8aa36 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -832,6 +832,8 @@ 'browser/dock_info.cc', 'browser/dock_info.h', 'browser/dom_operation_notification_details.h', + 'browser/dom_ui/app_launcher_ui.cc', + 'browser/dom_ui/app_launcher_ui.h', 'browser/dom_ui/bookmarks_ui.cc', 'browser/dom_ui/bookmarks_ui.h', 'browser/dom_ui/chrome_url_data_manager.cc', @@ -2689,7 +2691,7 @@ ['exclude', '^browser/views/'], ], 'conditions': [ - ['OS=="linux" and (toolkit_views==1 or chromeos==1)',{ + ['OS=="linux" and (toolkit_views==1 or chromeos==1)',{ 'dependencies': [ '../views/views.gyp:views', ], diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index 20018b9..fc7198d 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -51,6 +51,7 @@ const char kAboutTermsURL[] = "about:terms"; // to be used for testing. const char kAboutBrowserCrash[] = "about:inducebrowsercrashforrealz"; +const char kChromeUIAppsURL[] = "chrome://apps/"; const char kChromeUIBookmarksURL[] = "chrome://bookmarks/"; const char kChromeUIDevToolsURL[] = "chrome://devtools/"; const char kChromeUIDownloadsURL[] = "chrome://downloads/"; @@ -63,6 +64,7 @@ const char kChromeUIIPCURL[] = "chrome://about/ipc"; const char kChromeUINetworkURL[] = "chrome://about/network"; const char kChromeUINewTabURL[] = "chrome://newtab"; +const char kChromeUIAppsHost[] = "apps"; const char kChromeUIBookmarksHost[] = "bookmarks"; const char kChromeUIDevToolsHost[] = "devtools"; const char kChromeUIDialogHost[] = "dialog"; diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index 2d59c1e..4118a99 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -47,6 +47,7 @@ extern const char kAboutTermsURL[]; // chrome: URLs (including schemes). Should be kept in sync with the // components below. +extern const char kChromeUIAppsURL[]; extern const char kChromeUIBookmarksURL[]; extern const char kChromeUIDevToolsURL[]; extern const char kChromeUIDownloadsURL[]; @@ -61,6 +62,7 @@ extern const char kChromeUINewTabURL[]; // chrome components of URLs. Should be kept in sync with the full URLs // above. +extern const char kChromeUIAppsHost[]; extern const char kChromeUIBookmarksHost[]; extern const char kChromeUIDevToolsHost[]; extern const char kChromeUIDialogHost[]; |