| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/extensions/api/extension_action/extension_browser_actio
ns_api.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/values.h" | |
| 10 #include "chrome/browser/ui/browser_list.h" | |
| 11 #include "chrome/common/chrome_notification_types.h" | |
| 12 #include "chrome/common/extensions/extension.h" | |
| 13 #include "content/public/browser/notification_service.h" | |
| 14 | |
| 15 namespace { | |
| 16 // Errors. | |
| 17 const char kNoBrowserActionError[] = | |
| 18 "This extension has no browser action specified."; | |
| 19 } | |
| 20 | |
| 21 void BrowserActionFunction::FireUpdateNotification() { | |
| 22 content::NotificationService::current()->Notify( | |
| 23 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, | |
| 24 content::Source<ExtensionAction>(extension_action_), | |
| 25 content::NotificationService::NoDetails()); | |
| 26 } | |
| 27 | |
| 28 bool BrowserActionFunction::RunImpl() { | |
| 29 ExtensionActionFunction::RunImpl(); | |
| 30 extension_action_ = GetExtension()->browser_action(); | |
| 31 if (!extension_action_) { | |
| 32 error_ = kNoBrowserActionError; | |
| 33 return false; | |
| 34 } | |
| 35 | |
| 36 return RunExtensionAction(); | |
| 37 } | |
| 38 | |
| 39 bool BrowserActionSetIconFunction::RunExtensionAction() { | |
| 40 if (!SetIcon()) | |
| 41 return false; | |
| 42 FireUpdateNotification(); | |
| 43 return true; | |
| 44 } | |
| 45 | |
| 46 bool BrowserActionSetTitleFunction::RunExtensionAction() { | |
| 47 if (!SetTitle()) | |
| 48 return false; | |
| 49 FireUpdateNotification(); | |
| 50 return true; | |
| 51 } | |
| 52 | |
| 53 bool BrowserActionSetPopupFunction::RunExtensionAction() { | |
| 54 if (!SetPopup()) | |
| 55 return false; | |
| 56 FireUpdateNotification(); | |
| 57 return true; | |
| 58 } | |
| 59 | |
| 60 bool BrowserActionSetBadgeTextFunction::RunExtensionAction() { | |
| 61 if (!SetBadgeText()) | |
| 62 return false; | |
| 63 FireUpdateNotification(); | |
| 64 return true; | |
| 65 } | |
| 66 | |
| 67 bool BrowserActionSetBadgeBackgroundColorFunction::RunExtensionAction() { | |
| 68 if (!SetBadgeBackgroundColor()) | |
| 69 return false; | |
| 70 FireUpdateNotification(); | |
| 71 return true; | |
| 72 } | |
| 73 | |
| 74 bool BrowserActionGetTitleFunction::RunExtensionAction() { | |
| 75 return GetTitle(); | |
| 76 } | |
| 77 | |
| 78 bool BrowserActionGetPopupFunction::RunExtensionAction() { | |
| 79 return GetPopup(); | |
| 80 } | |
| 81 | |
| 82 bool BrowserActionGetBadgeTextFunction::RunExtensionAction() { | |
| 83 return GetBadgeText(); | |
| 84 } | |
| 85 | |
| 86 bool BrowserActionGetBadgeBackgroundColorFunction::RunExtensionAction() { | |
| 87 return GetBadgeBackgroundColor(); | |
| 88 } | |
| OLD | NEW |