diff options
author | mtytel@chromium.org <mtytel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-15 20:55:16 +0000 |
---|---|---|
committer | mtytel@chromium.org <mtytel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-15 20:55:16 +0000 |
commit | 6afb0e81d1eccd19864a6462d3a505471e141294 (patch) | |
tree | 7cded3f2bace378a345ed609eb1236237f6cca93 | |
parent | b44f8adbee594abffab0246815a0614675adf07b (diff) | |
download | chromium_src-6afb0e81d1eccd19864a6462d3a505471e141294.zip chromium_src-6afb0e81d1eccd19864a6462d3a505471e141294.tar.gz chromium_src-6afb0e81d1eccd19864a6462d3a505471e141294.tar.bz2 |
Updated web navigation extension api to use json schema compiler.
BUG=121174
TEST=
Review URL: https://chromiumcodereview.appspot.com/10541190
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142475 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 30 insertions, 37 deletions
diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc index 998130d..906294a 100644 --- a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc +++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc @@ -19,6 +19,7 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/view_type_utils.h" #include "chrome/common/chrome_notification_types.h" +#include "chrome/common/extensions/api/web_navigation.h" #include "chrome/common/url_constants.h" #include "content/public/browser/resource_request_details.h" #include "content/public/browser/navigation_details.h" @@ -28,6 +29,9 @@ #include "content/public/browser/web_contents.h" #include "net/base/net_errors.h" +namespace GetFrame = extensions::api::web_navigation::GetFrame; +namespace GetAllFrames = extensions::api::web_navigation::GetAllFrames; + using content::BrowserContext; using content::ResourceRedirectDetails; using content::WebContents; @@ -718,15 +722,10 @@ bool WebNavigationTabObserver::IsReferenceFragmentNavigation( } bool GetFrameFunction::RunImpl() { - DictionaryValue* details; - EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); - DCHECK(details); - - int tab_id; - int frame_id; - EXTENSION_FUNCTION_VALIDATE(details->GetInteger(keys::kTabIdKey, &tab_id)); - EXTENSION_FUNCTION_VALIDATE( - details->GetInteger(keys::kFrameIdKey, &frame_id)); + scoped_ptr<GetFrame::Params> params(GetFrame::Params::Create(*args_)); + EXTENSION_FUNCTION_VALIDATE(params.get()); + int tab_id = params->details.tab_id; + int frame_id = params->details.frame_id; result_.reset(Value::CreateNullValue()); @@ -758,22 +757,18 @@ bool GetFrameFunction::RunImpl() { if (!frame_navigation_state.IsValidUrl(frame_url)) return true; - DictionaryValue* resultDict = new DictionaryValue(); - resultDict->SetString(keys::kUrlKey, frame_url.spec()); - resultDict->SetBoolean( - keys::kErrorOccurredKey, - frame_navigation_state.GetErrorOccurredInFrame(frame_id)); - result_.reset(resultDict); + GetFrame::Result::Details frame_details; + frame_details.url = frame_url.spec(); + frame_details.error_occurred = + frame_navigation_state.GetErrorOccurredInFrame(frame_id); + result_.reset(GetFrame::Result::Create(frame_details)); return true; } bool GetAllFramesFunction::RunImpl() { - DictionaryValue* details; - EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); - DCHECK(details); - - int tab_id; - EXTENSION_FUNCTION_VALIDATE(details->GetInteger(keys::kTabIdKey, &tab_id)); + scoped_ptr<GetAllFrames::Params> params(GetAllFrames::Params::Create(*args_)); + EXTENSION_FUNCTION_VALIDATE(params.get()); + int tab_id = params->details.tab_id; result_.reset(Value::CreateNullValue()); @@ -796,23 +791,22 @@ bool GetAllFramesFunction::RunImpl() { const FrameNavigationState& navigation_state = observer->frame_navigation_state(); - ListValue* resultList = new ListValue(); - for (FrameNavigationState::const_iterator frame = navigation_state.begin(); - frame != navigation_state.end(); ++frame) { - GURL frame_url = navigation_state.GetUrl(*frame); + std::vector<linked_ptr<GetAllFrames::Result::DetailsElement> > result_list; + for (FrameNavigationState::const_iterator it = navigation_state.begin(); + it != navigation_state.end(); ++it) { + int64 frame_id = *it; + GURL frame_url = navigation_state.GetUrl(frame_id); if (!navigation_state.IsValidUrl(frame_url)) continue; - DictionaryValue* frameDict = new DictionaryValue(); - frameDict->SetString(keys::kUrlKey, frame_url.spec()); - frameDict->SetInteger( - keys::kFrameIdKey, - GetFrameId(navigation_state.IsMainFrame(*frame), *frame)); - frameDict->SetBoolean( - keys::kErrorOccurredKey, - navigation_state.GetErrorOccurredInFrame(*frame)); - resultList->Append(frameDict); + linked_ptr<GetAllFrames::Result::DetailsElement> frame( + new GetAllFrames::Result::DetailsElement()); + frame->url = frame_url.spec(); + frame->frame_id = GetFrameId(navigation_state.IsMainFrame(frame_id), + frame_id); + frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id); + result_list.push_back(frame); } - result_.reset(resultList); + result_.reset(GetAllFrames::Result::Create(result_list)); return true; } diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api_constants.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_api_constants.cc index ebc3523..1696526 100644 --- a/chrome/browser/extensions/api/web_navigation/web_navigation_api_constants.cc +++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api_constants.cc @@ -9,7 +9,6 @@ namespace extensions { namespace web_navigation_api_constants { const char kErrorKey[] = "error"; -const char kErrorOccurredKey[] = "errorOccurred"; const char kFrameIdKey[] = "frameId"; const char kSourceTabIdKey[] = "sourceTabId"; const char kSourceFrameIdKey[] = "sourceFrameId"; diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api_constants.h b/chrome/browser/extensions/api/web_navigation/web_navigation_api_constants.h index bfb4b3a..9695983 100644 --- a/chrome/browser/extensions/api/web_navigation/web_navigation_api_constants.h +++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api_constants.h @@ -14,7 +14,6 @@ namespace web_navigation_api_constants { // Keys. extern const char kErrorKey[]; -extern const char kErrorOccurredKey[]; extern const char kFrameIdKey[]; extern const char kSourceTabIdKey[]; extern const char kSourceFrameIdKey[]; diff --git a/chrome/common/extensions/api/api.gyp b/chrome/common/extensions/api/api.gyp index e2bc07b..86b98df 100644 --- a/chrome/common/extensions/api/api.gyp +++ b/chrome/common/extensions/api/api.gyp @@ -25,6 +25,7 @@ 'permissions.json', 'storage.json', 'tabs.json', + 'web_navigation.json', 'windows.json', ], 'idl_schema_files': [ |