summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/page_launcher
diff options
context:
space:
mode:
authorrfevang@chromium.org <rfevang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-12 03:46:12 +0000
committerrfevang@chromium.org <rfevang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-12 03:46:12 +0000
commit79e4ec9037f047c737e7ffdc3fe00c2e033cf31b (patch)
tree8e1371209781ecac0b96fde6eb62661bc5ad14a6 /chrome/browser/extensions/api/page_launcher
parent4abba3b4ecc67886716c98600e567725931276b4 (diff)
downloadchromium_src-79e4ec9037f047c737e7ffdc3fe00c2e033cf31b.zip
chromium_src-79e4ec9037f047c737e7ffdc3fe00c2e033cf31b.tar.gz
chromium_src-79e4ec9037f047c737e7ffdc3fe00c2e033cf31b.tar.bz2
Allow platform apps to add themselves to the Action Box.
This change allows apps to declare a page_launcher key in the manifest to add themselves to the action box. When the corresponding action is clicked, the app will receive a pageLauncher.onClicked event. ActionBox design document: https://docs.google.com/a/google.com/document/d/1Qxiey4vnbX0YwCRi5BGQbeCuH3DxHGMOtYnQOjBpcCI/edit BUG=125307 Review URL: https://chromiumcodereview.appspot.com/12095023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181837 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/api/page_launcher')
-rw-r--r--chrome/browser/extensions/api/page_launcher/page_launcher_api.cc59
-rw-r--r--chrome/browser/extensions/api/page_launcher/page_launcher_api.h48
2 files changed, 107 insertions, 0 deletions
diff --git a/chrome/browser/extensions/api/page_launcher/page_launcher_api.cc b/chrome/browser/extensions/api/page_launcher/page_launcher_api.cc
new file mode 100644
index 0000000..e7c70c1
--- /dev/null
+++ b/chrome/browser/extensions/api/page_launcher/page_launcher_api.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2013 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/extensions/api/page_launcher/page_launcher_api.h"
+
+#include "base/lazy_instance.h"
+#include "base/memory/linked_ptr.h"
+#include "chrome/browser/extensions/event_router.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/common/extensions/api/page_launcher.h"
+#include "chrome/common/extensions/api/page_launcher/page_launcher_handler.h"
+#include "chrome/common/extensions/extension_manifest_constants.h"
+#include "chrome/common/extensions/manifest_handler.h"
+#include "googleurl/src/gurl.h"
+
+namespace extensions {
+
+static base::LazyInstance<ProfileKeyedAPIFactory<PageLauncherAPI> >
+ g_factory = LAZY_INSTANCE_INITIALIZER;
+
+PageLauncherAPI::PageLauncherAPI(Profile* profile) {
+ ManifestHandler::Register(extension_manifest_keys::kPageLauncher,
+ make_linked_ptr(new PageLauncherHandler));
+}
+
+PageLauncherAPI::~PageLauncherAPI() {
+}
+
+// static
+void PageLauncherAPI::DispatchOnClickedEvent(
+ Profile* profile,
+ const std::string& extension_id,
+ const GURL& url,
+ const std::string& mimetype,
+ const std::string* page_title,
+ const std::string* selected_text) {
+ api::page_launcher::PageData data;
+ data.url = url.spec();
+ data.mimetype = mimetype;
+ if (page_title)
+ data.title.reset(new std::string(*page_title));
+ if (selected_text)
+ data.selection_text.reset(new std::string(*selected_text));
+
+ scoped_ptr<Event> event(
+ new Event("pageLauncher.onClicked",
+ api::page_launcher::OnClicked::Create(data)));
+ EventRouter* event_router = ExtensionSystem::Get(profile)->event_router();
+ event_router->DispatchEventToExtension(extension_id, event.Pass());
+}
+
+
+// static
+ProfileKeyedAPIFactory<PageLauncherAPI>* PageLauncherAPI::GetFactoryInstance() {
+ return &g_factory.Get();
+}
+
+} // namespace extensions
diff --git a/chrome/browser/extensions/api/page_launcher/page_launcher_api.h b/chrome/browser/extensions/api/page_launcher/page_launcher_api.h
new file mode 100644
index 0000000..4cd4483
--- /dev/null
+++ b/chrome/browser/extensions/api/page_launcher/page_launcher_api.h
@@ -0,0 +1,48 @@
+// Copyright (c) 2013 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_EXTENSIONS_API_PAGE_LAUNCHER_PAGE_LAUNCHER_API_H_
+#define CHROME_BROWSER_EXTENSIONS_API_PAGE_LAUNCHER_PAGE_LAUNCHER_API_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
+
+class GURL;
+class Profile;
+
+namespace extensions {
+
+class PageLauncherAPI : public ProfileKeyedAPI {
+ public:
+ explicit PageLauncherAPI(Profile* profile);
+ virtual ~PageLauncherAPI();
+
+ static void DispatchOnClickedEvent(Profile* profile,
+ const std::string& extension_id,
+ const GURL& url,
+ const std::string& mimetype,
+ const std::string* page_title,
+ const std::string* selected_text);
+
+ // ProfileKeyedAPI implementation.
+ static ProfileKeyedAPIFactory<PageLauncherAPI>* GetFactoryInstance();
+
+ private:
+ friend class ProfileKeyedAPIFactory<PageLauncherAPI>;
+
+ // ProfileKeyedAPI implementation.
+ static const char* service_name() {
+ return "PageLauncherAPI";
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(PageLauncherAPI);
+};
+
+} // namespace extensions
+
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_PAGE_LAUNCHER_PAGE_LAUNCHER_API_H_