summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-15 00:02:24 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-15 00:02:24 +0000
commit1288ba0949c899dce33fc6fcc8e212aee704bc48 (patch)
treebc9c5b2a1c969670e1b8a32bc5736b6dc1bb7f63 /chrome/browser/extensions
parentbe1c57d6ca0e4661760202621db55b536c189041 (diff)
downloadchromium_src-1288ba0949c899dce33fc6fcc8e212aee704bc48.zip
chromium_src-1288ba0949c899dce33fc6fcc8e212aee704bc48.tar.gz
chromium_src-1288ba0949c899dce33fc6fcc8e212aee704bc48.tar.bz2
Update browser actions api to be like new design doc.
BUG=23879 TEST=Install sample gmail browser action sample. Review URL: http://codereview.chromium.org/264046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29068 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_browser_actions_api.cc60
-rwxr-xr-xchrome/browser/extensions/extension_browser_actions_api.h4
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.cc10
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.h2
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc2
-rw-r--r--chrome/browser/extensions/image_loading_tracker.cc10
6 files changed, 50 insertions, 38 deletions
diff --git a/chrome/browser/extensions/extension_browser_actions_api.cc b/chrome/browser/extensions/extension_browser_actions_api.cc
index e671d15..d2cb604 100644
--- a/chrome/browser/extensions/extension_browser_actions_api.cc
+++ b/chrome/browser/extensions/extension_browser_actions_api.cc
@@ -17,30 +17,11 @@ const char kIconIndexOutOfBounds[] =
"Browser action icon index out of bounds.";
}
-bool BrowserActionSetNameFunction::RunImpl() {
- std::string title;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&title));
-
- Extension* extension = dispatcher()->GetExtension();
- if (!extension->browser_action()) {
- error_ = kNoBrowserActionError;
- return false;
- }
-
- extension->browser_action_state()->set_title(title);
-
- NotificationService::current()->Notify(
- NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
- Source<ExtensionAction>(extension->browser_action()),
- Details<ExtensionActionState>(extension->browser_action_state()));
- return true;
-}
-
bool BrowserActionSetIconFunction::RunImpl() {
// setIcon can take a variant argument: either a canvas ImageData, or an
// icon index.
EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_BINARY) ||
- args_->IsType(Value::TYPE_INTEGER));
+ args_->IsType(Value::TYPE_DICTIONARY));
Extension* extension = dispatcher()->GetExtension();
if (!extension->browser_action()) {
@@ -58,8 +39,9 @@ bool BrowserActionSetIconFunction::RunImpl() {
extension->browser_action_state()->set_icon(bitmap.release());
} else {
int icon_index = -1;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&icon_index));
-
+ EXTENSION_FUNCTION_VALIDATE(
+ static_cast<DictionaryValue*>(args_)->GetInteger(
+ L"iconIndex", &icon_index));
if (icon_index < 0 ||
static_cast<size_t>(icon_index) >=
extension->browser_action()->icon_paths().size()) {
@@ -77,9 +59,34 @@ bool BrowserActionSetIconFunction::RunImpl() {
return true;
}
+bool BrowserActionSetTitleFunction::RunImpl() {
+ EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
+ DictionaryValue* details = static_cast<DictionaryValue*>(args_);
+
+ std::string title;
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(L"title", &title));
+
+ Extension* extension = dispatcher()->GetExtension();
+ if (!extension->browser_action()) {
+ error_ = kNoBrowserActionError;
+ return false;
+ }
+
+ extension->browser_action_state()->set_title(title);
+
+ NotificationService::current()->Notify(
+ NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
+ Source<ExtensionAction>(extension->browser_action()),
+ Details<ExtensionActionState>(extension->browser_action_state()));
+ return true;
+}
+
bool BrowserActionSetBadgeTextFunction::RunImpl() {
+ EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
+ DictionaryValue* details = static_cast<DictionaryValue*>(args_);
+
std::string badge_text;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&badge_text));
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(L"text", &badge_text));
Extension* extension = dispatcher()->GetExtension();
if (!extension->browser_action()) {
@@ -97,8 +104,11 @@ bool BrowserActionSetBadgeTextFunction::RunImpl() {
}
bool BrowserActionSetBadgeBackgroundColorFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
- ListValue* list = static_cast<ListValue*>(args_);
+ EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
+ DictionaryValue* details = static_cast<DictionaryValue*>(args_);
+
+ ListValue* list = NULL;
+ EXTENSION_FUNCTION_VALIDATE(details->GetList(L"color", &list));
EXTENSION_FUNCTION_VALIDATE(list->GetSize() == 4);
int color_array[4] = {0};
diff --git a/chrome/browser/extensions/extension_browser_actions_api.h b/chrome/browser/extensions/extension_browser_actions_api.h
index c5193d6..1becc70 100755
--- a/chrome/browser/extensions/extension_browser_actions_api.h
+++ b/chrome/browser/extensions/extension_browser_actions_api.h
@@ -7,12 +7,12 @@
#include "chrome/browser/extensions/extension_function.h"
-class BrowserActionSetNameFunction : public SyncExtensionFunction {
+class BrowserActionSetIconFunction : public SyncExtensionFunction {
virtual bool RunImpl();
DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setName")
};
-class BrowserActionSetIconFunction : public SyncExtensionFunction {
+class BrowserActionSetTitleFunction : public SyncExtensionFunction {
virtual bool RunImpl();
DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setIcon")
};
diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc
index 3604942..9a0f14a 100644
--- a/chrome/browser/extensions/extension_browser_event_router.cc
+++ b/chrome/browser/extensions/extension_browser_event_router.cc
@@ -375,10 +375,14 @@ void ExtensionBrowserEventRouter::PageActionExecuted(
}
void ExtensionBrowserEventRouter::BrowserActionExecuted(
- Profile* profile, const std::string& extension_id, int window_id) {
- ListValue args;
- args.Append(Value::CreateIntegerValue(window_id));
+ Profile* profile, const std::string& extension_id, Browser* browser) {
+ TabContents* tab_contents = NULL;
+ int tab_id = 0;
+ if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id))
+ return;
+ ListValue args;
+ args.Append(ExtensionTabUtil::CreateTabValue(tab_contents));
std::string json_args;
JSONWriter::Write(&args, false, &json_args);
diff --git a/chrome/browser/extensions/extension_browser_event_router.h b/chrome/browser/extensions/extension_browser_event_router.h
index 681b448..dd56d29 100644
--- a/chrome/browser/extensions/extension_browser_event_router.h
+++ b/chrome/browser/extensions/extension_browser_event_router.h
@@ -62,7 +62,7 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver,
// Browser Actions execute event.
void BrowserActionExecuted(Profile* profile,
const std::string& extension_id,
- int window_id);
+ Browser* browser);
// NotificationObserver.
void Observe(NotificationType type,
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index 4b07658..1870701 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -103,8 +103,8 @@ void FactoryRegistry::ResetFunctions() {
RegisterFunction<DisablePageActionFunction>();
// Browser Actions.
- RegisterFunction<BrowserActionSetNameFunction>();
RegisterFunction<BrowserActionSetIconFunction>();
+ RegisterFunction<BrowserActionSetTitleFunction>();
RegisterFunction<BrowserActionSetBadgeTextFunction>();
RegisterFunction<BrowserActionSetBadgeBackgroundColorFunction>();
diff --git a/chrome/browser/extensions/image_loading_tracker.cc b/chrome/browser/extensions/image_loading_tracker.cc
index e141391..a2e4281 100644
--- a/chrome/browser/extensions/image_loading_tracker.cc
+++ b/chrome/browser/extensions/image_loading_tracker.cc
@@ -38,7 +38,6 @@ class ImageLoadingTracker::LoadImageTask : public Task {
index_(index) {}
void ReportBack(SkBitmap* image) {
- DCHECK(image);
callback_loop_->PostTask(FROM_HERE, NewRunnableMethod(tracker_,
&ImageLoadingTracker::OnImageLoaded,
image,
@@ -103,13 +102,12 @@ void ImageLoadingTracker::PostLoadImageTask(const ExtensionResource& resource) {
}
void ImageLoadingTracker::OnImageLoaded(SkBitmap* image, size_t index) {
- if (image == NULL) {
- NOTREACHED() << "Image failed to decode.";
- image = new SkBitmap();
- }
if (observer_)
observer_->OnImageLoaded(image, index);
- delete image;
+
+ if (image)
+ delete image;
+
if (--image_count_ == 0)
Release(); // We are no longer needed.
}