diff options
Diffstat (limited to 'chrome/browser')
11 files changed, 39 insertions, 32 deletions
diff --git a/chrome/browser/extensions/execute_code_in_tab_function.cc b/chrome/browser/extensions/execute_code_in_tab_function.cc index 989d5f2..98bd3be 100644 --- a/chrome/browser/extensions/execute_code_in_tab_function.cc +++ b/chrome/browser/extensions/execute_code_in_tab_function.cc @@ -20,7 +20,7 @@ const wchar_t* kFileKey = L"file"; bool ExecuteCodeInTabFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); - const ListValue* args = static_cast<const ListValue*>(args_); + const ListValue* args = args_as_list(); DictionaryValue* script_info; EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &script_info)); diff --git a/chrome/browser/extensions/extension_bookmarks_module.cc b/chrome/browser/extensions/extension_bookmarks_module.cc index ee5257c..fb9bc47 100644 --- a/chrome/browser/extensions/extension_bookmarks_module.cc +++ b/chrome/browser/extensions/extension_bookmarks_module.cc @@ -277,7 +277,7 @@ bool GetBookmarksFunction::RunImpl() { BookmarkModel* model = profile()->GetBookmarkModel(); scoped_ptr<ListValue> json(new ListValue()); if (args_->IsType(Value::TYPE_LIST)) { - ListValue* ids = static_cast<ListValue*>(args_); + const ListValue* ids = args_as_list(); size_t count = ids->GetSize(); EXTENSION_FUNCTION_VALIDATE(count > 0); for (size_t i = 0; i < count; ++i) { @@ -379,7 +379,7 @@ bool RemoveBookmarkFunction::RunImpl() { return ExtensionBookmarks::RemoveNode(model, id, recursive, &error_); } else { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); - ListValue* ids = static_cast<ListValue*>(args_); + const ListValue* ids = args_as_list(); size_t count = ids->GetSize(); EXTENSION_FUNCTION_VALIDATE(count > 0); for (size_t i = 0; i < count; ++i) { @@ -395,7 +395,7 @@ bool RemoveBookmarkFunction::RunImpl() { bool CreateBookmarkFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - DictionaryValue* json = static_cast<DictionaryValue*>(args_); + const DictionaryValue* json = args_as_dictionary(); BookmarkModel* model = profile()->GetBookmarkModel(); int64 parentId; @@ -459,7 +459,7 @@ bool CreateBookmarkFunction::RunImpl() { bool MoveBookmarkFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); - const ListValue* args = static_cast<const ListValue*>(args_); + const ListValue* args = args_as_list(); int64 id; std::string id_string; EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &id_string)); @@ -527,7 +527,7 @@ bool MoveBookmarkFunction::RunImpl() { bool UpdateBookmarkFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); - const ListValue* args = static_cast<const ListValue*>(args_); + const ListValue* args = args_as_list(); int64 id; std::string id_string; EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &id_string)); diff --git a/chrome/browser/extensions/extension_browser_actions_api.cc b/chrome/browser/extensions/extension_browser_actions_api.cc index bc83fd0..012f582 100644 --- a/chrome/browser/extensions/extension_browser_actions_api.cc +++ b/chrome/browser/extensions/extension_browser_actions_api.cc @@ -19,7 +19,7 @@ const char kIconIndexOutOfBounds[] = bool BrowserActionFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - details_ = static_cast<DictionaryValue*>(args_); + details_ = args_as_dictionary(); if (details_->HasKey(L"tabId")) EXTENSION_FUNCTION_VALIDATE(details_->GetInteger(L"tabId", &tab_id_)); diff --git a/chrome/browser/extensions/extension_browser_actions_api.h b/chrome/browser/extensions/extension_browser_actions_api.h index fceab48..7853d09 100644 --- a/chrome/browser/extensions/extension_browser_actions_api.h +++ b/chrome/browser/extensions/extension_browser_actions_api.h @@ -20,7 +20,7 @@ class BrowserActionFunction : public SyncExtensionFunction { // All the browser action APIs take a single argument called details that is // a dictionary. - DictionaryValue* details_; + const DictionaryValue* details_; // The tab id the browser action function should apply to, if any, or // kDefaultTabId if none was specified. diff --git a/chrome/browser/extensions/extension_function.cc b/chrome/browser/extensions/extension_function.cc index b8aaae1..27ce5eb 100644 --- a/chrome/browser/extensions/extension_function.cc +++ b/chrome/browser/extensions/extension_function.cc @@ -9,8 +9,8 @@ #include "chrome/browser/extensions/extension_function_dispatcher.h" void AsyncExtensionFunction::SetArgs(const Value* args) { - DCHECK(!args_); // Should only be called once. - args_ = args->DeepCopy(); + DCHECK(!args_.get()); // Should only be called once. + args_.reset(args->DeepCopy()); } const std::string AsyncExtensionFunction::GetResult() { diff --git a/chrome/browser/extensions/extension_function.h b/chrome/browser/extensions/extension_function.h index 2766eb7..be74f36 100644 --- a/chrome/browser/extensions/extension_function.h +++ b/chrome/browser/extensions/extension_function.h @@ -124,13 +124,20 @@ class AsyncExtensionFunction : public ExtensionFunction { void SendResponse(bool success); + const ListValue* args_as_list() { + return static_cast<ListValue*>(args_.get()); + } + const DictionaryValue* args_as_dictionary() { + return static_cast<DictionaryValue*>(args_.get()); + } + // Note: After Run() returns, dispatcher() can be NULL. Since these getters // rely on dispatcher(), make sure it is valid before using them. std::string extension_id(); Profile* profile(); // The arguments to the API. Only non-null if argument were specified. - Value* args_; + scoped_ptr<Value> args_; // The result of the API. This should be populated by the derived class before // SendResponse() is called. diff --git a/chrome/browser/extensions/extension_history_api.cc b/chrome/browser/extensions/extension_history_api.cc index ee856de..80897ad 100644 --- a/chrome/browser/extensions/extension_history_api.cc +++ b/chrome/browser/extensions/extension_history_api.cc @@ -201,7 +201,7 @@ void HistoryFunctionWithCallback::SendResponseToCallback() { bool GetVisitsHistoryFunction::RunAsyncImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - DictionaryValue* json = static_cast<DictionaryValue*>(args_); + const DictionaryValue* json = args_as_dictionary(); Value* value; EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kUrlKey, &value)); @@ -238,7 +238,7 @@ void GetVisitsHistoryFunction::QueryComplete( bool SearchHistoryFunction::RunAsyncImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - DictionaryValue* json = static_cast<DictionaryValue*>(args_); + const DictionaryValue* json = args_as_dictionary(); // Initialize the HistoryQuery std::wstring search_text; @@ -288,7 +288,7 @@ void SearchHistoryFunction::SearchComplete( bool AddUrlHistoryFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - DictionaryValue* json = static_cast<DictionaryValue*>(args_); + const DictionaryValue* json = args_as_dictionary(); Value* value; EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kUrlKey, &value)); @@ -306,7 +306,7 @@ bool AddUrlHistoryFunction::RunImpl() { bool DeleteUrlHistoryFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - DictionaryValue* json = static_cast<DictionaryValue*>(args_); + const DictionaryValue* json = args_as_dictionary(); Value* value; EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kUrlKey, &value)); @@ -324,7 +324,7 @@ bool DeleteUrlHistoryFunction::RunImpl() { bool DeleteRangeHistoryFunction::RunAsyncImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - DictionaryValue* json = static_cast<DictionaryValue*>(args_); + const DictionaryValue* json = args_as_dictionary(); Value* value = NULL; EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kStartTimeKey, &value)); diff --git a/chrome/browser/extensions/extension_page_actions_module.cc b/chrome/browser/extensions/extension_page_actions_module.cc index 528f5a4..ace9317 100644 --- a/chrome/browser/extensions/extension_page_actions_module.cc +++ b/chrome/browser/extensions/extension_page_actions_module.cc @@ -32,7 +32,7 @@ const char kNoIconSpecified[] = "Page action has no icons to show."; // TODO(EXTENSIONS_DEPRECATED): obsolete API. bool PageActionFunction::SetPageActionEnabled(bool enable) { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); - const ListValue* args = static_cast<const ListValue*>(args_); + const ListValue* args = args_as_list(); std::string page_action_id; EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &page_action_id)); @@ -141,7 +141,7 @@ bool PageActionHideFunction::RunImpl() { bool PageActionSetIconFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); + const DictionaryValue* args = args_as_dictionary(); int tab_id; EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"tabId", &tab_id)); @@ -177,7 +177,7 @@ bool PageActionSetIconFunction::RunImpl() { bool PageActionSetTitleFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); + const DictionaryValue* args = args_as_dictionary(); int tab_id; EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"tabId", &tab_id)); @@ -196,7 +196,7 @@ bool PageActionSetTitleFunction::RunImpl() { // extension_function_dispatcher. bool PageActionSetBadgeBackgroundColorFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); + const DictionaryValue* args = args_as_dictionary(); int tab_id; EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"tabId", &tab_id)); @@ -222,7 +222,7 @@ bool PageActionSetBadgeBackgroundColorFunction::RunImpl() { // extension_function_dispatcher. bool PageActionSetBadgeTextColorFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); + const DictionaryValue* args = args_as_dictionary(); int tab_id; EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"tabId", &tab_id)); @@ -248,7 +248,7 @@ bool PageActionSetBadgeTextColorFunction::RunImpl() { // extension_function_dispatcher. bool PageActionSetBadgeTextFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); + const DictionaryValue* args = args_as_dictionary(); int tab_id; EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"tabId", &tab_id)); diff --git a/chrome/browser/extensions/extension_popup_api.cc b/chrome/browser/extensions/extension_popup_api.cc index 3059079..8ef2fe8 100644 --- a/chrome/browser/extensions/extension_popup_api.cc +++ b/chrome/browser/extensions/extension_popup_api.cc @@ -73,7 +73,7 @@ void PopupShowFunction::Run() { bool PopupShowFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); - const ListValue* args = static_cast<const ListValue*>(args_); + const ListValue* args = args_as_list(); DictionaryValue* popup_info = NULL; EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(0, &popup_info)); diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc index 89cb48c..059b97f 100644 --- a/chrome/browser/extensions/extension_tabs_module.cc +++ b/chrome/browser/extensions/extension_tabs_module.cc @@ -242,7 +242,7 @@ bool GetAllWindowsFunction::RunImpl() { bool populate_tabs = false; if (!args_->IsType(Value::TYPE_NULL)) { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); + const DictionaryValue* args = args_as_dictionary(); if (args->HasKey(keys::kPopulateKey)) { EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey, &populate_tabs)); @@ -268,7 +268,7 @@ bool CreateWindowFunction::RunImpl() { // Look for optional url. if (!args_->IsType(Value::TYPE_NULL)) { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - const DictionaryValue *args = static_cast<const DictionaryValue*>(args_); + const DictionaryValue *args = args_as_dictionary(); std::string url_input; if (args->HasKey(keys::kUrlKey)) { EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kUrlKey, @@ -302,7 +302,7 @@ bool CreateWindowFunction::RunImpl() { // Any part of the bounds can optionally be set by the caller. if (args_->IsType(Value::TYPE_DICTIONARY)) { - const DictionaryValue *args = static_cast<const DictionaryValue*>(args_); + const DictionaryValue *args = args_as_dictionary(); int bounds_val; if (args->HasKey(keys::kLeftKey)) { EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey, @@ -345,7 +345,7 @@ bool CreateWindowFunction::RunImpl() { bool UpdateWindowFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); - const ListValue* args = static_cast<const ListValue*>(args_); + const ListValue* args = args_as_list(); int window_id; EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &window_id)); DictionaryValue* update_props; @@ -457,7 +457,7 @@ bool GetAllTabsInWindowFunction::RunImpl() { bool CreateTabFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); + const DictionaryValue* args = args_as_dictionary(); Browser *browser; // windowId defaults to "current" window. @@ -548,7 +548,7 @@ bool GetTabFunction::RunImpl() { bool UpdateTabFunction::RunImpl() { int tab_id; EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); - const ListValue* args = static_cast<const ListValue*>(args_); + const ListValue* args = args_as_list(); EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &tab_id)); DictionaryValue* update_props; EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &update_props)); @@ -628,7 +628,7 @@ bool UpdateTabFunction::RunImpl() { bool MoveTabFunction::RunImpl() { int tab_id; EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); - const ListValue* args = static_cast<const ListValue*>(args_); + const ListValue* args = args_as_list(); EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &tab_id)); DictionaryValue* update_props; EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &update_props)); diff --git a/chrome/browser/extensions/extension_toolstrip_api.cc b/chrome/browser/extensions/extension_toolstrip_api.cc index 3c52b16..18d1839 100644 --- a/chrome/browser/extensions/extension_toolstrip_api.cc +++ b/chrome/browser/extensions/extension_toolstrip_api.cc @@ -67,7 +67,7 @@ bool ToolstripExpandFunction::RunImpl() { } EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); + const DictionaryValue* args = args_as_dictionary(); int height; EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey, @@ -106,7 +106,7 @@ bool ToolstripCollapseFunction::RunImpl() { GURL url; if (args_->GetType() != Value::TYPE_NULL) { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); - const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); + const DictionaryValue* args = args_as_dictionary(); if (args->HasKey(keys::kUrlKey)) { std::string url_string; |