diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-01 22:02:34 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-01 22:02:34 +0000 |
commit | f7f3a5f86a24f65666284802b51d0eaa5c9d7741 (patch) | |
tree | 5605992d68c1b48fe47f7fbee560dca7cda6693b /chrome/browser/extensions/extension_page_actions_module.cc | |
parent | 32d371758f777380486f9c8ef28b1faca37ab26c (diff) | |
download | chromium_src-f7f3a5f86a24f65666284802b51d0eaa5c9d7741.zip chromium_src-f7f3a5f86a24f65666284802b51d0eaa5c9d7741.tar.gz chromium_src-f7f3a5f86a24f65666284802b51d0eaa5c9d7741.tar.bz2 |
This is the first part of the PageAction implementation. More work is required, but this is a good checkpoint.
Design doc: http://dev.chromium.org/developers/design-documents/extensions/page-actions-api
This checkin only covers Tab scoped page actions (not type "permanent"). It works end to end (if you have an extension that supplies the page action info -- I created an RSS page action that links to Google Reader).
Please note that TabIndex is hard coded to 0 until the extension system can provide the tab id to the extensions (which I understand is in progress). This means that page action(s) only show up for the first tab in the tabstrip. :)
BUG=None
TEST=There is a unit test for the API, but apart from that it is not possible to test this manually without writing an extension that adds a PageAction. My RSS page action is not ready to be checked in but I can provide it if there is interest in a sneak preview during review/QA.
Review URL: http://codereview.chromium.org/99253
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15105 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_page_actions_module.cc')
-rw-r--r-- | chrome/browser/extensions/extension_page_actions_module.cc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_page_actions_module.cc b/chrome/browser/extensions/extension_page_actions_module.cc new file mode 100644 index 0000000..edf08dd --- /dev/null +++ b/chrome/browser/extensions/extension_page_actions_module.cc @@ -0,0 +1,64 @@ +// Copyright (c) 2009 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/extension_page_actions_module.h" + +#include "chrome/browser/browser.h" +#include "chrome/browser/browser_list.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/extensions/extension.h" +#include "chrome/browser/extensions/extension_tabs_module.h" +#include "chrome/browser/extensions/extensions_service.h" + +bool EnablePageActionFunction::RunImpl() { + EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); + const ListValue* args = static_cast<const ListValue*>(args_); + + std::string page_action_id; + EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &page_action_id)); + DictionaryValue* action; + EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &action)); + + int tab_id; + EXTENSION_FUNCTION_VALIDATE(action->GetInteger(L"tabId", &tab_id)); + std::string url; + EXTENSION_FUNCTION_VALIDATE(action->GetString(L"url", &url)); + + Browser* browser = BrowserList::GetLastActive(); + if (!browser) + return false; + + // HACK: We need to figure out the tab index from the tab_id (pending). + // For now we only support page actions in the first tab in the strip (tab 0). + int tab_index = 0; + + TabStripModel* tab_strip = browser->tabstrip_model(); + TabContents* contents = tab_strip->GetTabContentsAt(tab_index); + + // Not needed when we stop hard-coding the tab index. + tab_id = ExtensionTabUtil::GetTabId(contents); + + // Find our extension. + Extension* extension = NULL; + if (profile()->GetExtensionsService()) { + const ExtensionList* extensions = + profile()->GetExtensionsService()->extensions(); + for (ExtensionList::const_iterator iter = extensions->begin(); + iter != extensions->end(); ++iter) { + if ((*iter)->id() == extension_id()) { + extension = (*iter); + break; // Found our extension. + } + } + } + + if (!extension || + !extension->UpdatePageAction(page_action_id, tab_id, GURL(url))) + return false; + + // Broadcast notifications when the UI should be updated. + contents->NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS); + + return true; +} |