Index: chrome/browser/extensions/api/app_runtime/app_runtime_api.cc |
diff --git a/chrome/browser/extensions/api/app/app_api.cc b/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc |
similarity index 50% |
copy from chrome/browser/extensions/api/app/app_api.cc |
copy to chrome/browser/extensions/api/app_runtime/app_runtime_api.cc |
index 22ccab68a4cb7ae663f60c773569eed38751ca7a..287468ecdd837dd275468ed6f82244ac71de331f 100644 |
--- a/chrome/browser/extensions/api/app/app_api.cc |
+++ b/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc |
@@ -2,122 +2,27 @@ |
// 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/app/app_api.h" |
+#include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" |
#include "base/json/json_writer.h" |
+#include "base/string16.h" |
#include "base/string_number_conversions.h" |
-#include "base/time.h" |
#include "base/utf_string_conversions.h" |
#include "base/values.h" |
-#include "chrome/browser/extensions/app_notification_manager.h" |
#include "chrome/browser/extensions/event_router.h" |
-#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/profiles/profile.h" |
-#include "chrome/common/chrome_notification_types.h" |
#include "chrome/common/extensions/extension.h" |
-#include "chrome/common/extensions/extension_constants.h" |
-#include "content/public/browser/notification_service.h" |
#include "googleurl/src/gurl.h" |
#include "webkit/glue/web_intent_data.h" |
namespace { |
-const char kBodyTextKey[] = "bodyText"; |
-const char kExtensionIdKey[] = "extensionId"; |
-const char kLinkTextKey[] = "linkText"; |
-const char kLinkUrlKey[] = "linkUrl"; |
-const char kTitleKey[] = "title"; |
- |
-const char kInvalidExtensionIdError[] = |
- "Invalid extension id"; |
-const char kMissingLinkTextError[] = |
- "You must specify linkText if you use linkUrl"; |
-const char kOnLaunchedEvent[] = "experimental.app.onLaunched"; |
+const char kOnLaunchedEvent[] = "app.runtime.onLaunched"; |
} // anonymous namespace |
namespace extensions { |
-bool AppNotifyFunction::RunImpl() { |
- if (!include_incognito() && profile_->IsOffTheRecord()) { |
- error_ = extension_misc::kAppNotificationsIncognitoError; |
- return false; |
- } |
- |
- DictionaryValue* details; |
- EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
- EXTENSION_FUNCTION_VALIDATE(details != NULL); |
- |
- // TODO(asargent) remove this before the API leaves experimental. |
- std::string id = extension_id(); |
- if (details->HasKey(kExtensionIdKey)) { |
- EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); |
- if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { |
- error_ = kInvalidExtensionIdError; |
- return false; |
- } |
- } |
- |
- std::string title; |
- if (details->HasKey(kTitleKey)) |
- EXTENSION_FUNCTION_VALIDATE(details->GetString(kTitleKey, &title)); |
- |
- std::string body; |
- if (details->HasKey(kBodyTextKey)) |
- EXTENSION_FUNCTION_VALIDATE(details->GetString(kBodyTextKey, &body)); |
- |
- scoped_ptr<AppNotification> item(new AppNotification( |
- true, base::Time::Now(), "", id, title, body)); |
- |
- if (details->HasKey(kLinkUrlKey)) { |
- std::string link_url; |
- EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkUrlKey, &link_url)); |
- item->set_link_url(GURL(link_url)); |
- if (!item->link_url().is_valid()) { |
- error_ = "Invalid url: " + link_url; |
- return false; |
- } |
- if (!details->HasKey(kLinkTextKey)) { |
- error_ = kMissingLinkTextError; |
- return false; |
- } |
- std::string link_text; |
- EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkTextKey, |
- &link_text)); |
- item->set_link_text(link_text); |
- } |
- |
- AppNotificationManager* manager = |
- profile()->GetExtensionService()->app_notification_manager(); |
- |
- // TODO(beaudoin) We should probably report an error if Add returns false. |
- manager->Add(item.release()); |
- |
- return true; |
-} |
- |
-bool AppClearAllNotificationsFunction::RunImpl() { |
- if (!include_incognito() && profile_->IsOffTheRecord()) { |
- error_ = extension_misc::kAppNotificationsIncognitoError; |
- return false; |
- } |
- |
- std::string id = extension_id(); |
- DictionaryValue* details = NULL; |
- if (args_->GetDictionary(0, &details) && details->HasKey(kExtensionIdKey)) { |
- EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); |
- if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { |
- error_ = kInvalidExtensionIdError; |
- return false; |
- } |
- } |
- |
- AppNotificationManager* manager = |
- profile()->GetExtensionService()->app_notification_manager(); |
- manager->ClearAll(id); |
- return true; |
-} |
- |
// static. |
void AppEventRouter::DispatchOnLaunchedEvent( |
Profile* profile, const Extension* extension) { |
@@ -141,6 +46,8 @@ void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
intent_data->SetString("format", "fileEntry"); |
intent_data->SetString("fileSystemId", file_system_id); |
intent_data->SetString("baseName", base_name); |
+ // TODO(miu): This recently-added second argument needs to be mentioned in |
+ // common/extensions/api/app_runtime.idl. |
asargent_no_longer_on_chrome
2012/08/10 18:43:58
nit: can you make sure there is a bug filed in crb
|
args->Append(intent_data); |
profile->GetExtensionEventRouter()->DispatchEventToExtension( |
extension->id(), kOnLaunchedEvent, args.Pass(), NULL, GURL()); |
@@ -163,6 +70,8 @@ void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
intent_data = new DictionaryValue(); |
intent_data->SetString("format", "serialized"); |
intent_data->SetString("data", UTF16ToUTF8(web_intent_data.data)); |
+ // TODO(miu): This recently-added second argument needs to be mentioned in |
+ // common/extensions/api/app_runtime.idl. |
args->Append(intent_data); |
break; |
case webkit_glue::WebIntentData::UNSERIALIZED: |
@@ -174,6 +83,8 @@ void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
intent_data->SetString("blobFileName", web_intent_data.blob_file.value()); |
intent_data->SetString("blobLength", |
base::Int64ToString(web_intent_data.blob_length)); |
+ // TODO(miu): This recently-added second argument needs to be mentioned in |
+ // common/extensions/api/app_runtime.idl. |
args->Append(intent_data); |
break; |
default: |