From 79e4ec9037f047c737e7ffdc3fe00c2e033cf31b Mon Sep 17 00:00:00 2001 From: "rfevang@chromium.org" Date: Tue, 12 Feb 2013 03:46:12 +0000 Subject: 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 --- .../api/page_launcher/page_launcher_api.cc | 59 ++++++++++++++++++++++ .../api/page_launcher/page_launcher_api.h | 48 ++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 chrome/browser/extensions/api/page_launcher/page_launcher_api.cc create mode 100644 chrome/browser/extensions/api/page_launcher/page_launcher_api.h (limited to 'chrome/browser/extensions/api/page_launcher') 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 > + 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( + 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::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 + +#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* GetFactoryInstance(); + + private: + friend class ProfileKeyedAPIFactory; + + // 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_ -- cgit v1.1