| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 5 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/json_reader.h" | 7 #include "base/json_reader.h" |
| 8 #include "base/json_writer.h" | 8 #include "base/json_writer.h" |
| 9 #include "base/singleton.h" | 9 #include "base/singleton.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 ExtensionFunction* NewExtensionFunction() { | 38 ExtensionFunction* NewExtensionFunction() { |
| 39 return new T(); | 39 return new T(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 FactoryRegistry* FactoryRegistry::instance() { | 42 FactoryRegistry* FactoryRegistry::instance() { |
| 43 return Singleton<FactoryRegistry>::get(); | 43 return Singleton<FactoryRegistry>::get(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 FactoryRegistry::FactoryRegistry() { | 46 FactoryRegistry::FactoryRegistry() { |
| 47 // Register all functions here. | 47 // Register all functions here. |
| 48 factories_["GetWindows"] = &NewExtensionFunction<GetWindowsFunction>; |
| 48 factories_["GetTabsForWindow"] = | 49 factories_["GetTabsForWindow"] = |
| 49 &NewExtensionFunction<GetTabsForWindowFunction>; | 50 &NewExtensionFunction<GetTabsForWindowFunction>; |
| 50 factories_["GetTab"] = &NewExtensionFunction<GetTabFunction>; | 51 factories_["GetTab"] = &NewExtensionFunction<GetTabFunction>; |
| 51 factories_["CreateTab"] = &NewExtensionFunction<CreateTabFunction>; | 52 factories_["CreateTab"] = &NewExtensionFunction<CreateTabFunction>; |
| 52 factories_["UpdateTab"] = &NewExtensionFunction<UpdateTabFunction>; | 53 factories_["UpdateTab"] = &NewExtensionFunction<UpdateTabFunction>; |
| 54 factories_["MoveTab"] = &NewExtensionFunction<MoveTabFunction>; |
| 53 factories_["RemoveTab"] = &NewExtensionFunction<RemoveTabFunction>; | 55 factories_["RemoveTab"] = &NewExtensionFunction<RemoveTabFunction>; |
| 54 } | 56 } |
| 55 | 57 |
| 56 void FactoryRegistry::GetAllNames( | 58 void FactoryRegistry::GetAllNames( |
| 57 std::vector<std::string>* names) { | 59 std::vector<std::string>* names) { |
| 58 for (FactoryMap::iterator iter = factories_.begin(); iter != factories_.end(); | 60 for (FactoryMap::iterator iter = factories_.begin(); iter != factories_.end(); |
| 59 ++iter) { | 61 ++iter) { |
| 60 names->push_back(iter->first); | 62 names->push_back(iter->first); |
| 61 } | 63 } |
| 62 } | 64 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 111 |
| 110 void ExtensionFunctionDispatcher::SendResponse(ExtensionFunction* function) { | 112 void ExtensionFunctionDispatcher::SendResponse(ExtensionFunction* function) { |
| 111 std::string json; | 113 std::string json; |
| 112 | 114 |
| 113 // Some functions might not need to return any results. | 115 // Some functions might not need to return any results. |
| 114 if (function->result()) | 116 if (function->result()) |
| 115 JSONWriter::Write(function->result(), false, &json); | 117 JSONWriter::Write(function->result(), false, &json); |
| 116 | 118 |
| 117 render_view_host_->SendExtensionResponse(function->callback_id(), json); | 119 render_view_host_->SendExtensionResponse(function->callback_id(), json); |
| 118 } | 120 } |
| OLD | NEW |